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

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.