From: axelcl Date: Fri, 18 Feb 2005 20:51:38 +0000 (+0000) Subject: Improved PDF export (every article is a chapter, outline, FileDialog) X-Git-Url: http://secure.phpeclipse.com Improved PDF export (every article is a chapter, outline, FileDialog) --- diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java index 7726ecc..e32b44a 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/post/PostJob.java @@ -15,6 +15,7 @@ import net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions.UnexpectedAn import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.preferences.Util; +import net.sourceforge.phpeclipse.wiki.renderer.StringUtil; import net.sourceforge.phpeclipse.wiki.velocity.EditorText; import net.sourceforge.phpeclipse.wiki.xml.Page; import net.sourceforge.phpeclipse.wiki.xml.XStreamManager; @@ -133,7 +134,7 @@ public class PostJob extends WorkspaceJob { wikiURLTitle = Util.getURLWikiName(file); String body = StoreWikipediaAction.getInputStreamAsString(is, wikipedia.getCharSet()); char ch; - boolean noContent = checkNoContent(body); + boolean noContent = StringUtil.checkNoContent(body); String srcBasePath = Util.getWikiTextsPath(file); String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); @@ -235,43 +236,6 @@ public class PostJob extends WorkspaceJob { return Status.CANCEL_STATUS; } - /** - * @param body - * @param j - * @return - */ - private boolean checkNoContent(String body) { - char ch; - boolean noContent = true; - int j = 0; - try { - while (true) { - ch = body.charAt(j++); - if (!Character.isWhitespace(ch)) { - if (ch == '<' && body.charAt(j) == '!' && body.charAt(j + 1) == '-' && body.charAt(j + 2) == '-') { - // - j += 3; - while (true) { - ch = body.charAt(j++); - if (ch == '-' && body.charAt(j) == '-' && body.charAt(j + 1) == '>') { - j += 2; - break; - } - } - } else if (ch == '<' && body.charAt(j) == 'b' && body.charAt(j + 1) == 'r' && body.charAt(j + 2) == '>') { - //
- } else { - noContent = false; - break; - } - } - } - } catch (IndexOutOfBoundsException e) { - - } - return noContent; - } - public boolean isModal(Job job) { Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG); if (isModal == null) { diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java index 1e4a8db..a2305b7 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/builder/CreatePageAction.java @@ -14,6 +14,7 @@ import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import net.sourceforge.phpeclipse.wiki.preferences.Util; import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer; import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory; +import net.sourceforge.phpeclipse.wiki.renderer.StringUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -87,8 +88,9 @@ public class CreatePageAction implements IObjectActionDelegate { public void selectionChanged(IAction action, ISelection selection) { } - public static void createFragmentPage(IFile file, StringBuffer htmlBuffer) { + public static boolean createFragmentPage(IFile file, StringBuffer htmlBuffer) { BufferedInputStream stream = null; + boolean noContent = true; try { // String templateFileName = Util.getLocalTemplate(file); // String cssUrl = Util.getLocalCssUrl(file); @@ -99,6 +101,7 @@ public class CreatePageAction implements IObjectActionDelegate { String fileName = Util.getHTMLFileName(file, binBasePath, srcBasePath); String content = new String(getInputStreamAsCharArray(stream, -1, "utf-8")); + noContent = StringUtil.checkNoContent(content); String filePath = file.getLocation().toString(); // file.getProjectRelativePath().toString() if (filePath.startsWith(srcBasePath)) { filePath = filePath.substring(srcBasePath.length() + 1); @@ -125,7 +128,7 @@ public class CreatePageAction implements IObjectActionDelegate { } catch (IOException e) { } } - + return noContent; } public static void createPage(IFile file) { diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WPHtmlParser.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WPHtmlParser.java new file mode 100644 index 0000000..be8cf53 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WPHtmlParser.java @@ -0,0 +1,92 @@ +/* + * $Id: WPHtmlParser.java,v 1.1 2005-02-18 20:51:37 axelcl Exp $ + * $Name: not supported by cvs2svn $ + * + * Copyright 2001, 2002 by Bruno Lowagie. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the License. + * + * The Original Code is 'iText, a free JAVA-PDF library'. + * + * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by + * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. + * All Rights Reserved. + * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer + * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. + * + * Contributor(s): all the names of the contributors are added in the source code + * where applicable. + * + * Alternatively, the contents of this file may be used under the terms of the + * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the + * provisions of LGPL are applicable instead of those above. If you wish to + * allow use of your version of this file only under the terms of the LGPL + * License and not to allow others to use your version of this file under + * the MPL, indicate your decision by deleting the provisions above and + * replace them with the notice and other provisions required by the LGPL. + * If you do not delete the provisions above, a recipient may use your version + * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the MPL as stated above or under the terms of the GNU + * Library General Public License as published by the Free Software Foundation; + * either version 2 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more + * details. + * + * If you didn't download this code from the following link, you should check if + * you aren't using an obsolete version: + * http://www.lowagie.com/iText/ + */ + +package net.sourceforge.phpeclipse.wiki.export.pdf; + +import java.io.IOException; +import java.io.Reader; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import com.lowagie.text.DocListener; +import com.lowagie.text.ExceptionConverter; +import com.lowagie.text.html.SAXmyHtmlHandler; +import com.lowagie.text.xml.XmlParser; + +/** + * This class can be used to parse some HTML files. + */ + +public class WPHtmlParser extends XmlParser { + + /** + * Parses a given file. + * + * @param document + * the document the parser will write to + * @param is + * the Reader with the content + */ + + public void go(DocListener document, Reader is) { + try { + SAXmyHtmlHandler handler = new SAXmyHtmlHandler(document); + handler.setControlOpenClose(false); + parser.parse(new InputSource(is), handler); + } catch (SAXException se) { + throw new ExceptionConverter(se); + } catch (IOException ioe) { + throw new ExceptionConverter(ioe); + } + } + + +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizard.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizard.java index 891c0ea..013f69d 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizard.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizard.java @@ -58,9 +58,9 @@ public final class WikiPDFExportWizard extends Wizard implements INewWizard { } private void persistExportProperties() { - IProject project = page.getFolder().getProject(); + IProject project = page.getFile().getProject(); try { - project.setPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME, new File(page.getExportDirectoryPath()) + project.setPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME, new File(page.getDestinationValue()) .getAbsolutePath()); } catch (CoreException cex) { noteException(cex); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizardPage.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizardPage.java index 729effe..a71bcf6 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizardPage.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExportWizardPage.java @@ -13,25 +13,17 @@ import java.util.List; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.DialogSettings; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -41,18 +33,16 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.dialogs.ContainerSelectionDialog; import org.eclipse.ui.dialogs.WizardExportResourcesPage; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; public final class WikiPDFExportWizardPage extends WizardExportResourcesPage implements IPropertyChangeListener, SelectionListener { - private StringFieldEditor folderText; +// private StringFieldEditor folderText; private static final String[] PDF_EXTENSION = { "pdf" }; @@ -61,7 +51,7 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp private static final String STORE_OVERWRITE_EXISTING_FILES_ID = "WikiPDFExportWizardPage.STORE_OVERWRITE_EXISTING_FILES_ID"; //$NON-NLS-1$ - private StringFieldEditor exportFileText; +// private StringFieldEditor exportFileText; private Combo destinationNameField; @@ -70,6 +60,7 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp protected Button overwriteExistingFilesCheckbox; private ISelection selection; + private IDialogSettings fSettings = null; public WikiPDFExportWizardPage(IStructuredSelection selection) { super(WikiEditorPlugin.getResourceString("Export.wizardTitle"), selection); @@ -117,36 +108,38 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp new Label(parent, SWT.NONE); // vertical spacer } + /** - * Create the options specification widgets. - * - * @param parent org.eclipse.swt.widgets.Composite - */ - protected void createOptionsGroup(Composite parent) { - // options group - Group optionsGroup = new Group(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - optionsGroup.setLayout(layout); - optionsGroup.setLayoutData( - new GridData( - GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); - optionsGroup.setText(IDEWorkbenchMessages.getString("WizardExportPage.options")); //$NON-NLS-1$ - optionsGroup.setFont(parent.getFont()); - - createOptionsGroupButtons(optionsGroup); - - } + * Create the options specification widgets. + * + * @param parent + * org.eclipse.swt.widgets.Composite + */ + protected void createOptionsGroup(Composite parent) { + // options group + Group optionsGroup = new Group(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + optionsGroup.setLayout(layout); + optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); + optionsGroup.setText(IDEWorkbenchMessages.getString("WizardExportPage.options")); //$NON-NLS-1$ + optionsGroup.setFont(parent.getFont()); + + createOptionsGroupButtons(optionsGroup); + + } + /** - * Create the buttons in the options group. - */ + * Create the buttons in the options group. + */ - protected void createOptionsGroupButtons(Group optionsGroup) { + protected void createOptionsGroupButtons(Group optionsGroup) { - Font font = optionsGroup.getFont(); - createOverwriteExisting(optionsGroup, font); + Font font = optionsGroup.getFont(); + createOverwriteExisting(optionsGroup, font); + + // createDirectoryStructureOptions(optionsGroup, font); + } -// createDirectoryStructureOptions(optionsGroup, font); - } /** * Create the button for checking if we should ask if we are going to overwrite existing files. * @@ -179,15 +172,15 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp * Open an appropriate destination browser so that the user can specify a source to import from */ protected void handleDestinationBrowseButtonPressed() { - DirectoryDialog dialog = new DirectoryDialog(getContainer().getShell(), SWT.SAVE); - dialog.setMessage("Select destination"); - dialog.setText("Select title"); + FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE); + dialog.setFilterExtensions(PDF_EXTENSION); + dialog.setText("Select pdf file"); dialog.setFilterPath(getDestinationValue()); - String selectedDirectoryName = dialog.open(); + String selectedFileName = dialog.open(); - if (selectedDirectoryName != null) { + if (selectedFileName != null) { setErrorMessage(null); - setDestinationValue(selectedDirectoryName); + setDestinationValue(selectedFileName); } } @@ -215,12 +208,12 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp // update directory names history IDialogSettings settings = getDialogSettings(); if (settings != null) { - String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID); - if (directoryNames == null) - directoryNames = new String[0]; + String[] fileNames = settings.getArray(STORE_DESTINATION_NAMES_ID); + if (fileNames == null) + fileNames = new String[0]; - directoryNames = addToHistory(directoryNames, getDestinationValue()); - settings.put(STORE_DESTINATION_NAMES_ID, directoryNames); + fileNames = addToHistory(fileNames, getDestinationValue()); + settings.put(STORE_DESTINATION_NAMES_ID, fileNames); // options settings.put(STORE_OVERWRITE_EXISTING_FILES_ID, overwriteExistingFilesCheckbox.getSelection()); @@ -238,14 +231,14 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp protected void restoreWidgetValues() { IDialogSettings settings = getDialogSettings(); if (settings != null) { - String[] directoryNames = settings.getArray(STORE_DESTINATION_NAMES_ID); - if (directoryNames == null) + String[] fileNames = settings.getArray(STORE_DESTINATION_NAMES_ID); + if (fileNames == null) return; // ie.- no settings stored // destination - setDestinationValue(directoryNames[0]); - for (int i = 0; i < directoryNames.length; i++) - addDestinationItem(directoryNames[i]); + setDestinationValue(fileNames[0]); + for (int i = 0; i < fileNames.length; i++) + addDestinationItem(fileNames[i]); // options overwriteExistingFilesCheckbox.setSelection(settings.getBoolean(STORE_OVERWRITE_EXISTING_FILES_ID)); @@ -256,14 +249,17 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp // createSelectionOnlyButton.setSelection(!createDirectories); } } + /** - * Add the passed value to self's destination widget's history - * - * @param value java.lang.String - */ - protected void addDestinationItem(String value) { - destinationNameField.add(value); - } + * Add the passed value to self's destination widget's history + * + * @param value + * java.lang.String + */ + protected void addDestinationItem(String value) { + destinationNameField.add(value); + } + /** * (non-Javadoc) Method declared on IDialogPage. */ @@ -349,66 +345,74 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp // return editor; // } - private void initialize() throws CoreException { - if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) { - return; - } - - IStructuredSelection ssel = (IStructuredSelection) selection; - if (ssel.size() == 1) { - initialiseFromSelectedObject(ssel.getFirstElement()); - } - } - - private void initialiseFromSelectedObject(Object obj) throws CoreException { - if (obj instanceof IFolder || obj instanceof IProject) { - initialiseFolder(((IResource) obj)); - } - } - - private void initialiseFolder(IResource resource) throws CoreException { - folderText.setStringValue(resource.getFullPath().toString()); - initialiseExportDirectoryText(resource); - } - - private void initialiseExportDirectoryText(IResource resource) throws CoreException { - String exportDir = resource.getProject().getPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME); - if (exportDir != null) { - exportFileText.setStringValue(exportDir); - } else { - exportFileText.setStringValue(""); - } - } - - private void handleBrowseHtmlExportLocation() { - FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.OPEN); - dialog.setFilterExtensions(PDF_EXTENSION); - String path = dialog.open(); - if (path != null) { - exportFileText.setStringValue(path); - } - } - - private void handleBrowseFolders() throws CoreException { - ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, - WikiEditorPlugin.getResourceString("Export.wizardSelectFolder")); - if (dialog.open() == Window.OK) { - Object[] result = dialog.getResult(); - if (result != null && result.length == 1) { - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[0]); - if (resource instanceof IFile) { - return; - } - initialiseFolder(resource); - } - } - } - +// private void initialize() throws CoreException { +// if (selection == null || selection.isEmpty() || !(selection instanceof IStructuredSelection)) { +// return; +// } +// +// IStructuredSelection ssel = (IStructuredSelection) selection; +// if (ssel.size() == 1) { +// initialiseFromSelectedObject(ssel.getFirstElement()); +// } +// } + +// private void initialiseFromSelectedObject(Object obj) throws CoreException { +// if (obj instanceof IFolder || obj instanceof IProject) { +// initialiseFolder(((IResource) obj)); +// } +// } + +// private void initialiseFolder(IResource resource) throws CoreException { +// folderText.setStringValue(resource.getFullPath().toString()); +// initialiseExportDirectoryText(resource); +// } + +// private void initialiseExportDirectoryText(IResource resource) throws CoreException { +// String exportDir = resource.getProject().getPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME); +// if (exportDir != null) { +// exportFileText.setStringValue(exportDir); +// } else { +// exportFileText.setStringValue(""); +// } +// } + +// private void handleBrowseHtmlExportLocation() { +// FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE | SWT.OPEN); +// dialog.setFilterExtensions(PDF_EXTENSION); +// String path = dialog.open(); +// if (path != null) { +// setDestinationValue(path); +//// exportFileText.setStringValue(path); +// } +// } +// +// private void handleBrowseFolders() throws CoreException { +// FileDialog dialog = new FileDialog(getShell()); +// //, ResourcesPlugin.getWorkspace().getRoot(), false, +// // WikiEditorPlugin.getResourceString("Export.wizardSelectFolder")); +// String filePath = dialog.open(); +// // if (dialog.open() == Window.OK) { +// // Object[] result = dialog.getResult(); +// if (filePath != null) { +// // if (result != null && result.length == 1) { +// // IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember((IPath) result[0]); +// IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filePath); +// if (!(resource instanceof IFile)) { +// return; +// } +//// initialiseFolder(resource); +// // } +// } +// } + + private void dialogChanged() { - if (getFolderText().length() == 0) { - updateStatus("Folder must be specified"); - } else if (getExportDirectoryPath().length() == 0) { - updateStatus("Directory must be specified"); +// if (getFolderText().length() == 0) { +// updateStatus("File must be specified"); +// } else + + if (getDestinationValue().length() == 0) { + updateStatus("PDF export file must be specified"); } else { updateStatus(null); } @@ -419,9 +423,9 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp setPageComplete(message == null); } - public String getExportDirectoryPath() { - return exportFileText.getStringValue(); - } +// public String getExportDirectoryPath() { +// return exportFileText.getStringValue(); +// } public void propertyChange(PropertyChangeEvent event) { dialogChanged(); @@ -435,12 +439,12 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp dialogChanged(); } - String getFolderText() { - return folderText.getStringValue(); - } +// String getFolderText() { +// return folderText.getStringValue(); +// } - public IContainer getFolder() { - return (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getFolderText())); + public IContainer getFile() { + return (IContainer) ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getDestinationValue())); } protected boolean executeExportOperation(WikiPDFExporter op) { @@ -493,4 +497,20 @@ public final class WikiPDFExportWizardPage extends WizardExportResourcesPage imp return false; } + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#getDialogSettings() + */ +// protected IDialogSettings getDialogSettings() { +// IDialogSettings dialogBounds= fSettings.getSection(DIALOG_BOUNDS_KEY); +// if (dialogBounds == null) { +// dialogBounds= new DialogSettings(DIALOG_BOUNDS_KEY); +// fSettings.addSection(dialogBounds); +// } +// dialogBounds.put(X, bounds.x); +// dialogBounds.put(Y, bounds.y); +// dialogBounds.put(WIDTH, bounds.width); +// dialogBounds.put(HEIGHT, bounds.height); +// // TODO Auto-generated method stub +// return super.getDialogSettings(); +// } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExporter.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExporter.java index 8ab96ef..0b387dd 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExporter.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/export/pdf/WikiPDFExporter.java @@ -1,6 +1,6 @@ package net.sourceforge.phpeclipse.wiki.export.pdf; -import java.io.FileNotFoundException; +import java.awt.Color; import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; @@ -25,9 +25,12 @@ import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.IOverwriteQuery; +import com.lowagie.text.Chapter; import com.lowagie.text.Document; -import com.lowagie.text.DocumentException; -import com.lowagie.text.html.HtmlParser; +import com.lowagie.text.Font; +import com.lowagie.text.FontFactory; +import com.lowagie.text.PageSize; +import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; //import de.java2html.converter.JavaSource2HTMLConverter; @@ -182,7 +185,7 @@ public final class WikiPDFExporter implements IRunnableWithProgress { * * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) */ -public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { WikiFilesVisitor visitor = new WikiFilesVisitor(); for (int i = 0; i < fResourcesToExport.size(); i++) { @@ -196,65 +199,174 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte List list = visitor.getList(); Collections.sort(list, new IFileComparator()); IFile file; - StringBuffer htmlBuffer = new StringBuffer(); - htmlBuffer.append(""); - for (int i = 0; i < list.size(); i++) { - try { - file = (IFile) list.get(i); - monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFile") + file.getLocation()); - System.out.println(file.getLocation().toString()); - // TODO add the real title here: - htmlBuffer.append("

"+file.getName()+"


"); - CreatePageAction.createFragmentPage(file, htmlBuffer); - if (i < list.size()-1) { -// TODO create a boolean flag to determine, if we would like a new page or only horizontal ruler - htmlBuffer.append("
"); - } - System.out.println(htmlBuffer.toString()); - // CreatePageAction.createPage(templateFileName, (IFile) resources[i], exportDirectoryName, srcBasePath); - monitor.worked(1); - } catch (Exception e) { - addError("PDF export exception", e); - } - } - htmlBuffer.append(""); - - StringReader stream = null; - String pdffilename = fPath.toString(); + FileOutputStream os = null; + String pdffilename = fPath.toString(); + + Document document = new Document(PageSize.A4); + PdfWriter pdfWriter = null; try { - - HtmlParser parser = new HtmlParser(); - Document document = new Document(); - document.open(); os = new FileOutputStream(pdffilename); - monitor.subTask("Generating PDF file: "+pdffilename); - stream = new StringReader(htmlBuffer.toString()); - PdfWriter pdfWriter = PdfWriter.getInstance(document, os); -// pdfWriter.s - parser.go(document, stream); - } catch (FileNotFoundException e) { - e.printStackTrace(); + pdfWriter = PdfWriter.getInstance(document, os); + pdfWriter.setViewerPreferences(PdfWriter.PageModeUseOutlines); + + document.open(); + document.resetPageCount(); + int chapterNumber = 1; + for (int i = 0; i < list.size(); i++) { + try { + file = (IFile) list.get(i); + if (file.exists()) { + monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFile") + file.getLocation()); + System.out.println(file.getLocation().toString()); + StringBuffer htmlBuffer = new StringBuffer(); + htmlBuffer.append(""); + + boolean noContent = CreatePageAction.createFragmentPage(file, htmlBuffer); + htmlBuffer.append(""); + System.out.println(htmlBuffer.toString()); + + if (!noContent) { + // TODO add the real title from corresponding *.xml file here: + Paragraph title = new Paragraph(file.getName(), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, + new Color(0, 0, 255))); + Chapter chapter = new Chapter(title, chapterNumber++); + document.add(chapter); + appendArticle(document, htmlBuffer); + } + monitor.worked(1); + } + } catch (Exception e) { + addError("PDF export exception", e); + } + } } catch (Exception e) { - e.printStackTrace(); + addError("PDF export exception", e); } finally { - if (stream!=null) { - stream.close(); + document.close(); + if (pdfWriter != null) { + pdfWriter.close(); } - if (os!=null) { + if (os != null) { try { os.close(); } catch (IOException e1) { } } + } System.out.println(fPath.toString()); } + + /** + * @param document + * @param htmlBuffer + * @param monitor + */ + private void appendArticle(Document document, StringBuffer htmlBuffer) { + StringReader stream = null; + try { + WPHtmlParser parser = new WPHtmlParser(); + stream = new StringReader(htmlBuffer.toString()); + parser.go(document, stream); + } catch (Exception e) { + addError("PDF export exception", e); + } finally { + if (stream != null) { + stream.close(); + } + } + } + + // public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + // + // WikiFilesVisitor visitor = new WikiFilesVisitor(); + // for (int i = 0; i < fResourcesToExport.size(); i++) { + // try { + // ((IResource) fResourcesToExport.get(i)).accept(visitor); + // } catch (CoreException e) { + // e.printStackTrace(); + // } + // } + // + // List list = visitor.getList(); + // Collections.sort(list, new IFileComparator()); + // IFile file; + // + // FileOutputStream os = null; + // String pdffilename = fPath.toString(); + // try { + // os = new FileOutputStream(pdffilename); + // Document document = new Document(PageSize.A4); + // PdfWriter pdfWriter = PdfWriter.getInstance(document, os); + // document.open(); + // document.resetPageCount(); + // for (int i = 0; i < list.size(); i++) { + // try { + // file = (IFile) list.get(i); + // monitor.subTask(WikiEditorPlugin.getResourceString("Export.exportFile") + file.getLocation()); + //// System.out.println(file.getLocation().toString()); + // StringBuffer htmlBuffer = new StringBuffer(); + // // TODO add the real title here: + // htmlBuffer.append("

" + file.getName() + "


"); + // boolean noContent = CreatePageAction.createFragmentPage(file, htmlBuffer); + // if (i < list.size() - 1) { + // // TODO create a boolean flag to determine, if we would like a new page or only horizontal ruler + // htmlBuffer.append("
"); + // } + //// System.out.println(htmlBuffer.toString()); + // + // if (!noContent) { + // appendArticle(document, htmlBuffer); + // } + // // CreatePageAction.createPage(templateFileName, (IFile) resources[i], exportDirectoryName, srcBasePath); + // monitor.worked(1); + // } catch (Exception e) { + // addError("PDF export exception", e); + // } + // } + // document.close(); + // } catch (Exception e) { + // addError("PDF export exception", e); + // } finally { + // if (os != null) { + // try { + // os.close(); + // } catch (IOException e1) { + // } + // } + // } + // + // System.out.println(fPath.toString()); + // } + // + // /** + // * @param document + // * @param htmlBuffer + // * @param monitor + // */ + // private void appendArticle(Document document, StringBuffer htmlBuffer) { + // StringReader stream = null; + // try { + //// WPHtmlParser parser = new WPHtmlParser(); + // stream = new StringReader(htmlBuffer.toString()); + //// parser.go(document, stream); + // new HTMLWorker(document).parse(stream); + // } catch (Exception e) { + // addError("PDF export exception", e); + // } finally { + // if (stream != null) { + // stream.close(); + // } + // } + // } + /** * Add a new entry to the error table with the passed information */ protected void addError(String message, Throwable e) { + e.printStackTrace(); errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, message, e)); } @@ -282,21 +394,21 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte return new MultiStatus(PlatformUI.PLUGIN_ID, IStatus.OK, errors, "PDF export problems occured", //$NON-NLS-1$ null); } - + // test -// public static void main(String[] args) { -// try { -// HtmlParser parser = new HtmlParser(); -// Document document = new Document(); -// String htmlfilename = "C:/eclipse/wikibooks/wpbin/Synästhesie.html"; -// String pdffilename = "C:/eclipse/wikibooks/wpbin/code_java1.pdf"; -// -// PdfWriter.getInstance(document, new FileOutputStream(pdffilename)); -// parser.go(document, htmlfilename); -// } catch (FileNotFoundException e) { -// e.printStackTrace(); -// } catch (DocumentException e) { -// e.printStackTrace(); -// } -// } + // public static void main(String[] args) { + // try { + // WPHtmlParser parser = new WPHtmlParser(); + // Document document = new Document(); + // String htmlfilename = "C:/eclipse/wikibooks/wpbin/Synästhesie.html"; + // String pdffilename = "C:/eclipse/wikibooks/wpbin/code_java1.pdf"; + // + // PdfWriter.getInstance(document, new FileOutputStream(pdffilename)); + // parser.go(document, htmlfilename); + // } catch (FileNotFoundException e) { + // e.printStackTrace(); + // } catch (DocumentException e) { + // e.printStackTrace(); + // } + // } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/renderer/StringUtil.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/renderer/StringUtil.java new file mode 100644 index 0000000..bcb3046 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/renderer/StringUtil.java @@ -0,0 +1,42 @@ +package net.sourceforge.phpeclipse.wiki.renderer; + +public class StringUtil { + + /** + * @param body + * @param j + * @return + */ + public static boolean checkNoContent(String body) { + char ch; + boolean noContent = true; + int j = 0; + try { + while (true) { + ch = body.charAt(j++); + if (!Character.isWhitespace(ch)) { + if (ch == '<' && body.charAt(j) == '!' && body.charAt(j + 1) == '-' && body.charAt(j + 2) == '-') { + // + j += 3; + while (true) { + ch = body.charAt(j++); + if (ch == '-' && body.charAt(j) == '-' && body.charAt(j + 1) == '>') { + j += 2; + break; + } + } + } else if (ch == '<' && body.charAt(j) == 'b' && body.charAt(j + 1) == 'r' && body.charAt(j + 2) == '>') { + //
+ } else { + noContent = false; + break; + } + } + } + } catch (IndexOutOfBoundsException e) { + + } + return noContent; + } + +}