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 a50202d..cc38239 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 @@ -47,63 +47,52 @@ public class RefreshJob extends WorkspaceJob { public IStatus runInWorkspace(IProgressMonitor monitor) { ProblemConsole console = new ProblemConsole(); IFile file = null; + try { - monitor.beginTask("Download Wiki Articles: ", 100); + int totalWork = files.length; + if (totalWork <= 0) { + totalWork = 100; + } + monitor.beginTask("Download Wiki Articles: ", totalWork); // ArrayList wikiTitles = new ArrayList(); // for (int i = 0; i < files.length; i++) { // wikiTitles.add( Util.getReadableWikiName(files[i]) ); // } StringBuffer buffer = new StringBuffer(); HashMap map = new HashMap(); + MediaWikiConnector mwConnector = new MediaWikiConnector(); String wikiTitle; + int titleCounter = 0; for (int i = 0; i < files.length; i++) { file = 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; - - if (list.size() == 0&&files.length>0) { - console.println("File: " + file.getLocation().toString() + " not available on the server."); - } else { - if (list.size() < files.length) { - console.println("Not all requested files are available on the server."); - } - 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 (monitor.isCanceled()) { + if (i % 5 == 0) { + // read only 5 files at a time + IStatus status = readWikisFromBuffer(mwConnector, buffer, map, monitor, console); + if (status.equals(Status.CANCEL_STATUS)) { return Status.CANCEL_STATUS; } + buffer = new StringBuffer(); + titleCounter = 0; } } + if (titleCounter > 0) { + IStatus status = readWikisFromBuffer(mwConnector, 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(); } else { // setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); // setProperty(IProgressConstants.ACTION_PROPERTY, getWikisCompletedAction()); @@ -123,17 +112,76 @@ 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(); } if (isModal(this)) { // The progress dialog is still open show the message - console.reportError(); } return Status.OK_STATUS; } /** + * @param buffer + * @param map + * @param monitor + * @param console + * @param file + * @return + * @throws UnexpectedAnswerException + * @throws MethodException + */ + private IStatus readWikisFromBuffer(MediaWikiConnector mwConnector, StringBuffer buffer, HashMap map, IProgressMonitor monitor, + ProblemConsole console) throws UnexpectedAnswerException, InterruptedException, MethodException { + String wikiTitle; + boolean showConsole = WikiEditorPlugin.getDefault().getPreferenceStore().getBoolean(WikiEditorPlugin.CONSOLE_OUTPUT); + + 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); + } + } + } + monitor.worked(1); + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + } + + return Status.OK_STATUS; + } + + /** * @param file * @param wikiTitle * @param i