You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by un...@apache.org on 2009/05/10 21:47:30 UTC
svn commit: r773395 - in
/incubator/chemistry/trunk/chemistry/chemistry-jsclient: ./ webroot/
Author: uncled
Date: Sun May 10 19:47:29 2009
New Revision: 773395
URL: http://svn.apache.org/viewvc?rev=773395&view=rev
Log:
CMIS-15: Getting started on the JS Client
Added:
incubator/chemistry/trunk/chemistry/chemistry-jsclient/
incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-body.png (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-twocols.png (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/logo.png (with props)
incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css (with props)
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt Sun May 10 19:47:29 2009
@@ -0,0 +1,8 @@
+Contains the JavaScript Client, Tests and Examples.
+
+The JavaScript Client library is designed to run from the same server (URL) as
+your CMIS Server. Depending on the implementation the cmisclient.js (and the additional
+html files) can be dropped into the repository and accessed with a browser.
+
+To get started just drop all the files in the webroot in your repository and access
+the index.html.
\ No newline at end of file
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-body.png
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-body.png?rev=773395&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-body.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-twocols.png
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-twocols.png?rev=773395&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/bg-twocols.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js Sun May 10 19:47:29 2009
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The CMIS javascript client gives access to a CMIS document management system
+ * from client-side java script code.
+ *
+ * @version $Rev: $, $Date: 2007-03-27 16:30:52 +0200 (Tue, 27 Mar 2007) $
+ */
+
+CMISClient = function (url) {
+ this.CMIS_SERVICE_URL=url;
+ this.info = this.getRepositoryInfo();
+}
+
+CMISClient.NAME_OF_THIS_FILE = "cmisclient.js";
+
+/** trim helper */
+CMISClient.trim = function(s) {
+ return s.replace(/^\s*/, "").replace(/\s*$/, "");
+}
+
+
+/** implements transformation from an xml document to a reasonable js object
+essentially poor mans jquery
+*/
+CMISClient.flatten = function(elem, obj) {
+ if (!obj) obj=new Object();
+ var i=0;
+ while (i<elem.childNodes.length) {
+
+ /* iterate through all the child nodes of the atom structure */
+
+ var child=elem.childNodes[i];
+
+ var value="";
+
+ switch (child.nodeType) {
+
+ /* found an element */
+ case Node.ELEMENT_NODE:
+ if (child.attributes.length==0 && child.childNodes.length==1 && child.childNodes[0].nodeType==Node.TEXT_NODE && child.childNodes[0].nodeValue) {
+ /* fold simple cdata into a property */
+ obj[child.nodeName]=this.trim(child.childNodes[0].nodeValue);
+ } else {
+ if (!obj[child.nodeName]) {
+
+ /* proper substructure without same name sibling */
+ obj[child.nodeName]=new Object();
+ this.flatten(child, obj[child.nodeName]);
+ } else {
+ /* ugly same name sibling handling needs fixing */
+ var j=1;
+ while (obj[child.nodeName+"_"+j]) {
+ j++;
+ }
+ obj[child.nodeName+"_"+j]=new Object();
+ CMISClient.flatten(child, obj[child.nodeName+"_"+j]);
+ }
+ }
+ break;
+
+
+ case Node.TEXT_NODE:
+ /* cdata in unexpected place */
+ var val=CMISClient.trim(child.nodeValue);
+ if (val) {
+ obj["text"]=CMISClient.trim(child.nodeValue);
+ }
+
+ break;
+
+ }
+
+
+
+ i++;
+ }
+ var i=0;
+ if (elem.attributes) {
+ while (i<elem.attributes.length) {
+
+ /* place attribute values with their names */
+ var child=elem.attributes[i];
+ obj[child.nodeName]=child.nodeValue;
+
+ i++;
+ }
+ }
+ return (obj);
+}
+/** Processes an Atom entry into a usable js object */
+CMISClient.processEntry = function(node) {
+ var entry=new Object();
+ for (var a in node) {
+ var elem=node[a];
+ if (a.indexOf("link")==0) {
+ entry[elem.rel]=elem.href;
+ } else if (a=="cmis:object") {
+ var props=elem["cmis:properties"];
+ for (var b in props) {
+ var prop=props[b];
+ entry[prop["cmis:name"]]=prop["cmis:value"];
+ }
+ } else {
+ entry[a]=elem;
+ }
+ }
+
+ entry.author=node.author.name;
+ entry.content=node.content;
+ entry.id=node.id;
+ return (entry);
+}
+
+/** Gets a folder from via atom url */
+CMISClient.prototype.getFolder = function(url) {
+
+ if (url=="/" || !url) {
+ url=this.info.collections["rootchildren"];
+ }
+ var htcon=this.httpGet(url);
+ var doc=htcon.responseXML;
+ var flatres=CMISClient.flatten(doc);
+
+ var feed=flatres.feed;
+
+ var res=new Object();
+ res.author=feed.author.name;
+ res.id=feed.id;
+ res.title=feed.title;
+ res.updated=feed.updated;
+
+ res.links=new Object();
+ res.entries=new Object();
+
+ var linkcount=0;
+ var entrycount=0;
+
+ for (var a in feed) {
+ var node=feed[a];
+ if (a.indexOf("entry")==0) {
+ res.entries[entrycount++]=CMISClient.processEntry(node);
+ }
+ if (a.indexOf("link")==0) {
+
+ }
+
+ }
+
+ return(res);
+}
+
+/** This method reads the repository Info */
+CMISClient.prototype.getRepositoryInfo = function() {
+ var htcon=this.httpGet(this.CMIS_URL);
+ var doc=htcon.responseXML;
+ var flatres=CMISClient.flatten(doc);
+ var res=new Object();
+
+ var repoinfo=flatres.service.workspace["cmis:repositoryInfo"];
+
+ res.repositoryId = repoinfo["cmis:repositoryId"];
+ res.repositoryName = repoinfo["cmis:repositoryName"];
+ res.repositoryRelationship = repoinfo["cmis:repositoryRelationship"];
+ res.repositoryDescription = repoinfo["cmis:repositoryDescription"];
+ res.vendorName = repoinfo["cmis:vendorName"];
+ res.productName = repoinfo["cmis:productName"];
+ res.productVersion = repoinfo["cmis:productVersion"];
+ res.rootFolderId= repoinfo["cmis:rootFolderId"];
+
+ var caps=repoinfo["cmis:capabilities"];
+ res.capabilities = new Object();
+ res.capabilities.multifiling = caps["cmis:capabilityMultifiling"];
+ res.capabilities.unfiling = caps["cmis:capabilityUnfiling"];
+
+ res.cmisVersionsSupported = repoinfo["cmis:cmisVersionsSupported"];
+
+ res.collections = new Object();
+
+ for (var a in flatres.service.workspace) {
+ if (a.indexOf("collection")==0) {
+ var collection=flatres.service.workspace[a];
+ res.collections[collection["cmis:collectionType"]]=collection.href;
+ }
+ }
+ return (res);
+}
+
+/**
+ * Get an XMLHttpRequest in a portable way
+ *
+ */
+CMISClient.prototype.getXHR = function () {
+ var xhr=null;
+
+ if(!xhr) {
+ try {
+ // built-in (firefox, recent Opera versions, etc)
+ xhr=new XMLHttpRequest();
+ } catch (e) {
+ // ignore
+ }
+ }
+
+ if(!xhr) {
+ try {
+ // IE, newer versions
+ xhr=new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ // ignore
+ }
+ }
+
+ if(!xhr) {
+ try {
+ // IE, older versions
+ xhr=new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {
+ // ignore
+ }
+ }
+
+ if(!xhr) {
+ alert("Unable to access XMLHttpRequest object, cmis client will not work!");
+ }
+
+ return xhr;
+}
+
+/**
+ * HTTP GET XHR Helper
+ * @param {String} url The URL
+ * @return the XHR object, use .responseText for the data
+ * @type String
+ */
+CMISClient.prototype.httpGet = function(url) {
+ var httpcon = this.getXHR();
+ if (httpcon) {
+ httpcon.open('GET', url, false);
+ httpcon.send(null);
+ return httpcon;
+ } else {
+ return null;
+ }
+}
+
+/**
+ * Produces a "sort-of-json" string representation of a object
+ * for debugging purposes only
+ * @param {Object} obj The object
+ * @param {int} level The indentation level
+ * @return The result
+ * @type String
+ */
+CMISClient.dumpObj = function(obj, level) {
+ var res="";
+ for (var a in obj) {
+ if (typeof(obj[a])!="object") {
+ res+=a+":"+obj[a]+" ";
+ } else {
+ res+=a+": { ";
+ res+=this.dumpObj(obj[a])+"} ";
+ }
+ }
+ return (res);
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/cmisclient.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js Sun May 10 19:47:29 2009
@@ -0,0 +1,2 @@
+document.write('<div class="footer"><a href="http://www.apache.org/licenses/">License</a> | Powered by <a href="http://jackrabbit.apache.org/">Apache Jackrabbit</a></div>');
+
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/footer.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js Sun May 10 19:47:29 2009
@@ -0,0 +1 @@
+document.write('<div class="header"><div class="logo"><a href="http://jackrabbit.apache.org/" align="right"><img src="logo.png" align="right"></a></div><a href="index.html">CMIS v0.61+ JavaScript Client</a><br>Content Management Interoperability Services (CMIS) draft implementation</div>');
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/header.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html Sun May 10 19:47:29 2009
@@ -0,0 +1,67 @@
+<html>
+<head>
+<title>CMIS JavaScript Client / Example</title>
+<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
+<link rel="stylesheet" type="text/css" href="main.css"></link>
+</head>
+
+<body>
+ <!-- poor mans client side include for header layout -->
+ <script src="header.js"></script>
+
+ <!-- cmis client include -->
+ <script src="cmisclient.js"></script>
+
+<script>
+function traverse (cmisclient, folder) {
+ var tree=document.getElementById("tree");
+ for (var a in folder.entries) {
+ var entry=folder.entries[a];
+ var newdiv = document.createElement("div");
+ newdiv.innerHTML = entry.title.text + (entry["children"]?(":" + entry["children"]):"");
+ tree.appendChild(newdiv);
+ if (entry.children) {
+ var childfolder=cmisclient.getFolder(entry["children"]);
+ traverse(cmisclient, childfolder);
+ }
+ }
+}
+
+function start() {
+ /* get url from form */
+ var cmisurl=document.getElementById("url").value;
+
+ /* instantiate cmisclient */
+ var cmisclient= new CMISClient(cmisurl);
+
+ /* get root folder */
+ var rootfolder=cmisclient.getFolder("/");
+
+ /* start traversal */
+ traverse(cmisclient, rootfolder);
+ }
+</script>
+<style>
+</style>
+ <div class="content">
+ <h1>CMIS JavaScript Client Traversal Example</h1>
+ <h2>Setup Instructions</h2>
+ <p>To make this work the CMISClient.js needs to be located / accessible on the same server
+ as the CMIS service document due to XSS limitations of the browser.
+ </p>
+ <form method="GET" action="getRepositoryInfo.xml" target="result">
+ <table class="formtable">
+ <tr>
+ <td>Service document / Connection URL</td>
+ <td><input class="text" type="text" value="/chemistry/repository" name="url" id="url"></td>
+ </tr><tr><td> </td><td>
+ <input type="button" value="Start Traversal" onClick="start()"><br></td></tr></table>
+ </form>
+ <div id="tree">
+
+ </div>
+ <!-- poor mans client side include for footer layout -->
+ <script src="footer.js"></script>
+ </div>
+</body>
+</html>
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/logo.png
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/logo.png?rev=773395&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/logo.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css?rev=773395&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css Sun May 10 19:47:29 2009
@@ -0,0 +1,151 @@
+body {
+ background: #eee url(bg-body.png) top center repeat-y;
+ color: #333;
+ font-family: Georgia, Times New Roman;
+ margin: 0 auto 0;
+ padding: 0;
+}
+
+.logo {
+ float: right;
+}
+
+.twocols {
+ background: #eee url(bg-twocols.png) top center repeat-y;
+}
+
+a, a:visited {
+ color: #58a;
+ text-decoration: none;
+}
+
+a:hover {
+ background-color: #ffc;
+ text-decoration: underline;
+}
+
+img {
+ border-style: none;
+}
+
+.header {
+ background: #fff;
+ margin: 0 auto 0;
+ text-align: left;
+ padding: 9px 0 29px 0;
+ width: 960px;
+ border-top: 10px solid #ccc;
+}
+
+.header a {
+ font-family: Helvetica, Verdana;
+ letter-spacing: -1px;
+ font-size: 31px;
+ font-weight: bold;
+ color: #58a;
+ text-decoration: none;
+ padding: 0 10px 0 0;
+ margin: 0;
+}
+
+.header a:hover {
+ color: #69d;
+ text-decoration: underline;
+}
+
+.leftcol {
+ width: 440px;
+ margin: 0 20px 0 0;
+ padding: 5px 0 5px 0;
+}
+
+.rightcol {
+ width: 440px;
+ margin: 0 20px 0 0;
+ padding: 5px 0 5px 0;
+}
+
+.formtable {
+ margin-top: 20px;
+ width: 600px;
+ padding: 0;
+ clear: both;
+}
+
+.formtable td {
+ padding: 5px;
+ width: 300px;
+ border-top: dotted #ddd 1px;
+}
+
+.formtable input.text {
+ width: 300px;
+}
+
+
+.content {
+ width: 960px;
+ margin: 0 auto 0;
+ padding: 0;
+ clear: both;
+}
+
+.content p {
+ padding: 0 0 15px 0;
+ margin: 0;
+ line-height: 20px;
+ font-size: 14px;
+}
+
+.content p img {
+ float: left;
+ border: none;
+ margin-right: 15px;
+ margin-bottom: 10px;
+}
+
+.content h1 {
+ border-top: 2px solid olive;
+ color: #58a;
+ font-family: Helvetica,Verdana;
+ font-size: 18px;
+ font-weight: bold;
+ line-height: 20px;
+ margin: 0;
+ padding: 5px 0;
+}
+
+.content h1 a {
+ color: #58a;
+ margin-left: -5px;
+ padding: 0 10px 0 5px;
+ text-decoration: none;
+}
+
+.content h1 a:hover {
+ background-color: #ffc;
+ color: #68b;
+}
+
+.content h2 {
+ color: olive;
+ font-size: 12px;
+ font-family: Helvetica, Verdana;
+ font-weight: bold;
+ margin: 20px 0 5px 0;
+ padding: 3px 0 3px 0;
+ border-top: 2px solid olive;
+ border-bottom: 1px dotted #ccc;
+}
+
+.footer {
+ font-size: 12px;
+ background: #fff;
+ width: 960px;
+ margin: 0 auto 0;
+ padding: 10px 0 10px 0;
+ text-align: left;
+ border-top: 1px solid #ccc;
+ clear: both;
+}
+
Propchange: incubator/chemistry/trunk/chemistry/chemistry-jsclient/webroot/main.css
------------------------------------------------------------------------------
svn:eol-style = native