Changeset 26046 for main


Ignore:
Timestamp:
2012-07-31T15:22:22+12:00 (12 years ago)
Author:
kjdon
Message:

moved a heap of duplicated code out of service racks and into BasicDocument classes

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractBrowse.java

    r25977 r26046  
    2323
    2424import org.apache.log4j.Logger;
     25import org.greenstone.gsdl3.util.AbstractBasicDocument;
     26import org.greenstone.gsdl3.util.BasicDocument;
    2527import org.greenstone.gsdl3.util.GSPath;
    2628import org.greenstone.gsdl3.util.GSXML;
     
    6163    protected static final String INFO_SIB_POS = "siblingPosition";
    6264
     65    protected AbstractBasicDocument gs_doc = null;
     66
    6367    protected Element config_info = null; // the xml from the config file
    6468
    6569    protected MacroResolver macro_resolver = null;
    6670
     71    /**
     72     * the default document type - use if all documents are the same type
     73     */
    6774    protected String default_document_type = null;
    6875
     
    175182            }
    176183        }
     184
     185        // Base line for document (might be overriden by sub-classes)
     186        gs_doc = new BasicDocument(this.doc, this.default_document_type);
    177187
    178188        return true;
     
    644654    protected Element createDocNode(String node_id)
    645655    {
    646         Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    647         node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    648 
    649         String doc_type = null;
    650         if (default_document_type != null)
    651         {
    652             doc_type = default_document_type;
    653         }
    654         else
    655         {
    656             doc_type = getDocType(node_id);
    657         }
    658         node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
    659         String node_type = getNodeType(node_id, doc_type);
    660         node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
    661         return node;
     656      return this.gs_doc.createDocNode(node_id);
    662657    }
    663658
     
    668663    protected String getNodeType(String node_id, String doc_type)
    669664    {
    670         if (doc_type.equals(GSXML.DOC_TYPE_SIMPLE))
    671         {
    672             return GSXML.NODE_TYPE_LEAF;
    673         }
    674 
    675         if (getParentId(node_id) == null)
    676         {
    677             return GSXML.NODE_TYPE_ROOT;
    678         }
    679         if (doc_type.equals(GSXML.DOC_TYPE_PAGED))
    680         {
    681             return GSXML.NODE_TYPE_LEAF;
    682         }
    683         if (getChildrenIds(node_id) == null)
    684         {
    685             return GSXML.NODE_TYPE_LEAF;
    686         }
    687         return GSXML.NODE_TYPE_INTERNAL;
    688 
     665      return this.gs_doc.getNodeType(node_id, doc_type);
    689666    }
    690667
     
    734711        parent_node.removeChild(current_node);
    735712
    736         // add in all the siblings,
     713        // add in all the siblings,- might be classifier/document nodes
    737714        addDescendants(parent_node, parent_id, false);
    738715
     
    743720        Element new_current = GSXML.getNamedElement(parent_node, current_node.getNodeName(), GSXML.NODE_ID_ATT, current_id);
    744721        return new_current;
     722
    745723    }
    746724
     
    758736    protected ArrayList<String> getSiblingIds(String node_id)
    759737    {
    760         String parent_id = getParentId(node_id);
    761         if (parent_id == null)
    762         {
    763             return null;
    764         }
    765         return getChildrenIds(parent_id);
    766 
     738      return this.gs_doc.getSiblingIds(node_id);
    767739    }
    768740
     
    778750     * GSXML.DOC_TYPE_HIERARCHY
    779751     */
    780     abstract protected String getDocType(String node_id);
     752  protected String getDocType(String node_id) {
     753    return this.gs_doc.getDocType(node_id);
     754  }
    781755
    782756    /**
     
    784758     * . may be the same as node_id
    785759     */
    786     abstract protected String getRootId(String node_id);
     760  protected String getRootId(String node_id) {
     761    return this.gs_doc.getRootId(node_id);
     762  }
    787763
    788764    /** returns a list of the child ids in order, null if no children */
    789     abstract protected ArrayList<String> getChildrenIds(String node_id);
     765  protected ArrayList<String> getChildrenIds(String node_id) {
     766    return this.gs_doc.getChildrenIds(node_id);
     767  }
    790768
    791769    /** returns the node id of the parent node, null if no parent */
    792     abstract protected String getParentId(String node_id);
     770  protected String getParentId(String node_id) {
     771    return this.gs_doc.getParentId(node_id);
     772  }
    793773
    794774    /**
     
    815795    /**
    816796     * returns the structural information asked for. info_type may be one of
    817      * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
    818      */
    819     abstract protected String getStructureInfo(String node_id, String info_type);
     797     * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS, INFO_DOC_TYPE
     798     */
     799  protected String getStructureInfo(String node_id, String info_type) {
     800    return this.gs_doc.getStructureInfo(node_id, info_type);
     801  }
    820802
    821803}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java

    r25818 r26046  
    2424import org.greenstone.util.GlobalProperties;
    2525import org.greenstone.gsdl3.core.GSException;
     26import org.greenstone.gsdl3.util.AbstractBasicDocument;
     27import org.greenstone.gsdl3.util.BasicDocument;
    2628import org.greenstone.gsdl3.util.GSXML;
    2729import org.greenstone.gsdl3.util.GSPath;
     
    6769    protected static final String STRUCT_ENTIRE = "entire";
    6870
    69     protected static final String INFO_NUM_SIBS = "numSiblings";
    70     protected static final String INFO_NUM_CHILDREN = "numChildren";
    71     protected static final String INFO_SIB_POS = "siblingPosition";
    72     protected static final String INFO_DOC_TYPE = "documentType";
     71
     72    protected AbstractBasicDocument gs_doc = null;
    7373
    7474    // means the id is not a greenstone id and needs translating
     
    169169            }
    170170        }
     171
     172        // Base line for document (might be overriden by sub-classes)
     173        gs_doc = new BasicDocument(this.doc, this.default_document_type);
    171174
    172175        return true;
     
    631634    protected Element createDocNode(String node_id)
    632635    {
    633         Element node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    634         node.setAttribute(GSXML.NODE_ID_ATT, node_id);
    635 
    636         String doc_type = null;
    637         if (default_document_type != null)
    638         {
    639             doc_type = default_document_type;
    640         }
    641         else
    642         {
    643             doc_type = getDocType(node_id);
    644         }
    645         node.setAttribute(GSXML.DOC_TYPE_ATT, doc_type);
    646         String node_type = getNodeType(node_id, doc_type);
    647         node.setAttribute(GSXML.NODE_TYPE_ATT, node_type);
    648         return node;
     636        return this.gs_doc.createDocNode(node_id);
    649637    }
    650638
     
    655643    protected void addDescendants(Element doc, String doc_id, boolean recursive)
    656644    {
    657         ArrayList<String> child_ids = getChildrenIds(doc_id);
    658         if (child_ids == null)
    659             return;
    660         for (int i = 0; i < child_ids.size(); i++)
    661         {
    662             String child_id = child_ids.get(i);
    663             Element child_elem = createDocNode(child_id);
    664             doc.appendChild(child_elem);
    665             if (recursive && (!child_elem.getAttribute(GSXML.NODE_TYPE_ATT).equals(GSXML.NODE_TYPE_LEAF) || child_elem.getAttribute(GSXML.DOC_TYPE_ATT).equals(GSXML.DOC_TYPE_PAGED)))
    666             {
    667                 addDescendants(child_elem, child_id, recursive);
    668             }
    669         }
     645      this.gs_doc.addDescendants(doc, doc_id, recursive);
    670646    }
    671647
     
    676652    protected Element addSiblings(Element parent_node, String parent_id, String current_id)
    677653    {
    678         Element current_node = GSXML.getFirstElementChild(parent_node);//(Element)parent_node.getFirstChild();
    679         if (current_node == null)
    680         {
    681             // create a sensible error message
    682             logger.error(" there should be a first child.");
    683             return null;
    684         }
    685         // remove the current child,- will add it in later in its correct place
    686         parent_node.removeChild(current_node);
    687 
    688         // add in all the siblings,
    689         addDescendants(parent_node, parent_id, false);
    690 
    691         // find the node that is now the current node
    692         // this assumes that the new node that was created is the same as
    693         // the old one that was removed - we may want to replace the new one
    694         // with the old one.
    695         Element new_current = GSXML.getNamedElement(parent_node, current_node.getNodeName(), GSXML.NODE_ID_ATT, current_id);
    696         return new_current;
     654      return this.gs_doc.addSiblings(parent_node, parent_id, current_id);
    697655    }
    698656
     
    725683    protected String getNodeType(String node_id, String doc_type)
    726684    {
    727         if (doc_type.equals(GSXML.DOC_TYPE_SIMPLE))
    728         {
    729             return GSXML.NODE_TYPE_LEAF;
    730         }
    731 
    732         if (getParentId(node_id) == null)
    733         {
    734             return GSXML.NODE_TYPE_ROOT;
    735         }
    736         if (doc_type.equals(GSXML.DOC_TYPE_PAGED))
    737         {
    738             return GSXML.NODE_TYPE_LEAF;
    739         }
    740         if (getChildrenIds(node_id) == null)
    741         {
    742             return GSXML.NODE_TYPE_LEAF;
    743         }
    744         return GSXML.NODE_TYPE_INTERNAL;
    745 
    746     }
    747 
    748     /**
    749      * if id ends in .fc, .pc etc, then translate it to the correct id default
    750      * implementation: just remove the suffix
     685    return this.gs_doc.getNodeType(node_id, doc_type);
     686    }
     687
     688    /**
     689     * if id ends in .fc, .pc etc, then translate it to the correct id
     690     * default implementation: just remove the suffix
    751691     */
    752692    protected String translateId(String id)
     
    784724     * returns the document type of the doc that the specified node belongs to.
    785725     * should be one of GSXML.DOC_TYPE_SIMPLE, GSXML.DOC_TYPE_PAGED,
    786      * GSXML.DOC_TYPE_HIERARCHY default implementation: return DOC_TYPE_SIMPLE
     726     * GSXML.DOC_TYPE_HIERARCHY
    787727     */
    788728    protected String getDocType(String node_id)
    789729    {
    790         return GSXML.DOC_TYPE_HIERARCHY;
     730        return this.gs_doc.getDocType(node_id);
    791731    }
    792732
    793733    /**
    794734     * returns the id of the root node of the document containing node node_id.
    795      * may be the same as node_id default implemntation: return node_id
     735     * may be the same as node_id
    796736     */
    797737    protected String getRootId(String node_id)
    798738    {
    799         return node_id;
    800     }
    801 
    802     /**
    803      * returns a list of the child ids in order, null if no children default
    804      * implementation: return null
     739        return  this.gs_doc.getRootId(node_id);
     740    }
     741
     742    /**
     743     * returns a list of the child ids in order, null if no children
    805744     */
    806745    protected ArrayList<String> getChildrenIds(String node_id)
    807746    {
    808         return null;
    809     }
    810 
    811     /**
    812      * returns the node id of the parent node, null if no parent default
    813      * implementation: return null
     747      return this.gs_doc.getChildrenIds(node_id);
     748    }
     749
     750    /**
     751     * returns the node id of the parent node, null if no parent
    814752     */
    815753    protected String getParentId(String node_id)
    816754    {
    817         return null;
     755      return this.gs_doc.getParentId(node_id);
    818756    }
    819757
     
    834772     * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
    835773     */
    836     abstract protected String getStructureInfo(String doc_id, String info_type);
    837 
    838     protected String getHrefOID(String href_url)
    839     {
    840         return null;
    841     }
     774  protected String getStructureInfo(String doc_id, String info_type) {
     775
     776    return this.gs_doc.getStructureInfo(doc_id, info_type);
     777  }
     778
    842779
    843780}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java

    r26023 r26046  
    2121// Greenstone classes
    2222import org.greenstone.gsdl3.core.GSException;
     23import org.greenstone.gsdl3.util.BasicDocumentDatabase;
    2324import org.greenstone.gsdl3.util.GSXML;
    2425import org.greenstone.gsdl3.util.GSFile;
     
    6364
    6465    protected SimpleCollectionDatabase coll_db = null;
    65 
     66  BasicDocumentDatabase gs_doc_db = null;
    6667    /** constructor */
    6768    protected AbstractGS2DocumentRetrieve()
     
    7475        super.cleanUp();
    7576        this.coll_db.closeDatabase();
     77        this.gs_doc_db.cleanUp();
    7678    }
    7779
     
    124126            return false;
    125127        }
     128
     129        gs_doc_db = new BasicDocumentDatabase(this.doc, database_type, this.site_home, this.cluster_name, this.index_stem);
     130        if (!gs_doc_db.isValid())
     131        {
     132            logger.error("Failed to open Document Database.");
     133            return false;
     134        }
     135        this.gs_doc = gs_doc_db;
    126136
    127137        // we need to set the database for our GS2 macro resolver
     
    153163    protected String getRootId(String node_id)
    154164    {
    155         return OID.getTop(node_id);
    156     }
    157 
    158     /** returns a list of the child ids in order, null if no children */
    159     protected ArrayList<String> getChildrenIds(String node_id)
    160     {
    161         DBInfo info = this.coll_db.getInfo(node_id);
    162         if (info == null)
    163         {
    164             return null;
    165         }
    166 
    167         String contains = info.getInfo("contains");
    168         if (contains.equals(""))
    169         {
    170             return null;
    171         }
    172         ArrayList<String> children = new ArrayList<String>();
    173         StringTokenizer st = new StringTokenizer(contains, ";");
    174         while (st.hasMoreTokens())
    175         {
    176             String child_id = StringUtils.replace(st.nextToken(), "\"", node_id);
    177             children.add(child_id);
    178         }
    179         return children;
    180 
    181     }
    182 
    183     /** returns the node id of the parent node, null if no parent */
    184     protected String getParentId(String node_id)
    185     {
    186         String parent = OID.getParent(node_id);
    187         if (parent.equals(node_id))
    188         {
    189             return null;
    190         }
    191         return parent;
    192     }
     165      return this.gs_doc.getRootId(node_id);
     166    }
     167
     168
    193169
    194170    /**
     
    236212    }
    237213
    238     /**
    239      * returns the structural information asked for. info_type may be one of
    240      * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
    241      */
    242     protected String getStructureInfo(String doc_id, String info_type)
    243     {
    244         String value = "";
    245         if (info_type.equals(INFO_NUM_SIBS))
    246         {
    247             String parent_id = OID.getParent(doc_id);
    248             if (parent_id.equals(doc_id))
    249             {
    250                 value = "0";
    251             }
    252             else
    253             {
    254                 value = String.valueOf(getNumChildren(parent_id));
    255             }
    256             return value;
    257         }
    258 
    259         if (info_type.equals(INFO_NUM_CHILDREN))
    260         {
    261             return String.valueOf(getNumChildren(doc_id));
    262         }
    263 
    264         if (info_type.equals(INFO_SIB_POS))
    265         {
    266             String parent_id = OID.getParent(doc_id);
    267             if (parent_id.equals(doc_id))
    268             {
    269                 return "-1";
    270             }
    271 
    272             DBInfo info = this.coll_db.getInfo(parent_id);
    273             if (info == null)
    274             {
    275                 return "-1";
    276             }
    277 
    278             String contains = info.getInfo("contains");
    279             contains = StringUtils.replace(contains, "\"", parent_id);
    280             String[] children = contains.split(";");
    281             for (int i = 0; i < children.length; i++)
    282             {
    283                 String child_id = children[i];
    284                 if (child_id.equals(doc_id))
    285                 {
    286                     return String.valueOf(i + 1); // make it from 1 to length
    287 
    288                 }
    289             }
    290 
    291             return "-1";
    292         }
    293         if (info_type.equals(INFO_DOC_TYPE))
    294    
    295         {
    296           return getDocType(doc_id);
    297         }
    298         return null;
    299     }
    300214
    301215    protected int getNumChildren(String node_id)
    302216    {
    303         DBInfo info = this.coll_db.getInfo(node_id);
    304         if (info == null)
    305         {
    306             return 0;
    307         }
    308         String contains = info.getInfo("contains");
    309         if (contains.equals(""))
    310         {
    311             return 0;
    312         }
    313         String[] children = contains.split(";");
    314         return children.length;
    315     }
    316 
    317     /**
    318      * returns the document type of the doc that the specified node belongs to.
    319      * should be one of GSXML.DOC_TYPE_SIMPLE, GSXML.DOC_TYPE_PAGED,
    320      * GSXML.DOC_TYPE_HIERARCHY
    321      */
    322     protected String getDocType(String node_id)
    323     {
    324         DBInfo info = this.coll_db.getInfo(node_id);
    325         if (info == null)
    326         {
    327             return GSXML.DOC_TYPE_SIMPLE;
    328         }
    329         String doc_type = info.getInfo("doctype");
    330         if (!doc_type.equals("") && !doc_type.equals("doc"))
    331         {
    332             return doc_type;
    333         }
    334 
    335         String top_id = OID.getTop(node_id);
    336         boolean is_top = (top_id.equals(node_id) ? true : false);
    337 
    338         String children = info.getInfo("contains");
    339         boolean is_leaf = (children.equals("") ? true : false);
    340 
    341         if (is_top && is_leaf)
    342         { // a single section document
    343             return GSXML.DOC_TYPE_SIMPLE;
    344         }
    345 
    346         // now we just check the top node
    347         if (!is_top)
    348         { // we need to look at the top info
    349             info = this.coll_db.getInfo(top_id);
    350         }
    351         if (info == null)
    352         {
    353             return GSXML.DOC_TYPE_HIERARCHY;
    354         }
    355 
    356         String childtype = info.getInfo("childtype");
    357         if (childtype.equals("Paged"))
    358         {
    359             return GSXML.DOC_TYPE_PAGED;
    360         }
    361         if (childtype.equals("PagedHierarchy"))
    362           {
    363             return GSXML.DOC_TYPE_PAGED_HIERARCHY;
    364           }
    365         return GSXML.DOC_TYPE_HIERARCHY;
    366     }
     217      return this.gs_doc.getNumChildren(node_id);
     218    }
     219
    367220
    368221    /**
     
    591444    }
    592445
    593     protected Element getInfo(String doc_id, String info_type)
    594     {
    595 
    596         String value = "";
    597         if (info_type.equals(INFO_NUM_SIBS))
    598         {
    599             String parent_id = OID.getParent(doc_id);
    600             if (parent_id.equals(doc_id))
    601             {
    602                 value = "0";
    603             }
    604             else
    605             {
    606                 value = String.valueOf(getNumChildren(parent_id));
    607             }
    608         }
    609         else if (info_type.equals(INFO_NUM_CHILDREN))
    610         {
    611             value = String.valueOf(getNumChildren(doc_id));
    612         }
    613         else if (info_type.equals(INFO_SIB_POS))
    614         {
    615             String parent_id = OID.getParent(doc_id);
    616             if (parent_id.equals(doc_id))
    617             {
    618                 value = "-1";
    619             }
    620             else
    621             {
    622                 DBInfo info = this.coll_db.getInfo(parent_id);
    623                 if (info == null)
    624                 {
    625                     value = "-1";
    626                 }
    627                 else
    628                 {
    629                     String contains = info.getInfo("contains");
    630                     contains = StringUtils.replace(contains, "\"", parent_id);
    631                     String[] children = contains.split(";");
    632                     for (int i = 0; i < children.length; i++)
    633                     {
    634                         String child_id = children[i];
    635                         if (child_id.equals(doc_id))
    636                         {
    637                             value = String.valueOf(i + 1); // make it from 1 to length
    638                             break;
    639                         }
    640                     }
    641                 }
    642             }
    643         }
    644         else
    645         {
    646             return null;
    647         }
    648         Element info_elem = this.doc.createElement("info");
    649         info_elem.setAttribute(GSXML.NAME_ATT, info_type);
    650         info_elem.setAttribute(GSXML.VALUE_ATT, value);
    651         return info_elem;
    652     }
    653 
    654     protected String getHrefOID(String href_url)
    655     {
    656         return this.coll_db.docnum2OID(href_url);
    657     }
     446
    658447
    659448}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2TextSearch.java

    r26042 r26046  
    1818package org.greenstone.gsdl3.service;
    1919
    20 // Greenstone classes
    2120import java.util.ArrayList;
    2221
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r25967 r26046  
    2626
    2727import org.apache.log4j.Logger;
     28import org.greenstone.gsdl3.util.BasicDocumentDatabase;
    2829import org.greenstone.gsdl3.util.DBInfo;
    2930import org.greenstone.gsdl3.util.GS2MacroResolver;
     
    4546
    4647    protected SimpleCollectionDatabase coll_db = null;
    47 
     48  BasicDocumentDatabase gs_doc_db = null;
    4849    public GS2Browse()
    4950    {
     
    5455        super.cleanUp();
    5556        this.coll_db.closeDatabase();
     57        this.gs_doc_db.cleanUp();
    5658    }
    5759
     
    8890            database_type = "gdbm"; // the default
    8991        }
     92
     93        // do we still need this????
    9094        coll_db = new SimpleCollectionDatabase(database_type);
    9195        if (!coll_db.databaseOK())
     
    103107        }
    104108        this.macro_resolver = new GS2MacroResolver(this.coll_db);
     109       
     110        gs_doc_db = new BasicDocumentDatabase(this.doc, database_type, this.site_home, this.cluster_name, index_stem);
     111        if (!gs_doc_db.isValid())
     112        {
     113            logger.error("Failed to open Document Database.");
     114            return false;
     115        }
     116        this.gs_doc = gs_doc_db;
     117
     118   
    105119        return true;
    106120    }
     
    122136    }
    123137
    124     /**
    125      * returns the document type of the doc that the specified node belongs to.
    126      * should be one of GSXML.DOC_TYPE_SIMPLE, GSXML.DOC_TYPE_PAGED,
    127      * GSXML.DOC_TYPE_HIERARCHY
    128      */
    129     protected String getDocType(String node_id)
    130     {
    131         DBInfo info = this.coll_db.getInfo(node_id);
    132         if (info == null)
    133         {
    134             return GSXML.DOC_TYPE_SIMPLE;
    135         }
    136         String doc_type = info.getInfo("doctype");
    137         if (!doc_type.equals("") && !doc_type.equals("doc"))
    138         {
    139             return doc_type;
    140         }
    141 
    142         String top_id = OID.getTop(node_id);
    143         boolean is_top = (top_id.equals(node_id) ? true : false);
    144 
    145         String children = info.getInfo("contains");
    146         boolean is_leaf = (children.equals("") ? true : false);
    147 
    148         if (is_top && is_leaf)
    149         { // a single section document
    150             return GSXML.DOC_TYPE_SIMPLE;
    151         }
    152 
    153         // now we just check the top node
    154         if (!is_top)
    155         { // we need to look at the top info
    156             info = this.coll_db.getInfo(top_id);
    157         }
    158         if (info == null)
    159         {
    160             return GSXML.DOC_TYPE_HIERARCHY;
    161         }
    162 
    163         String childtype = info.getInfo("childtype");
    164         if (childtype.equals("Paged"))
    165         {
    166             return GSXML.DOC_TYPE_PAGED;
    167         }
    168         if (childtype.equals("PagedHierarchy"))
    169           {
    170             return GSXML.DOC_TYPE_PAGED_HIERARCHY;
    171           }
    172         return GSXML.DOC_TYPE_HIERARCHY;
    173 
    174     }
    175 
    176     /**
    177      * returns the id of the root node of the document containing node node_id.
    178      * . may be the same as node_id
    179      */
    180     protected String getRootId(String node_id)
    181     {
    182         return OID.getTop(node_id);
    183     }
    184 
    185     /** returns a list of the child ids in order, null if no children */
    186     protected ArrayList<String> getChildrenIds(String node_id)
    187     {
    188         DBInfo info = this.coll_db.getInfo(node_id);
    189         if (info == null)
    190         {
    191             return null;
    192         }
    193 
    194         ArrayList<String> children = new ArrayList<String>();
    195 
    196         String contains = info.getInfo("contains");
    197         StringTokenizer st = new StringTokenizer(contains, ";");
    198         while (st.hasMoreTokens())
    199         {
    200             String child_id = st.nextToken().replaceAll("\"", node_id);
    201             children.add(child_id);
    202         }
    203         return children;
    204 
    205     }
    206 
    207     /** returns the node id of the parent node, null if no parent */
    208     protected String getParentId(String node_id)
    209     {
    210         String parent = OID.getParent(node_id);
    211         if (parent.equals(node_id))
    212         {
    213             return null;
    214         }
    215         return parent;
    216     }
     138
     139
    217140
    218141    protected String getMetadata(String node_id, String key)
     
    281204    }
    282205
    283     /**
    284      * returns the structural information asked for. info_type may be one of
    285      * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
    286      */
    287     protected String getStructureInfo(String doc_id, String info_type)
    288     {
    289         String value = "";
    290         if (info_type.equals(INFO_NUM_SIBS))
    291         {
    292             String parent_id = OID.getParent(doc_id);
    293             if (parent_id.equals(doc_id))
    294             {
    295                 value = "0";
    296             }
    297             else
    298             {
    299                 value = String.valueOf(getNumChildren(parent_id));
    300             }
    301             return value;
    302         }
    303 
    304         if (info_type.equals(INFO_NUM_CHILDREN))
    305         {
    306             return String.valueOf(getNumChildren(doc_id));
    307         }
    308 
    309         if (info_type.equals(INFO_SIB_POS))
    310         {
    311             String parent_id = OID.getParent(doc_id);
    312             if (parent_id.equals(doc_id))
    313             {
    314                 return "-1";
    315             }
    316 
    317             DBInfo info = this.coll_db.getInfo(parent_id);
    318             if (info == null)
    319             {
    320                 return "-1";
    321             }
    322 
    323             String contains = info.getInfo("contains");
    324             contains = contains.replaceAll("\"", parent_id);
    325             String[] children = contains.split(";");
    326             for (int i = 0; i < children.length; i++)
    327             {
    328                 String child_id = children[i];
    329                 if (child_id.equals(doc_id))
    330                 {
    331                     return String.valueOf(i + 1); // make it from 1 to length
    332 
    333                 }
    334             }
    335 
    336             return "-1";
    337         }
    338         else
    339         {
    340             return null;
    341         }
    342 
    343     }
    344206
    345207    protected int getNumChildren(String node_id)
    346208    {
    347         DBInfo info = this.coll_db.getInfo(node_id);
    348         if (info == null)
    349         {
    350             return 0;
    351         }
    352         String contains = info.getInfo("contains");
    353         if (contains.equals(""))
    354         {
    355             return 0;
    356         }
    357         String[] children = contains.split(";");
    358         return children.length;
     209      return this.gs_doc.getNumChildren(node_id);
    359210    }
    360211
Note: See TracChangeset for help on using the changeset viewer.