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          }
62          else {
63              propertyMap.put(key, value);
64          }
65          setPropertyMap(propertyMap);
66      }
67  
68      @Override
69      public String toString() {
70          StringBuilder sb = new StringBuilder();
71          sb.append(getPath() + "\n");
72          Map<String, Object> resultMap = (Map<String, Object>) getPropertyMap();
73          if (resultMap.size() > 0) {
74              Set<String> result = resultMap.keySet();
75              for (Iterator<String> iterator1 = result.iterator(); iterator1.hasNext(); ) {
76                  String key = iterator1.next();
77                  Object value = resultMap.get(key);
78                  if (value instanceof List) {
79                      for (int i = 0; i < ((List) value).size(); i++) {
80                          sb.append(getPath() + "/" + key + " = " + ((List) value).get(i) + "\n");
81                      }
82                  }
83                  else if(value instanceof Long ) {
84                      long longValue = ((Long) value).longValue();
85                      sb.append(getPath() + "/" + key + " = " + longValue + "\n");
86                  }
87                  else {
88                      value = (String) resultMap.get(key);
89                      if (getPath().equalsIgnoreCase("/")) {
90                          sb.append("/" + key + " = " + value + "\n");
91                      }
92                      else {
93                          sb.append(getPath() + "/" + key + " = " + value + "\n");
94                      }
95                  }
96              }
97          }
98          return sb.toString();
99      }
100 }