Index: trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java	(revision 11277)
+++ trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java	(revision 11278)
@@ -158,6 +158,7 @@
      * .pr (parent), .rt (root) .fc (first child), .lc (last child),
      * .ns (next sibling), .ps (previous sibling) 
+     * .np (next page), .pp (previous page) : links sections in the order that you'd read the document
      * a suffix is expected to be present so test before using 
-     * TODO: fc, lc, ns, ps, .rt .ss*/
+     */
     public String translateOID(String oid) {
 
@@ -170,69 +171,114 @@
 	String top = oid.substring(0, p);
 	String suff = oid.substring(p+1);
+	// just in case we have multiple extensions, we must translate
+	// we process inner ones first
+	if (OID.needsTranslating(top)) {
+	    top = translateOID(top);
+	}
 	if (suff.equals("pr")) {
 	    return OID.getParent(top);
-	} else if (suff.equals("rt")) {
+	} 
+	if (suff.equals("rt")) {
 	    return OID.getTop(top);
+	} 
+	if (suff.equals("np")) {
+	    // try first child
+	    String node_id = translateOID(top+".fc");
+	    if (!node_id.equals(top)) {
+		return node_id;
+	    }
+	    // try next sibling
+	    node_id = translateOID(top+".ns");
+	    if (!node_id.equals(top)) {
+		return node_id;
+	    }
+	    // otherwise we keep trying parents sibling
+	    String child_id = top;
+	    String parent_id = OID.getParent(child_id);
+	    while(!parent_id.equals(child_id)) {
+		node_id = translateOID(parent_id+".ns");
+		if (!node_id.equals(parent_id)) {
+		    return node_id;
+		}
+		child_id = parent_id;
+		parent_id = OID.getParent(child_id);
+	    }
+	    return top; // we couldn't get a next page, so just return the original
+	} 
+	if (suff.equals("pp")) {
+	    String prev_sib = translateOID(top+".ps");
+	    if (prev_sib.equals(top)) {
+		// no previous sibling, so return the parent
+		return OID.getParent(top);
+	    }
+	    // there is a previous sibling, so its either this section, or the last child of the last child..
+	    String last_child = translateOID(prev_sib+".lc");
+	    while (!last_child.equals(prev_sib)) {
+		prev_sib = last_child;
+		last_child = translateOID(prev_sib+".lc");
+	    }
+	    return last_child;
+	} 
+	
+	int sibling_num = 0;
+	if (suff.equals("ss")) {
+	    // we have to remove the sib num before we get top
+	    p = top.lastIndexOf('.');
+	    sibling_num = Integer.parseInt(top.substring(p+1));
+	    top = top.substring(0, p);
+	}
+	
+	// need to get info out of gdbm db -
+	String doc_id = top;
+	if (suff.endsWith("s")) {
+	    doc_id = OID.getParent(top);
+	    if (doc_id.equals(top)) {
+		// i.e. we are already at the top
+		return top;
+	    }
+	}
+	DBInfo info = getInfo(doc_id);
+	if (info==null) {
+	    System.out.println("info is null!!");
+	    return top;
+	}
+	
+	String contains = info.getInfo("contains");
+	if (contains.equals("")) {
+	    // something is wrong
+	    return top;
+	}
+	contains = contains.replaceAll("\"", doc_id);
+	String [] children = contains.split(";");
+	if (suff.equals("fc")) {
+	    return children[0];
+	} else if (suff.equals("lc")) {
+	    return children[children.length-1];
 	} else {
-	    int sibling_num = 0;
 	    if (suff.equals("ss")) {
-		// we have to remove the sib num before we get top
-		p = top.lastIndexOf('.');
-		sibling_num = Integer.parseInt(top.substring(p+1));
-		top = top.substring(0, p);
+		return children[sibling_num-1];
+	    }
+	    // find the position that we are at.
+	    int i=0;
+	    while (i<children.length) {
+		if (children[i].equals(top)) {
+		    break;
+		}
+		i++;
 	    }
 	    
-	    // need to get info out of gdbm db -
-	    String doc_id = top;
-	    if (suff.endsWith("s")) {
-		doc_id = OID.getParent(top);
-	    }
-	    DBInfo info = getInfo(doc_id);
-	    if (info==null) {
-		System.out.println("info is null!!");
-		return top;
-	    }
-
-
-	    /** ATTACK OF THE RANDOM BLARG!!!! **/
-	    /** All your code are belong to me! **/
-
-	    String contains = info.getInfo("contains");
-	    if (contains.equals("")) {
-		// something is wrong
-		return top;
-	    }
-	    contains = contains.replaceAll("\"", doc_id);
-	    String [] children = contains.split(";");
-	    if (suff.equals("fc")) {
-		return children[0];
-	    } else if (suff.equals("lc")) {
-		return children[children.length-1];
-	    } else {
-		if (suff.equals("ss")) {
-		    return children[sibling_num-1];
-		}
-		// find the position that we are at.
-		int i=0;
-		while (i<children.length) {
-		    if (children[i].equals(top)) {
-			break;
-		    }
-		    i++;
-		}
-		
-		if (suff.equals("ns")) {
-		    if (i==children.length-1) {
-			return children[i];
-		    }
-		    return children[i+1];
-		} else if (suff.equals("ps")) {
-		    if (i==0) {
-			return children[i];
-		    }
-		    return children[i-1];
-		}
-	    }
-	}
+	    if (suff.equals("ns")) {
+		if (i==children.length-1) {
+		    return children[i];
+		}
+		return children[i+1];
+	    } else if (suff.equals("ps")) {
+		if (i==0) {
+		    return children[i];
+		}
+		return children[i-1];
+	    }
+	}
+	
 	return top;
     }
