chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1428028 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main: java/org/apache/chemistry/opencmis/workbench/ resources/META-INF/
Date Wed, 02 Jan 2013 20:58:21 GMT
Author: fmui
Date: Wed Jan  2 20:58:21 2013
New Revision: 1428028

URL: http://svn.apache.org/viewvc?rev=1428028&view=rev
Log:
CMIS-610: Workbench: external config and script files

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/META-INF/README

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java?rev=1428028&r1=1428027&r2=1428028&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
Wed Jan  2 20:58:21 2013
@@ -29,7 +29,9 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
+import java.io.File;
 import java.lang.reflect.Method;
+import java.net.URI;
 import java.util.Collections;
 import java.util.List;
 import java.util.prefs.Preferences;
@@ -52,6 +54,8 @@ public class ClientFrame extends JFrame 
 
     private static final long serialVersionUID = 1L;
 
+    public static final String SYSPROP_SCRIPTS = ClientSession.WORKBENCH_PREFIX + "scripts";
+
     private static final String WINDOW_TITLE = "CMIS Workbench";
 
     private static final int BUTTON_CONNECT = 0;
@@ -217,7 +221,7 @@ public class ClientFrame extends JFrame 
         toolbarConsolePopup = new JPopupMenu();
         for (FileEntry fe : readScriptLibrary()) {
             JMenuItem menuItem = new JMenuItem(fe.getName());
-            final String file = fe.getFile();
+            final URI file = fe.getFile();
             menuItem.addActionListener(new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) {
@@ -389,8 +393,18 @@ public class ClientFrame extends JFrame 
     }
 
     private List<FileEntry> readScriptLibrary() {
-        List<FileEntry> result = ClientHelper.readFileProperties(GROOVY_SCRIPT_FOLDER
+ GROOVY_SCRIPT_LIBRARY,
-                GROOVY_SCRIPT_FOLDER);
+
+        URI propFile = null;
+
+        String externalScripts = System.getProperty(SYSPROP_SCRIPTS);
+        if (externalScripts == null) {
+            propFile = ClientHelper.getClasspathURI(GROOVY_SCRIPT_FOLDER + GROOVY_SCRIPT_LIBRARY);
+        } else {
+            propFile = (new File(externalScripts)).toURI();
+        }
+
+        List<FileEntry> result = ClientHelper.readFileProperties(propFile);
+
         if (result == null) {
             result = Collections.singletonList(new FileEntry("Groovy Console", null));
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1428028&r1=1428027&r2=1428028&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
Wed Jan  2 20:58:21 2013
@@ -47,6 +47,7 @@ import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Writer;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -467,69 +468,136 @@ public class ClientHelper {
         return value.toString();
     }
 
-    public static String readFileAndRemoveHeader(String file) {
+    public static URI getClasspathURI(String path) {
+        try {
+            return ClientHelper.class.getResource(path).toURI();
+        } catch (URISyntaxException e) {
+            // not very likely
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public static String readFileAndRemoveHeader(final URI file) {
         if (file == null) {
             return "";
         }
 
-        InputStream stream = ClientHelper.class.getResourceAsStream(file);
+        final InputStream stream;
+        try {
+            stream = file.toURL().openStream();
+        } catch (Exception e) {
+            return "";
+        }
+
+        final String result = readStreamAndRemoveHeader(stream);
+
+        try {
+            stream.close();
+        } catch (IOException e) {
+            // ignore
+        }
+
+        return result;
+    }
+
+    public static String readStreamAndRemoveHeader(final InputStream stream) {
         if (stream == null) {
             return "";
-        } else {
-            try {
-                BufferedReader reader = new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
-                StringBuilder sb = new StringBuilder();
-                String s;
-                boolean header = true;
+        }
 
-                while ((s = reader.readLine()) != null) {
-                    // remove header
-                    if (header) {
-                        String st = s.trim();
-                        if (st.length() == 0) {
-                            header = false;
-                            continue;
-                        }
-
-                        char c = st.charAt(0);
-                        header = (c == '/') || (c == '*') || (c == '#');
-                        if (header) {
-                            continue;
-                        }
+        try {
+            final BufferedReader reader = new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
+            final StringBuilder sb = new StringBuilder();
+            String s;
+            boolean header = true;
+
+            while ((s = reader.readLine()) != null) {
+                // remove header
+                if (header) {
+                    String st = s.trim();
+                    if (st.length() == 0) {
+                        header = false;
+                        continue;
                     }
 
-                    sb.append(s);
-                    sb.append("\n");
+                    char c = st.charAt(0);
+                    header = (c == '/') || (c == '*') || (c == '#');
+                    if (header) {
+                        continue;
+                    }
                 }
 
-                reader.close();
-
-                return sb.toString();
-            } catch (Exception e) {
-                return "";
+                sb.append(s);
+                sb.append("\n");
             }
+
+            reader.close();
+
+            return sb.toString();
+        } catch (Exception e) {
+            return "";
         }
     }
 
-    public static List<FileEntry> readFileProperties(String propertiesFile, String
path) {
-        InputStream stream = ClientHelper.class.getResourceAsStream(propertiesFile);
-        if (stream == null) {
+    public static List<FileEntry> readFileProperties(URI propertiesFile) {
+
+        final InputStream stream;
+        try {
+            stream = propertiesFile.toURL().openStream();
+            if (stream == null) {
+                return null;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
             return null;
         }
 
+        String classpathParent = null;
+        if ("classpath".equalsIgnoreCase(propertiesFile.getScheme())) {
+            String path = propertiesFile.getSchemeSpecificPart();
+            int x = path.lastIndexOf('/');
+            if (x > -1) {
+                classpathParent = path.substring(0, x);
+            }
+        }
+
+        String fileParent = null;
+        if ("file".equalsIgnoreCase(propertiesFile.getScheme())) {
+            fileParent = (new File(propertiesFile)).getParent();
+        }
+
         try {
             Properties properties = new Properties();
             properties.load(stream);
             stream.close();
 
-            List<FileEntry> result = new ArrayList<FileEntry>();
+            final List<FileEntry> result = new ArrayList<FileEntry>();
             for (String file : properties.stringPropertyNames()) {
-                result.add(new FileEntry(properties.getProperty(file), path + file));
+
+                try {
+                    URI uri = null;
+
+                    if (classpathParent != null) {
+                        uri = ClientHelper.class.getResource(classpathParent + "/" + file).toURI();
+                    }
+
+                    if (fileParent != null) {
+                        uri = (new File(fileParent, file)).toURI();
+                    }
+
+                    if (uri != null) {
+                        result.add(new FileEntry(properties.getProperty(file), uri));
+                    }
+                } catch (URISyntaxException e) {
+                    // ignore entry
+                }
             }
             Collections.sort(result);
 
             return result;
         } catch (IOException e) {
+            e.printStackTrace();
             return null;
         } finally {
             try {
@@ -539,7 +607,7 @@ public class ClientHelper {
         }
     }
 
-    public static Console openConsole(final Component parent, final ClientModel model, final
String file) {
+    public static Console openConsole(final Component parent, final ClientModel model, final
URI file) {
         try {
             parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
@@ -554,12 +622,14 @@ public class ClientHelper {
 
             addConsoleMenu(cmisMenu, "CMIS 1.0 Specification", new URI(
                     "http://docs.oasis-open.org/cmis/CMIS/v1.0/os/cmis-spec-v1.0.html"));
+            addConsoleMenu(cmisMenu, "CMIS 1.1 Specification", new URI(
+                    "http://docs.oasis-open.org/cmis/CMIS/v1.1/CMIS-v1.1.html"));
             addConsoleMenu(cmisMenu, "OpenCMIS Documentation",
                     new URI("http://chemistry.apache.org/java/opencmis.html"));
             addConsoleMenu(cmisMenu, "OpenCMIS Client API JavaDoc", new URI(
-                    "http://chemistry.apache.org/java/0.7.0/maven/apidocs/"));
+                    "http://chemistry.apache.org/java/0.8.0/maven/apidocs/"));
 
-            console.getInputArea().setText(ClientHelper.readFileAndRemoveHeader(file));
+            console.getInputArea().setText(readFileAndRemoveHeader(file));
 
             return console;
         } catch (Exception ex) {
@@ -630,9 +700,9 @@ public class ClientHelper {
 
     public static class FileEntry implements Comparable<FileEntry> {
         private final String name;
-        private final String file;
+        private final URI file;
 
-        public FileEntry(String name, String file) {
+        public FileEntry(String name, URI file) {
             this.name = name;
             this.file = file;
         }
@@ -641,7 +711,7 @@ public class ClientHelper {
             return name;
         }
 
-        public String getFile() {
+        public URI getFile() {
             return file;
         }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java?rev=1428028&r1=1428027&r2=1428028&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
Wed Jan  2 20:58:21 2013
@@ -29,6 +29,8 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.io.File;
+import java.net.URI;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -75,6 +77,7 @@ public class LoginDialog extends JDialog
     public static final String SYSPROP_COOKIES = ClientSession.WORKBENCH_PREFIX + "cookies";
     public static final String SYSPROP_USER = ClientSession.WORKBENCH_PREFIX + "user";
     public static final String SYSPROP_PASSWORD = ClientSession.WORKBENCH_PREFIX + "password";
+    public static final String SYSPROP_CONFIGS = ClientSession.WORKBENCH_PREFIX + "configs";
 
     private static final String CONFIGS_FOLDER = "/configs/";
     private static final String CONFIGS_LIBRARY = "config-library.properties";
@@ -256,7 +259,16 @@ public class LoginDialog extends JDialog
         final JPanel expertPanel = new JPanel(new BorderLayout());
         expertPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
 
-        sessionConfigurations = ClientHelper.readFileProperties(CONFIGS_FOLDER + CONFIGS_LIBRARY,
CONFIGS_FOLDER);
+        URI propFile = null;
+
+        String externalConfigs = System.getProperty(SYSPROP_CONFIGS);
+        if (externalConfigs == null) {
+            propFile = ClientHelper.getClasspathURI(CONFIGS_FOLDER + CONFIGS_LIBRARY);
+        } else {
+            propFile = (new File(externalConfigs)).toURI();
+        }
+
+        sessionConfigurations = ClientHelper.readFileProperties(propFile);
 
         final JComboBox configs = new JComboBox();
         configs.setMaximumRowCount(20);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/META-INF/README
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/META-INF/README?rev=1428028&r1=1428027&r2=1428028&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/META-INF/README
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/META-INF/README
Wed Jan  2 20:58:21 2013
@@ -61,4 +61,7 @@ cmis.workbench.version.maxItemsPerPage
 
 Others:
 
-cmis.workbench.acceptSelfSignedCertificates - disable SSL certificate check (true/false)
\ No newline at end of file
+cmis.workbench.acceptSelfSignedCertificates - disable SSL certificate check (true/false)
+
+cmis.workbench.configs - path to a repository configuration library properties file
+cmis.workbench.scripts - path to Groovy scripts library properties file
\ No newline at end of file



Mime
View raw message