Changeset 11278
- Timestamp:
- 2006-02-17T11:36:27+13:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java
r9874 r11278 158 158 * .pr (parent), .rt (root) .fc (first child), .lc (last child), 159 159 * .ns (next sibling), .ps (previous sibling) 160 * .np (next page), .pp (previous page) : links sections in the order that you'd read the document 160 161 * a suffix is expected to be present so test before using 161 * TODO: fc, lc, ns, ps, .rt .ss*/162 */ 162 163 public String translateOID(String oid) { 163 164 … … 170 171 String top = oid.substring(0, p); 171 172 String suff = oid.substring(p+1); 173 // just in case we have multiple extensions, we must translate 174 // we process inner ones first 175 if (OID.needsTranslating(top)) { 176 top = translateOID(top); 177 } 172 178 if (suff.equals("pr")) { 173 179 return OID.getParent(top); 174 } else if (suff.equals("rt")) { 180 } 181 if (suff.equals("rt")) { 175 182 return OID.getTop(top); 183 } 184 if (suff.equals("np")) { 185 // try first child 186 String node_id = translateOID(top+".fc"); 187 if (!node_id.equals(top)) { 188 return node_id; 189 } 190 // try next sibling 191 node_id = translateOID(top+".ns"); 192 if (!node_id.equals(top)) { 193 return node_id; 194 } 195 // otherwise we keep trying parents sibling 196 String child_id = top; 197 String parent_id = OID.getParent(child_id); 198 while(!parent_id.equals(child_id)) { 199 node_id = translateOID(parent_id+".ns"); 200 if (!node_id.equals(parent_id)) { 201 return node_id; 202 } 203 child_id = parent_id; 204 parent_id = OID.getParent(child_id); 205 } 206 return top; // we couldn't get a next page, so just return the original 207 } 208 if (suff.equals("pp")) { 209 String prev_sib = translateOID(top+".ps"); 210 if (prev_sib.equals(top)) { 211 // no previous sibling, so return the parent 212 return OID.getParent(top); 213 } 214 // there is a previous sibling, so its either this section, or the last child of the last child.. 215 String last_child = translateOID(prev_sib+".lc"); 216 while (!last_child.equals(prev_sib)) { 217 prev_sib = last_child; 218 last_child = translateOID(prev_sib+".lc"); 219 } 220 return last_child; 221 } 222 223 int sibling_num = 0; 224 if (suff.equals("ss")) { 225 // we have to remove the sib num before we get top 226 p = top.lastIndexOf('.'); 227 sibling_num = Integer.parseInt(top.substring(p+1)); 228 top = top.substring(0, p); 229 } 230 231 // need to get info out of gdbm db - 232 String doc_id = top; 233 if (suff.endsWith("s")) { 234 doc_id = OID.getParent(top); 235 if (doc_id.equals(top)) { 236 // i.e. we are already at the top 237 return top; 238 } 239 } 240 DBInfo info = getInfo(doc_id); 241 if (info==null) { 242 System.out.println("info is null!!"); 243 return top; 244 } 245 246 String contains = info.getInfo("contains"); 247 if (contains.equals("")) { 248 // something is wrong 249 return top; 250 } 251 contains = contains.replaceAll("\"", doc_id); 252 String [] children = contains.split(";"); 253 if (suff.equals("fc")) { 254 return children[0]; 255 } else if (suff.equals("lc")) { 256 return children[children.length-1]; 176 257 } else { 177 int sibling_num = 0;178 258 if (suff.equals("ss")) { 179 // we have to remove the sib num before we get top 180 p = top.lastIndexOf('.'); 181 sibling_num = Integer.parseInt(top.substring(p+1)); 182 top = top.substring(0, p); 259 return children[sibling_num-1]; 260 } 261 // find the position that we are at. 262 int i=0; 263 while (i<children.length) { 264 if (children[i].equals(top)) { 265 break; 266 } 267 i++; 183 268 } 184 269 185 // need to get info out of gdbm db - 186 String doc_id = top; 187 if (suff.endsWith("s")) { 188 doc_id = OID.getParent(top); 189 } 190 DBInfo info = getInfo(doc_id); 191 if (info==null) { 192 System.out.println("info is null!!"); 193 return top; 194 } 195 196 197 /** ATTACK OF THE RANDOM BLARG!!!! **/ 198 /** All your code are belong to me! **/ 199 200 String contains = info.getInfo("contains"); 201 if (contains.equals("")) { 202 // something is wrong 203 return top; 204 } 205 contains = contains.replaceAll("\"", doc_id); 206 String [] children = contains.split(";"); 207 if (suff.equals("fc")) { 208 return children[0]; 209 } else if (suff.equals("lc")) { 210 return children[children.length-1]; 211 } else { 212 if (suff.equals("ss")) { 213 return children[sibling_num-1]; 214 } 215 // find the position that we are at. 216 int i=0; 217 while (i<children.length) { 218 if (children[i].equals(top)) { 219 break; 220 } 221 i++; 222 } 223 224 if (suff.equals("ns")) { 225 if (i==children.length-1) { 226 return children[i]; 227 } 228 return children[i+1]; 229 } else if (suff.equals("ps")) { 230 if (i==0) { 231 return children[i]; 232 } 233 return children[i-1]; 234 } 235 } 236 } 270 if (suff.equals("ns")) { 271 if (i==children.length-1) { 272 return children[i]; 273 } 274 return children[i+1]; 275 } else if (suff.equals("ps")) { 276 if (i==0) { 277 return children[i]; 278 } 279 return children[i-1]; 280 } 281 } 282 237 283 return top; 238 284 }
Note:
See TracChangeset
for help on using the changeset viewer.