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;
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);
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) == '>') {
- // <br>
- } 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) {
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;
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);
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);
} catch (IOException e) {
}
}
-
+ return noContent;
}
public static void createPage(IFile file) {
--- /dev/null
+/*
+ * $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
}
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);
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;
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" };
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;
protected Button overwriteExistingFilesCheckbox;
private ISelection selection;
+ private IDialogSettings fSettings = null;
public WikiPDFExportWizardPage(IStructuredSelection selection) {
super(WikiEditorPlugin.getResourceString("Export.wizardTitle"), selection);
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.
*
* 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);
}
}
// 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());
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));
// 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.
*/
// 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);
}
setPageComplete(message == null);
}
- public String getExportDirectoryPath() {
- return exportFileText.getStringValue();
- }
+// public String getExportDirectoryPath() {
+// return exportFileText.getStringValue();
+// }
public void propertyChange(PropertyChangeEvent event) {
dialogChanged();
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) {
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
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;
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;
*
* @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++) {
List list = visitor.getList();
Collections.sort(list, new IFileComparator());
IFile file;
- StringBuffer htmlBuffer = new StringBuffer();
- htmlBuffer.append("<html><head></head><body>");
- 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("<h2>"+file.getName()+"</h2><br/>");
- 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("<hr/>");
- }
- 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("</body></html>");
-
- 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("<html><head></head><body>");
+
+ boolean noContent = CreatePageAction.createFragmentPage(file, htmlBuffer);
+ htmlBuffer.append("</body></html>");
+ 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("<h2>" + file.getName() + "</h2><br/>");
+ // 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("<hr/>");
+ // }
+ //// 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));
}
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
--- /dev/null
+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) == '>') {
+ // <br>
+ } else {
+ noContent = false;
+ break;
+ }
+ }
+ }
+ } catch (IndexOutOfBoundsException e) {
+
+ }
+ return noContent;
+ }
+
+}