X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshJob.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshJob.java index e3e72e8..9758384 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshJob.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshJob.java @@ -42,11 +42,12 @@ public class RefreshJob extends WorkspaceJob { this.files = files; this.configuration = configuration; this.actionURL = actionURL; - } + } public IStatus runInWorkspace(IProgressMonitor monitor) { ProblemConsole console = new ProblemConsole(); IFile file = null; + try { monitor.beginTask("Download Wiki Articles: ", 100); // ArrayList wikiTitles = new ArrayList(); @@ -56,64 +57,35 @@ public class RefreshJob extends WorkspaceJob { StringBuffer buffer = new StringBuffer(); HashMap map = new HashMap(); String wikiTitle; + int titleCounter = 0; for (int i = 0; i < files.length; i++) { - wikiTitle = null; file = files[i]; - String srcBasePath = Util.getWikiTextsPath(file); - String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); - - String fileXMLName = Util.getXMLFileName(file, binBasePath, srcBasePath); - IPath path = new Path(fileXMLName); - IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); - if (xmlFile.exists()) { - try { - Page page = XStreamManager.fromXML(xmlFile.getContents()); - if (page != null) { - wikiTitle = page.getTitle(); - } - // timestamp = XMLReader.getDateTimestamp(xmlFile.getContents()); - } catch (Exception e2) { - } - } - if (wikiTitle==null) { - // if no XML file exists we create the name from the filename - wikiTitle = Util.getReadableWikiName(files[i]); - } + wikiTitle = createWikiTitle(file, i); buffer.append(wikiTitle); + titleCounter++; map.put(wikiTitle, file); if (i != files.length - 1) { buffer.append("\n"); } - } - 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 = mwConnector.loadXML(configuration, url, buffer.toString()); - String body; - - for (int i = 0; i < list.size(); i++) { - Parsed parsed = (Parsed) list.get(i); - wikiTitle = parsed.getTitle(); - if (wikiTitle != null) { - body = parsed.getBody(); - if (body != null) { - file = (IFile) map.get(wikiTitle); - if (file != null) { - // 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); - } + if (i % 10 == 0) { + // read only 10 files at a time + IStatus status = readWikisFromBuffer(buffer, map, monitor, console); + if (status.equals(Status.CANCEL_STATUS)) { + return Status.CANCEL_STATUS; } + buffer = new StringBuffer(); + titleCounter = 0; } - if (monitor.isCanceled()) { + } + if (titleCounter > 0) { + IStatus status = readWikisFromBuffer(buffer, map, monitor, console); + if (status.equals(Status.CANCEL_STATUS)) { return Status.CANCEL_STATUS; } + buffer = new StringBuffer(); + titleCounter = 0; } + if (isModal(this)) { // The progress dialog is still open show the message console.reportError(); @@ -136,6 +108,12 @@ public class RefreshJob extends WorkspaceJob { } else { console.println("HTTP-MethodException: " + e.getMessage()); } + } catch (InterruptedException e) { + if (file != null) { + console.println("File: " + file.getLocation().toString() + "\n==>InterruptedException: " + e.getMessage()); + } else { + console.println("InterruptedException: " + e.getMessage()); + } } finally { monitor.done(); } @@ -146,6 +124,90 @@ public class RefreshJob extends WorkspaceJob { return Status.OK_STATUS; } + /** + * @param buffer + * @param map + * @param monitor + * @param console + * @param file + * @return + * @throws UnexpectedAnswerException + * @throws MethodException + */ + private IStatus readWikisFromBuffer(StringBuffer buffer, HashMap map, IProgressMonitor monitor, ProblemConsole console) + throws UnexpectedAnswerException, InterruptedException, MethodException { + String wikiTitle; + boolean showConsole = WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiEditorPlugin.CONSOLE_OUTPUT); + 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)"); + if (showConsole) { + console.println("Downloading (XML Import):\n" + buffer.toString()); + } + ArrayList list = mwConnector.loadXML(configuration, url, buffer.toString()); + String body; + IFile file = null; + for (int i = 0; i < list.size(); i++) { + Parsed parsed = (Parsed) list.get(i); + wikiTitle = parsed.getTitle(); + if (wikiTitle != null) { + body = parsed.getBody(); + if (body != null) { + file = (IFile) map.get(wikiTitle); + if (file != null) { + // rearrange parsed data into a page for XStream hamdling: + Page page = new Page(parsed.getDateTimestamp(), wikiTitle, body); + monitor.subTask("Modify file: " + file.getLocation().toString()); + if (showConsole) { + console.println("Update file: " + file.getLocation().toString()); + } + updateFileContent(console, file, page, body, configuration, monitor); + } + } + } + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + } + + return Status.OK_STATUS; + } + + /** + * @param file + * @param wikiTitle + * @param i + * @return + */ + private String createWikiTitle(IFile file, int i) { + String wikiTitle = null; + String srcBasePath = Util.getWikiTextsPath(file); + String binBasePath = Util.getProjectsWikiOutputPath(file.getProject(), WikiEditorPlugin.HTML_OUTPUT_PATH); + + String fileXMLName = Util.getXMLFileName(file, binBasePath, srcBasePath); + IPath path = new Path(fileXMLName); + IFile xmlFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + if (xmlFile.exists()) { + try { + Page page = XStreamManager.fromXML(xmlFile.getContents()); + if (page != null) { + wikiTitle = page.getTitle(); + } + // timestamp = XMLReader.getDateTimestamp(xmlFile.getContents()); + } catch (Exception e2) { + } + } + if (wikiTitle == null) { + // if no XML file exists we create the name from the filename + wikiTitle = Util.getReadableWikiName(files[i]); + } + return wikiTitle; + } + public boolean isModal(Job job) { Boolean isModal = (Boolean) job.getProperty(IProgressConstants.PROPERTY_IN_DIALOG); if (isModal == null) {