1 package net.sourceforge.phpeclipse.wiki.xml;
3 import java.io.ByteArrayInputStream;
4 import java.util.ArrayList;
6 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
7 import net.sourceforge.phpeclipse.wiki.preferences.Util;
9 import org.eclipse.core.resources.IContainer;
10 import org.eclipse.core.resources.IFile;
11 import org.eclipse.core.resources.IFolder;
12 import org.eclipse.core.resources.ResourcesPlugin;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.Path;
21 * <page> XML data from Wikipedia Special:Export pages may be <code>null</code>
25 /* package private */String title = null;
27 /* package private */ArrayList listOfRevisions = null;
29 // Revision revision = null;
31 /* package private */Page() {
34 public Page(String timeStamp, String title, String body) {
35 listOfRevisions = new ArrayList();
36 Revision revision = new Revision(timeStamp, body);
37 listOfRevisions.add(revision);
41 public void add(Revision revision) {
42 listOfRevisions.add(revision);
48 * @see java.lang.Object#toString()
50 public String toString() {
51 StringBuffer buffer = new StringBuffer();
54 buffer.append("==>Title: ");
59 // if (revision != null) {
60 // buffer.append("==>Revision:\n");
61 // buffer.append(revision);
62 // buffer.append("\n");
64 for (int i = 0; i < listOfRevisions.size(); i++) {
65 Revision revision = (Revision) listOfRevisions.get(i);
66 if (revision != null) {
67 buffer.append("==>Revision:\n");
68 buffer.append(revision);
72 return buffer.toString();
76 * @return Returns the title.
78 public String getTitle() {
82 public String getURLTitle() {
83 return title.replaceAll(" ", "_");
89 public boolean isEmpty() {
90 return listOfRevisions.isEmpty();
97 return listOfRevisions.size();
104 public Revision get(int index) {
105 return (Revision) listOfRevisions.get(index);
108 public void createXMLFile(IFile file, boolean modify) throws CoreException {
109 String srcBasePath = Util.getWikiTextsPath(file);
110 String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH);
112 String filename = Util.getXMLFileName(file, binBasePath, srcBasePath);
113 IPath path = new Path(filename);
114 IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
115 IContainer parent = xmlFile.getParent();
116 if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
117 Util.createFolder((IFolder) parent, null);
119 // Page page = new Page("", wikiTitle, "");
120 byte[] buffer = XStreamManager.toXML(this).getBytes();
121 ByteArrayInputStream source = new ByteArrayInputStream(buffer);
122 if (!xmlFile.exists()) {
123 // only if file doesn't exists
124 xmlFile.create(source, true, null);
127 xmlFile.setContents(source, true, true, null);