01-28-2008 04:28 AM
/*
    json.js 
(modified 2006-09-07): added support for RHINO
(modified 2006-05-02): json.parse, json,stringify added
   USAGE:
   var jsObj = JSON.parse(jsonStr);
   var jsonStr = JSON.stringify(jsObj);
*/
if (!this.json) {
   var json = (function () {
       var m = {
               '\b': '\\b',
               '\t': '\\t',
               '\n': '\\n',
               '\f': '\\f',
               '\r': '\\r',
               '"' : '\\"',
               '\\': '\\\\'
           },
           s = {
               array: function (x) {
                   var a = ['['], b, f, i, l = x.length, v;
                   for (i = 0; i < l; i += 1) {
                       v = x[i];
                       f = s[typeof v];
                       if (f) {
                           v = f(v);
                           if (typeof v == 'string') {
                               if (b) {
                                   a[a.length] = ',';
                               }
                               a[a.length] = v;
                               b = true;
                           }
                       }
                   }
                   a[a.length] = ']';
                   return a.join('');
               },
               'boolean': function (x) {
                   return String(x);
               },
               'null': function (x) {
                   return "null";
               },
               number: function (x) {
                   return isFinite(x) ? String(x) : 'null';
               },
               object: function (x) {
                   if (x) {
   
                       if (x instanceof Array) {
                           return s.array(x);
                       }
                       if (x.hashCode) return s.string(''+x.toString());
   
                       var a = ['{'], b, f, i, v;
                       for (i in x) {
                           v = x[i];
                           f = s[typeof v];
                           if (f) {
   
                               v = f(v);
   
                               if (typeof v == 'string') {
                                   if (b) {
                                       a[a.length] = ',';
                                   }
                                   a.push(s.string(i), ':', v);
                                   b = true;
                               }
                           }
                       }
                       a[a.length] = '}';
                       return a.join('');
                   }
                   return 'null';
               },
               string: function (x) {
                   if (/["\\\x00-\x1f]/.test(x)) {
                       x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                           var c = m[b];
                           if © {
                               return c;
                           }
                           c = b.charCodeAt();
                           return '\\u00' +
                               Math.floor(c / 16).toString(16) +
                               (c % 16).toString(16);
                       });
                   }
                   return '"' + x + '"';
               }
           };
   
      return {
         parse: function(s) {
            try {
               return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                  s.replace(/"(\\.|[^"\\])*"/g, ''))) &&
                  eval('(' + s + ')');
            } catch (e) {
               return false;
            }
         },
         stringify: s.object
      };
   })();
}
var WEBSERVICE_PATH = '/com/onepoint/alfresco/webservices/folderbrowser';
/**
 * This is a Javascript object that can be used 
 * for JSON serialization.
 * @param folder The Java object that is going to be transformed into a Javascript object. 
 */
function JsonFolder(folder) {
   this.displayPath = folder.displayPath;
   this.name        = folder.name;
   this.hasParent   = folder.parent.parent != null;
   this.parentPath  = escape(encodePath(folder.parent));
   this.folders     = new Array();
   this.files       = new Array();
   this.fileLinks   = new Array();
   
   for(var i = 0, length = folder.children.length; i < length; i++) {
      var child = folder.children[i];
      if (child.isContainer) {
         this.folders[this.folders.length] = escape(encodePath(child));
      }
      else {
         this.files[this.files.length] = escape(encodePath(child));
         var childName = child.name != null ? child.name : "";
         this.fileLinks[this.files.length] = escape(url.serviceContext + "/api/node/content/" 
            + child.nodeRef.storeRef.protocol + "/" + child.nodeRef.storeRef.identifier + "/" 
            + child.nodeRef.id + "/" + childName);
      }
   }
}
/**
 * Encodes the path of one node.
 * @param node The node that is to be encoded.
 */
function encodePath(node) {
   var path = "";
   if(node.parent) {
      path = node.name;
      path = encodePath(node.parent) + '/' + path;
   }
   return path;
}
// locate folder by path
if ((args.p == null || args.p.length == 0) && (url.extension == null || url.extension.length == 0))
{
   status.code = 400;
   status.message = "No folder has been specified.";
   status.redirect = true;
}
else {
   var folder = roothome.childByNamePath(args.p != null ? args.p : url.extension);
   model.folder = folder;
   var jsonFolder = new JsonFolder(folder);
   model.jsonFolder = json.stringify(jsonFolder);
}
01-28-2008 07:07 PM
01-30-2008 12:33 PM
01-30-2008 01:01 PM
01-30-2008 01:07 PM
${jsonFolder}01-30-2008 01:32 PM
08-09-2010 03:47 AM
08-09-2010 04:53 AM
08-31-2010 06:02 AM
08-31-2010 09:49 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.