package org.greenstone.gsdl3.util;

public class GS3OID extends OID {

    /**  public static boolean isTop(String oid) {
	if (oid.equals("")) {
	    return false;
	}
	int pos = oid.indexOf('.');
	if (pos == -1) { // its the top document, not the top structure
	    return false;
	}
	pos = pod.indexOf('.', pos+1);
	if (pos == -1) {
	    return true; // there is only one dot
	}
	return false; // there is more than one dot
		
	}*/

    public static boolean isDocTop(String oid) {
	return oid.indexOf('-')==-1;
    }

    public static String createOID(String doc_id, String section_label) {
	return doc_id + "-"+section_label;
    }

    public static String getDocID(String oid) {
	if (isDocTop(oid)) {
	    return oid;
	}
	return oid.substring(0, oid.indexOf('-'));
    }
    public static String getSectionLabel(String oid) {

	if (isDocTop(oid)) {
	    return "";
	}
	return oid.substring(oid.indexOf('-')+1);

    }

    // put this here for now - may need to go with SQL stuff later
    public static String translateOID(String oid) {
	
	int p = oid.lastIndexOf('.');
	if (p != oid.length()-3) {
	    System.out.println("translateoid error: '.' is not the third to last char!!");
	    return oid;
	}
	
	String top = oid.substring(0, p);
	String suff = oid.substring(p+1);
	if (suff.equals("pr")) {
	    return getParent(top);
	} else if (suff.equals("rt")) {
	    return getTop(top);
	} 
	return oid;

    }

}
