X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/xml/Page.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/xml/Page.java index adafff1..2421ed0 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/xml/Page.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/xml/Page.java @@ -1,7 +1,19 @@ package net.sourceforge.phpeclipse.wiki.xml; +import java.io.ByteArrayInputStream; import java.util.ArrayList; +import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; +import net.sourceforge.phpeclipse.wiki.preferences.Util; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + // public class Page { @@ -92,4 +104,28 @@ public class Page { public Revision get(int index) { return (Revision) listOfRevisions.get(index); } + + public void createXMLFile(IFile file, boolean modify) throws CoreException { + String srcBasePath = Util.getWikiTextsPath(file); + String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); + + String filename = Util.getXMLFileName(file, binBasePath, srcBasePath); + IPath path = new Path(filename); + IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + IContainer parent = xmlFile.getParent(); + if (parent instanceof IFolder && (!((IFolder) parent).exists())) { + Util.createFolder((IFolder) parent, null); + } +// Page page = new Page("", wikiTitle, ""); + byte[] buffer = XStreamManager.toXML(this).getBytes(); + ByteArrayInputStream source = new ByteArrayInputStream(buffer); + if (!xmlFile.exists()) { + // only if file doesn't exists + xmlFile.create(source, true, null); + } else { + if (modify) { + xmlFile.setContents(source, true, true, null); + } + } + } } \ No newline at end of file