1 17 package org.alfresco.jcr.item; 18 19 import java.util.StringTokenizer ; 20 21 import org.alfresco.service.cmr.repository.Path; 22 import org.alfresco.service.namespace.NamespacePrefixResolver; 23 import org.alfresco.service.namespace.QName; 24 25 30 public class JCRPath 31 { 32 private Path path; 33 34 39 public JCRPath(NamespacePrefixResolver resolver, String strPath) 40 { 41 boolean root = false; 43 int pos = 0; 44 path = new Path(); 45 StringTokenizer tokenizer = new StringTokenizer (strPath, "/", true); 46 while (tokenizer.hasMoreTokens()) 47 { 48 String token = tokenizer.nextToken(); 49 if (pos == 0 && token.equals("/")) 50 { 51 root = true; 52 } 53 else if (!token.equals("/")) 54 { 55 if (root) 56 { 57 path.append(new RootSimpleElement(resolver, token)); 58 root = false; 59 } 60 else 61 { 62 path.append(new SimpleElement(resolver, token)); 63 } 64 } 65 pos++; 66 } 67 } 68 69 74 public Path getPath() 75 { 76 return path; 77 } 78 79 80 @Override 81 public String toString() 82 { 83 return path.toString(); 84 } 85 86 91 public static class SimpleElement extends Path.Element 92 { 93 private static final long serialVersionUID = -6510331182652872996L; 94 private QName path; 95 96 100 public SimpleElement(QName path) 101 { 102 this.path = path; 103 } 104 105 108 public SimpleElement(NamespacePrefixResolver resolver, String path) 109 { 110 this.path = QName.createQName(path, resolver); 111 } 112 113 116 public QName getQName() 117 { 118 return path; 119 } 120 121 @Override 122 public String getElementString() 123 { 124 return path.toString(); 125 } 126 127 @Override 128 public String getPrefixedString(NamespacePrefixResolver resolver) 129 { 130 return path.toPrefixString(resolver); 131 } 132 133 136 public boolean equals(Object o) 137 { 138 if(o == this) 139 { 140 return true; 141 } 142 if(!(o instanceof SimpleElement)) 143 { 144 return false; 145 } 146 SimpleElement other = (SimpleElement)o; 147 return this.path.equals(other.path); 148 } 149 150 153 public int hashCode() 154 { 155 return path.hashCode(); 156 } 157 158 } 159 160 165 public static class RootSimpleElement extends SimpleElement 166 { 167 private static final long serialVersionUID = -4827016063963328324L; 168 169 174 public RootSimpleElement(NamespacePrefixResolver resolver, String path) 175 { 176 super(resolver, path); 177 } 178 179 @Override 180 public String getElementString() 181 { 182 return "/" + super.getElementString(); 183 } 184 185 @Override 186 public String getPrefixedString(NamespacePrefixResolver resolver) 187 { 188 return "/" + super.getPrefixedString(resolver); 189 } 190 } 191 192 } 193 | Popular Tags |