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$
+ "<config name=\"Leo.org Translation\" type-id=\"HTTP Query\" url=\"http://dict.leo.org/?search=$text.selection\"/>"
+ "<config name=\"Wikipedia-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikipedia.org/w/wiki.phtml?title=$text.wikiname&action=edit\"/>"
+ "<config name=\"Wikibooks-en\" type-id=\"Wikipedia-Load Text\" url=\"http://en.wikibooks.org/w/wiki.phtml?title=$text.wikiname&action=edit\"/>"
+ + "<config name=\"Wikipedia-SQL\" type-id=\"Wikipedia SQL access\" user=\"root\" url=\"jdbc:mysql://localhost/wikidb\"/>"
+ "</configurations>";
public static WikipediaDB fWikiDB = null;
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 {
}
}
-// 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;
// 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 ?");
}