path="rest">
</menu>
<action
- label="Refresh Current Wiki Text (Wikibooks.org)"
- class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction"
+ label="Refresh Wikibooks-en"
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"
menubarPath="mediawikiMenu/additions"
- id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction">
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction">
</action>
- <action
+ <action
+ label="Refresh Wikipedia-en"
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction"
+ menubarPath="mediawikiMenu/additions"
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction">
+ </action>
+<!-- <action
label="Download Link's Wiki Text (Wikibooks.org)"
class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction"
menubarPath="mediawikiMenu/additions"
id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction">
+ </action> -->
+ <action
+ label="Refresh Wikipedia..."
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction"
+ menubarPath="mediawikiMenu/additions"
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction">
</action>
</viewerContribution>
<viewerContribution
label="%MediaWiki.label"
path="rest">
</menu>
- <action
- label="Refresh Current Wiki Text (Wikibooks.org)"
- class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction"
+ <action
+ label="Refresh Wikibooks-en"
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"
menubarPath="mediawikiMenu/additions"
- id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.RefreshWikiTextEditorAction">
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction">
</action>
<action
+ label="Refresh Wikipedia-en"
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction"
+ menubarPath="mediawikiMenu/additions"
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaENAction">
+ </action>
+ <!-- <action
label="Download Link's Wiki Text (Wikibooks.org)"
class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction"
menubarPath="mediawikiMenu/additions"
id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikiLinkEditorAction">
+ </action> -->
+ <action
+ label="Refresh Wikipedia..."
+ class="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction"
+ menubarPath="mediawikiMenu/additions"
+ id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikipediaAction">
</action>
</viewerContribution>
<viewerContribution
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
</action>
<action
- label="Run HTTP Query"
+ label="HTTP Query..."
class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
menubarPath="httpqueryMenu/additions"
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
</action>
<action
- label="Run HTTP Query"
+ label="HTTP Query..."
class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
menubarPath="httpqueryMenu/additions"
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction">
</action>
<action
- label="Run HTTP Query"
+ label="HTTP Query..."
class="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction"
menubarPath="httpqueryMenu/additions"
id="net.sourceforge.phpeclipse.wiki.actions.httpquery.HTTPQueryAction">
package net.sourceforge.phpeclipse.wiki.actions.mediawiki;
import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
+import net.sourceforge.phpeclipse.wiki.internal.Configuration;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
+import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy;
+import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
import net.sourceforge.phpeclipse.wiki.preferences.Util;
+import net.sourceforge.phpeclipse.wiki.velocity.EditorText;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.texteditor.AbstractTextEditor;
-public final class RefreshWikiTextEditorAction implements IEditorActionDelegate {
-
- private IWorkbenchWindow window;
+public class DownloadWikipediaAction implements IEditorActionDelegate {
private AbstractTextEditor fEditor;
- public void dispose() {
- }
+ private EditorText text;
- public void init(IWorkbenchWindow window) {
- this.window = window;
- }
+ private IWorkbenchWindow window;
- public void selectionChanged(IAction action, ISelection selection) {
- if (selection.isEmpty()) {
- return;
- }
- if (selection instanceof TextSelection) {
- action.setEnabled(true);
- return;
- }
- if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
- action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
+ private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
+ try {
+ // Create the folder resource in the workspace
+ // Recursive to create any folders which do not exist already
+ if (!folderHandle.exists()) {
+ IContainer parent = folderHandle.getParent();
+ if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+ createFolder((IFolder) parent, monitor);
+ }
+ folderHandle.create(false, true, monitor);
+ }
+ } catch (CoreException e) {
+ // If the folder already existed locally, just refresh to get contents
+ if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
+ folderHandle.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
+ else
+ throw e;
}
}
- public void run(IAction action) {
- if (fEditor == null) {
- IEditorPart targetEditor = window.getActivePage().getActiveEditor();
- if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
- fEditor = (AbstractTextEditor) targetEditor;
- }
- }
- if (fEditor != null) {
- openWikiLinkOnSelection();
- }
+ /**
+ * Creates a folder resource handle for the folder with the given workspace path. This method does not create the folder resource;
+ * this is the responsibility of <code>createFolder</code>.
+ *
+ * @param folderPath
+ * the path of the folder resource to create a handle for
+ * @return the new folder resource handle
+ * @see #createFolder
+ */
+ private IFolder createFolderHandle(IPath folderPath) {
+ return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
}
- public void setActiveEditor(IAction action, IEditorPart targetEditor) {
- if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
- fEditor = (AbstractTextEditor) targetEditor;
+ private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
+ if (!file.exists()) {
+ createWikiFile(file, word);
}
}
- public IDocument getDocument() {
- IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
- return doc;
+ private void createWikiFile(IFile file, String word) throws CoreException {
+ IContainer parent = file.getParent();
+ if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
+ createFolder((IFolder) parent, null);
+ }
+ String newText = "<!--" + word + "-->";
+ byte[] buffer = newText.getBytes();
+ ByteArrayInputStream source = new ByteArrayInputStream(buffer);
+ file.create(source, true, null);
}
- public void openWikiLinkOnSelection() {
- IDocument doc = getDocument();
- ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
- int pos = selection.getOffset();
- // String textRegion = getWikiString(fEditor, doc, pos);
- IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
- openWikiFile(ei.getFile());
+ public void dispose() {
}
- void openWikiFile(IFile cfile) {
- String wikiName = getWikiFile(cfile);
+ public String generateUrl(Configuration config, String template, String wikiname) {
+
+ /* first, we init the runtime engine. Defaults are fine. */
+
try {
- if (fEditor != null) {
- selectWiki(wikiName);
- }
- } catch (Exception e) {
- }
+ Velocity.init();
- }
+ /* lets make a Context and put data into it */
- private void selectWiki(String wikiName) {
- String exampleWikiURL = "http://en.wikibooks.org/w/wiki.phtml";
- String selectedWikiURL = null;
- ArrayList locationsList = new ArrayList();
- locationsList.add(exampleWikiURL);
+ VelocityContext context = new VelocityContext();
- Collections.sort(locationsList);
+ context.put("config", config);
+ text.clear();
+ text.setWikiname(wikiname);
+ context.put("text", text);
+ /* lets make our own string to render */
+ StringWriter w = new StringWriter();
+ w = new StringWriter();
+ Velocity.evaluate(context, w, "mystring", template);
+ return w.toString();
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return template;
+ }
+
+ protected Configuration getConfiguration(){
+ List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
+ ArrayList configsList = new ArrayList();
+ for (int i = 0; i < allConfigsList.size(); i++) {
+ IConfiguration temp = (IConfiguration) allConfigsList.get(i);
+ if (temp.getType().equals(WikiEditorPlugin.WIKIPEDIA_GET_TEXT)) {
+ configsList.add(temp);
+ }
+ }
+ Collections.sort(configsList);
+ Configuration configuration = null;
ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getShell(), locationsList, new ListContentProvider(), new LabelProvider(),
+ .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(),
"Select the refresh URL.");
listSelectionDialog.setTitle("Multiple active configuration found");
if (listSelectionDialog.open() == Window.OK) {
Object[] locations = listSelectionDialog.getResult();
if (locations != null) {
for (int i = 0; i < locations.length; i++) {
- selectedWikiURL = (String) locations[i];
+ configuration = (Configuration) locations[i];
break;
}
}
}
-
- if (selectedWikiURL != null && !selectedWikiURL.equals("")) {
- String wikiContent = MediaWikiConnector.getWikiText(wikiName, selectedWikiURL);
- if (wikiContent != null) {
- IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
- doc.set(wikiContent);
- }
- }
+ return configuration;
}
- private void createNewFileIfNeeded(IFile file, String word) throws CoreException {
- if (!file.exists()) {
- createWikiFile(file, word);
- }
+ public IDocument getDocument() {
+ IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ return doc;
}
private String getWikiFile(IFile file) {
return Util.getFileWikiName(file, WikiEditorPlugin.HTML_OUTPUT_PATH);
- // IPath path = new Path(wikiFileName);
- // return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
}
- /**
- * Creates a folder resource handle for the folder with the given workspace path. This method does not create the folder resource;
- * this is the responsibility of <code>createFolder</code>.
- *
- * @param folderPath
- * the path of the folder resource to create a handle for
- * @return the new folder resource handle
- * @see #createFolder
- */
- private IFolder createFolderHandle(IPath folderPath) {
- return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath);
+ public void init(IWorkbenchWindow window) {
+ this.window = window;
}
- private void createFolder(IFolder folderHandle, IProgressMonitor monitor) throws CoreException {
+ void openWikiFile(IFile cfile) {
+ String wikiName = getWikiFile(cfile);
try {
- // Create the folder resource in the workspace
- // Recursive to create any folders which do not exist already
- if (!folderHandle.exists()) {
- IContainer parent = folderHandle.getParent();
- if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
- createFolder((IFolder) parent, monitor);
- }
- // if (linkTargetPath != null)
- // folderHandle.createLink(linkTargetPath, IResource.ALLOW_MISSING_LOCAL, monitor);
- // else
- folderHandle.create(false, true, monitor);
+ if (fEditor != null) {
+ selectWiki(wikiName);
}
- } catch (CoreException e) {
- // If the folder already existed locally, just refresh to get contents
- if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
- folderHandle.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
- else
- throw e;
+ } catch (Exception e) {
}
+
}
- private void createWikiFile(IFile file, String word) throws CoreException {
- IContainer parent = file.getParent();
- if (parent instanceof IFolder && (!((IFolder) parent).exists())) {
- createFolder((IFolder) parent, null);
+ public void openWikiLinkOnSelection() {
+ IDocument doc = getDocument();
+ ITextSelection selection = (ITextSelection) fEditor.getSelectionProvider().getSelection();
+ int pos = selection.getOffset();
+ IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
+ openWikiFile(ei.getFile());
+ }
+
+ public void run(IAction action) {
+ if (fEditor == null) {
+ IEditorPart targetEditor = window.getActivePage().getActiveEditor();
+ if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+ fEditor = (AbstractTextEditor) targetEditor;
+ }
+ }
+ if (fEditor != null) {
+ openWikiLinkOnSelection();
}
- String newText = "<!--" + word + "-->";
- byte[] buffer = newText.getBytes();
- ByteArrayInputStream source = new ByteArrayInputStream(buffer);
- file.create(source, true, null);
}
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (selection.isEmpty()) {
+ return;
+ }
+ if (selection instanceof TextSelection) {
+ action.setEnabled(true);
+ return;
+ }
+ if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
+ action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
+ }
+ }
+
+ private void selectWiki(String wikiName) {
+ Configuration configuration = getConfiguration();
+ if (configuration != null && !configuration.equals("")) {
+ String url = generateUrl(configuration, configuration.getURL(), wikiName);
+ String wikiContent = MediaWikiConnector.getWikiText(wikiName, url);
+ if (wikiContent != null) {
+ IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
+ doc.set(wikiContent);
+ }
+ }
+ }
+
+ public void setActiveEditor(IAction action, IEditorPart targetEditor) {
+ if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
+ fEditor = (AbstractTextEditor) targetEditor;
+ text = new EditorText(targetEditor);
+ }
+ }
}
\ No newline at end of file