source: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/OID.java@ 3618

Last change on this file since 3618 was 3449, checked in by kjdon, 22 years ago

changed some comments

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1package org.greenstone.gsdl3.util;
2
3/** utitility class to handle greenstone OIDs
4 *
5 * based around OIDtools.h from gsdl
6 */
7public class OID {
8
9 /** returns everything up to the first dot
10 if no dot, returns oid */
11 public static String getTop(String oid) {
12 int pos = oid.indexOf('.');
13 if (pos == -1) {
14 return oid;
15 }
16 return oid.substring(0, pos);
17
18 }
19 /** returns true is oid is top level (ie has no dots)
20 returns false for an empty oid */
21 public static boolean isTop(String oid) {
22 if (oid.equals("")) {
23 return false;
24 }
25 return (oid.indexOf('.')==-1);
26 }
27
28 /** returns the parent of oid (everything up to last dot)
29 returns "" if oid has no parent */
30 public static String getParent(String oid) {
31 int pos = oid.lastIndexOf('.');
32 if (pos == -1) {
33 return "";
34 }
35 return oid.substring(0, pos);
36 }
37
38 /** returns the full name - replaces all " with parent */
39 public static String translateParent(String oid, String parent) {
40 return oid.replaceAll("\"", parent);
41 }
42 /** does the opposite to translate_parent */
43 public static String shrinkParent(String oid) {
44 int pos = oid.lastIndexOf('.');
45 if (pos==-1) return oid;
46 return "\""+oid.substring(pos);
47 }
48 /** returns true if oid uses .fc, .lc, .pr, .ns, .ps */
49 public static boolean needsTranslating(String oid) {
50 String tail = oid.substring(oid.length()-3);
51 return (tail.equals(".fc") || tail.equals(".lc") || tail.equals(".pr")
52 || tail.equals(".ns") || tail.equals(".ps"));
53 }
54 /** strips suffix from end */
55 public static String stripSuffix(String oid) {
56 String tail = oid.substring(oid.length()-3);
57 while (tail.equals(".fc") || tail.equals(".lc") || tail.equals(".pr")
58 || tail.equals(".ns") || tail.equals(".ps")) {
59 oid = oid.substring(0, oid.length()-3);
60 tail = oid.substring(oid.length()-3);
61 }
62 return oid;
63 }
64 /** returns true if child is a child of parent
65 an oid is not a child of itself */
66 public static boolean isChildOf(String parent, String child) {
67 if (parent.equals(child)) {
68 return false;
69 }
70 return child.startsWith(parent);
71 }
72}
Note: See TracBrowser for help on using the repository browser.