Ignore:
Timestamp:
2017-11-14T14:14:01+13:00 (6 years ago)
Author:
kjdon
Message:

if docEdit=1, then we just retrieve the entire document from archives, then convert to internal format using xslt. Also, don;t get document text if noText=1

File:
1 edited

Legend:

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

    r31686 r32068  
    5252    public static final String EXPAND_CONTENTS_ARG = "ec";
    5353    public static final String REALISTIC_BOOK_ARG = "book";
    54 
     54        public static final String NO_TEXT_ARG = "noText";
     55        public static final String DOC_EDIT_ARG = "docEdit";
     56 
    5557    /**
    5658     * if this is set to true, when a document is displayed, any annotation type
     
    8284
    8385        Element message = GSXML.nodeToElement(message_node);
    84         Document doc = message.getOwnerDocument();
     86        Document doc = XMLConverter.newDOM(); //message.getOwnerDocument();
    8587       
    8688        // the response
     
    146148          }
    147149        }
     150
     151
     152        boolean editing_document = false;
     153        String doc_edit = (String) params.get(DOC_EDIT_ARG);
     154        if (doc_edit != null && doc_edit.equals("1")) {
     155          editing_document = true;
     156        }
     157
     158        // are we editing mode? just get the archive document, convert to our internal doc format, and return it
     159        if (editing_document) {
     160
     161          // call get archive doc
     162          Element dx_message = doc.createElement(GSXML.MESSAGE_ELEM);
     163          String to = "DocXMLGetSection";
     164          Element dx_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     165          dx_message.appendChild(dx_request);
     166          Element dx_section = doc.createElement(GSXML.DOCXML_SECTION_ELEM);
     167          dx_section.setAttribute(GSXML.NODE_ID_ATT, document_id);
     168          dx_section.setAttribute(GSXML.COLLECTION_ATT, collection);
     169          dx_request.appendChild(dx_section);
     170
     171          Element dx_response_message = (Element) this.mr.process(dx_message);
     172          if (processErrorElements(dx_response_message, page_response))
     173            {
     174              return result;
     175            }
     176
     177          // get the section out
     178          String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOCXML_SECTION_ELEM);
     179          Element section = (Element) GSXML.getNodeByPath(dx_response_message, path);
     180          if (section == null) {
     181            logger.error("no archive doc returned for "+document_id);
     182            return result;
     183          }
     184          // convert the archive format into the internal format that the page response requires
     185
     186          Element doc_elem = doc.createElement(GSXML.DOCUMENT_ELEM);
     187          page_response.appendChild(doc_elem);
     188          section.setAttribute(GSXML.NODE_ID_ATT, document_id);
     189
     190          Element transformed_section = transformArchiveToDocument(section);
     191          doc_elem.appendChild(doc.importNode(transformed_section, true));
     192          logger.error("dx result = "+XMLConverter.getPrettyString(result));
     193          return result;
     194        }
     195
    148196        String document_type = (String) params.get(GSParams.DOCUMENT_TYPE);
    149197        if (document_type != null && document_type.equals(""))
     
    189237        }
    190238
    191         // UserContext userContext = new UserContext(request);
    192 
    193         // //append site metadata
    194         // addSiteMetadata(page_response, userContext);
    195         // addInterfaceOptions(page_response);
    196 
    197         // // get the additional data needed for the page
    198         // getBackgroundData(page_response, collection, userContext);
    199         // Element format_elem = (Element) GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM);
     239        // do we want text content? Not if no_text=1.
     240        // expand_document overrides this. - should it??
     241        boolean get_text = true;
     242        String nt_arg = (String) params.get(NO_TEXT_ARG);
     243       
     244        if (!expand_document && nt_arg!=null && nt_arg.equals("1")) {
     245          logger.error("SETTING GET TEXT TO FALSE");
     246          get_text = false;
     247        } else {
     248          logger.error("GET TEXT REMAINS TRUE");
     249        }
    200250
    201251        // the_document is where all the doc info - structure and metadata etc
     
    500550        Element top_doc_node = (Element) GSXML.getNodeByPath(doc_meta_response, "documentNodeList/documentNode");
    501551        GSXML.mergeMetadataLists(the_document, top_doc_node);
     552
     553        // do we want doc text content? If not, we are done.
     554        if (!get_text) {
     555          // don't get text
     556          return result;
     557        }
    502558
    503559        // Build a request to obtain some document content
     
    831887    }
    832888
     889  /** run the XSLT transform which converts from doc.xml format to our internal document format */
     890    protected Element transformArchiveToDocument(Element section) {
     891   
     892    String stylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), "", (String) this.config_params.get(GSConstants.INTERFACE_NAME), null, "archive2document.xsl");
     893    Document stylesheet_doc = XMLConverter.getDOM(new File(stylesheet_file));
     894    if (stylesheet_doc == null) {
     895      logger.error("Couldn't load in stylesheet "+stylesheet_file);
     896      return section;
     897    }
     898
     899    Document section_doc = XMLConverter.newDOM();
     900    section_doc.appendChild(section_doc.importNode(section, true));
     901    Node result = this.transformer.transform(stylesheet_doc, section_doc);
     902    logger.error("transform result = "+XMLConverter.getPrettyString(result));
     903
     904    Element new_element;
     905    if (result.getNodeType() == Node.DOCUMENT_NODE)
     906      {
     907    new_element = ((Document) result).getDocumentElement();
     908      }
     909    else
     910      {
     911    new_element = (Element) result;
     912      }
     913
     914   
     915    return new_element;
     916
     917  }
     918
     919
    833920    /**
    834921     * this involves a bit of a hack to get the equivalent query terms - has to
Note: See TracChangeset for help on using the changeset viewer.