import net.sourceforge.phpeclipse.wiki.actions.mediawiki.exceptions.UnexpectedAnswerException;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.xml.Page;
+import net.sourceforge.phpeclipse.wiki.xml.XStreamManager;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
this.files = files;
this.configuration = configuration;
this.actionURL = actionURL;
- }
+ }
public IStatus runInWorkspace(IProgressMonitor monitor) {
ProblemConsole console = new ProblemConsole();
buffer.append("\n");
}
}
- MediaWikiConnector mwc = new MediaWikiConnector();
+ MediaWikiConnector mwConnector = new MediaWikiConnector();
String url = actionURL;
if (url == null) {
url = configuration.getActionUrl() + "/" + configuration.getSpecialNs() + ":Export";
}
// get a list of Parsed elements
monitor.subTask("Downloading (XML Import)");
- ArrayList list = mwc.loadXML(configuration, url, buffer.toString());
+ ArrayList list = mwConnector.loadXML(configuration, url, buffer.toString());
String body;
for (int i = 0; i < list.size(); i++) {
if (body != null) {
file = (IFile) map.get(wikiTitle);
if (file != null) {
- monitor.subTask("Modify file: "+file.getLocation().toString());
- updateFileContent(console, file, parsed, body, configuration, monitor);
+ // rearrange parsed data into a page for XStream hamdling:
+ Page page = new Page(parsed.getDateTimestamp(), wikiTitle, body);
+ monitor.subTask("Modify file: " + file.getLocation().toString());
+ updateFileContent(console, file, page, body, configuration, monitor);
}
}
}
return isModal.booleanValue();
}
- private static void updateFileContent(ProblemConsole console, IFile file, Parsed parsed, String body, IWikipedia wp,
+ private static void updateFileContent(ProblemConsole console, IFile file, Page page, String body, IWikipedia wp,
IProgressMonitor monitor) {
try {
if (file.exists()) {
Util.createFolder((IFolder) parent, monitor);
}
try {
- String xmlData = parsed.getXmlData();
- String charSet = "UTF-8";
- StringBuffer buf = new StringBuffer();
- int index = xmlData.indexOf("<page>");
- if (index<0) {
- console.println("File: " + xmlFile.getLocation().toString() + "\n==>Couldn't create xml file - <page> tag not found");
- return;
- }
- xmlData = xmlData.substring(index);
-// buf.setLength(xmlData.length() + WikiEditorPlugin.XML_START_1.length() + WikiEditorPlugin.XML_START_2.length()
-// + WikiEditorPlugin.XML_END.length() + charSet.length());
-//
- buf.append(WikiEditorPlugin.XML_START_1);
- buf.append(charSet);
- buf.append(WikiEditorPlugin.XML_START_2);
- buf.append(xmlData);
- buf.append(WikiEditorPlugin.XML_END);
+ // String xmlData = parsed.getXmlData();
+ // String charSet = "UTF-8";
+ // StringBuffer buf = new StringBuffer();
+ // int index = xmlData.indexOf("<page>");
+ // if (index<0) {
+ // console.println("File: " + xmlFile.getLocation().toString() + "\n==>Couldn't create xml file - <page> tag not found");
+ // return;
+ // }
+ // xmlData = xmlData.substring(index);
+ // buf.append(WikiEditorPlugin.XML_START_1);
+ // buf.append(charSet);
+ // buf.append(WikiEditorPlugin.XML_START_2);
+ // buf.append(xmlData);
+ // buf.append(WikiEditorPlugin.XML_END);
- byte[] buffer = buf.toString().getBytes();
+ // byte[] buffer = buf.toString().getBytes();
+ byte[] buffer = XStreamManager.toXML(page).getBytes();
ByteArrayInputStream source = new ByteArrayInputStream(buffer);
if (!xmlFile.exists()) {
xmlFile.create(source, true, monitor);
}
} catch (UnsupportedEncodingException e) {
console.println("File: " + file.getLocation().toString() + "\n==>UnsupportedEncodingException: " + e.getMessage());
- } catch (CoreException e) {
- console.println("File: " + file.getLocation().toString() + "\n==>CoreException: " + e.getMessage());
+ } catch (Exception e) {
+ console.println("File: " + file.getLocation().toString() + "\n==>Exception: " + e.getMessage());
}
}
}
\ No newline at end of file