Changeset 24992


Ignore:
Timestamp:
2012-01-26T11:41:25+13:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

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

    r16688 r24992  
    55import org.greenstone.gsdl3.service.TEIRetrieve;
    66// XML classes
    7 import org.w3c.dom.Node; 
    8 import org.w3c.dom.NodeList; 
    9 import org.w3c.dom.Text; 
    10 import org.w3c.dom.Document; 
    11 import org.w3c.dom.Element; 
     7import org.w3c.dom.Node;
     8import org.w3c.dom.NodeList;
     9import org.w3c.dom.Text;
     10import org.w3c.dom.Document;
     11import org.w3c.dom.Element;
    1212
    1313import java.util.HashMap;
     
    1919
    2020/** action class for retrieving parts of XML documents */
    21 public class XMLDocumentAction extends Action {
    22    
    23    
    24     /** process - processes a request.
    25      */
    26     public Node process (Node message_node) {
    27    
    28     Element message = this.converter.nodeToElement(message_node);
     21public class XMLDocumentAction extends Action
     22{
    2923
    30     // get the request - assume there is only one
    31     Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     24    /**
     25     * process - processes a request.
     26     */
     27    public Node process(Node message_node)
     28    {
    3229
    33     // create the return message
    34     Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    35     Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
    36     result.appendChild(page_response);
    37    
    38     // extract the params from the cgi-request, and check that we have a coll specified
    39     Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    40     HashMap params = GSXML.extractParams(cgi_param_list, false);
     30        Element message = this.converter.nodeToElement(message_node);
    4131
    42     String collection = (String)params.get(GSParams.COLLECTION);
    43     if (collection == null || collection.equals("")) {
    44         return result;
     32        // get the request - assume there is only one
     33        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     34
     35        // create the return message
     36        Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
     37        Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     38        result.appendChild(page_response);
     39
     40        // extract the params from the cgi-request, and check that we have a coll specified
     41        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     42        HashMap params = GSXML.extractParams(cgi_param_list, false);
     43
     44        String collection = (String) params.get(GSParams.COLLECTION);
     45        if (collection == null || collection.equals(""))
     46        {
     47            return result;
     48        }
     49        String doc_name = (String) params.get(GSParams.DOCUMENT);
     50        if (doc_name == null || doc_name.equals(""))
     51        {
     52            return result;
     53        }
     54        String lang = request.getAttribute(GSXML.LANG_ATT);
     55        String uid = request.getAttribute(GSXML.USER_ID_ATT);
     56
     57        // subaction used to decide if we are returning content or structure
     58        String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
     59        String to = null;
     60        if (document_mode.equals("text"))
     61        {
     62            to = GSPath.appendLink(collection, "DocumentContentRetrieve");
     63        }
     64        else if (document_mode.equals("toc"))
     65        {
     66            to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
     67        }
     68        else
     69        { // the default is text
     70            to = GSPath.appendLink(collection, "DocumentContentRetrieve");
     71        }
     72
     73        // make the request to the collection
     74        Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     75
     76        Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     77        mr_message.appendChild(ret_request);
     78
     79        Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     80        ret_request.appendChild(doc_list);
     81        Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     82        doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
     83        doc_list.appendChild(doc);
     84
     85        // also add in a request for the Title metadata
     86        to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
     87        Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     88        // copy the doc list
     89        meta_request.appendChild(doc_list.cloneNode(true));
     90        // add in a metadata param
     91        Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     92        meta_request.appendChild(param_list);
     93        Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
     94        param_list.appendChild(param);
     95
     96        // add the request to the message
     97        mr_message.appendChild(meta_request);
     98
     99        Element ret_response = (Element) this.mr.process(mr_message);
     100        String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
     101        String path = GSPath.createPath(links);
     102        Element doc_node = (Element) this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
     103        page_response.appendChild(doc_node);
     104
     105        // get the metadata list
     106        Element meta_response = (Element) ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
     107        String[] mlinks = { GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER };
     108        path = GSPath.createPath(mlinks);
     109
     110        Element meta_list = (Element) GSXML.getNodeByPath(meta_response, path);
     111        if (meta_list != null)
     112        {
     113            doc_node.appendChild(this.doc.importNode(meta_list, true));
     114        }
     115        return result;
    45116    }
    46     String doc_name = (String) params.get(GSParams.DOCUMENT);
    47     if (doc_name == null || doc_name.equals("")) {
    48         return result;
    49     }
    50     String lang = request.getAttribute(GSXML.LANG_ATT);
    51     String uid = request.getAttribute(GSXML.USER_ID_ATT);
    52    
    53     // subaction used to decide if we are returning content or structure
    54     String document_mode = request.getAttribute(GSXML.SUBACTION_ATT);
    55     String to = null;
    56     if (document_mode.equals("text")) {
    57         to = GSPath.appendLink(collection, "DocumentContentRetrieve");
    58     } else if (document_mode.equals("toc")) {
    59         to = GSPath.appendLink(collection, "DocumentStructureRetrieve");
    60     } else { // the default is text
    61         to = GSPath.appendLink(collection, "DocumentContentRetrieve");
    62     }
    63    
    64     // make the request to the collection
    65     Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    66    
    67     Element ret_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    68     mr_message.appendChild(ret_request);
    69 
    70     Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    71     ret_request.appendChild(doc_list);
    72     Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    73     doc.setAttribute(GSXML.NODE_ID_ATT, doc_name);
    74     doc_list.appendChild(doc);
    75    
    76     // also add in a request for the Title metadata
    77     to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
    78     Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    79     // copy the doc list
    80     meta_request.appendChild(doc_list.cloneNode(true));
    81     // add in a metadata param
    82     Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    83     meta_request.appendChild(param_list);
    84     Element param = GSXML.createParameter(this.doc, "metadata", "root_Title");
    85     param_list.appendChild(param);
    86    
    87     // add the request to the message
    88     mr_message.appendChild(meta_request);
    89    
    90     Element ret_response = (Element)this.mr.process(mr_message);
    91     String [] links = {GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM};
    92     String path = GSPath.createPath(links);
    93     Element doc_node = (Element)this.doc.importNode(GSXML.getNodeByPath(ret_response, path), true);
    94     page_response.appendChild(doc_node);
    95 
    96     // get the metadata list
    97     Element meta_response = (Element)ret_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
    98     String [] mlinks  = {GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER};
    99     path = GSPath.createPath(mlinks);
    100    
    101     Element meta_list = (Element)GSXML.getNodeByPath(meta_response, path);
    102     if (meta_list != null) {
    103         doc_node.appendChild(this.doc.importNode(meta_list, true));
    104     }
    105     return result;
    106     }
    107117
    108118}
Note: See TracChangeset for help on using the changeset viewer.