chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1000255 - in /incubator/chemistry/opencmis-swingclient/trunk: pom.xml src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java src/main/resources/scripts/CMIS.groovy src/main/resources/scripts/startup.groovy
Date Wed, 22 Sep 2010 22:00:18 GMT
Author: fmui
Date: Wed Sep 22 22:00:18 2010
New Revision: 1000255

URL: http://svn.apache.org/viewvc?rev=1000255&view=rev
Log:
- made the Swing Client even more Groovy

Added:
    incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
Modified:
    incubator/chemistry/opencmis-swingclient/trunk/pom.xml
    incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
    incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy

Modified: incubator/chemistry/opencmis-swingclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/pom.xml?rev=1000255&r1=1000254&r2=1000255&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/pom.xml (original)
+++ incubator/chemistry/opencmis-swingclient/trunk/pom.xml Wed Sep 22 22:00:18 2010
@@ -231,7 +231,7 @@
         </dependency>
         <dependency>
             <groupId>org.codehaus.groovy</groupId>
-            <artifactId>groovy-all</artifactId>
+            <artifactId>groovy</artifactId>
             <version>1.7.5</version>
         </dependency>
         <dependency>

Modified: incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java?rev=1000255&r1=1000254&r2=1000255&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
(original)
+++ incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
Wed Sep 22 22:00:18 2010
@@ -162,7 +162,6 @@ public class ClientFrame extends JFrame 
                     if (stream == null) {
                         throw new Exception("Groovy startup script is missing!");
                     } else {
-
                         BufferedReader reader = new BufferedReader(new InputStreamReader(stream,
"UTF-8"));
                         StringBuilder sb = new StringBuilder();
                         String s;
@@ -173,6 +172,8 @@ public class ClientFrame extends JFrame 
                         }
 
                         console.getInputArea().setText(sb.toString());
+
+                        reader.close();
                     }
                 } catch (Exception ex) {
                     ClientHelper.showError(thisFrame, ex);

Added: incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy?rev=1000255&view=auto
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
(added)
+++ incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
Wed Sep 22 22:00:18 2010
@@ -0,0 +1,91 @@
+package scripts
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.chemistry.opencmis.commons.*
+import org.apache.chemistry.opencmis.commons.data.*
+import org.apache.chemistry.opencmis.commons.enums.*
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.client.api.*
+
+class CMIS {
+    
+    Session session
+    
+    CMIS(Session session) {
+        this.session = session
+    }
+    
+    CmisObject getObject(id) {
+        CmisObject result = null
+        
+        if(id instanceof CmisObject) {
+            result = id
+        } else if(id instanceof ObjectId) {
+            result = session.getObject(id)
+        } else if(id instanceof String) {
+            if(id.startsWith("/")) {
+                result = session.getObjectByPath(id)
+            } else {
+                result = session.getObject(session.createObjectId(id))
+            }
+        }
+        
+        if(result == null) {
+            throw new Exception("Object not found!")
+        }
+        
+        return result
+    }
+    
+    void printProperties(id) {
+        CmisObject object = getObject(id)
+        
+        for(Property prop: object.getProperties()) {
+            printProperty(prop)
+        }
+    }
+    
+    void printProperty(Property prop) {
+        println prop.getId() + ": " + prop.getValuesAsString()
+    }
+    
+    Folder createFolder(parent, String name, String type = "cmis:folder") {
+        
+        CmisObject parentFolder = getObject(parent)
+        if(!(parentFolder instanceof Folder)) {
+            throw new Exception("Parent is not a folder!")
+        }
+        
+        def properties = [
+                    (PropertyIds.OBJECT_TYPE_ID): type, 
+                    (PropertyIds.NAME): name
+                ]
+        
+        return ((Folder) parentFolder).createFolder(properties, session.getDefaultContext())
+    }
+    
+    Document createTextDocument(parent, String name, String content, String type = "cmis:document",

+    VersioningState versioningState = VersioningState.MAJOR) {
+        
+        CmisObject parentFolder = getObject(parent)
+        if(!(parentFolder instanceof Folder)) {
+            throw new Exception("Parent is not a folder!")
+        }
+        
+        def properties = [
+                    (PropertyIds.OBJECT_TYPE_ID): type,
+                    (PropertyIds.NAME): name
+                ]
+        
+        def stream = new ByteArrayInputStream(content.bytes)
+        def contentStream = new ContentStreamImpl(name, content.bytes.length, "text/plain",
stream)
+        
+        return ((Folder) parentFolder).createDocument(properties, contentStream, 
+        versioningState, session.getDefaultContext())
+    }
+    
+    void delete(id) {
+        getObject(id).delete(true)
+    }
+}
\ No newline at end of file

Modified: incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy?rev=1000255&r1=1000254&r2=1000255&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
(original)
+++ incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
Wed Sep 22 22:00:18 2010
@@ -1,17 +1,36 @@
 import org.apache.chemistry.opencmis.commons.*
 import org.apache.chemistry.opencmis.commons.data.*
+import org.apache.chemistry.opencmis.commons.enums.*
 import org.apache.chemistry.opencmis.client.api.*
-import org.apache.chemistry.opencmis.commons.enums.*;
 
-println "Variable 'session' is bound to the current OpenCMIS session."
-println ""
-println "Reposiory: " + session.getRepositoryInfo().getName()
-println ""
+// variable 'session' is bound to the current OpenCMIS session
 
+// print the repository name - Java style
+println "Repository: " + session.getRepositoryInfo().getName()
+
+// print the repository name - Groovy style
+println "Repository: " + session.repositoryInfo.name
+
+
+// get root folder
 Folder root = session.getRootFolder()
 println "--- Root Folder: " + root.getName() + " ---"
-println ""
 
+// print root folder children
 for(CmisObject object: root.getChildren()) { 
   println object.getName() + " \t(" + object.getType().getId() + ")"
 }
+
+// CMIS helper script
+def cmis = new scripts.CMIS(session)
+
+cmis.printProperties "/"                    // access by path
+cmis.printProperties session.rootFolder.id  // access by id
+cmis.printProperties session.rootFolder     // access by object
+
+// Folder folder = cmis.createFolder("/", "test-folder", "cmis:folder")
+// cmis.delete folder
+
+// Document doc = cmis.createTextDocument("/", "test.txt", "Hello World!", "cmis:document")
+
+// see /scripts/CMIS.groovy for more methods
\ No newline at end of file



Mime
View raw message