- Timestamp:
- 2009-02-11T15:44:57+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/util/OID.java
r16869 r18503 26 26 27 27 /** returns everything up to the first dot 28 28 if no dot, returns oid */ 29 29 public static String getTop(String oid) { 30 31 32 33 34 35 30 int pos = oid.indexOf('.'); 31 if (pos == -1) { 32 return oid; 33 } 34 return oid.substring(0, pos); 35 36 36 } 37 37 /** returns true is oid is top level (ie has no dots) 38 38 returns false for an empty oid */ 39 39 public static boolean isTop(String oid) { 40 41 42 43 40 if (oid.equals("")) { 41 return false; 42 } 43 return (oid.indexOf('.')==-1); 44 44 } 45 45 46 46 /** returns the parent of oid (everything up to last dot) 47 47 returns oid if oid has no parent */ 48 48 public static String getParent(String oid) { 49 50 51 52 53 49 int pos = oid.lastIndexOf('.'); 50 if (pos == -1) { 51 return oid; 52 } 53 return oid.substring(0, pos); 54 54 } 55 55 56 56 /** returns the full name - replaces all " with parent */ 57 57 public static String translateParent(String oid, String parent) { 58 58 return oid.replaceAll("\"", parent); 59 59 } 60 60 /** does the opposite to translate_parent */ 61 61 public static String shrinkParent(String oid) { 62 63 64 62 int pos = oid.lastIndexOf('.'); 63 if (pos==-1) return oid; 64 return "\""+oid.substring(pos); 65 65 } 66 66 /** returns true if oid uses .fc, .lc, .pr, .ns, .ps .rt (root) .ss (specified sibling)*/ 67 67 public static boolean needsTranslating(String oid) { 68 69 70 71 72 73 74 68 if (oid.length()<4) return false; 69 String tail = oid.substring(oid.length()-3); 70 return (tail.equals(".fc") || tail.equals(".lc") || 71 tail.equals(".pr") || tail.equals(".ns") || 72 tail.equals(".ps") || tail.equals(".rt") || 73 tail.equals(".ss") || tail.equals(".np") || 74 tail.equals(".pp")); 75 75 } 76 76 /** strips suffix from end */ 77 77 public static String stripSuffix(String oid) { 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 78 String tail = oid.substring(oid.length()-3); 79 while (tail.equals(".fc") || tail.equals(".lc") || 80 tail.equals(".pr") || tail.equals(".ns") || 81 tail.equals(".ps") || tail.equals(".ss") || 82 tail.equals(".np") || tail.equals(".pp") || 83 tail.equals(".rt") ) { 84 if (tail.equals(".ss")) { // have doc.sibnum.ss 85 oid = oid.substring(0, oid.length()-3); 86 int pos = oid.lastIndexOf('.'); 87 //strip that too 88 oid = oid.substring(0, pos); 89 } 90 oid = oid.substring(0, oid.length()-3); 91 tail = oid.substring(oid.length()-3); 92 } 93 94 return oid; 95 95 } 96 96 /** returns true if child is a child of parent 97 97 an oid is not a child of itself */ 98 98 public static boolean isChildOf(String parent, String child) { 99 100 101 102 99 if (parent.equals(child)) { 100 return false; 101 } 102 return child.startsWith(parent); 103 103 } 104 104 }
Note:
See TracChangeset
for help on using the changeset viewer.