From f4052f7f827132301a20d2ca7afa6463987ee290 Mon Sep 17 00:00:00 2001 From: axelcl Date: Sat, 11 Dec 2004 17:56:11 +0000 Subject: [PATCH] integrated velocity engine for URL templates --- archive/net.sourceforge.phpeclipse.wiki/plugin.xml | 46 +++- .../actions/httpquery/AbstractHTTPQueryAction.java | 18 +- .../wiki/actions/httpquery/GoogleAction.java | 4 +- .../wiki/actions/httpquery/HTTPQueryAction.java | 6 +- .../wiki/actions/httpquery/KodersAction.java | 4 +- .../mediawiki/DownloadWikibooksENAction.java | 12 + .../actions/mediawiki/DownloadWikipediaAction.java | 237 ++++++++++++++++++++ .../mediawiki/DownloadWikipediaENAction.java | 12 + .../wiki/actions/mediawiki/MediaWikiConnector.java | 11 +- .../mediawiki/RefreshWikiTextEditorAction.java | 195 ---------------- .../phpeclipse/wiki/editor/WikiEditorPlugin.java | 11 +- .../wiki/internal/ConfigurationManager.java | 2 +- .../phpeclipse/wiki/velocity/EditorText.java | 18 ++ 13 files changed, 344 insertions(+), 232 deletions(-) create mode 100644 archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java create mode 100644 archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java create mode 100644 archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java delete mode 100644 archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshWikiTextEditorAction.java diff --git a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml index 56770b6..de70df9 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml @@ -294,16 +294,28 @@ path="rest"> + id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"> - + + + - + id="net.sourceforge.phpeclipse.wiki.actions.mediawiki.DownloadWikibooksENAction"> + + + @@ -375,7 +399,7 @@ id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction"> @@ -402,7 +426,7 @@ id="net.sourceforge.phpeclipse.wiki.actions.httpquery.GoogleAction"> diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/AbstractHTTPQueryAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/AbstractHTTPQueryAction.java index 1aaad74..c721086 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/AbstractHTTPQueryAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/AbstractHTTPQueryAction.java @@ -4,8 +4,8 @@ import java.io.StringWriter; import java.net.URL; import net.sourceforge.phpeclipse.webbrowser.views.BrowserView; +import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; -import net.sourceforge.phpeclipse.wiki.internal.IConfiguration; import net.sourceforge.phpeclipse.wiki.velocity.EditorText; import org.apache.velocity.VelocityContext; @@ -32,13 +32,9 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate { text = new EditorText(targetEditor); } - abstract protected IConfiguration getUrl(); + abstract protected Configuration getConfiguration(); public void run(IAction action) { -// String selection = findSelectedText(); -// if (selection == null || selection.trim().length() == 0) { -// selection = ""; -// } URL url; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { @@ -50,8 +46,8 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate { } else { page.bringToTop(part); } - IConfiguration config = getUrl(); - String templateString = generateUrl(config.getURL()); + Configuration config = getConfiguration(); + String templateString = generateUrl(config, config.getURL()); if (templateString != null && !templateString.equals("")) { ((BrowserView) part).setUrl(templateString); } @@ -63,7 +59,7 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate { public void selectionChanged(IAction action, ISelection selection) { } - public String generateUrl(String template) { + public String generateUrl(Configuration config, String template) { /* first, we init the runtime engine. Defaults are fine. */ @@ -74,10 +70,6 @@ public abstract class AbstractHTTPQueryAction implements IEditorActionDelegate { VelocityContext context = new VelocityContext(); - ConfigurationWorkingCopy config = new ConfigurationWorkingCopy(); - config.setName("test"); - config.setPassword("pw"); - context.put("config", config); text.clear(); context.put("text", text); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/GoogleAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/GoogleAction.java index d44a588..5eab038 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/GoogleAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/GoogleAction.java @@ -1,8 +1,8 @@ package net.sourceforge.phpeclipse.wiki.actions.httpquery; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; +import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; -import net.sourceforge.phpeclipse.wiki.internal.IConfiguration; public class GoogleAction extends AbstractHTTPQueryAction { @@ -11,7 +11,7 @@ public class GoogleAction extends AbstractHTTPQueryAction { super(); } - protected IConfiguration getUrl() { + protected Configuration getConfiguration() { ConfigurationWorkingCopy config = new ConfigurationWorkingCopy(); config.setName("Google Search"); config.setURL("http://www.google.com/search?q=$text.selection"); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/HTTPQueryAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/HTTPQueryAction.java index 1c41e37..d18f979 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/HTTPQueryAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/HTTPQueryAction.java @@ -5,7 +5,9 @@ import java.util.Collections; import java.util.List; 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 org.eclipse.jface.viewers.LabelProvider; @@ -19,7 +21,7 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction { super(); } - protected IConfiguration getUrl() { + protected Configuration getConfiguration() { String selectedURL = null; List allConfigsList = ConfigurationManager.getInstance().getConfigurations(); @@ -39,7 +41,7 @@ public class HTTPQueryAction extends AbstractHTTPQueryAction { Object[] configurations = listSelectionDialog.getResult(); if (configurations != null) { for (int i = 0; i < configurations.length; i++) { - return ((IConfiguration) configurations[i]); // .getURL(); + return ((Configuration) configurations[i]); // .getURL(); } } } diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/KodersAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/KodersAction.java index 909f29c..365d4fa 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/KodersAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/httpquery/KodersAction.java @@ -1,8 +1,8 @@ package net.sourceforge.phpeclipse.wiki.actions.httpquery; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; +import net.sourceforge.phpeclipse.wiki.internal.Configuration; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; -import net.sourceforge.phpeclipse.wiki.internal.IConfiguration; public class KodersAction extends AbstractHTTPQueryAction { @@ -11,7 +11,7 @@ public class KodersAction extends AbstractHTTPQueryAction { super(); } - protected IConfiguration getUrl() { + protected Configuration getConfiguration() { ConfigurationWorkingCopy config = new ConfigurationWorkingCopy(); config.setName("Koders.com Search"); config.setURL("http://koders.com/?s=$text.selection"); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java new file mode 100644 index 0000000..495db99 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikibooksENAction.java @@ -0,0 +1,12 @@ +package net.sourceforge.phpeclipse.wiki.actions.mediawiki; + +import net.sourceforge.phpeclipse.wiki.internal.Configuration; +import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; + +public final class DownloadWikibooksENAction extends DownloadWikipediaAction { + protected Configuration getConfiguration(){ + ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy(); + configuration.setURL("http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&action=edit"); + return configuration; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java new file mode 100644 index 0000000..bf82b88 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaAction.java @@ -0,0 +1,237 @@ +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.core.resources.IResource; +import org.eclipse.core.resources.IResourceStatus; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.ui.IEditorActionDelegate; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.dialogs.ListSelectionDialog; +import org.eclipse.ui.internal.dialogs.ListContentProvider; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.texteditor.AbstractTextEditor; + +public class DownloadWikipediaAction implements IEditorActionDelegate { + + private AbstractTextEditor fEditor; + + private EditorText text; + + private IWorkbenchWindow window; + + 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; + } + } + + /** + * 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 createFolder. + * + * @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); + } + + private void createNewFileIfNeeded(IFile file, String word) throws CoreException { + if (!file.exists()) { + createWikiFile(file, word); + } + } + + 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 = ""; + byte[] buffer = newText.getBytes(); + ByteArrayInputStream source = new ByteArrayInputStream(buffer); + file.create(source, true, null); + } + + public void dispose() { + } + + public String generateUrl(Configuration config, String template, String wikiname) { + + /* first, we init the runtime engine. Defaults are fine. */ + + try { + Velocity.init(); + + /* lets make a Context and put data into it */ + + VelocityContext context = new VelocityContext(); + + 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(), 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++) { + configuration = (Configuration) locations[i]; + break; + } + } + } + return configuration; + } + + 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); + } + + public void init(IWorkbenchWindow window) { + this.window = window; + } + + void openWikiFile(IFile cfile) { + String wikiName = getWikiFile(cfile); + try { + if (fEditor != null) { + selectWiki(wikiName); + } + } catch (Exception e) { + } + + } + + 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(); + } + } + + 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 diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java new file mode 100644 index 0000000..14dd2ae --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/DownloadWikipediaENAction.java @@ -0,0 +1,12 @@ +package net.sourceforge.phpeclipse.wiki.actions.mediawiki; + +import net.sourceforge.phpeclipse.wiki.internal.Configuration; +import net.sourceforge.phpeclipse.wiki.internal.ConfigurationWorkingCopy; + +public final class DownloadWikipediaENAction extends DownloadWikipediaAction { + protected Configuration getConfiguration(){ + ConfigurationWorkingCopy configuration = new ConfigurationWorkingCopy(); + configuration.setURL("http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&action=edit"); + return configuration; + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java index c9d2bda..b2e845e 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/MediaWikiConnector.java @@ -35,7 +35,7 @@ public class MediaWikiConnector { * Get the text of a wikimedia Wiki-Description * */ - public static String getWikiText(String wikiDescriptor, String urlStr) { + public static String getWikiText(String wikiname, String urlStr) { // examples // http://en.wikipedia.org/w/wiki.phtml?title=Main_Page&action=edit // http://en.wikibooks.org/w/wiki.phtml?title=Programming:PHP:SQL_Injection&action=edit @@ -43,10 +43,11 @@ public class MediaWikiConnector { HttpMethod method = null; try { if (urlStr == null) { - urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiDescriptor + "&action=edit"; - } else { - urlStr = urlStr + "?title=" + wikiDescriptor + "&action=edit"; - } + urlStr = "http://en.wikipedia.org/w/wiki.phtml?title=" + wikiname + "&action=edit"; + } +// else { +// urlStr = urlStr + "?title=" + wikiname + "&action=edit"; +// } URI uri = new URI(urlStr.toCharArray()); String schema = uri.getScheme(); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshWikiTextEditorAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshWikiTextEditorAction.java deleted file mode 100644 index f00d446..0000000 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/mediawiki/RefreshWikiTextEditorAction.java +++ /dev/null @@ -1,195 +0,0 @@ -package net.sourceforge.phpeclipse.wiki.actions.mediawiki; - -import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Collections; - -import net.sourceforge.phpeclipse.wiki.editor.WikiEditor; -import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; -import net.sourceforge.phpeclipse.wiki.preferences.Util; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.dialogs.ListSelectionDialog; -import org.eclipse.ui.internal.dialogs.ListContentProvider; -import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; -import org.eclipse.ui.texteditor.AbstractTextEditor; - -public final class RefreshWikiTextEditorAction implements IEditorActionDelegate { - - private IWorkbenchWindow window; - - private AbstractTextEditor fEditor; - - public void dispose() { - } - - public void init(IWorkbenchWindow window) { - this.window = 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)); - } - } - - 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(); - } - } - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) { - fEditor = (AbstractTextEditor) targetEditor; - } - } - - public IDocument getDocument() { - IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); - return doc; - } - - 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()); - } - - void openWikiFile(IFile cfile) { - String wikiName = getWikiFile(cfile); - try { - if (fEditor != null) { - selectWiki(wikiName); - } - } catch (Exception e) { - } - - } - - private void selectWiki(String wikiName) { - String exampleWikiURL = "http://en.wikibooks.org/w/wiki.phtml"; - String selectedWikiURL = null; - ArrayList locationsList = new ArrayList(); - locationsList.add(exampleWikiURL); - - Collections.sort(locationsList); - - ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench() - .getActiveWorkbenchWindow().getShell(), locationsList, 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]; - 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); - } - } - } - - private void createNewFileIfNeeded(IFile file, String word) throws CoreException { - if (!file.exists()) { - createWikiFile(file, word); - } - } - - 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 createFolder. - * - * @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); - } - - 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); - } - // if (linkTargetPath != null) - // folderHandle.createLink(linkTargetPath, IResource.ALLOW_MISSING_LOCAL, monitor); - // else - 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; - } - } - - 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 = ""; - byte[] buffer = newText.getBytes(); - ByteArrayInputStream source = new ByteArrayInputStream(buffer); - file.create(source, true, null); - } - -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java index 3e5c839..b67d095 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiEditorPlugin.java @@ -53,7 +53,15 @@ public class WikiEditorPlugin extends AbstractUIPlugin { public final static String HTML_OUTPUT_PATH = "__static_wiki_folder"; public final static String WIKI_TEXTS_BASE_PATH = "__wiki_texts_base_path"; - + public final static String PREF_STRING_CONFIGURATIONS ="configurations"; + public final static String CONFIG_MEMENTO = "" + + ""+ +"" + +"" + +"" + +"" + +"" + +""; private static ConfigurationManager manager; // // public static final String IMG_MONITOR_ON = "monitorOn"; @@ -212,6 +220,7 @@ public class WikiEditorPlugin extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore) */ protected void initializeDefaultPreferences(IPreferenceStore store) { + store.setDefault(PREF_STRING_CONFIGURATIONS, CONFIG_MEMENTO); } /* diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationManager.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationManager.java index 3713a9b..146dae7 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationManager.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationManager.java @@ -143,7 +143,7 @@ public class ConfigurationManager { configurations = new ArrayList(); Preferences prefs = WikiEditorPlugin.getDefault().getPluginPreferences(); - String xmlString = prefs.getString("configurations"); + String xmlString = prefs.getString(WikiEditorPlugin.PREF_STRING_CONFIGURATIONS); if (xmlString != null && xmlString.length() > 0) { try { ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes()); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java index c1d58a2..092a7bc 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/velocity/EditorText.java @@ -16,6 +16,8 @@ public class EditorText { String text = null; + String wikiname = null; + public EditorText(IEditorPart targetEditor) { this.targetEditor = targetEditor; } @@ -23,6 +25,7 @@ public class EditorText { public void clear() { selection = null; text = null; + wikiname = null; } /** @@ -93,4 +96,19 @@ public class EditorText { int start = boundary.previous(); return source.substring(start, end); } + + /** + * @return Returns the wikiname. + */ + public String getWikiname() { + return wikiname; + } + + /** + * @param wikiname + * The wikiname to set. + */ + public void setWikiname(String wikiname) { + this.wikiname = wikiname; + } } \ No newline at end of file -- 1.7.1