View Javadoc
1   package org.kuali.ole.docstore.model.repopojo;
2   
3   import java.util.*;
4   
5   /**
6    * Base class for nodes in docstore
7    * User: Pranitha
8    * Date: 2/28/12
9    * Time: 3:02 PM
10   * To change this template use File | Settings | File Templates.
11   */
12  public class DocStoreNode {
13  
14      public final String UUID = "jcr:uuid";
15      public final String PRIMARY_TYPE = "jcr:primaryType";
16      public final String NODE_TYPE = "nodeType";
17      public final String MIXIN_TYPES = "jcr:mixinTypes";
18      public final String CREATED_BY = "jcr:createdBy";
19      public final String CREATED = "jcr:created";
20      public final String MIME_TYPE = "jcr:mimeType";
21      public final String CONTENT = "jcr:data";
22      public final String FILE_NODE_COUNT = "fileNodeCount";
23      private String name;
24      private String path;
25      private Map<String, Object> propertyMap = new LinkedHashMap<String, Object>();
26  
27      public Map<String, Object> getPropertyMap() {
28          return propertyMap;
29      }
30  
31      public void setPropertyMap(Map<String, Object> propertyMap) {
32          this.propertyMap = propertyMap;
33      }
34  
35      public String getName() {
36          return name;
37      }
38  
39      public void setName(String name) {
40          this.name = name;
41      }
42  
43      public String getPath() {
44          return path;
45      }
46  
47      public void setPath(String path) {
48          this.path = path;
49      }
50  
51      public Object getProperty(String propertyName) {
52          return propertyMap.get(propertyName);
53      }
54  
55      public void setProperty(String key, Object value) {
56          if (propertyMap.containsKey(key) && !key.equalsIgnoreCase("jcr:data")) {
57              List<Object> multiValue = new ArrayList<Object>();
58              multiValue.add(propertyMap.get(key));
59              multiValue.add(value);
60              propertyMap.put(key, multiValue);
61          } else {
62              propertyMap.put(key, value);
63          }
64          setPropertyMap(propertyMap);
65      }
66  
67      @Override
68      public String toString() {
69          StringBuilder sb = new StringBuilder();
70          sb.append(getPath() + "\n");
71          Map<String, Object> resultMap = (Map<String, Object>) getPropertyMap();
72          if (resultMap.size() > 0) {
73              Set<String> result = resultMap.keySet();
74              for (Iterator<String> iterator1 = result.iterator(); iterator1.hasNext(); ) {
75                  String key = iterator1.next();
76                  Object value = resultMap.get(key);
77                  if (value instanceof List) {
78                      for (int i = 0; i < ((List) value).size(); i++) {
79                          sb.append(getPath() + "/" + key + " = " + ((List) value).get(i) + "\n");
80                      }
81                  } else if (value instanceof Long) {
82                      long longValue = ((Long) value).longValue();
83                      sb.append(getPath() + "/" + key + " = " + longValue + "\n");
84                  } else {
85                      value = (String) resultMap.get(key);
86                      if (getPath().equalsIgnoreCase("/")) {
87                          sb.append("/" + key + " = " + value + "\n");
88                      } else {
89                          sb.append(getPath() + "/" + key + " = " + value + "\n");
90                      }
91                  }
92              }
93          }
94          return sb.toString();
95      }
96  }