1 5 6 package org.exoplatform.services.jcr.impl.storage.filesystem.nodedata; 7 8 import org.apache.commons.logging.Log; 9 import org.exoplatform.services.jcr.core.NodeData; 10 import org.exoplatform.services.jcr.impl.core.NodeImpl; 11 import org.exoplatform.services.jcr.impl.core.PropertyImpl; 12 import org.exoplatform.services.jcr.util.PathUtil; 13 import org.exoplatform.services.log.LogUtil; 14 15 import javax.jcr.DateValue; 16 import javax.jcr.PathNotFoundException; 17 import javax.jcr.PropertyType; 18 import javax.jcr.StringValue; 19 import java.io.File ; 20 import java.util.ArrayList ; 21 import java.util.Calendar ; 22 import java.util.Date ; 23 import java.util.List ; 24 25 31 32 public abstract class BaseNodeContainer implements NodeContainer { 33 34 protected static NodeContainerResolver resolver = new NodeContainerResolver(); 35 36 protected File storage; 37 protected String containerPath; 38 protected String nodeType; 39 protected ArrayList rootProperties; 40 protected Log log; 41 42 BaseNodeContainer() { 43 this.log = LogUtil.getLog("org.exoplatform.services.jcr"); 44 } 45 46 BaseNodeContainer(String jcrPath, String type, File storage) { 48 this(); 49 this.containerPath = jcrPath; 50 this.storage = storage; 51 this.nodeType = type; 52 } 53 54 public NodeData getRootNode() { 55 try { 56 return new NodeImpl(containerPath, getRootProps()); 57 } catch (Exception e) { 58 throw new RuntimeException ("getRootNode failed. Reason: " + e.getMessage()); 59 } 60 } 61 62 public NodeData getNodeById(String UUID) { 63 throw new RuntimeException ("getNodeById does not supported ! "); 64 } 65 66 67 public final String getNodeType() { 68 return this.nodeType; 69 } 70 71 public final String getContainerPath() { 72 return containerPath; 73 } 74 75 public final File getStorage() { 76 return storage; 77 } 78 79 public final String parseRelPath(String jcrPath) throws PathNotFoundException { 80 if (jcrPath.length() < containerPath.length()) 81 throw new PathNotFoundException("ParseRelPath failed. Path <" + jcrPath + ">. is too short."); 82 else if (jcrPath.length() == containerPath.length()) 83 return ""; 84 if (jcrPath.startsWith(containerPath)) 85 return jcrPath.substring(containerPath.length(), jcrPath.length()); 86 throw new PathNotFoundException("ParseRelPath failed. Unexpected Path <" + jcrPath + ">."); 87 } 88 89 protected String getJcrPath(String relPath) { 90 return containerPath + relPath; 91 } 92 93 protected String getParentRelPath(String relPath) { 94 95 try { 96 97 if (PathUtil.getDepth(relPath) <= 1) 98 return ""; 99 else 100 return PathUtil.getAncestorPath(relPath, 1); 101 } catch (Exception e) { 102 return null; 103 } 104 105 } 106 107 protected PropertyImpl getRootProperty(String relPath) { 108 try { 110 111 113 if (relPath.equals("/jcr:primaryType")) 114 return new PropertyImpl(getJcrPath("/jcr:primaryType"), new StringValue(nodeType), 115 PropertyType.STRING); 116 if (relPath.equals("/jcr:created") || relPath.equals("/jcr:lastModified")) { 117 long cr = storage.lastModified(); 118 Calendar cal = Calendar.getInstance(); 119 cal.setTime(new Date (cr)); 120 return new PropertyImpl(getJcrPath(relPath), new DateValue(cal), 121 PropertyType.DATE); 122 } 123 124 } catch (Exception e) { 125 return null; 126 } 127 128 return null; 129 } 130 131 protected List getRootProps() { 132 ArrayList properties = new ArrayList (); 133 properties.add(getRootProperty("/jcr:primaryType")); 134 properties.add(getRootProperty("/jcr:lastModified")); 135 properties.add(getRootProperty("/jcr:created")); 136 return properties; 137 } 138 139 } 140 | Popular Tags |