Changeset 25984


Ignore:
Timestamp:
2012-07-19T14:36:43+12:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file

File:
1 edited

Legend:

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

    r25635 r25984  
    11package org.greenstone.gsdl3.action;
    22
    3 import org.greenstone.gsdl3.core.ModuleInterface;
    4 import org.greenstone.gsdl3.util.*;
    5 // XML classes
    6 import org.w3c.dom.Node;
    7 import org.w3c.dom.NodeList;
    8 import org.w3c.dom.Document;
    9 import org.w3c.dom.Element;
    10 
     3import java.io.Serializable;
    114import java.util.HashMap;
    125import java.util.HashSet;
    13 import java.util.Vector;
    14 import java.io.File;
    15 import java.io.Serializable;
    16 
    17 import org.apache.log4j.*;
    18 
    19 //NOTE: this class not used at present!!!!!
     6
     7import org.apache.log4j.Logger;
     8import org.greenstone.gsdl3.util.GSParams;
     9import org.greenstone.gsdl3.util.GSPath;
     10import org.greenstone.gsdl3.util.GSXML;
     11import org.greenstone.gsdl3.util.OID;
     12import org.greenstone.gsdl3.util.UserContext;
     13import org.w3c.dom.Element;
     14import org.w3c.dom.Node;
     15import org.w3c.dom.NodeList;
     16OTE: this class not used at present!!!!!
    2017/** action for classifier browsing */
    21 public class BrowseAction extends Action {
    22 
    23     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.BrowseAction.class.getName());
    24 
    25     public static final String CLASSIFIER_ARG = "cl";
    26     public static final String SIBLING_ARG = "sib";
    27 
    28     /** process the request */
    29     public Node process (Node message_node) {
    30 
    31     Element message = this.converter.nodeToElement(message_node);
    32 
    33     // get the request - assume only one
    34     Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    35 
    36     // the result
    37     Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    38     Element response = classifierBrowse(request);
    39     result.appendChild(response);
    40     return result;
    41     }
    42    
    43 
    44     protected Element classifierBrowse(Element request) {
    45 
    46     Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
    47 
    48     // extract the params from the cgi-request, and check that we have a coll specified
    49     Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    50     HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
    51 
    52     String service_name = (String)params.get(GSParams.SERVICE);
    53     String collection = (String)params.get(GSParams.COLLECTION);
    54     if (collection == null || collection.equals("")) {
    55         logger.error("classifierBrowse, need to specify a collection!");
    56         return page_response;
    57        
     18public class BrowseAction extends Action
     19{
     20
     21    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.BrowseAction.class.getName());
     22
     23    public static final String CLASSIFIER_ARG = "cl";
     24    public static final String SIBLING_ARG = "sib";
     25
     26    /** process the request */
     27    public Node process(Node message_node)
     28    {
     29
     30        Element message = this.converter.nodeToElement(message_node);
     31
     32        // get the request - assume only one
     33        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     34
     35        // the result
     36        Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
     37        Element response = classifierBrowse(request);
     38        result.appendChild(response);
     39        return result;
    5840    }
    59    
    60     //whether to retrieve siblings or not
    61     boolean get_siblings = false;
    62     String sibs = (String) params.get(SIBLING_ARG);
    63     if (sibs != null && sibs.equals("1")) {
    64         get_siblings = true;
     41
     42    protected Element classifierBrowse(Element request)
     43    {
     44
     45        Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     46
     47        // extract the params from the cgi-request, and check that we have a coll specified
     48        Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     49        HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
     50
     51        String service_name = (String) params.get(GSParams.SERVICE);
     52        String collection = (String) params.get(GSParams.COLLECTION);
     53        if (collection == null || collection.equals(""))
     54        {
     55            logger.error("classifierBrowse, need to specify a collection!");
     56            return page_response;
     57
     58        }
     59
     60        //whether to retrieve siblings or not
     61        boolean get_siblings = false;
     62        String sibs = (String) params.get(SIBLING_ARG);
     63        if (sibs != null && sibs.equals("1"))
     64        {
     65            get_siblings = true;
     66        }
     67
     68        UserContext userContext = new UserContext(request);
     69        String to = GSPath.appendLink(collection, service_name);
     70
     71        // the first part of the response is the service description
     72        // for now get this again from the service.
     73        // this should be cached somehow later on.
     74
     75        Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     76        Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
     77        info_message.appendChild(info_request);
     78
     79        // also get the format stuff now if there is some
     80        Element format_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, to, userContext);
     81        info_message.appendChild(format_request);
     82        // process the requests
     83
     84        Element info_response = (Element) this.mr.process(info_message);
     85
     86        // the two responses
     87        NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
     88        Element service_response = (Element) responses.item(0);
     89        Element format_response = (Element) responses.item(1);
     90
     91        Element service_description = (Element) GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM);
     92        page_response.appendChild(this.doc.importNode(service_description, true));
     93
     94        //append site metadata
     95        addSiteMetadata(page_response, userContext);
     96        addInterfaceOptions(page_response);
     97
     98        // if rt=d, then we are just displaying the service
     99        String request_type = (String) params.get(GSParams.REQUEST_TYPE);
     100        if (request_type.equals("d"))
     101        {
     102            //return the page that we have so far
     103            return page_response;
     104        }
     105
     106        // get the node that the user has clicked on
     107        String classifier_node = (String) params.get(CLASSIFIER_ARG);
     108
     109        // if the node is not defined, return the page that we have so far
     110        if (classifier_node == null || classifier_node.equals(""))
     111        {
     112            return page_response;
     113        }
     114
     115        // the id of the classifier is the top id of the selected node
     116        String top_id = OID.getTop(classifier_node);
     117
     118        HashSet<String> metadata_names = new HashSet<String>();
     119
     120        // add the format info into the response
     121        Element format_elem = (Element) GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM);
     122        if (format_elem != null)
     123        {
     124            // find the one for the classifier we are in
     125            Element this_format = GSXML.getNamedElement(format_elem, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
     126            if (this_format == null)
     127            {
     128                this_format = (Element) GSXML.getChildByTagName(format_elem, GSXML.DEFAULT_ELEM);
     129            }
     130            if (this_format != null)
     131            {
     132                Element new_format = GSXML.duplicateWithNewName(this.doc, this_format, GSXML.FORMAT_ELEM, false);
     133                // set teh format type
     134                new_format.setAttribute(GSXML.TYPE_ATT, "browse");
     135
     136                page_response.appendChild(new_format);
     137                getRequiredMetadataNames(new_format, metadata_names);
     138            }
     139        }
     140
     141        logger.info("extracted meta names, " + metadata_names.toString());
     142        // get the browse structure for the selected node
     143        Element classify_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     144        Element classify_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     145        classify_message.appendChild(classify_request);
     146
     147        //Create a parameter list to specify the required structure information
     148        // for now, always get ancestors and children
     149        Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     150        classify_request.appendChild(param_list);
     151        Element param = this.doc.createElement(GSXML.PARAM_ELEM);
     152        param_list.appendChild(param);
     153        param.setAttribute(GSXML.NAME_ATT, "structure");
     154        param.setAttribute(GSXML.VALUE_ATT, "ancestors");
     155        param = this.doc.createElement(GSXML.PARAM_ELEM);
     156        param_list.appendChild(param);
     157        param.setAttribute(GSXML.NAME_ATT, "structure");
     158        param.setAttribute(GSXML.VALUE_ATT, "children");
     159        if (get_siblings)
     160        {
     161            param = this.doc.createElement(GSXML.PARAM_ELEM);
     162            param_list.appendChild(param);
     163            param.setAttribute(GSXML.NAME_ATT, "structure");
     164            param.setAttribute(GSXML.VALUE_ATT, "siblings");
     165        }
     166
     167        // put the classifier node into a classifier node list
     168        Element classifier_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
     169        Element classifier = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
     170        classifier.setAttribute(GSXML.NODE_ID_ATT, classifier_node);
     171        classifier_list.appendChild(classifier);
     172        classify_request.appendChild(classifier_list);
     173
     174        // process the request
     175        Element classify_response = (Element) this.mr.process(classify_message);
     176        // get the structure element
     177        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
     178        path = GSPath.appendLink(path, GSXML.CLASS_NODE_ELEM);
     179        path = GSPath.appendLink(path, GSXML.NODE_STRUCTURE_ELEM);
     180        // assume that we always get back the top level CL1 node - this becomes the page_classifier node
     181        path = GSPath.appendLink(path, GSXML.CLASS_NODE_ELEM);
     182        Element cl_structure = (Element) GSXML.getNodeByPath(classify_response, path);
     183        if (cl_structure == null)
     184        {
     185            logger.error("classifier structure request returned no structure");
     186            return page_response;
     187        }
     188
     189        // add the classifier node as the page classifier
     190        Element page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure, GSXML.CLASSIFIER_ELEM, true);
     191        page_response.appendChild(page_classifier);
     192        page_classifier.setAttribute(GSXML.NAME_ATT, top_id);
     193
     194        // get the metadata for each classifier node,
     195        // then for each document node
     196
     197        Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     198
     199        boolean did_classifier = false;
     200        boolean did_documents = false;
     201
     202        // if there are classifier nodes
     203        // create a metadata request for the classifier, and add it to
     204        // the the message
     205        NodeList cl_nodes = page_classifier.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
     206
     207        if (cl_nodes.getLength() > 0)
     208        {
     209            did_classifier = true;
     210            Element cl_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to + "MetadataRetrieve", userContext);
     211            metadata_message.appendChild(cl_meta_request);
     212
     213            Element new_cl_nodes_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
     214            cl_meta_request.appendChild(new_cl_nodes_list);
     215
     216            for (int c = 0; c < cl_nodes.getLength(); c++)
     217            {
     218
     219                Element cl = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
     220                cl.setAttribute(GSXML.NODE_ID_ATT, ((Element) cl_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
     221                new_cl_nodes_list.appendChild(cl);
     222            }
     223
     224            // create and add in the param list - for now get all the metadata
     225            // should be based on info sent in from the recept, and the
     226            // format stuff
     227            Element cl_param_list = null;
     228            if (metadata_names.isEmpty())
     229            {
     230                cl_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     231                Element p = this.doc.createElement(GSXML.PARAM_ELEM);
     232                cl_param_list.appendChild(p);
     233                p.setAttribute(GSXML.NAME_ATT, "metadata");
     234                p.setAttribute(GSXML.VALUE_ATT, "Title");
     235            }
     236            else
     237            {
     238                cl_param_list = createMetadataParamList(metadata_names);
     239            }
     240
     241            cl_meta_request.appendChild(cl_param_list);
     242
     243        }
     244
     245        // if there are document nodes in the classification (happens
     246        // sometimes), create a second request for document metadata and
     247        // append to the message
     248        NodeList doc_nodes = page_classifier.getElementsByTagName(GSXML.DOC_NODE_ELEM);
     249        if (doc_nodes.getLength() > 0)
     250        {
     251            did_documents = true;
     252            Element doc_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(collection, "DocumentMetadataRetrieve"), userContext);
     253            metadata_message.appendChild(doc_meta_request);
     254
     255            Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     256            doc_meta_request.appendChild(doc_list);
     257
     258            for (int c = 0; c < doc_nodes.getLength(); c++)
     259            {
     260
     261                Element d = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     262                d.setAttribute(GSXML.NODE_ID_ATT, ((Element) doc_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
     263                doc_list.appendChild(d);
     264            }
     265
     266            // create and add in the param list - add all for now
     267            Element doc_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     268            Element p = this.doc.createElement(GSXML.PARAM_ELEM);
     269            doc_param_list.appendChild(p);
     270            p.setAttribute(GSXML.NAME_ATT, "metadata");
     271            p.setAttribute(GSXML.VALUE_ATT, "all");
     272            doc_meta_request.appendChild(doc_param_list);
     273
     274        }
     275
     276        // process the metadata requests
     277        Element metadata_response = (Element) this.mr.process(metadata_message);
     278        if (did_classifier)
     279        {
     280            // the classifier one will be the first response
     281            // add the metadata lists for each node back into the
     282            // page_classifier nodes
     283            path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
     284            NodeList meta_response_cls = GSXML.getNodeByPath(metadata_response, path).getChildNodes();
     285            for (int i = 0; i < cl_nodes.getLength(); i++)
     286            {
     287                GSXML.mergeMetadataLists(cl_nodes.item(i), meta_response_cls.item(i));
     288            }
     289        }
     290        if (did_documents)
     291        {
     292            NodeList meta_response_docs = null;
     293            if (!did_classifier)
     294            {
     295                // its the first response
     296                path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     297                meta_response_docs = GSXML.getNodeByPath(metadata_response, path).getChildNodes();
     298            }
     299            else
     300            { // its the second response
     301                meta_response_docs = GSXML.getChildByTagName(metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1), GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER).getChildNodes();
     302            }
     303
     304            for (int i = 0; i < doc_nodes.getLength(); i++)
     305            {
     306                GSXML.mergeMetadataLists(doc_nodes.item(i), meta_response_docs.item(i));
     307            }
     308        }
     309
     310        logger.debug("(BrowseAction) Page:\n" + this.converter.getPrettyString(page_response));
     311        return page_response;
    65312    }
    66313
    67     UserContext userContext = new UserContext(request);
    68     String to = GSPath.appendLink(collection, service_name);
    69    
    70     // the first part of the response is the service description
    71     // for now get this again from the service.
    72     // this should be cached somehow later on.
    73    
    74     Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    75     Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
    76     info_message.appendChild(info_request);
    77    
    78     // also get the format stuff now if there is some
    79     Element format_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, to, userContext);
    80     info_message.appendChild(format_request);
    81     // process the requests
    82 
    83     Element info_response = (Element) this.mr.process(info_message);
    84 
    85     // the two responses
    86     NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    87     Element service_response = (Element)responses.item(0);
    88     Element format_response = (Element)responses.item(1);
    89 
    90     Element service_description = (Element)GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM);
    91     page_response.appendChild(this.doc.importNode(service_description, true));
    92    
    93     //append site metadata
    94     addSiteMetadata(page_response, userContext);
    95     addInterfaceOptions(page_response);
    96 
    97     // if rt=d, then we are just displaying the service
    98     String request_type = (String)params.get(GSParams.REQUEST_TYPE);
    99     if (request_type.equals("d")) {
    100         //return the page that we have so far
    101         return page_response;
     314    protected Element unknownBrowse(Element page, Element request, String browse_type)
     315    {
     316        logger.error("unknown browse subtype: " + browse_type);
     317        return null;
    102318    }
    103    
    104     // get the node that the user has clicked on
    105     String classifier_node = (String)params.get(CLASSIFIER_ARG);
    106    
    107     // if the node is not defined, return the page that we have so far
    108     if (classifier_node ==null || classifier_node.equals("")) {
    109         return page_response;
    110     }
    111    
    112     // the id of the classifier is the top id of the selected node
    113     String top_id = OID.getTop(classifier_node);
    114    
    115     HashSet<String> metadata_names = new HashSet<String>();
    116 
    117     // add the format info into the response
    118     Element format_elem = (Element)GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM);
    119     if (format_elem != null) {
    120         // find the one for the classifier we are in
    121         Element this_format = GSXML.getNamedElement(format_elem, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
    122         if (this_format == null) {
    123         this_format = (Element)GSXML.getChildByTagName(format_elem, GSXML.DEFAULT_ELEM);
    124         }
    125         if (this_format != null) {
    126         Element new_format = GSXML.duplicateWithNewName(this.doc, this_format, GSXML.FORMAT_ELEM, false);
    127         // set teh format type
    128         new_format.setAttribute(GSXML.TYPE_ATT, "browse");
    129 
    130         page_response.appendChild(new_format);
    131         getRequiredMetadataNames(new_format, metadata_names);
    132         }
    133     }
    134    
    135     logger.info("extracted meta names, "+metadata_names.toString());
    136     // get the browse structure for the selected node
    137     Element classify_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    138     Element classify_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    139     classify_message.appendChild(classify_request);
    140        
    141     //Create a parameter list to specify the required structure information
    142     // for now, always get ancestors and children
    143     Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    144     classify_request.appendChild(param_list);
    145     Element param = this.doc.createElement(GSXML.PARAM_ELEM);
    146     param_list.appendChild(param);
    147     param.setAttribute(GSXML.NAME_ATT, "structure");
    148     param.setAttribute(GSXML.VALUE_ATT, "ancestors");
    149     param = this.doc.createElement(GSXML.PARAM_ELEM);
    150     param_list.appendChild(param);
    151     param.setAttribute(GSXML.NAME_ATT, "structure");
    152     param.setAttribute(GSXML.VALUE_ATT, "children");
    153     if (get_siblings) {
    154         param = this.doc.createElement(GSXML.PARAM_ELEM);
    155         param_list.appendChild(param);
    156         param.setAttribute(GSXML.NAME_ATT, "structure");
    157         param.setAttribute(GSXML.VALUE_ATT, "siblings");
    158     }
    159 
    160     // put the classifier node into a classifier node list
    161     Element classifier_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
    162     Element classifier = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
    163     classifier.setAttribute(GSXML.NODE_ID_ATT, classifier_node);
    164     classifier_list.appendChild(classifier);
    165     classify_request.appendChild(classifier_list);
    166        
    167     // process the request
    168     Element classify_response = (Element)this.mr.process(classify_message);
    169     // get the structure element
    170     String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
    171     path = GSPath.appendLink(path, GSXML.CLASS_NODE_ELEM);
    172     path = GSPath.appendLink(path, GSXML.NODE_STRUCTURE_ELEM);
    173     // assume that we always get back the top level CL1 node - this becomes the page_classifier node
    174     path = GSPath.appendLink(path, GSXML.CLASS_NODE_ELEM);
    175     Element cl_structure = (Element)GSXML.getNodeByPath(classify_response,
    176                                 path);
    177     if (cl_structure ==null) {
    178         logger.error("classifier structure request returned no structure");
    179         return page_response;
    180     }   
    181    
    182     // add the classifier node as the page classifier
    183     Element page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure,  GSXML.CLASSIFIER_ELEM, true);
    184     page_response.appendChild(page_classifier);
    185     page_classifier.setAttribute(GSXML.NAME_ATT, top_id);
    186    
    187     // get the metadata for each classifier node,
    188     // then for each document node
    189 
    190     Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    191 
    192     boolean did_classifier = false;
    193     boolean did_documents = false;
    194    
    195    
    196     // if there are classifier nodes
    197     // create a metadata request for the classifier, and add it to
    198     // the the message
    199     NodeList cl_nodes = page_classifier.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
    200    
    201     if (cl_nodes.getLength() > 0) {
    202         did_classifier = true;
    203         Element cl_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to+"MetadataRetrieve", userContext);
    204         metadata_message.appendChild(cl_meta_request);
    205        
    206         Element new_cl_nodes_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
    207         cl_meta_request.appendChild(new_cl_nodes_list);
    208        
    209         for (int c=0; c<cl_nodes.getLength(); c++) {
    210 
    211         Element cl = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
    212         cl.setAttribute(GSXML.NODE_ID_ATT, ((Element)cl_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
    213         new_cl_nodes_list.appendChild(cl);
    214         }
    215 
    216         // create and add in the param list - for now get all the metadata
    217         // should be based on info sent in from the recept, and the
    218         // format stuff
    219         Element cl_param_list = null;
    220         if (metadata_names.isEmpty()) {
    221         cl_param_list  = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    222         Element p = this.doc.createElement(GSXML.PARAM_ELEM);
    223         cl_param_list.appendChild(p);
    224         p.setAttribute(GSXML.NAME_ATT, "metadata");
    225         p.setAttribute(GSXML.VALUE_ATT, "Title");
    226         } else {
    227         cl_param_list  = createMetadataParamList(metadata_names);
    228         }
    229 
    230         cl_meta_request.appendChild(cl_param_list);
    231        
    232     }
    233 
    234     // if there are document nodes in the classification (happens
    235     // sometimes), create a second request for document metadata and
    236     // append to the message
    237     NodeList doc_nodes = page_classifier.getElementsByTagName(GSXML.DOC_NODE_ELEM);
    238     if (doc_nodes.getLength() > 0) {
    239         did_documents = true;
    240         Element doc_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(collection, "DocumentMetadataRetrieve"), userContext);
    241         metadata_message.appendChild(doc_meta_request);
    242        
    243         Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    244         doc_meta_request.appendChild(doc_list);
    245        
    246         for (int c=0; c<doc_nodes.getLength(); c++) {
    247        
    248         Element d = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    249         d.setAttribute(GSXML.NODE_ID_ATT, ((Element)doc_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
    250         doc_list.appendChild(d);
    251         }
    252 
    253         // create and add in the param list - add all for now
    254         Element doc_param_list  = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    255         Element p = this.doc.createElement(GSXML.PARAM_ELEM);
    256         doc_param_list.appendChild(p);
    257         p.setAttribute(GSXML.NAME_ATT, "metadata");
    258         p.setAttribute(GSXML.VALUE_ATT, "all");
    259         doc_meta_request.appendChild(doc_param_list);
    260 
    261     }
    262    
    263     // process the metadata requests
    264     Element metadata_response = (Element)this.mr.process(metadata_message);
    265     if (did_classifier) {
    266         // the classifier one will be the first response
    267         // add the metadata lists for each node back into the
    268         // page_classifier nodes
    269         path = GSPath.appendLink(GSXML.RESPONSE_ELEM,
    270                    GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
    271         NodeList meta_response_cls = GSXML.getNodeByPath(metadata_response, path).getChildNodes();
    272         for (int i = 0; i < cl_nodes.getLength(); i++) {
    273         GSXML.mergeMetadataLists(cl_nodes.item(i), meta_response_cls.item(i));
    274         }
    275     }
    276     if (did_documents) {
    277         NodeList meta_response_docs = null;
    278         if (!did_classifier) {
    279         // its the first response
    280         path = GSPath.appendLink(GSXML.RESPONSE_ELEM,
    281                      GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    282         meta_response_docs = GSXML.getNodeByPath(metadata_response, path).getChildNodes();
    283         } else { // its the second response
    284         meta_response_docs = GSXML.getChildByTagName(metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1), GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER).getChildNodes();
    285         }
    286        
    287         for (int i = 0; i < doc_nodes.getLength(); i++) {
    288         GSXML.mergeMetadataLists(doc_nodes.item(i), meta_response_docs.item(i));
    289         }
    290     }
    291        
    292 
    293     logger.debug("(BrowseAction) Page:\n" + this.converter.getPrettyString(page_response));
    294     return page_response;
    295     }
    296 
    297     protected Element unknownBrowse(Element page, Element request, String browse_type) {
    298     logger.error("unknown browse subtype: "+browse_type);
    299     return null;
    300     }
    301319}
    302 
    303 
Note: See TracChangeset for help on using the changeset viewer.