Ignore:
Timestamp:
2017-11-14T23:50:42+13:00 (6 years ago)
Author:
ak19
Message:

Changes to set the docType of the <document> element and to set the docType, nodeType and nodeID on each <documentNode>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java

    r32070 r32071  
    158158        // what if it is null here?? Anu to check...
    159159
     160
    160161        boolean editing_document = false;
    161162        String doc_edit = (String) params.get(DOC_EDIT_ARG);
     
    192193          // convert the archive format into the internal format that the page response requires
    193194
    194           Element doc_elem = doc.createElement(GSXML.DOCUMENT_ELEM);
     195          // work out doctype
     196          // create a basic doc list containing the current node
     197          Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     198          Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM);
     199          basic_doc_list.appendChild(current_doc);
     200          current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id);     
     201          basic_doc_list.appendChild(current_doc);
     202          if (document_type == null) {
     203              document_type = getDocumentType(basic_doc_list, collection, userContext, page_response);
     204          }
     205          if (document_type == null) {
     206              logger.debug("@@@ doctype is null, setting to simple");
     207              document_type = GSXML.DOC_TYPE_SIMPLE;
     208          }       
     209         
     210          Element doc_elem = doc.createElement(GSXML.DOCUMENT_ELEM);         
    195211          doc_elem.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
    196212          page_response.appendChild(doc_elem);
    197213          section.setAttribute(GSXML.NODE_ID_ATT, document_id);
    198214
     215       
    199216          Element transformed_section = transformArchiveToDocument(section);
     217          // In docEdit mode, we obtain the text from archives, from doc.xml
     218          // Now the transformation has replaced <Section> with <documentNode>
     219          // Need to add nodeID, nodeType and docType attributes to each docNode
     220          // as doc.xml doesn't store that.
     221          insertDocNodeAttributes(transformed_section, document_type, null);         
    200222          doc_elem.appendChild(doc.importNode(transformed_section, true));
    201           logger.error("dx result = "+XMLConverter.getPrettyString(result));
     223          logger.debug("dx result = "+XMLConverter.getPrettyString(result));
     224
    202225          return result;
    203226        }
    204 
     227       
    205228        //whether to retrieve siblings or not
    206229        boolean get_siblings = false;
     
    246269       
    247270        if (!expand_document && nt_arg!=null && nt_arg.equals("1")) {
    248           logger.error("SETTING GET TEXT TO FALSE");
     271          logger.debug("SETTING GET TEXT TO FALSE");
    249272          get_text = false;
    250273        } else {
    251           logger.error("GET TEXT REMAINS TRUE");
     274          logger.debug("GET TEXT REMAINS TRUE");
    252275        }
    253276
     
    271294            current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
    272295        }
    273 
     296       
    274297        if (document_type == null)
    275298        {
     
    278301        if (document_type == null)
    279302        {
    280             logger.debug("doctype is null, setting to simple");
     303            logger.debug("##### doctype is null, setting to simple");
    281304            document_type = GSXML.DOC_TYPE_SIMPLE;
    282305        }
     
    284307        the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
    285308       
    286 
    287309        // Create a parameter list to specify the required structure information
    288310        Element ds_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     
    890912    }
    891913
     914    // Recursive method to set the docType, nodeType and nodeID attributes of each docNode
     915    // The docType remains constant as in parameter document_type
     916    // The nodeID for the first (root) docNode is already set. For all children, the rootNode id
     917    // is updated to be <parent-id>.<num-child>, where the first parent-id is rootNode id.
     918    // The nodeType is root if rootNode, internal if there are children and leaf if no children
     919    protected void insertDocNodeAttributes(Element docNode, String document_type, String id) {
     920
     921    boolean isRoot =  false;
     922    if(id == null) { // rootNode, get the root nodeID to work with recursively
     923        id = docNode.getAttribute(GSXML.NODE_ID_ATT);
     924        isRoot = true;
     925    } else { // for all but the root node, need to still set the nodeID
     926        docNode.setAttribute(GSXML.NODE_ID_ATT, id);
     927    }
     928   
     929    docNode.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
     930   
     931    NodeList docNodes = GSXML.getChildrenByTagName(docNode, GSXML.DOC_NODE_ELEM);
     932    if(docNodes.getLength() > 0) {     
     933        docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL);
     934        for(int i = 0; i < docNodes.getLength(); i++) {
     935        Element childDocNode = (Element)docNodes.item(i);
     936       
     937        // work out the child docNode's nodeID based on current id
     938        String nodeID = id + "." + (i+1);       
     939        insertDocNodeAttributes(childDocNode, document_type, nodeID); //recursion step
     940        }
     941    } else {
     942        docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
     943    }
     944
     945    // rootNode's nodeType is a special case: it's "root", not "leaf" or "internal"
     946    if(isRoot) docNode.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
     947   
     948    }
     949
    892950  /** run the XSLT transform which converts from doc.xml format to our internal document format */
    893951    protected Element transformArchiveToDocument(Element section) {
     
    903961    section_doc.appendChild(section_doc.importNode(section, true));
    904962    Node result = this.transformer.transform(stylesheet_doc, section_doc);
    905     logger.error("transform result = "+XMLConverter.getPrettyString(result));
     963    logger.debug("transform result = "+XMLConverter.getPrettyString(result));
    906964
    907965    Element new_element;
    908     if (result.getNodeType() == Node.DOCUMENT_NODE)
    909       {
     966    if (result.getNodeType() == Node.DOCUMENT_NODE) {
    910967    new_element = ((Document) result).getDocumentElement();
    911       }
    912     else
    913       {
     968    } else {
    914969    new_element = (Element) result;
    915       }
     970    }
    916971
    917972   
Note: See TracChangeset for help on using the changeset viewer.