From ae05d7d4dc2e404355f4e3164236a297f2a2cd14 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Fri, 16 May 2008 12:45:17 +0000 Subject: [PATCH] First cut of metadata service (SLNG-234) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9136 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/jscript/ScriptNode.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index a22f6c13d3..da0ee0adc2 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -73,6 +73,8 @@ import org.alfresco.util.ParameterCheck; import org.alfresco.util.URLEncoder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.json.JSONException; +import org.json.JSONObject; import org.mozilla.javascript.Context; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; @@ -1900,6 +1902,47 @@ public class ScriptNode implements Serializable, Scopeable } } + /** + * Returns the JSON representation of this node. + * + * NOTE: This is a temporary method to support the /api/metadata web script + * + * @return The JSON representation of this node + */ + public String toJSON() + { + String jsonStr = "{}"; + + if (this.nodeService.exists(nodeRef)) + { + if (this.services.getPermissionService().hasPermission(nodeRef, PermissionService.READ_PROPERTIES) == AccessStatus.ALLOWED) + { + JSONObject json = new JSONObject(); + + try + { + // add type info + json.put("nodeRef", this.getNodeRef().toString()); + json.put("type", this.getType()); + json.put("mimetype", this.getMimetype()); + + // add properties + json.put("properties", this.nodeService.getProperties(this.nodeRef)); + + // add aspects as an array + json.put("aspects", this.nodeService.getAspects(this.nodeRef)); + } + catch (JSONException error) + { + error.printStackTrace(); + } + + jsonStr = json.toString(); + } + } + + return jsonStr; + } /** * Helper to create a QName from either a fully qualified or short-name QName string