From e229739b8f0945e605265ef06396b91091afc62d Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 22 Dec 2004 21:30:12 +0000 Subject: [PATCH] Wikipedia SQL access configurable through type ''Wikipedia SQL access'' --- .../phpeclipse/wiki/editor/WikiEditorPlugin.java | 5 +- .../phpeclipse/wiki/sql/WikipediaDB.java | 87 ++++++++++++-------- 2 files changed, 58 insertions(+), 34 deletions(-) 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 1b3b0c1..88dff81 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 @@ -43,11 +43,13 @@ public class WikiEditorPlugin extends AbstractUIPlugin { public static final String WIKIPEDIA_GET_TEXT = "Wikipedia-Load Text"; + public static final String WIKIPEDIA_SQL = "Wikipedia SQL access"; + 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 }; + public static final String[] CONFIGURATION_TYPES = { HTTP_QUERY, WIKIPEDIA_GET_TEXT, WIKIPEDIA_SQL, BLOG_A_WIKI, BLOG_A_HTML }; //image paths public static final String ICON_PATH = "icons/full/"; //$NON-NLS-1$ @@ -75,6 +77,7 @@ public class WikiEditorPlugin extends AbstractUIPlugin { + "" + "" + "" + + "" + ""; public static WikipediaDB fWikiDB = null; 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 index 204d563..9bbad44 100644 --- 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 @@ -12,8 +12,12 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.List; import net.sourceforge.phpeclipse.wiki.editor.LineTokenizer; +import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; +import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager; +import net.sourceforge.phpeclipse.wiki.internal.IConfiguration; public class WikipediaDB { @@ -95,36 +99,36 @@ public class WikipediaDB { } } -// 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(); -// } -// } + // 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; @@ -137,15 +141,32 @@ public class WikipediaDB { // mysql-connector.jar should be in the class path or made part of the current jar Class.forName("com.mysql.jdbc.Driver"); + // determine the foirst SQL configuration + List allConfigsList = ConfigurationManager.getInstance().getConfigurations(); + ArrayList configsList = new ArrayList(); + IConfiguration configuration = null; + for (int i = 0; i < allConfigsList.size(); i++) { + configuration = (IConfiguration) allConfigsList.get(i); + if (configuration.getType().equals(WikiEditorPlugin.WIKIPEDIA_SQL)) { + break; + } + configuration = null; + } + // 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 + if (configuration != null) { + conn = DriverManager.getConnection(configuration.getURL(), configuration.getUser(), configuration.getPassword()); + } else { + // default configuration for XAMPP distribution + conn = DriverManager.getConnection("jdbc:mysql://localhost/wikidb", // filenames + "root", // username + ""); // password + } fGetPrefixTitles = conn.prepareStatement("SELECT cur_title FROM cur WHERE LOWER( cur_title ) like ?"); } -- 1.7.1