From 3bfabd220ce6c644168184a8464d78564adb05f5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 29 Jul 2008 00:48:41 +0000 Subject: Added database Because of the lack of SQLite Java wrappers, InstaDisc instead uses a BDB database. --- client/trunk/nbproject/project.properties | 16 +- .../fourisland/instadisc/CloseObjectThread.java | 33 ---- .../instadisc/CloseServerSocketThread.java | 33 ++++ .../instadisc/Database/CloseEntityStoreThread.java | 33 ++++ .../instadisc/Database/CloseEnvironmentThread.java | 32 +++ .../fourisland/instadisc/Database/IDConfig.java | 43 ++++ .../fourisland/instadisc/Database/OldVerID.java | 31 +++ .../com/fourisland/instadisc/Database/Wrapper.java | 129 ++++++++++++ .../instadisc/FirstRun/FirstRunWizard.java | 35 ++++ .../com/fourisland/instadisc/FirstRun/Step1.form | 142 +++++++++++++ .../com/fourisland/instadisc/FirstRun/Step1.java | 156 +++++++++++++++ .../com/fourisland/instadisc/FirstRun/Step2.form | 176 +++++++++++++++++ .../com/fourisland/instadisc/FirstRun/Step2.java | 219 +++++++++++++++++++++ .../com/fourisland/instadisc/FirstRun/Step3.form | 100 ++++++++++ .../com/fourisland/instadisc/FirstRun/Step3.java | 122 ++++++++++++ .../instadisc/FirstRun/StepEndResults.java | 16 ++ .../instadisc/FirstRun/resources/Step1.properties | 11 ++ .../instadisc/FirstRun/resources/Step2.properties | 14 ++ .../instadisc/FirstRun/resources/Step3.properties | 7 + .../src/com/fourisland/instadisc/InstaDiscApp.java | 32 ++- .../com/fourisland/instadisc/InstaDiscThread.java | 7 +- .../src/com/fourisland/instadisc/Item/Item.java | 5 +- .../fourisland/instadisc/Item/Verification.java | 68 +++++++ .../Item/VerificationIDReusedException.java | 17 ++ .../trunk/src/com/fourisland/instadisc/XmlRpc.java | 84 ++++++++ 25 files changed, 1520 insertions(+), 41 deletions(-) delete mode 100644 client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java create mode 100644 client/trunk/src/com/fourisland/instadisc/CloseServerSocketThread.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Database/CloseEntityStoreThread.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Database/CloseEnvironmentThread.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Database/IDConfig.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Database/OldVerID.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.form create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.form create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.form create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/StepEndResults.java create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step1.properties create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step2.properties create mode 100644 client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step3.properties create mode 100644 client/trunk/src/com/fourisland/instadisc/Item/Verification.java create mode 100644 client/trunk/src/com/fourisland/instadisc/Item/VerificationIDReusedException.java create mode 100644 client/trunk/src/com/fourisland/instadisc/XmlRpc.java diff --git a/client/trunk/nbproject/project.properties b/client/trunk/nbproject/project.properties index cb41155..078acf2 100644 --- a/client/trunk/nbproject/project.properties +++ b/client/trunk/nbproject/project.properties @@ -20,10 +20,18 @@ dist.dir=dist dist.jar=${dist.dir}/InstaDisc.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= +file.reference.commons-logging-1.1.jar=../../Desktop/xmlrpc-3.1/lib/commons-logging-1.1.jar +file.reference.sqlite.jar=../../Desktop/javasqlite-20080420/sqlite.jar +file.reference.sqlitejdbc-v052.jar=../../Desktop/sqlitejdbc-v052.jar +file.reference.ws-commons-util-1.0.2.jar=../../Desktop/xmlrpc-3.1/lib/ws-commons-util-1.0.2.jar includes=** jar.compress=false javac.classpath=\ - ${libs.swing-app-framework.classpath} + ${libs.swing-app-framework.classpath}:\ + ${libs.XML-RPC.classpath}:\ + ${file.reference.ws-commons-util-1.0.2.jar}:\ + ${file.reference.commons-logging-1.1.jar}:\ + ${libs.BDB.classpath} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false @@ -45,6 +53,12 @@ javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= +# Property libs.BDB.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.BDB.classpath=../../Desktop/je-3.3.62/lib/je-3.3.62.jar +# Property libs.XML-RPC.classpath is set here just to make sharing of project simpler. +# The library definition has always preference over this property. +libs.XML-RPC.classpath=../../Desktop/xmlrpc-3.1/lib/xmlrpc-client-3.1.jar:../../Desktop/xmlrpc-3.1/lib/xmlrpc-common-3.1.jar:../../Desktop/xmlrpc-3.1/lib/xmlrpc-server-3.1.jar main.class=com.fourisland.instadisc.InstaDiscApp manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF diff --git a/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java b/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java deleted file mode 100644 index af8cecc..0000000 --- a/client/trunk/src/com/fourisland/instadisc/CloseObjectThread.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.fourisland.instadisc; - -import java.io.IOException; -import java.net.ServerSocket; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author hatkirby - */ -class CloseObjectThread implements Runnable{ - - ServerSocket svr; - - public CloseObjectThread(ServerSocket svr) { - this.svr = svr; - } - - public void run() { - try { - svr.close(); - } catch (IOException ex) { - Logger.getLogger(CloseObjectThread.class.getName()).log(Level.SEVERE, null, ex); - } - } - -} diff --git a/client/trunk/src/com/fourisland/instadisc/CloseServerSocketThread.java b/client/trunk/src/com/fourisland/instadisc/CloseServerSocketThread.java new file mode 100644 index 0000000..cfe1820 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/CloseServerSocketThread.java @@ -0,0 +1,33 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +class CloseServerSocketThread implements Runnable { + + ServerSocket svr; + + public CloseServerSocketThread(ServerSocket svr) { + this.svr = svr; + } + + public void run() { + try { + svr.close(); + } catch (IOException ex) { + Logger.getLogger(CloseServerSocketThread.class.getName()).log(Level.SEVERE, null, ex); + } + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/CloseEntityStoreThread.java b/client/trunk/src/com/fourisland/instadisc/Database/CloseEntityStoreThread.java new file mode 100644 index 0000000..14ed006 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/CloseEntityStoreThread.java @@ -0,0 +1,33 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.Database; + +import com.sleepycat.je.DatabaseException; +import com.sleepycat.persist.EntityStore; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class CloseEntityStoreThread implements Runnable { + + EntityStore es; + + public CloseEntityStoreThread(EntityStore es) { + this.es = es; + } + + public void run() { + try { + es.close(); + } catch (DatabaseException ex) { + Logger.getLogger(CloseEntityStoreThread.class.getName()).log(Level.SEVERE, null, ex); + } + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/CloseEnvironmentThread.java b/client/trunk/src/com/fourisland/instadisc/Database/CloseEnvironmentThread.java new file mode 100644 index 0000000..2a23aeb --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/CloseEnvironmentThread.java @@ -0,0 +1,32 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.instadisc.Database; + +import com.sleepycat.je.DatabaseException; +import com.sleepycat.je.Environment; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class CloseEnvironmentThread implements Runnable{ + + Environment svr; + + public CloseEnvironmentThread(Environment e) { + svr = e; + } + + public void run() { + try { + svr.cleanLog(); + svr.close(); + } catch (DatabaseException ex) { + Logger.getLogger(CloseEnvironmentThread.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/IDConfig.java b/client/trunk/src/com/fourisland/instadisc/Database/IDConfig.java new file mode 100644 index 0000000..9799d6d --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/IDConfig.java @@ -0,0 +1,43 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.Database; + +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.PrimaryKey; + +/** + * + * @author hatkirby + */ +@Entity +public class IDConfig { + + @PrimaryKey + private String key; + + private String value; + + public String getKey() + { + return key; + } + + public String getValue() + { + return value; + } + + public void setKey(String key) + { + this.key = key; + } + + public void setValue(String value) + { + this.value = value; + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/OldVerID.java b/client/trunk/src/com/fourisland/instadisc/Database/OldVerID.java new file mode 100644 index 0000000..d8cfcb9 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/OldVerID.java @@ -0,0 +1,31 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.Database; + +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.PrimaryKey; + +/** + * + * @author hatkirby + */ +@Entity +public class OldVerID { + + @PrimaryKey + private Integer ID; + + public void setID(Integer ID) + { + this.ID = ID; + } + + public Integer getID() + { + return ID; + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java new file mode 100644 index 0000000..1f905ee --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java @@ -0,0 +1,129 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.instadisc.Database; + +import com.sleepycat.je.DatabaseException; +import com.sleepycat.je.Environment; +import com.sleepycat.je.EnvironmentConfig; +import com.sleepycat.persist.EntityCursor; +import com.sleepycat.persist.EntityStore; +import com.sleepycat.persist.PrimaryIndex; +import com.sleepycat.persist.StoreConfig; +import java.io.File; +import java.util.Iterator; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author hatkirby + */ +public class Wrapper { + + public static Environment e = null; + public static EntityStore es = null; + public static PrimaryIndex oldVerID; + public static PrimaryIndex idConfig; + + public static void init(String loc) { + + EnvironmentConfig envConfig = new EnvironmentConfig(); + StoreConfig esConfig = new StoreConfig(); + envConfig.setAllowCreate(true); + esConfig.setAllowCreate(true); + try { + e = new Environment(new File(loc + "db"), envConfig); + es = new EntityStore(e, "EntityStore", esConfig); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + System.exit(1); + } + Runtime.getRuntime().addShutdownHook(new Thread(new CloseEnvironmentThread(e))); + Runtime.getRuntime().addShutdownHook(new Thread(new CloseEntityStoreThread(es))); + + try { + oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class); + idConfig = es.getPrimaryIndex(String.class, IDConfig.class); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static String getConfig(String key) + { + try { + return idConfig.get(key).getValue(); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + return ""; + } + } + + public static void setConfig(String key, String value) + { + try { + if (idConfig.contains(key)) { + IDConfig temp = idConfig.get(key); + temp.setValue(value); + idConfig.put(temp); + } else { + IDConfig temp = new IDConfig(); + temp.setKey(key); + temp.setValue(value); + idConfig.put(temp); + } + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static boolean containsOldVerID(Integer id) + { + try { + return oldVerID.contains(id); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } + + public static int countOldVerID() + { + try { + return (int) oldVerID.count(); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + return 0; + } + } + + public static void emptyOldVerID() + { + try { + EntityCursor ec = oldVerID.entities(); + try { + Iterator i = ec.iterator(); + while (i.hasNext()) { + i.remove(); + } + } finally { + ec.close(); + } + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public static void addOldVerID(Integer id) + { + try { + OldVerID temp = new OldVerID(); + temp.setID(id); + oldVerID.put(temp); + } catch (DatabaseException ex) { + Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java new file mode 100644 index 0000000..0919f21 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/FirstRunWizard.java @@ -0,0 +1,35 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.FirstRun; + +import javax.swing.JFrame; + +/** + * + * @author hatkirby + */ +public class FirstRunWizard implements Runnable { + + public void run() + { + Step1 s1 = new Step1(new JFrame(), true); + s1.setVisible(true); + if (StepEndResults.ok) + { + StepEndResults.ok = false; + Step2 s2 = new Step2(new JFrame(), true); + s2.setVisible(true); + if (StepEndResults.ok) + { + StepEndResults.ok = false; + Step3 s3 = new Step3(new JFrame(), true); + s3.setVisible(true); + } + } + System.exit(0); + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.form b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.form new file mode 100644 index 0000000..b186d78 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.form @@ -0,0 +1,142 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.java new file mode 100644 index 0000000..c0abbfa --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step1.java @@ -0,0 +1,156 @@ +/* + * Step1.java + * + * Created on July 28, 2008, 4:04 PM + */ + +package com.fourisland.instadisc.FirstRun; + +/** + * + * @author hatkirby + */ +public class Step1 extends javax.swing.JDialog { + + /** Creates new form Step1 */ + public Step1(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel2 = new javax.swing.JLabel(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTextArea2 = new javax.swing.JTextArea(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(Step1.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jScrollPane1.setName("jScrollPane1"); // NOI18N + + jTextArea1.setBackground(resourceMap.getColor("jTextArea1.background")); // NOI18N + jTextArea1.setColumns(20); + jTextArea1.setEditable(false); + jTextArea1.setLineWrap(true); + jTextArea1.setRows(5); + jTextArea1.setText(resourceMap.getString("jTextArea1.text")); // NOI18N + jTextArea1.setWrapStyleWord(true); + jTextArea1.setName("jTextArea1"); // NOI18N + jScrollPane1.setViewportView(jTextArea1); + + jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N + jLabel2.setName("jLabel2"); // NOI18N + + jScrollPane2.setName("jScrollPane2"); // NOI18N + + jTextArea2.setBackground(resourceMap.getColor("jTextArea2.background")); // NOI18N + jTextArea2.setColumns(20); + jTextArea2.setEditable(false); + jTextArea2.setLineWrap(true); + jTextArea2.setRows(5); + jTextArea2.setText(resourceMap.getString("jTextArea2.text")); // NOI18N + jTextArea2.setWrapStyleWord(true); + jTextArea2.setName("jTextArea2"); // NOI18N + jScrollPane2.setViewportView(jTextArea2); + + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(134, 134, 134) + .addComponent(jLabel2) + .addContainerGap(178, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGap(43, 43, 43) + .addComponent(jLabel1) + .addContainerGap(56, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(57, 57, 57) + .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE) + .addGap(76, 76, 76)) + .addGroup(layout.createSequentialGroup() + .addGap(202, 202, 202) + .addComponent(jButton1) + .addContainerGap(235, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addGap(23, 23, 23) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(30, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jButton1) + .addContainerGap(30, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + StepEndResults.ok = true; + this.setVisible(false); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Step1 dialog = new Step1(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextArea jTextArea2; + // End of variables declaration//GEN-END:variables + +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.form b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.form new file mode 100644 index 0000000..e408762 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.form @@ -0,0 +1,176 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java new file mode 100644 index 0000000..5460bc4 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step2.java @@ -0,0 +1,219 @@ +/* + * Step2.java + * + * Created on July 28, 2008, 4:18 PM + */ +package com.fourisland.instadisc.FirstRun; + +import com.fourisland.instadisc.Database.Wrapper; +import com.fourisland.instadisc.XmlRpc; +import java.net.MalformedURLException; +import java.net.URL; + +/** + * + * @author hatkirby + */ +public class Step2 extends javax.swing.JDialog { + + /** Creates new form Step2 */ + public Step2(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jLabel2 = new javax.swing.JLabel(); + jTextField1 = new javax.swing.JTextField(); + jTextField2 = new javax.swing.JTextField(); + jTextField3 = new javax.swing.JTextField(); + jLabel3 = new javax.swing.JLabel(); + jLabel4 = new javax.swing.JLabel(); + jLabel5 = new javax.swing.JLabel(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(Step2.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jScrollPane1.setName("jScrollPane1"); // NOI18N + + jTextArea1.setBackground(resourceMap.getColor("jTextArea1.background")); // NOI18N + jTextArea1.setColumns(20); + jTextArea1.setEditable(false); + jTextArea1.setRows(5); + jTextArea1.setText(resourceMap.getString("jTextArea1.text")); // NOI18N + jTextArea1.setName("jTextArea1"); // NOI18N + jScrollPane1.setViewportView(jTextArea1); + + jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N + jLabel2.setName("jLabel2"); // NOI18N + + jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N + jTextField1.setName("jTextField1"); // NOI18N + + jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N + jTextField2.setName("jTextField2"); // NOI18N + + jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N + jTextField3.setName("jTextField3"); // NOI18N + + jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N + jLabel3.setName("jLabel3"); // NOI18N + + jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N + jLabel4.setName("jLabel4"); // NOI18N + + jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N + jLabel5.setName("jLabel5"); // NOI18N + + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1) + .addGroup(layout.createSequentialGroup() + .addGap(12, 12, 12) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(jLabel3) + .addComponent(jLabel4)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE) + .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE) + .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(24, 24, 24) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel3)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel4)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jButton1) + .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(47, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + if (jTextField1.getText().equals("")) { + jLabel5.setText("Error: You forgot to enter a username"); + } else { + if (jTextField2.getText().equals("")) { + jLabel5.setText("Error: You forgot to enter a password"); + } else { + if (jTextField3.getText().equals("")) { + jLabel5.setText("Error: You forgot to enter a Central Server URL"); + } else { + try { + URL url = new URL(jTextField3.getText()); + + XmlRpc xmlrpc = new XmlRpc("checkRegistration", jTextField3.getText(), jTextField1.getText(), jTextField2.getText()); + Integer r = (Integer) xmlrpc.execute(); + + if (r == 1) + { + jLabel5.setText("Error: No registration exists on the specified Central Server with the specified UN/PW combination"); + } else { + Wrapper.setConfig("username", jTextField1.getText()); + Wrapper.setConfig("password", jTextField2.getText()); + Wrapper.setConfig("centralServerURL", jTextField3.getText()); + + StepEndResults.ok = true; + this.setVisible(false); + } + } catch (MalformedURLException ex) { + jLabel5.setText("Error: The Central Server URL is malformed"); + } catch (NullPointerException ex) { + jLabel5.setText("Error: The Central Server URL specified does not exist"); + } + } + } + } + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + Step2 dialog = new Step2(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + private javax.swing.JTextField jTextField1; + private javax.swing.JTextField jTextField2; + private javax.swing.JTextField jTextField3; + // End of variables declaration//GEN-END:variables +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.form b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.form new file mode 100644 index 0000000..473876c --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.form @@ -0,0 +1,100 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.java new file mode 100644 index 0000000..5eb7840 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/Step3.java @@ -0,0 +1,122 @@ +/* + * Step3.java + * + * Created on July 28, 2008, 4:51 PM + */ + +package com.fourisland.instadisc.FirstRun; + +/** + * + * @author hatkirby + */ +public class Step3 extends javax.swing.JDialog { + + /** Creates new form Step3 */ + public Step3(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jButton1 = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.fourisland.instadisc.InstaDiscApp.class).getContext().getResourceMap(Step3.class); + jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N + jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N + jLabel1.setName("jLabel1"); // NOI18N + + jScrollPane1.setName("jScrollPane1"); // NOI18N + + jTextArea1.setBackground(resourceMap.getColor("jTextArea1.background")); // NOI18N + jTextArea1.setColumns(20); + jTextArea1.setEditable(false); + jTextArea1.setRows(5); + jTextArea1.setText(resourceMap.getString("jTextArea1.text")); // NOI18N + jTextArea1.setName("jTextArea1"); // NOI18N + jScrollPane1.setViewportView(jTextArea1); + + jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N + jButton1.setName("jButton1"); // NOI18N + jButton1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton1ActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(12, 12, 12) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)) + .addComponent(jLabel1))) + .addGroup(layout.createSequentialGroup() + .addGap(167, 167, 167) + .addComponent(jButton1))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + StepEndResults.ok = true; + this.setVisible(false); + }//GEN-LAST:event_jButton1ActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + Step3 dialog = new Step3(new javax.swing.JFrame(), true); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton jButton1; + private javax.swing.JLabel jLabel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea jTextArea1; + // End of variables declaration//GEN-END:variables + +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/StepEndResults.java b/client/trunk/src/com/fourisland/instadisc/FirstRun/StepEndResults.java new file mode 100644 index 0000000..ccdd4b9 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/StepEndResults.java @@ -0,0 +1,16 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.FirstRun; + +/** + * + * @author hatkirby + */ +public class StepEndResults { + + public static boolean ok = false; + +} diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step1.properties b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step1.properties new file mode 100644 index 0000000..8da8235 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step1.properties @@ -0,0 +1,11 @@ +jLabel1.text=Welcome to the InstaDisc FirstRun Wizard! +jTextArea1.text=This is, apparently, the first time you've run InstaDisc, so you need to step through me before being able to use InstaDisc.\n\nFirst, ensure that you've chosen and signed up for a Central Server. If you haven't, or don't even know what that means, please read:\n +#NOI18N +jTextArea1.background=239, 235, 231 +jLabel2.text=Choosing a Central Server +#NOI18N +jLabel1.font=DejaVu Sans-Plain-18 +jTextArea2.text=before continuing. If you do know what you're doing, feel free to click on the NEXT button and get on with InstaDisc. +#NOI18N +jTextArea2.background=239, 235, 231 +jButton1.text=Next diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step2.properties b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step2.properties new file mode 100644 index 0000000..0c1f735 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step2.properties @@ -0,0 +1,14 @@ +jLabel1.text=Central Server Details +#NOI18N +jLabel1.font=DejaVu Sans-Plain-18 +jTextArea1.text=To use InstaDisc, you must have chosen and signed up\nfor a Central Server. Please input below the details it\ngave you after registration. +#NOI18N +jTextArea1.background=239, 235, 231 +jLabel2.text=Username: +jTextField1.text= +jTextField2.text= +jTextField3.text= +jLabel3.text=Password: +jLabel4.text=Central Server URL: +jLabel5.text= +jButton1.text=Next diff --git a/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step3.properties b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step3.properties new file mode 100644 index 0000000..948623f --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/FirstRun/resources/Step3.properties @@ -0,0 +1,7 @@ +jLabel1.text=Congradulations +#NOI18N +jLabel1.font=DejaVu Sans-Plain-18 +jTextArea1.text=YAY! You've successfully set up InstaDisc. To start using\nInstaDisc, quit this wizard (the DONE button), open\nInstaDisc again, and have fun!\n\nIf you're ever confused, remember, the Help menu is\nyour friend. +#NOI18N +jTextArea1.background=239, 235, 231 +jButton1.text=Done diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscApp.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscApp.java index 806460a..ffac22d 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscApp.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscApp.java @@ -1,9 +1,11 @@ /* * InstaDiscApp.java */ - package com.fourisland.instadisc; +import com.fourisland.instadisc.Database.Wrapper; +import com.fourisland.instadisc.FirstRun.FirstRunWizard; +import java.io.File; import org.jdesktop.application.Application; import org.jdesktop.application.SingleFrameApplication; @@ -15,7 +17,8 @@ public class InstaDiscApp extends SingleFrameApplication { /** * At startup create and show the main frame of the application. */ - @Override protected void startup() { + @Override + protected void startup() { show(new InstaDiscView(this)); } @@ -24,7 +27,8 @@ public class InstaDiscApp extends SingleFrameApplication { * Windows shown in our application come fully initialized from the GUI * builder, so this additional configuration is not needed. */ - @Override protected void configureWindow(java.awt.Window root) { + @Override + protected void configureWindow(java.awt.Window root) { } /** @@ -39,6 +43,26 @@ public class InstaDiscApp extends SingleFrameApplication { * Main method launching the application. */ public static void main(String[] args) { - launch(InstaDiscApp.class, args); + if (args.length > 0) { + File db = new File(args[0] + "db"); + if (!db.exists()) { + db.mkdir(); + } + + Wrapper.init(args[0]); + if (args.length > 1) { + if (args[1].equals("-r")) { + XmlRpc xmlrpc = new XmlRpc("requestRetained"); + xmlrpc.execute(); + } else if (args[1].equals("-n")) { + Thread th = new Thread(new FirstRunWizard()); + th.start(); + } + } else { + launch(InstaDiscApp.class, args); + } + } else { + System.out.println("Oops, you seem to be running this application incorrectly. Try running it using the startup script provided."); + } } } diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java index fcde8d8..55baf28 100644 --- a/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java +++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscThread.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -30,13 +31,15 @@ public class InstaDiscThread implements Runnable { ServerSocket svr = new ServerSocket(); java.net.InetSocketAddress addr = new java.net.InetSocketAddress(4444); svr.bind(addr); - Runtime.getRuntime().addShutdownHook(new Thread(new CloseObjectThread(svr))); + Runtime.getRuntime().addShutdownHook(new Thread(new CloseServerSocketThread(svr))); while (!cancelled) { try { Socket s = svr.accept(); HandleItemThread hit = new HandleItemThread(s); Thread hitt = new Thread(hit); hitt.start(); + } catch (SocketException ex) { + cancel(); } catch (Exception ex) { cancel(); Logger.getLogger(InstaDiscThread.class.getName()).log(Level.SEVERE, null, ex); @@ -105,7 +108,7 @@ class HandleItemThread implements Runnable { } catch (IOException ex) { Logger.getLogger(HandleItemThread.class.getName()).log(Level.SEVERE, null, ex); } - + Item idI = new Item(headerMap); idI.start(); } catch (IOException ex) { diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java index fd52d5f..56bc03c 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java @@ -5,6 +5,7 @@ package com.fourisland.instadisc.Item; +import com.fourisland.instadisc.XmlRpc; import java.util.HashMap; /** @@ -25,7 +26,9 @@ public class Item { WellFormedItem wfi = new WellFormedItem(this); if (wfi.check()) { - + XmlRpc xmlrpc = new XmlRpc("deleteItem"); + xmlrpc.addParam(Integer.decode(headerMap.get("ID"))); + xmlrpc.execute(); } } } diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Verification.java b/client/trunk/src/com/fourisland/instadisc/Item/Verification.java new file mode 100644 index 0000000..57c69f4 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Item/Verification.java @@ -0,0 +1,68 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.instadisc.Item; + +import com.fourisland.instadisc.Database.Wrapper; +import java.util.Random; + +/** + * + * @author hatkirby + */ +public class Verification { + + private String username; + private String hash; + private int id; + + public Verification() { + Random r = new Random(); + id = r.nextInt(Integer.MAX_VALUE); + username = Wrapper.getConfig("username"); + String temp = username + ":" + Wrapper.getConfig("password") + ":" + id; + MD5 md5 = new MD5(temp); + hash = md5.hash(); + } + + public Verification(int ID) throws VerificationIDReusedException { + id = ID; + if (Wrapper.containsOldVerID(id)) { + throw new VerificationIDReusedException(); + } else { + if (Wrapper.countOldVerID() == 100) { + Wrapper.emptyOldVerID(); + } + Wrapper.addOldVerID(id); + } + + username = Wrapper.getConfig("username"); + String temp = username + ":" + Wrapper.getConfig("password") + ":" + id; + MD5 md5 = new MD5(temp); + hash = md5.hash(); + System.out.println(temp); + } + + public Verification(String username, String password) { + Random r = new Random(); + id = r.nextInt(Integer.MAX_VALUE); + String temp = username + ":" + password + ":" + id; + MD5 md5 = new MD5(temp); + hash = md5.hash(); + this.username = username; + } + + public String getUsername() + { + return username; + } + + public String getHash() { + return hash; + } + + public int getID() { + return id; + } +} diff --git a/client/trunk/src/com/fourisland/instadisc/Item/VerificationIDReusedException.java b/client/trunk/src/com/fourisland/instadisc/Item/VerificationIDReusedException.java new file mode 100644 index 0000000..e56f60e --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/Item/VerificationIDReusedException.java @@ -0,0 +1,17 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.instadisc.Item; + +/** + * + * @author hatkirby + */ +class VerificationIDReusedException extends SecurityException { + + public VerificationIDReusedException() { + } + +} diff --git a/client/trunk/src/com/fourisland/instadisc/XmlRpc.java b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java new file mode 100644 index 0000000..8c22155 --- /dev/null +++ b/client/trunk/src/com/fourisland/instadisc/XmlRpc.java @@ -0,0 +1,84 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.instadisc; + +import com.fourisland.instadisc.Database.Wrapper; +import com.fourisland.instadisc.Item.Verification; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; + +/** + * + * @author hatkirby + */ +public class XmlRpc { + + private String function; + private Object[] params; + private int step = 3; + private String url = ""; + + public XmlRpc(String function) { + this.function = function; + if (url.equals("")) + { + url = Wrapper.getConfig("centralServerURL"); + } + + Verification ver = new Verification(); + params = new Object[3]; + params[0] = ver.getUsername(); + params[1] = ver.getHash(); + params[2] = ver.getID(); + } + + public XmlRpc(String function, String url, String username, String password) + { + this.function = function; + this.url = url; + + Verification ver = new Verification(username, password); + params = new Object[3]; + params[0] = ver.getUsername(); + params[1] = ver.getHash(); + params[2] = ver.getID(); + } + + public void addParam(Object param) + { + Object oldParams[] = params; + Object temp[] = new Object[step+1]; + int i=0; + for (i=0;i