1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.surf.resource.support;
20
21 import java.io.IOException;
22 import java.util.StringTokenizer;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.json.JSONObject;
27 import org.springframework.extensions.surf.resource.AbstractResource;
28 import org.springframework.extensions.surf.resource.ResourceContent;
29 import org.springframework.extensions.surf.resource.ResourceContentImpl;
30 import org.springframework.extensions.surf.resource.ResourceJSONContent;
31 import org.springframework.extensions.surf.resource.ResourceJSONContentImpl;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public class AlfrescoResource extends AbstractResource
53 {
54 private static Log logger = LogFactory.getLog(AlfrescoResource.class);
55
56 private String objectTypeId = null;
57
58 public AlfrescoResource(String protocolId, String endpointId, String objectId)
59 {
60 super(protocolId, endpointId, objectId);
61 }
62
63
64
65
66 public ResourceContent getMetadata() throws IOException
67 {
68 return new ResourceJSONContentImpl(this, getMetadataURL());
69 }
70
71
72
73
74 public String getMetadataURL()
75 {
76 String metadataURL = "/webframework/content/metadata";
77
78 if (getObjectId() != null)
79 {
80 metadataURL = "/webframework/content/metadata?id=" + this.getNodeRefId();
81 }
82
83 if (logger.isDebugEnabled())
84 logger.debug("Alfresco Resource metadata URL: " + metadataURL);
85
86 return metadataURL;
87 }
88
89
90
91
92 public ResourceContent getContent() throws IOException
93 {
94 return new ResourceContentImpl(this, getContentURL());
95 }
96
97
98
99
100 public String getContentURL()
101 {
102 String contentURL = null;
103
104 if (getObjectId() != null)
105 {
106 contentURL = "/api/node/" + getObjectId() + "/content";
107 }
108
109 if (logger.isDebugEnabled())
110 logger.debug("Alfresco Resource content URL: " + contentURL);
111
112 return contentURL;
113 }
114
115
116
117
118 public synchronized String getObjectTypeId()
119 {
120 if (objectTypeId == null)
121 {
122 JSONObject json = null;
123
124 try
125 {
126 json = ((ResourceJSONContent) getMetadata()).getJSON();
127 objectTypeId = json.getString("type");
128 }
129 catch (Exception e)
130 {
131 e.printStackTrace();
132 }
133 }
134
135 return objectTypeId;
136 }
137
138
139
140
141 public boolean isContainer()
142 {
143 boolean isContainer = false;
144
145 try
146 {
147 ResourceJSONContent jsonContent = (ResourceJSONContent) getMetadata();
148 isContainer = jsonContent.getJSON().getBoolean("isContainer");
149 }
150 catch (Exception e) { }
151
152 return isContainer;
153 }
154
155
156
157
158
159 protected String getNodeRefId()
160 {
161 String nodeRefId = null;
162
163 String objectId = getObjectId();
164 if (objectId != null)
165 {
166 String workspaceId = null;
167 String storeId = null;
168 String nodeId = null;
169
170 StringTokenizer tokenizer = new StringTokenizer(objectId, "/");
171 workspaceId = tokenizer.nextToken();
172 storeId = tokenizer.nextToken();
173 nodeId = tokenizer.nextToken();
174
175 nodeRefId = workspaceId + "://" + storeId + "/" + nodeId;
176 }
177
178 return nodeRefId;
179 }
180 }