From: axelcl Date: Wed, 22 Dec 2004 20:19:25 +0000 (+0000) Subject: Improved Templates i.e. X-Git-Url: http://git.phpeclipse.com Improved Templates i.e. - Preference Page to define templates; - get title from MySQL db (must be made configuarable though) --- diff --git a/archive/net.sourceforge.phpeclipse.wiki/.classpath b/archive/net.sourceforge.phpeclipse.wiki/.classpath index 9b111bc..caab244 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/.classpath +++ b/archive/net.sourceforge.phpeclipse.wiki/.classpath @@ -1,12 +1,13 @@ - + + diff --git a/archive/net.sourceforge.phpeclipse.wiki/lib/mysql-connector.jar b/archive/net.sourceforge.phpeclipse.wiki/lib/mysql-connector.jar new file mode 100644 index 0000000..8b1158d Binary files /dev/null and b/archive/net.sourceforge.phpeclipse.wiki/lib/mysql-connector.jar differ diff --git a/archive/net.sourceforge.phpeclipse.wiki/plugin.properties b/archive/net.sourceforge.phpeclipse.wiki/plugin.properties index e26cbb2..11feb4e 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/plugin.properties +++ b/archive/net.sourceforge.phpeclipse.wiki/plugin.properties @@ -1,4 +1,6 @@ MediaWiki.label=Wikipedia +BlogWiki.label=Blog as Wiki Text +BlogHTML.label=Blog as HTML Text HTTPQuery.label=HTTP Query # --------------- General UI --------------- diff --git a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml index 55114a6..4548f82 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.wiki/plugin.xml @@ -18,6 +18,7 @@ + @@ -215,14 +216,19 @@ + - + id="net.sourceforge.phpeclipse.wiki.preferences.WikiProjectPreferences"/> @@ -245,12 +251,6 @@ menubarPath="additions" id="net.sourceforge.phpeclipse.wiki.actions.OpenWikiLinkEditorAction"> - - - - - + + + + + + + + + + + + + diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogHTMLAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogHTMLAction.java similarity index 71% rename from archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogHTMLAction.java rename to archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogHTMLAction.java index fc3f721..dae6627 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogHTMLAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogHTMLAction.java @@ -1,9 +1,16 @@ -package net.sourceforge.phpeclipse.wiki.actions; +package net.sourceforge.phpeclipse.wiki.actions.blogwiki; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; -import net.sourceforge.phpeclipse.wiki.blog.Configuration; import net.sourceforge.phpeclipse.wiki.blog.MetaWeblog; import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction; 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.IConfiguration; import net.sourceforge.phpeclipse.wiki.preferences.Util; import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer; import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory; @@ -13,10 +20,14 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; 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.texteditor.AbstractTextEditor; public final class NewPostBlogHTMLAction implements IEditorActionDelegate { @@ -47,6 +58,33 @@ public final class NewPostBlogHTMLAction implements IEditorActionDelegate { } } + 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.BLOG_A_HTML)) { + configsList.add(temp); + } + } + Collections.sort(configsList); + Configuration configuration = null; + ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(), + "Select blog configuration for your wiki HTMl text."); + 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 void run(IAction action) { if (fEditor == null) { IEditorPart targetEditor = window.getActivePage().getActiveEditor(); @@ -56,7 +94,7 @@ public final class NewPostBlogHTMLAction implements IEditorActionDelegate { } if (fEditor != null) { try { - Configuration config = new Configuration("http://localhost:8080/blog/default", "1", "root", "******"); + Configuration config = getConfiguration(); IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput(); IFile file = ei.getFile(); IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject()); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogEditorAction.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogWikiAction.java similarity index 58% rename from archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogEditorAction.java rename to archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogWikiAction.java index de2aa65..2bf1895 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/NewPostBlogEditorAction.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/actions/blogwiki/NewPostBlogWikiAction.java @@ -1,12 +1,17 @@ -package net.sourceforge.phpeclipse.wiki.actions; +package net.sourceforge.phpeclipse.wiki.actions.blogwiki; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import net.sourceforge.phpeclipse.wiki.blog.Configuration; import net.sourceforge.phpeclipse.wiki.blog.MetaWeblog; import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction; 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 org.eclipse.core.resources.IFile; @@ -14,13 +19,17 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; 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.texteditor.AbstractTextEditor; -public final class NewPostBlogEditorAction implements IEditorActionDelegate { +public final class NewPostBlogWikiAction implements IEditorActionDelegate { // public static String APPKEY = // "1c0c75ffffffb512ffffff9575ffffff97ffffffd2ffffff87ffffff91ffffffe41dffffffc5320cffffffab544effffffc0546459ffffff83"; @@ -48,6 +57,33 @@ public final class NewPostBlogEditorAction implements IEditorActionDelegate { } } + protected ConfigurationWorkingCopy 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.BLOG_A_WIKI)) { + configsList.add(temp); + } + } + Collections.sort(configsList); + ConfigurationWorkingCopy configuration = null; + ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(), + "Select blog configuration for your wiki text."); + 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 = (ConfigurationWorkingCopy) locations[i]; + break; + } + } + } + return configuration; + } + public void run(IAction action) { if (fEditor == null) { IEditorPart targetEditor = window.getActivePage().getActiveEditor(); @@ -56,18 +92,20 @@ public final class NewPostBlogEditorAction implements IEditorActionDelegate { } } if (fEditor != null) { + boolean cache = true; + ConfigurationWorkingCopy config = getConfiguration(); //new Configuration("http://localhost:8080/snip/RPC2", "1", "admin", + // "admin"); try { - Configuration config = new Configuration("http://localhost:8080/snip/RPC2", "1", "admin", "admin"); IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput(); IFile file = ei.getFile(); StringBuffer htmlBuffer = new StringBuffer(); - CreatePageAction.getWikiBuffer(htmlBuffer,file); + CreatePageAction.getWikiBuffer(htmlBuffer, file); ArrayList images = new ArrayList(); getImages(htmlBuffer, images); String[] result = new String[2]; - boolean cache = config.promptForPassword(config.getUser(), "Insert Config", true, result); + cache = config.promptForPassword(config.getUser(), "Insert Config", true, result); if (result[0] == null || result[1] == null) { return; } @@ -77,6 +115,8 @@ public final class NewPostBlogEditorAction implements IEditorActionDelegate { String title = Util.getWikiTitle(file); if (title != null) { + config.setName(result[0]); + config.setPassword(result[1]); MetaWeblog metaWebLog = new MetaWeblog(config); String guid = metaWebLog.newPost(file, title, htmlBuffer, true); System.out.println(guid); @@ -85,11 +125,11 @@ public final class NewPostBlogEditorAction implements IEditorActionDelegate { String fullImagePath; String filePath = file.getLocation().toString(); int index = filePath.lastIndexOf('/'); - if (index>=0) { - filePath = filePath.substring(0,index+1); + if (index >= 0) { + filePath = filePath.substring(0, index + 1); } for (int i = 0; i < images.size(); i++) { - fullImagePath = filePath+"Image/"+images.get(i).toString(); + fullImagePath = filePath + "Image/" + images.get(i).toString(); metaWebLog.publishAttachement(guid, fullImagePath, false); } } @@ -99,13 +139,20 @@ public final class NewPostBlogEditorAction implements IEditorActionDelegate { } catch (Exception e) { MessageDialog.openError(null, "Exception: ", e.toString()); e.printStackTrace(); + } finally { + if (!cache && config != null) { + // reset password + config.setPassword(""); + } } } } /** - * @param content the wikitext - * @param images result List of image names + * @param content + * the wikitext + * @param images + * result List of image names */ private void getImages(StringBuffer content, List images) { int startIndex = 0; diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/Configuration.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/Configuration.java deleted file mode 100644 index 8d8843b..0000000 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/Configuration.java +++ /dev/null @@ -1,149 +0,0 @@ -package net.sourceforge.phpeclipse.wiki.blog; - -import net.sourceforge.phpeclipse.wiki.preferences.AlternateUserValidationDialog; -import net.sourceforge.phpeclipse.wiki.preferences.UserValidationDialog; -import net.sourceforge.phpeclipse.wiki.preferences.Util; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.swt.widgets.Shell; - -public class Configuration { - String fUrl; - - String fBlogID; - - String fUser; - - String fPassword; - - public Configuration(String url, String blogId, String user, String password) { - fUrl = url; - fBlogID = blogId; - fUser = user; - fPassword = password; - } - - /** - * @return Returns the blogID. - */ - public String getBlogID() { - return fBlogID; - } - - /** - * @param blogID - * The blogID to set. - */ - public void setBlogID(String blogID) { - fBlogID = blogID; - } - - /** - * @return Returns the fPassword. - */ - public String getPassword() { - return fPassword; - } - - /** - * @param fPassword - * The fPassword to set. - */ - public void setPassword(String password) { - fPassword = password; - } - - /** - * @return Returns the url. - */ - public String getUrl() { - return fUrl; - } - - /** - * @param url - * The url to set. - */ - public void setUrl(String url) { - fUrl = url; - } - - /** - * @return Returns the fUser. - */ - public String getUser() { - return fUser; - } - - /** - * @param fUser - * The fUser to set. - */ - public void setUser(String user) { - fUser = user; - } - - public boolean isUserComplete() { - if (fUser==null || fUser.equals("")) { - return false; - } - if (fPassword==null || fPassword.equals("")) { - return false; - } - return true; - } - /** - * Special alternate prompting. Returns the fPassword. Username must be fixed. - * - * - * String passWord = Configuration.alternatePromptForPassword(config.getUser()); - * if (passWord==null||passWord.equals("")) { - * return; - * } - * config.setPassword(passWord); - */ - public String alternatePromptForPassword(final String username) { - Shell shell = Util.findShell(); - AlternateUserValidationDialog dialog = new AlternateUserValidationDialog(shell, (username == null) ? "" : username); //$NON-NLS-1$ - dialog.setUsername(username); - int result = dialog.open(); - if (result == Dialog.CANCEL) - return null; - return dialog.getPassword(); - } - - /** - * Asks the User to enter a Password. Places the results in the supplied string[]. result[0] must contain the username, result[1] - * must contain the fPassword. If the fUser canceled, both values must be zero. - * - * @param location - * the location to obtain the fPassword for - * @param username - * the username - * @param message - * a message to display to the fUser - * @param userMutable - * whether the fUser can be changed in the dialog - * @param result - * a String array of length two in which to put the result - */ - public boolean promptForPassword(final String username, final String message, final boolean userMutable, final String[] result) { - if (isUserComplete()) { - result[0] = fUser; - result[1] = fPassword; - return false; - } - Shell shell = Util.findShell(); - if (shell == null) { - return false; - } - String domain = ""; //location == null ? null : location.getLocation(); - UserValidationDialog dialog = new UserValidationDialog(shell, domain, (username == null) ? "" : username, message);//$NON-NLS-1$ - dialog.setUsernameMutable(userMutable); - dialog.open(); - result[0] = dialog.getUsername(); - result[1] = dialog.getPassword(); - return dialog.getAllowCaching(); - } - -} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/MetaWeblog.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/MetaWeblog.java index 07de445..c02c1cd 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/MetaWeblog.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/blog/MetaWeblog.java @@ -10,6 +10,8 @@ import java.util.Date; import java.util.Hashtable; import java.util.Vector; +import net.sourceforge.phpeclipse.wiki.internal.Configuration; + import org.apache.xmlrpc.XmlRpcClient; import org.apache.xmlrpc.XmlRpcException; import org.eclipse.core.resources.IFile; @@ -23,7 +25,7 @@ public class MetaWeblog { public MetaWeblog(Configuration conf) throws MalformedURLException { config = conf; - xmlrpc = new XmlRpcClient(config.getUrl()); + xmlrpc = new XmlRpcClient(config.getURL()); } public String newPost(Configuration config, IFile file, String title, StringBuffer htmlBuffer) { @@ -41,7 +43,7 @@ public class MetaWeblog { Vector params = new Vector(); String guid = null; - params.add(config.getBlogID()); + params.add(config.getId()); params.add(config.getUser()); params.add(config.getPassword()); params.add(message); @@ -76,7 +78,7 @@ public class MetaWeblog { public void publishAttachement(String snipId, String attachementFilename, boolean delete) throws TransferFilesException { Vector params = new Vector(); - params.add(config.getBlogID()); + params.add(config.getId()); params.add(config.getUser()); params.add(config.getPassword()); Hashtable message = new Hashtable(); @@ -135,7 +137,7 @@ public class MetaWeblog { boolean deleteEntry(BlogEntry entry) throws TransferFilesException { Vector params = new Vector(5); // params.add(props.getProperty("blogid", "none")); //Should be the appkey, but what use is that? - params.add(config.getBlogID()); + params.add(config.getId()); params.add(entry.getGuid()); params.add(config.getUser()); params.add(config.getPassword()); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/LineTokenizer.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/LineTokenizer.java new file mode 100644 index 0000000..b00b8fa --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/LineTokenizer.java @@ -0,0 +1,110 @@ +/* + * Copyright 2003-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * 2004 - modified for PHPeclipse plugins + */ +package net.sourceforge.phpeclipse.wiki.editor; + +import java.io.Reader; +import java.io.IOException; + +/** + * class to tokenize the input as lines seperated + * by \r (mac style), \r\n (dos/windows style) or \n (unix style) + * @since Ant 1.6 + */ +public class LineTokenizer { + private String lineEnd = ""; + private int pushed = -2; + private boolean includeDelims = false; + + /** + * attribute includedelims - whether to include + * the line ending with the line, or to return + * it in the posttoken + * default false + * @param includeDelims if true include /r and /n in the line + */ + + public void setIncludeDelims(boolean includeDelims) { + this.includeDelims = includeDelims; + } + + /** + * get the next line from the input + * + * @param in the input reader + * @return the line excluding /r or /n, unless includedelims is set + * @exception IOException if an error occurs reading + */ + public boolean getToken(StringBuffer line, Reader in) throws IOException { + int ch = -1; + if (pushed != -2) { + ch = pushed; + pushed = -2; + } else { + ch = in.read(); + } + if (ch == -1) { + return false; + } + + lineEnd = ""; +// StringBuffer line = new StringBuffer(); + + int state = 0; + while (ch != -1) { + if (state == 0) { + if (ch == '\r') { + state = 1; + } else if (ch == '\n') { + lineEnd = "\n"; + break; + } else { + line.append((char) ch); + } + } else { + state = 0; + if (ch == '\n') { + lineEnd = "\r\n"; + } else { + pushed = ch; + lineEnd = "\r"; + } + break; + } + ch = in.read(); + } + if (ch == -1 && state == 1) { + lineEnd = "\r"; + } + + if (includeDelims) { + line.append(lineEnd); + } + return true; + } + + /** + * @return the line ending character(s) for the current line + */ + public String getPostToken() { + if (includeDelims) { + return ""; + } + return lineEnd; + } + +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiCompletionProcessor.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiCompletionProcessor.java index 533e894..d5d4866 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiCompletionProcessor.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/editor/WikiCompletionProcessor.java @@ -15,6 +15,7 @@ import java.util.List; import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaSection; import net.sourceforge.phpeclipse.wiki.editor.model.WikipediaText; +import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; @@ -40,11 +41,24 @@ import org.eclipse.swt.graphics.Image; public class WikiCompletionProcessor implements IContentAssistProcessor { - private static final String TEMPLATE_ICON = "icons/template.gif"; + static class StringComparator implements Comparator { + public int compare(Object o1, Object o2) { + String s1 = (String) o1; + String s2 = (String) o2; + return s1.compareTo(s2); + // return s1.toUpperCase().compareTo(s2.toUpperCase()); + } -// private static final String PREPARATION_TEMPLATE_CTX = "net.sourceforge.phpeclipse.wiki.editor.preparation"; + public boolean equals(Object o) { + // String s = (String) o; + return compare(this, o) == 0; + } + } - private static final String INGREDIENTS_TEMPLATE_CTX = "net.sourceforge.phpeclipse.wiki.editor.templates"; + private static final String TEMPLATE_ICON = "icons/template.gif"; + + // private static TreeSet TITLES_SET = null; + private static final String WIKIPEDIA_TEMPLATE_CTX = "net.sourceforge.phpeclipse.wiki.editor.templates"; private static final class ProposalComparator implements Comparator { public int compare(Object o1, Object o2) { @@ -60,6 +74,32 @@ public class WikiCompletionProcessor implements IContentAssistProcessor { fEditor = editor; } + // private static void readFile(String filename) { + // TITLES_SET = new TreeSet(new StringComparator()); + // FileReader fileReader; + // try { + // fileReader = new FileReader(filename); + // BufferedReader bufferedReader = new BufferedReader(fileReader); + // LineTokenizer lineTokenizer = new LineTokenizer(); + // StringBuffer line = new StringBuffer(1024); + // while (lineTokenizer.getToken(line, bufferedReader)) { + // if (line.length() == 0) { + // // this should not happen + // } else { + // TITLES_SET.add(line.toString()); + // line.delete(0, line.length()); + // } + // } + // bufferedReader.close(); + // } catch (FileNotFoundException e) { + // // ignore this + // // TODO DialogBox which asks the user if she/he likes to build new index? + // } catch (IOException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { WikipediaSection section = fEditor.getSection(); if (section == null) @@ -72,69 +112,79 @@ public class WikiCompletionProcessor implements IContentAssistProcessor { String prefix = getPrefix(viewer, offset); Region region = new Region(offset - prefix.length(), prefix.length() + selection.getLength()); + List result = new ArrayList(); + + if (prefix.length() > 2) { + if (WikiEditorPlugin.fWikiDB == null) { + try { + WikiEditorPlugin.fWikiDB = new WikipediaDB(); + } catch (Exception ex1) { + // ex1.printStackTrace(); // could not start db + WikiEditorPlugin.fWikiDB = null; + } + } + if (WikiEditorPlugin.fWikiDB != null) { + try { + ArrayList list = WikiEditorPlugin.fWikiDB.queryPrefix(prefix); + ICompletionProposal[] titleProposals = computeTitleProposals(list, region, viewer); + result.addAll(Arrays.asList(titleProposals)); + } catch (Exception ex1) { + // ex1.printStackTrace(); // could not start db + WikiEditorPlugin.fWikiDB = null; + } + } + } + // if (TITLES_SET==null) { + // TODO make this a preference + // readFile("c:\\temp\\titles.txt"); + // } + // if (TITLES_SET.size()>0 && prefix.length()>3) { + // SortedSet subSet = TITLES_SET.subSet(prefix, prefix + '\255'); + // Iterator iter = subSet.iterator(); + // ArrayList list; + // String title; + // int maxProposals = 200; + // while (iter.hasNext()) { + // title = (String) iter.next(); + // if (title.toLowerCase().startsWith(prefix.toLowerCase())) { + // result.add(title); + // } + // if (maxProposals-- < 0) { + // break; + // } + // } + // } ICompletionProposal[] templateProposals = computeTemplateProposals(viewer, region, section, prefix); -// ICompletionProposal[] ingredientProposals = computeIngredientsProposals(viewer, region, recipe, prefix); -// ICompletionProposal[] titleProposals = computeTitleProposals(viewer, region, recipe, prefix); - List result = new ArrayList(); -// result.addAll(Arrays.asList(ingredientProposals)); + // ICompletionProposal[] ingredientProposals = computeIngredientsProposals(viewer, region, recipe, prefix); + // ICompletionProposal[] titleProposals = computeTitleProposals(viewer, region, recipe, prefix); + + // result.addAll(Arrays.asList(ingredientProposals)); result.addAll(Arrays.asList(templateProposals)); -// result.addAll(Arrays.asList(titleProposals)); + // result.addAll(Arrays.asList(titleProposals)); return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]); } - private ICompletionProposal[] computeTitleProposals(ITextViewer viewer, IRegion region, WikipediaText recipe, String prefix) { - List props = new ArrayList(2); - // if (recipe.getIngredientsSection() == null) - // props.add(createTitleProposal("Zutaten:", region, viewer)); - // if (recipe.getPreparationSection() == null) - // props.add(createTitleProposal("Zubereitung:", region, viewer)); - return (ICompletionProposal[]) props.toArray(new ICompletionProposal[props.size()]); - } - - private CompletionProposal createTitleProposal(String name, IRegion region, ITextViewer viewer) { - String lineDelimiter = TextUtilities.getDefaultLineDelimiter(viewer.getDocument()); - return new CompletionProposal(name + lineDelimiter, region.getOffset(), region.getLength(), region.getOffset() + name.length() - + lineDelimiter.length(), null, name, null, null); - } - - private ICompletionProposal[] computeIngredientsProposals(ITextViewer viewer, IRegion region, WikipediaText recipe, String prefix) { - return new ICompletionProposal[0]; - // Step[] steps= recipe.getSteps(); - // if (steps == null || steps.length == 0) - // return new ICompletionProposal[0]; - // - // int offset= region.getOffset(); - // Step first= steps[0]; - // if (offset < first.getOffset()) - // return new ICompletionProposal[0]; - // - // Ingredient[] ingredients= recipe.getIngredients(); - // if (ingredients == null) - // return new ICompletionProposal[0]; - // - // prefix= prefix.toLowerCase(); - // - // ArrayList proposals= new ArrayList(); - // for (int i= 0; i < ingredients.length; i++) { - // String ingredient= ingredients[i].getName(); - // if (ingredient.toLowerCase().startsWith(prefix)) - // proposals.add(new CompletionProposal(ingredient, offset, region.getLength(), ingredient.length())); - // } - // return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); + private ICompletionProposal[] computeTitleProposals(ArrayList list, IRegion region, ITextViewer viewer) { + ICompletionProposal[] arr = new ICompletionProposal[list.size()]; + // String lineDelimiter = TextUtilities.getDefaultLineDelimiter(viewer.getDocument()); + String temp; + for (int i = 0; i < arr.length; i++) { + temp = (String) list.get(i); + arr[i] = new CompletionProposal(temp, region.getOffset(), region.getLength(), region.getOffset() + temp.length(), null, temp, + null, null); + } + return arr; } private TemplateContextType getContextType(WikipediaSection section, int offset) { -// if (recipe.getPreparationSection() != null && recipe.getPreparationSection().getOffset() < offset) -// return WikiEditorPlugin.getDefault().getContextTypeRegistry().getContextType(PREPARATION_TEMPLATE_CTX); -// else - return WikiEditorPlugin.getDefault().getContextTypeRegistry().getContextType(INGREDIENTS_TEMPLATE_CTX); + return WikiEditorPlugin.getDefault().getContextTypeRegistry().getContextType(WIKIPEDIA_TEMPLATE_CTX); } /** - * Creates a concrete template context for the given region in the document. This involves finding out which context fType is valid - * at the given location, and then creating a context of this fType. The default implementation returns a + * Creates a concrete template context for the given region in the document. This involves finding out which context fType is + * valid at the given location, and then creating a context of this fType. The default implementation returns a * DocumentTemplateContext for the context fType at the given location. * * @param viewer @@ -171,10 +221,10 @@ public class WikiCompletionProcessor implements IContentAssistProcessor { } catch (TemplateException e) { continue; } - int relevance = getRelevance(template, prefix); - if (relevance > 0) { - matches.add(new TemplateProposal(template, context, region, getImage(template), relevance)); - } + // int relevance = getRelevance(template, prefix); + // if (relevance > 0) { + matches.add(new TemplateProposal(template, context, region, getImage(template), 1)); + // } } Collections.sort(matches, fgProposalComparator); @@ -208,7 +258,7 @@ public class WikiCompletionProcessor implements IContentAssistProcessor { try { while (i > 0) { char ch = document.getChar(i - 1); - if (!Character.isLetterOrDigit(ch)) + if (!Character.isLetterOrDigit(ch) && (ch != ':') && (ch != '_')) break; i--; } 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 6e7669b..1b3b0c1 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 @@ -3,6 +3,7 @@ package net.sourceforge.phpeclipse.wiki.editor; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.sql.SQLException; import java.text.MessageFormat; import java.util.Hashtable; import java.util.List; @@ -11,6 +12,7 @@ import java.util.ResourceBundle; import net.sourceforge.phpeclipse.wiki.internal.IConfigurationWorkingCopy; import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager; +import net.sourceforge.phpeclipse.wiki.sql.WikipediaDB; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IExtension; @@ -36,15 +38,17 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; public class WikiEditorPlugin extends AbstractUIPlugin { private static WikiEditorPlugin fgPlugin; + public static final String HTTP_QUERY = "HTTP Query"; + public static final String WIKIPEDIA_GET_TEXT = "Wikipedia-Load Text"; - public static final String WEBLOG_API_SEND = "MetaWeblog API-Post"; - - public static final String[] CONFIGURATION_TYPES = { - HTTP_QUERY, - WIKIPEDIA_GET_TEXT, - WEBLOG_API_SEND - }; + + public static final String BLOG_A_WIKI = "Blog as Wiki Text"; + + public static final String BLOG_A_HTML = "Blog as HTML Text"; + + public static final String[] CONFIGURATION_TYPES = { HTTP_QUERY, WIKIPEDIA_GET_TEXT, BLOG_A_WIKI, BLOG_A_HTML }; + //image paths public static final String ICON_PATH = "icons/full/"; //$NON-NLS-1$ @@ -53,25 +57,34 @@ 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 LOCAL_TEMPLATE_FILE_NAME = "__local_template_file_name"; + public final static String EXPORT_TEMPLATE_FILE_NAME = "__export_template_file_name"; - public final static String LOCAL_CSS_URL = "__local_css_url"; + + public final static String LOCAL_CSS_URL = "__local_css_url"; + public final static String EXPORT_CSS_URL = "__export_css_url"; + public final static String PREF_STRING_CONFIGURATIONS = "configurations"; - public final static String CONFIG_MEMENTO = "" + - ""+ -"" + -"" + -"" + -"" + -"" + -""; + + public final static String CONFIG_MEMENTO = "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + public static WikipediaDB fWikiDB = null; + private static ConfigurationManager manager; -// -// public static final String IMG_MONITOR_ON = "monitorOn"; -// -// public static final String IMG_MONITOR_OFF = "monitorOff"; + + // + // public static final String IMG_MONITOR_ON = "monitorOn"; + // + // public static final String IMG_MONITOR_OFF = "monitorOff"; /** * Creates an image and places it in the image registry. @@ -357,8 +370,23 @@ public class WikiEditorPlugin extends AbstractUIPlugin { public static IConfigurationWorkingCopy createConfiguration() { return manager.createConfiguration(); } - + public static String[] getTypes() { return CONFIGURATION_TYPES; } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.Plugin#shutdown() + */ + public void shutdown() throws CoreException { + if (fWikiDB != null) { + try { + fWikiDB.shutdown(); + } catch (SQLException e) { + } + } + super.shutdown(); + } } \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/Configuration.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/Configuration.java index a8cf2e2..1cadc30 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/Configuration.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/Configuration.java @@ -11,6 +11,10 @@ package net.sourceforge.phpeclipse.wiki.internal; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; +import net.sourceforge.phpeclipse.wiki.preferences.UserValidationDialog; +import net.sourceforge.phpeclipse.wiki.preferences.Util; + +import org.eclipse.swt.widgets.Shell; /** * @@ -206,4 +210,49 @@ public class Configuration implements IConfiguration, Comparable { return new String(out); } + public boolean isUserComplete() { + if (fUser==null || fUser.equals("")) { + return false; + } + if (fPassword==null || fPassword.equals("")) { + return false; + } + return true; + } + /** + * Asks the User to enter a Password. Places the results in the supplied string[]. result[0] must contain the username, result[1] + * must contain the fPassword. If the fUser canceled, both values must be zero. + * + * @param location + * the location to obtain the fPassword for + * @param username + * the username + * @param message + * a message to display to the fUser + * @param userMutable + * whether the fUser can be changed in the dialog + * @param result + * a String array of length two in which to put the result + */ + public boolean promptForPassword(final String username, final String message, final boolean userMutable, final String[] result) { + if (isUserComplete()) { + result[0] = fUser; + result[1] = fPassword; + return true; + } + Shell shell = Util.findShell(); + if (shell == null) { + return false; + } + UserValidationDialog dialog = new UserValidationDialog(shell, fUrl, (username == null) ? "" : username, message);//$NON-NLS-1$ + dialog.setUsernameMutable(userMutable); + dialog.open(); + result[0] = dialog.getUsername(); + result[1] = dialog.getPassword(); + if (dialog.getAllowCaching()) { + fUser = result[0]; + fPassword = result[1]; + } + return dialog.getAllowCaching(); + } } \ No newline at end of file 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 146dae7..60e0b16 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 @@ -153,9 +153,9 @@ public class ConfigurationManager { if (children != null) { int size = children.length; for (int i = 0; i < size; i++) { - Configuration monitor = new Configuration(); - monitor.load(children[i]); - configurations.add(monitor); + Configuration configuration = new ConfigurationWorkingCopy(); + configuration.load(children[i]); + configurations.add(configuration); } } } catch (Exception e) { diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationWorkingCopy.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationWorkingCopy.java index b0cafc5..a6b5dba 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationWorkingCopy.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/internal/ConfigurationWorkingCopy.java @@ -64,15 +64,8 @@ public class ConfigurationWorkingCopy extends Configuration implements IConfigur public IConfiguration save() { ConfigurationManager mm = ConfigurationManager.getInstance(); if (configuration != null) { - //boolean restart = false; -// if (monitor.isRunning()) { -// //restart = true; -// mm.stopMonitor(monitor); -// } configuration.setInternal(this); mm.configurationChanged(configuration); - //if (restart) - // mm.startMonitor(monitor); } else { configuration = new Configuration(); configuration.setInternal(this); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/TemplatesPreferencePage.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/TemplatesPreferencePage.java new file mode 100644 index 0000000..05f2959 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/TemplatesPreferencePage.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpeclipse.wiki.preferences; + +import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; + +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; +/** + * @see org.eclipse.jface.preference.PreferencePage + */ +public class TemplatesPreferencePage extends TemplatePreferencePage implements IWorkbenchPreferencePage { + + public TemplatesPreferencePage() { + setPreferenceStore(WikiEditorPlugin.getDefault().getPreferenceStore()); + setTemplateStore(WikiEditorPlugin.getDefault().getTemplateStore()); + setContextTypeRegistry(WikiEditorPlugin.getDefault().getContextTypeRegistry()); + } + + protected boolean isShowFormatterSetting() { + return false; + } + + + public boolean performOk() { + boolean ok= super.performOk(); + + WikiEditorPlugin.getDefault().savePluginPreferences(); + + return ok; + } +} diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/UserValidationDialog.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/UserValidationDialog.java index 50633da..5ffc1fc 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/UserValidationDialog.java +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/preferences/UserValidationDialog.java @@ -227,7 +227,7 @@ public class UserValidationDialog extends Dialog { * the parent of the widgets */ protected void createUsernameFields(Composite parent) { - new Label(parent, SWT.NONE).setText(Messages.getString("UserValidationDialog.fUser")); //$NON-NLS-1$ + new Label(parent, SWT.NONE).setText(Messages.getString("UserValidationDialog.user")); //$NON-NLS-1$ usernameField = new Text(parent, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); diff --git a/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/sql/WikipediaDB.java b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/sql/WikipediaDB.java new file mode 100644 index 0000000..204d563 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.wiki/src/net/sourceforge/phpeclipse/wiki/sql/WikipediaDB.java @@ -0,0 +1,205 @@ +package net.sourceforge.phpeclipse.wiki.sql; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +import net.sourceforge.phpeclipse.wiki.editor.LineTokenizer; + +public class WikipediaDB { + + public static void dump(ResultSet rs) throws SQLException { + + // the order of the rows in a cursor + // are implementation dependent unless you use the SQL ORDER statement + ResultSetMetaData meta = rs.getMetaData(); + int colmax = meta.getColumnCount(); + int i; + Object o = null; + + // the result set is a cursor into the data. You can only + // point to one row at a time + // assume we are pointing to BEFORE the first row + // rs.next() points to next row and returns true + // or false if there is no next row, which breaks the loop + for (; rs.next();) { + for (i = 0; i < colmax; ++i) { + o = rs.getObject(i + 1); // Is SQL the first column is indexed + // with 1 not 0 + System.out.print(o.toString() + " "); + } + + System.out.println(" "); + } + } + + public static ArrayList getResultAsString(ResultSet rs) throws SQLException { + ArrayList list = new ArrayList(); + int maxProposals = 500; + // the order of the rows in a cursor + // are implementation dependent unless you use the SQL ORDER statement + ResultSetMetaData meta = rs.getMetaData(); + int colmax = meta.getColumnCount(); + int i; + Object o = null; + + // the result set is a cursor into the data. You can only + // point to one row at a time + // assume we are pointing to BEFORE the first row + // rs.next() points to next row and returns true + // or false if there is no next row, which breaks the loop + for (; rs.next();) { + for (i = 0; i < colmax; ++i) { + o = rs.getObject(i + 1); // Is SQL the first column is indexed + // with 1 not 0 + list.add(o.toString()); + maxProposals--; + if (maxProposals <= 0) { + return list; + } + } + } + return list; + } + + public static void main(String[] args) { + WikipediaDB db = null; + + try { + db = new WikipediaDB(); + } catch (Exception ex1) { + ex1.printStackTrace(); // could not start db + return; // bye bye + } + + try { + // do a query + ArrayList list = db.queryPrefix("Programming:PHP"); + // db.query("SELECT * FROM cur WHERE cur_title like 'Programming:PHP%'"); // WHERE num_col < 250"); + for (int i = 0; i < list.size(); i++) { + System.out.println(list.get(i).toString()); + } + // at end of program + db.shutdown(); + } catch (SQLException ex3) { + ex3.printStackTrace(); + } + } + +// private static void readFile(WikipediaDB db, String filename) { +// FileReader fileReader; +// try { +// BufferedReader bufferedReader = new BufferedReader(new FileReader(filename)); +// // String line; +// LineTokenizer lineTokenizer = new LineTokenizer(); +// StringBuffer line = new StringBuffer(1024); +// while (lineTokenizer.getToken(line, bufferedReader)) { +// if (line.length() == 0) { +// // this should not happen +// } else { +// // try { +// // db.update("INSERT INTO wp_titles(title) VALUES('" + line + "')"); +// System.out.println(line); +// line.delete(0, line.length()); +// // addLine(line); +// // } catch (SQLException ex3) { +// //// ex3.printStackTrace(); +// // } +// } +// } +// bufferedReader.close(); +// } catch (FileNotFoundException e) { +// // ignore this +// // TODO DialogBox which asks the user if she/he likes to build new index? +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } + + Connection conn; + + PreparedStatement fGetPrefixTitles; + + public WikipediaDB() throws Exception // note more general exception + { + + // Load the Database Engine JDBC driver + // mysql-connector.jar should be in the class path or made part of the current jar + Class.forName("com.mysql.jdbc.Driver"); + + // connect to the database. This will load the db files and start the + // database if it is not alread running. + // db_file_name_prefix is used to open or create files that hold the state + // of the db. + // It can contain directory names relative to the + // current working directory + conn = DriverManager.getConnection("jdbc:mysql://localhost/wikidb", // filenames + "root", // username + ""); // password + fGetPrefixTitles = conn.prepareStatement("SELECT cur_title FROM cur WHERE LOWER( cur_title ) like ?"); + } + + //use for SQL commands CREATE and SELECT + public synchronized void query(String expression) throws SQLException { + + Statement st = null; + ResultSet rs = null; + + st = conn.createStatement(); // statement objects can be reused with + // repeated calls to execute but we + // choose to make a new one each time + rs = st.executeQuery(expression); // run the query + + // do something with the result set. + dump(rs); + st.close(); // NOTE!! if you close a statement the associated ResultSet is + // closed too + // so you should copy the contents to some other object. + // the result set is invalidated also if you recycle an Statement + // and try to execute some other query before the result set has been + // completely examined. + } + + public synchronized ArrayList queryPrefix(String prefix) throws SQLException { + fGetPrefixTitles.setString(1, prefix.toLowerCase() + '%'); + ResultSet rs = null; + rs = fGetPrefixTitles.executeQuery(); // run the query + // do something with the result set. + return getResultAsString(rs); + // st.close(); // NOTE!! if you close a statement the associated ResultSet is + } + + public void shutdown() throws SQLException { + + conn.close(); // if there are no other open connection + // db writes out to files and shuts down + // this happens anyway at garbage collection + // when program ends + } + + //use for SQL commands DROP and INSERT and UPDATE + public synchronized void update(String expression) throws SQLException { + + Statement st = null; + + st = conn.createStatement(); // statements + + int i = st.executeUpdate(expression); // run the query + + if (i == -1) { + System.out.println("db error : " + expression); + } + + st.close(); + } +} \ No newline at end of file diff --git a/archive/net.sourceforge.phpeclipse.wiki/templates/templates.xml b/archive/net.sourceforge.phpeclipse.wiki/templates/templates.xml index 36f60e5..550bd36 100644 --- a/archive/net.sourceforge.phpeclipse.wiki/templates/templates.xml +++ b/archive/net.sourceforge.phpeclipse.wiki/templates/templates.xml @@ -1,6 +1,8 @@ + +