- Timestamp:
- 2010-06-28T17:28:42+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OID.java
r18503 r22319 19 19 package org.greenstone.gsdl3.util; 20 20 21 import org.apache.log4j.*; 22 21 23 /** utility class to handle greenstone OIDs 22 24 * … … 24 26 */ 25 27 public class OID { 28 29 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.OID.class.getName()); 30 31 public interface OIDTranslatable { 32 public String processOID(String doc_id, String top, String suffix, int sibling_num); 33 } 26 34 27 35 /** returns everything up to the first dot … … 102 110 return child.startsWith(parent); 103 111 } 112 113 114 /** translates relative oids into proper oids: 115 * .pr (parent), .rt (root) .fc (first child), .lc (last child), 116 * .ns (next sibling), .ps (previous sibling) 117 * .np (next page), .pp (previous page) : links sections in the order that you'd read the document 118 * a suffix is expected to be present so test before using 119 * Other classes can implement the method processOID of interface OIDTranslatable 120 * to process the oid further to handle siblings. 121 */ 122 public static String translateOID(OIDTranslatable translator, String oid) { 123 int p = oid.lastIndexOf('.'); 124 if (p != oid.length()-3) { 125 logger.info("translateoid error: '.' is not the third to last char!!"); 126 return oid; 127 } 128 129 String top = oid.substring(0, p); 130 String suff = oid.substring(p+1); 131 132 // just in case we have multiple extensions, we must translate 133 // we process inner ones first 134 if (OID.needsTranslating(top)) { 135 top = OID.translateOID(translator, top); 136 } 137 if (suff.equals("pr")) { 138 return OID.getParent(top); 139 } 140 if (suff.equals("rt")) { 141 return OID.getTop(top); 142 } 143 if (suff.equals("np")) { 144 // try first child 145 146 String node_id = OID.translateOID(translator, top+".fc"); 147 if (!node_id.equals(top)) { 148 return node_id; 149 } 150 151 // try next sibling 152 node_id = OID.translateOID(translator, top+".ns"); 153 if (!node_id.equals(top)) { 154 return node_id; 155 } 156 // otherwise we keep trying parents sibling 157 String child_id = top; 158 String parent_id = OID.getParent(child_id); 159 while(!parent_id.equals(child_id)) { 160 node_id = OID.translateOID(translator, parent_id+".ns"); 161 if (!node_id.equals(parent_id)) { 162 return node_id; 163 } 164 child_id = parent_id; 165 parent_id = OID.getParent(child_id); 166 } 167 return top; // we couldn't get a next page, so just return the original 168 } 169 if (suff.equals("pp")) { 170 String prev_sib = OID.translateOID(translator, top+".ps"); 171 if (prev_sib.equals(top)) { 172 // no previous sibling, so return the parent 173 return OID.getParent(top); 174 } 175 // there is a previous sibling, so it's either this section, or the last child of the last child 176 String last_child = OID.translateOID(translator, prev_sib+".lc"); 177 while (!last_child.equals(prev_sib)) { 178 prev_sib = last_child; 179 last_child = OID.translateOID(translator, prev_sib+".lc"); 180 } 181 return last_child; 182 } 183 184 int sibling_num = 0; 185 if (suff.equals("ss")) { 186 // we have to remove the sib num before we get top 187 p = top.lastIndexOf('.'); 188 sibling_num = Integer.parseInt(top.substring(p+1)); 189 top = top.substring(0, p); 190 } 191 192 // need to get info out of Fedora 193 String doc_id = top; 194 if (suff.endsWith("s")) { 195 doc_id = OID.getParent(top); 196 if (doc_id.equals(top)) { 197 // i.e. we are already at the top 198 return top; 199 } 200 } 201 202 return translator.processOID(doc_id, top, suff, sibling_num); 203 204 } 104 205 }
Note:
See TracChangeset
for help on using the changeset viewer.