Ignore:
Timestamp:
2011-11-14T13:01:00+13:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this for some modifications

File:
1 edited

Legend:

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

    r24116 r24812  
    11/*
    2 *    DocumentAction.java
    3 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
    4 *
    5 *    This program is free software; you can redistribute it and/or modify
    6 *    it under the terms of the GNU General Public License as published by
    7 *    the Free Software Foundation; either version 2 of the License, or
    8 *    (at your option) any later version.
    9 *
    10 *    This program is distributed in the hope that it will be useful,
    11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
    12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13 *    GNU General Public License for more details.
    14 *
    15 *    You should have received a copy of the GNU General Public License
    16 *    along with this program; if not, write to the Free Software
    17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    18 */
     2 *    DocumentAction.java
     3 *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
     4 *
     5 *    This program is free software; you can redistribute it and/or modify
     6 *    it under the terms of the GNU General Public License as published by
     7 *    the Free Software Foundation; either version 2 of the License, or
     8 *    (at your option) any later version.
     9 *
     10 *    This program is distributed in the hope that it will be useful,
     11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 *    GNU General Public License for more details.
     14 *
     15 *    You should have received a copy of the GNU General Public License
     16 *    along with this program; if not, write to the Free Software
     17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18 */
    1919package org.greenstone.gsdl3.action;
    2020
     
    2424
    2525// XML classes
    26 import org.w3c.dom.Document; 
    27 import org.w3c.dom.Element; 
    28 import org.w3c.dom.Node; 
     26import org.w3c.dom.Document;
     27import org.w3c.dom.Element;
     28import org.w3c.dom.Node;
    2929import org.w3c.dom.Text;
    3030import org.w3c.dom.NodeList;
     
    3838import org.apache.log4j.*;
    3939
    40 /** Action class for retrieving Documents  via the message router
    41 */
    42 public class DocumentAction extends Action {
     40/** Action class for retrieving Documents via the message router */
     41public class DocumentAction extends Action
     42{
    4343
    4444    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.DocumentAction.class.getName());
     
    4848    public static final String GOTO_PAGE_ARG = "gp";
    4949    public static final String ENRICH_DOC_ARG = "end";
    50    
    51     /** if this is set to true, when a document is displayed, any annotation
    52     * type services (enrich) will be offered to the user as well */
    53     protected boolean provide_annotations = false;
    54    
     50
     51    /**
     52     * if this is set to true, when a document is displayed, any annotation type
     53     * services (enrich) will be offered to the user as well
     54     */
     55    protected boolean provide_annotations = false;
     56
    5557    protected boolean highlight_query_terms = false;
    5658
    57     public boolean configure() {
     59    public boolean configure()
     60    {
    5861        super.configure();
    59         String highlight = (String)config_params.get("highlightQueryTerms");
    60         if (highlight != null && highlight.equals("true")) {
     62        String highlight = (String) config_params.get("highlightQueryTerms");
     63        if (highlight != null && highlight.equals("true"))
     64        {
    6165            highlight_query_terms = true;
    6266        }
    63         String annotate = (String)config_params.get("displayAnnotationService");
    64         if (annotate != null && annotate.equals("true")) {
     67        String annotate = (String) config_params.get("displayAnnotationService");
     68        if (annotate != null && annotate.equals("true"))
     69        {
    6570            provide_annotations = true;
    6671        }
    6772        return true;
    6873    }
    69     public Node process (Node message_node)
     74
     75    public Node process(Node message_node)
    7076    {
    7177        // for now, no subaction eventually we may want to have subactions such as text assoc or something ?
    72        
     78
    7379        Element message = this.converter.nodeToElement(message_node);
    7480
     
    7985
    8086        // get the request - assume only one
    81         Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    82         Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     87        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     88        Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    8389        HashMap params = GSXML.extractParams(cgi_paramList, false);
    8490
    8591        // just in case there are some that need to get passed to the services
    86         HashMap service_params = (HashMap)params.get("s0");
    87 
    88        
     92        HashMap service_params = (HashMap) params.get("s0");
     93
    8994        String has_rl = null;
    9095        String has_href = null;
     
    95100        String uid = request.getAttribute(GSXML.USER_ID_ATT);
    96101        String document_name = (String) params.get(GSParams.DOCUMENT);
    97         if ((document_name == null || document_name.equals("")) && (has_href == null || has_href.equals(""))) {
     102        if ((document_name == null || document_name.equals("")) && (has_href == null || has_href.equals("")))
     103        {
    98104            logger.error("no document specified!");
    99105            return result;
    100106        }
    101107        String document_type = (String) params.get(GSParams.DOCUMENT_TYPE);
    102         if (document_type == null) {
     108        if (document_type == null)
     109        {
    103110            document_type = "simple";
    104111        }
     
    106113        boolean get_siblings = false;
    107114        String sibs = (String) params.get(SIBLING_ARG);
    108         if (sibs != null && sibs.equals("1")) {
     115        if (sibs != null && sibs.equals("1"))
     116        {
    109117            get_siblings = true;
    110118        }
    111        
     119
    112120        String sibling_num = (String) params.get(GOTO_PAGE_ARG);
    113         if (sibling_num != null && !sibling_num.equals("")) {
     121        if (sibling_num != null && !sibling_num.equals(""))
     122        {
    114123            // we have to modify the doc name
    115             document_name = document_name+"."+sibling_num+".ss";
    116         }
    117        
     124            document_name = document_name + "." + sibling_num + ".ss";
     125        }
     126
    118127        boolean expand_document = false;
    119128        String ed_arg = (String) params.get(GSParams.EXPAND_DOCUMENT);
    120         if (ed_arg != null && ed_arg.equals("1")) {
     129        if (ed_arg != null && ed_arg.equals("1"))
     130        {
    121131            expand_document = true;
    122132        }
    123        
    124133
    125134        boolean expand_contents = false;
    126         if (expand_document) { // we always expand the contents with the text
     135        if (expand_document)
     136        { // we always expand the contents with the text
    127137            expand_contents = true;
    128         } else {
     138        }
     139        else
     140        {
    129141            String ec_arg = (String) params.get(GSParams.EXPAND_CONTENTS);
    130             if (ec_arg != null && ec_arg.equals("1")) {
     142            if (ec_arg != null && ec_arg.equals("1"))
     143            {
    131144                expand_contents = true;
    132145            }
     
    134147
    135148        //append site metadata
    136         addSiteMetadata( page_response, lang, uid);
     149        addSiteMetadata(page_response, lang, uid);
    137150
    138151        // get the additional data needed for the page
    139152        getBackgroundData(page_response, collection, lang, uid);
    140         Element format_elem = (Element)GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM);
    141        
     153        Element format_elem = (Element) GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM);
     154
    142155        // the_document is where all the doc info - structure and metadata etc
    143156        // is added into, to be returned in the page
     
    149162
    150163        // create a basic doc list containing the current node
    151         Element basic_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     164        Element basic_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    152165        Element current_doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    153166        basic_doc_list.appendChild(current_doc);
    154         if (document_name.length()!=0){
     167        if (document_name.length() != 0)
     168        {
    155169            current_doc.setAttribute(GSXML.NODE_ID_ATT, document_name);
    156         }else if (has_href.length()!=0){
     170        }
     171        else if (has_href.length() != 0)
     172        {
    157173            current_doc.setAttribute(GSXML.NODE_ID_ATT, has_href);
    158174            current_doc.setAttribute("externalURL", has_rl);
     
    160176
    161177        // Create a parameter list to specify the required structure information
    162         Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    163        
    164         if (service_params != null) {
     178        Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     179
     180        if (service_params != null)
     181        {
    165182            GSXML.addParametersToList(this.doc, ds_param_list, service_params);
    166183        }
    167184
    168         Element ds_param = null; 
     185        Element ds_param = null;
    169186        boolean get_structure = false;
    170187        boolean get_structure_info = false;
    171         if (document_type.equals("paged")) {
     188        if (document_type.equals("paged"))
     189        {
    172190            get_structure_info = true;
    173191            // get teh info needed for paged naviagtion
     
    184202            ds_param.setAttribute(GSXML.NAME_ATT, "info");
    185203            ds_param.setAttribute(GSXML.VALUE_ATT, "siblingPosition");
    186            
    187         } else if (document_type.equals("hierarchy")){
     204
     205        }
     206        else if (document_type.equals("hierarchy"))
     207        {
    188208            get_structure = true;
    189             if (expand_contents) {
     209            if (expand_contents)
     210            {
    190211                ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
    191212                ds_param_list.appendChild(ds_param);
    192213                ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    193214                ds_param.setAttribute(GSXML.VALUE_ATT, "entire");
    194             } else {
     215            }
     216            else
     217            {
    195218                // get the info needed for table of contents
    196219                ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
     
    202225                ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    203226                ds_param.setAttribute(GSXML.VALUE_ATT, "children");
    204                 if (get_siblings) {
     227                if (get_siblings)
     228                {
    205229                    ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
    206230                    ds_param_list.appendChild(ds_param);
     
    209233                }
    210234            }
    211         } else {
     235        }
     236        else
     237        {
    212238            // we dont need any structure
    213239        }
    214240
    215241        boolean has_dummy = false;
    216         if (get_structure || get_structure_info) {
     242        if (get_structure || get_structure_info)
     243        {
    217244
    218245            // Build a request to obtain the document structure
    219246            Element ds_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    220247            String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
    221             Element ds_request = GSXML.createBasicRequest(this.doc,GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     248            Element ds_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    222249            ds_message.appendChild(ds_request);
    223250            ds_request.appendChild(ds_param_list);
    224            
     251
    225252            // create a doc_node_list and put in the doc_node that we are interested in
    226253            ds_request.appendChild(basic_doc_list);
    227            
     254
    228255            // Process the document structure retrieve message
    229256            Element ds_response_message = (Element) this.mr.process(ds_message);
    230             if (processErrorElements(ds_response_message, page_response)) {
     257            if (processErrorElements(ds_response_message, page_response))
     258            {
    231259                return result;
    232260            }
    233261
    234262            // get the info and print out
    235             String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     263            String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    236264            path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    237265            path = GSPath.appendLink(path, "nodeStructureInfo");
    238266            Element ds_response_struct_info = (Element) GSXML.getNodeByPath(ds_response_message, path);
    239267            // get the doc_node bit
    240             if (ds_response_struct_info != null) {
    241                 the_document.appendChild(this.doc.importNode(ds_response_struct_info, true));
    242             }
    243             path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     268            if (ds_response_struct_info != null)
     269            {
     270                the_document.appendChild(this.doc.importNode(ds_response_struct_info, true));
     271            }
     272            path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    244273            path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    245274            path = GSPath.appendLink(path, GSXML.NODE_STRUCTURE_ELEM);
    246275            Element ds_response_structure = (Element) GSXML.getNodeByPath(ds_response_message, path);
    247            
    248             if (ds_response_structure != null) {
     276
     277            if (ds_response_structure != null)
     278            {
    249279                // add the contents of the structure bit into the_document
    250280                NodeList structs = ds_response_structure.getChildNodes();
    251                 for (int i=0; i<structs.getLength();i++) {
     281                for (int i = 0; i < structs.getLength(); i++)
     282                {
    252283                    the_document.appendChild(this.doc.importNode(structs.item(i), true));
    253284                }
    254             } else {
     285            }
     286            else
     287            {
    255288                // no structure nodes, so put in a dummy doc node
    256289                Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    257                 if (document_name.length()!=0){
     290                if (document_name.length() != 0)
     291                {
    258292                    doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name);
    259                 }else if (has_href.length()!=0){
     293                }
     294                else if (has_href.length() != 0)
     295                {
    260296                    doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href);
    261297                    doc_node.setAttribute("externalURL", has_rl);
     
    264300                has_dummy = true;
    265301            }
    266         } else { // a simple type - we dont have a dummy node for simple
     302        }
     303        else
     304        { // a simple type - we dont have a dummy node for simple
    267305            // should think about this more
    268306            // no structure request, so just put in a dummy doc node
    269307            Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    270             if (document_name.length()!=0){
     308            if (document_name.length() != 0)
     309            {
    271310                doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name);
    272             }else if (has_href.length()!=0){
     311            }
     312            else if (has_href.length() != 0)
     313            {
    273314                doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href);
    274315                doc_node.setAttribute("externalURL", has_rl);
     
    277318            has_dummy = true;
    278319        }
    279        
     320
    280321        // Build a request to obtain some document metadata
    281322        Element dm_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    282         String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");  // Hard-wired?
     323        String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired?
    283324        Element dm_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    284325        dm_message.appendChild(dm_request);
    285326        // Create a parameter list to specify the required metadata information
    286        
     327
    287328        HashSet meta_names = new HashSet();
    288329        meta_names.add("Title"); // the default
    289         if (format_elem != null) {
     330        if (format_elem != null)
     331        {
    290332            extractMetadataNames(format_elem, meta_names);
    291333        }
    292        
     334
    293335        Element dm_param_list = createMetadataParamList(meta_names);
    294         if (service_params != null) {
     336        if (service_params != null)
     337        {
    295338            GSXML.addParametersToList(this.doc, dm_param_list, service_params);
    296339        }
    297        
     340
    298341        dm_request.appendChild(dm_param_list);
    299        
    300        
     342
    301343        // create the doc node list for the metadata request
    302         Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     344        Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    303345        dm_request.appendChild(dm_doc_list);
    304346
    305347        // Add each node from the structure response into the metadata request
    306348        NodeList doc_nodes = the_document.getElementsByTagName(GSXML.DOC_NODE_ELEM);
    307         for (int i = 0; i < doc_nodes.getLength(); i++) {
     349        for (int i = 0; i < doc_nodes.getLength(); i++)
     350        {
    308351            Element doc_node = (Element) doc_nodes.item(i);
    309352            String doc_node_id = doc_node.getAttribute(GSXML.NODE_ID_ATT);
     
    313356            dm_doc_list.appendChild(dm_doc_node);
    314357            dm_doc_node.setAttribute(GSXML.NODE_ID_ATT, doc_node_id);
    315             dm_doc_node.setAttribute(GSXML.NODE_TYPE_ATT,
    316             doc_node.getAttribute(GSXML.NODE_TYPE_ATT));
     358            dm_doc_node.setAttribute(GSXML.NODE_TYPE_ATT, doc_node.getAttribute(GSXML.NODE_TYPE_ATT));
    317359        }
    318360
     
    321363        Element doc_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    322364        dm_message.appendChild(doc_meta_request);
    323         Element doc_meta_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    324         if (service_params != null) {
     365        Element doc_meta_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     366        if (service_params != null)
     367        {
    325368            GSXML.addParametersToList(this.doc, doc_meta_param_list, service_params);
    326369        }
     
    333376
    334377        // create the doc node list for the metadata request
    335         Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     378        Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    336379        doc_meta_request.appendChild(doc_list);
    337380
    338381        Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    339382        // the node we want is the root document node
    340         if (document_name.length()!=0){
    341             doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name+".rt");
    342         }else if (has_href.length()!=0){
    343             doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href+".rt");
     383        if (document_name.length() != 0)
     384        {
     385            doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name + ".rt");
     386        }
     387        else if (has_href.length() != 0)
     388        {
     389            doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href + ".rt");
    344390            doc_node.setAttribute("externalURL", has_rl);
    345391        }
    346392        doc_list.appendChild(doc_node);
    347393        Element dm_response_message = (Element) this.mr.process(dm_message);
    348         if (processErrorElements(dm_response_message, page_response)) {
     394        if (processErrorElements(dm_response_message, page_response))
     395        {
    349396            return result;
    350397        }
    351398
    352         String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     399        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    353400        Element dm_response_doc_list = (Element) GSXML.getNodeByPath(dm_response_message, path);
    354401
    355402        // Merge the metadata with the structure information
    356403        NodeList dm_response_docs = dm_response_doc_list.getChildNodes();
    357         for (int i = 0; i < doc_nodes.getLength(); i++) {
     404        for (int i = 0; i < doc_nodes.getLength(); i++)
     405        {
    358406            GSXML.mergeMetadataLists(doc_nodes.item(i), dm_response_docs.item(i));
    359407        }
    360408        // get the top level doc metadata out
    361         Element doc_meta_response = (Element)dm_response_message.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
    362         Element top_doc_node = (Element)GSXML.getNodeByPath(doc_meta_response, "documentNodeList/documentNode");
     409        Element doc_meta_response = (Element) dm_response_message.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
     410        Element top_doc_node = (Element) GSXML.getNodeByPath(doc_meta_response, "documentNodeList/documentNode");
    363411        GSXML.mergeMetadataLists(the_document, top_doc_node);
    364        
     412
    365413        // Build a request to obtain some document content
    366414        Element dc_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    367         to = GSPath.appendLink(collection, "DocumentContentRetrieve");  // Hard-wired?
     415        to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired?
    368416        Element dc_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    369417        dc_message.appendChild(dc_request);
    370        
    371418
    372419        // Create a parameter list to specify the request parameters - empty for now
    373         Element dc_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    374         if (service_params != null) {
     420        Element dc_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     421        if (service_params != null)
     422        {
    375423            GSXML.addParametersToList(this.doc, dc_param_list, service_params);
    376424        }
     
    380428        // get the content
    381429        // the doc list for the content request is the same as the one for the structure request unless we want the whole document, in which case its the same as for the metadata request.
    382         if (expand_document) {
     430        if (expand_document)
     431        {
    383432            dc_request.appendChild(dm_doc_list);
    384         } else {
     433        }
     434        else
     435        {
    385436            dc_request.appendChild(basic_doc_list);
    386437        }
    387         logger.debug("request = "+converter.getString(dc_message));
     438        logger.debug("request = " + converter.getString(dc_message));
    388439        Element dc_response_message = (Element) this.mr.process(dc_message);
    389         if (processErrorElements(dc_response_message, page_response)) {
     440        if (processErrorElements(dc_response_message, page_response))
     441        {
    390442            return result;
    391443        }
     
    393445        Element dc_response_doc_list = (Element) GSXML.getNodeByPath(dc_response_message, path);
    394446
    395         if (expand_document) {
     447        if (expand_document)
     448        {
    396449            // Merge the content with the structure information
    397450            NodeList dc_response_docs = dc_response_doc_list.getChildNodes();
    398             for (int i = 0; i < doc_nodes.getLength(); i++) {
    399                 Node content = GSXML.getChildByTagName((Element)dc_response_docs.item(i), "nodeContent");
    400                 if (content != null) {
    401                     if (highlight_query_terms) {
    402                         content = highlightQueryTerms(request, (Element)content);
     451            for (int i = 0; i < doc_nodes.getLength(); i++)
     452            {
     453                Node content = GSXML.getChildByTagName((Element) dc_response_docs.item(i), "nodeContent");
     454                if (content != null)
     455                {
     456                    if (highlight_query_terms)
     457                    {
     458                        content = highlightQueryTerms(request, (Element) content);
    403459                    }
    404460                    doc_nodes.item(i).appendChild(this.doc.importNode(content, true));
     
    406462                //GSXML.mergeMetadataLists(doc_nodes.item(i), dm_response_docs.item(i));
    407463            }
    408         } else {
     464        }
     465        else
     466        {
    409467            //path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    410468            Element dc_response_doc = (Element) GSXML.getChildByTagName(dc_response_doc_list, GSXML.DOC_NODE_ELEM);
    411469            Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM);
    412470            Element dc_response_doc_external = (Element) GSXML.getChildByTagName(dc_response_doc, "external");
    413            
    414             if (dc_response_doc_content == null) {
     471
     472            if (dc_response_doc_content == null)
     473            {
    415474                // no content to add
    416                 if (dc_response_doc_external !=null){
     475                if (dc_response_doc_external != null)
     476                {
    417477                    String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT);
    418                    
     478
    419479                    the_document.setAttribute("selectedNode", modified_doc_id);
    420480                    the_document.setAttribute("external", dc_response_doc_external.getAttribute("external_link"));
     
    422482                return result;
    423483            }
    424             if (highlight_query_terms) {
     484            if (highlight_query_terms)
     485            {
    425486                dc_response_doc.removeChild(dc_response_doc_content);
    426                
     487
    427488                dc_response_doc_content = highlightQueryTerms(request, dc_response_doc_content);
    428489                dc_response_doc.appendChild(dc_response_doc.getOwnerDocument().importNode(dc_response_doc_content, true));
    429490            }
    430            
    431            
    432             if (provide_annotations) {
    433                 String service_selected = (String)params.get(ENRICH_DOC_ARG);
    434                 if (service_selected != null && service_selected.equals("1")) {
     491
     492            if (provide_annotations)
     493            {
     494                String service_selected = (String) params.get(ENRICH_DOC_ARG);
     495                if (service_selected != null && service_selected.equals("1"))
     496                {
    435497                    // now we can modifiy the response doc if needed
    436                     String enrich_service = (String)params.get(GSParams.SERVICE);
     498                    String enrich_service = (String) params.get(GSParams.SERVICE);
    437499                    // send a message to the service
    438500                    Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     
    440502                    enrich_message.appendChild(enrich_request);
    441503                    // check for parameters
    442                     HashMap e_service_params = (HashMap)params.get("s1");
    443                     if (e_service_params != null) {
    444                         Element enrich_pl = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    445                         GSXML.addParametersToList(this.doc, enrich_pl, e_service_params);
     504                    HashMap e_service_params = (HashMap) params.get("s1");
     505                    if (e_service_params != null)
     506                    {
     507                        Element enrich_pl = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     508                        GSXML.addParametersToList(this.doc, enrich_pl, e_service_params);
    446509                        enrich_request.appendChild(enrich_pl);
    447510                    }
    448                     Element e_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     511                    Element e_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    449512                    enrich_request.appendChild(e_doc_list);
    450513                    e_doc_list.appendChild(this.doc.importNode(dc_response_doc, true));
    451                    
     514
    452515                    Node enrich_response = this.mr.process(enrich_message);
    453                    
    454                     String [] links = {GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.NODE_CONTENT_ELEM};
     516
     517                    String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.NODE_CONTENT_ELEM };
    455518                    path = GSPath.createPath(links);
    456                     dc_response_doc_content = (Element)GSXML.getNodeByPath(enrich_response, path);
    457                    
    458                 } 
     519                    dc_response_doc_content = (Element) GSXML.getNodeByPath(enrich_response, path);
     520
     521                }
    459522            } // if provide_annotations
    460523
    461            
    462524            // use the returned id rather than the sent one cos there may have
    463525            // been modifiers such as .pr that are removed.
    464526            String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT);
    465527            the_document.setAttribute("selectedNode", modified_doc_id);
    466             if (has_dummy) {
     528            if (has_dummy)
     529            {
    467530                // change the id if necessary and add the content
    468                 Element dummy_node = (Element)doc_nodes.item(0);
    469                
     531                Element dummy_node = (Element) doc_nodes.item(0);
     532
    470533                dummy_node.setAttribute(GSXML.NODE_ID_ATT, modified_doc_id);
    471534                dummy_node.appendChild(this.doc.importNode(dc_response_doc_content, true));
    472535                // hack for simple type
    473                 if (document_type.equals("simple")) {
     536                if (document_type.equals("simple"))
     537                {
    474538                    // we dont want the internal docNode, just want the content and metadata in the document
    475539                    // rethink this!!
     
    478542                    NodeList dummy_children = dummy_node.getChildNodes();
    479543                    //for (int i=0; i<dummy_children.getLength(); i++) {
    480                     for (int i=dummy_children.getLength()-1; i>=0; i--) {
     544                    for (int i = dummy_children.getLength() - 1; i >= 0; i--)
     545                    {
    481546                        // special case as we don't want more than one metadata list
    482                         if (dummy_children.item(i).getNodeName().equals(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER)) {
     547                        if (dummy_children.item(i).getNodeName().equals(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER))
     548                        {
    483549                            GSXML.mergeMetadataFromList(the_document, dummy_children.item(i));
    484                         } else {
     550                        }
     551                        else
     552                        {
    485553                            the_document.appendChild(dummy_children.item(i));
    486554                        }
    487555                    }
    488556                }
    489             } else {
     557            }
     558            else
     559            {
    490560                // Merge the document content with the metadata and structure information
    491                 for (int i = 0; i < doc_nodes.getLength(); i++) {
     561                for (int i = 0; i < doc_nodes.getLength(); i++)
     562                {
    492563                    Node dn = doc_nodes.item(i);
    493                     String dn_id = ((Element)dn).getAttribute(GSXML.NODE_ID_ATT);
    494                     if (dn_id.equals(modified_doc_id)) {
     564                    String dn_id = ((Element) dn).getAttribute(GSXML.NODE_ID_ATT);
     565                    if (dn_id.equals(modified_doc_id))
     566                    {
    495567                        dn.appendChild(this.doc.importNode(dc_response_doc_content, true));
    496568                        break;
     
    502574        return result;
    503575    }
    504    
    505     /** tell the param class what its arguments are
    506     * if an action has its own arguments, this should add them to the params
    507     * object - particularly important for args that should not be saved */
    508     public boolean getActionParameters(GSParams params) {
     576
     577    /**
     578     * tell the param class what its arguments are if an action has its own
     579     * arguments, this should add them to the params object - particularly
     580     * important for args that should not be saved
     581     */
     582    public boolean getActionParameters(GSParams params)
     583    {
    509584        params.addParameter(GOTO_PAGE_ARG, false);
    510585        params.addParameter(ENRICH_DOC_ARG, false);
     
    512587    }
    513588
    514 
    515     /** this method gets the collection description, the format info, the
    516     * list of enrich services, etc - stuff that is needed for the page,
    517     * but is the same whatever the query is - should be cached */
    518     protected  boolean getBackgroundData(Element page_response,
    519     String collection, String lang,
    520     String uid) {
     589    /**
     590     * this method gets the collection description, the format info, the list of
     591     * enrich services, etc - stuff that is needed for the page, but is the same
     592     * whatever the query is - should be cached
     593     */
     594    protected boolean getBackgroundData(Element page_response, String collection, String lang, String uid)
     595    {
    521596
    522597        // create a message to process - contains requests for the collection
     
    531606        // the enrich_services request - only do this if provide_annotations is true
    532607
    533         if (provide_annotations) {
     608        if (provide_annotations)
     609        {
    534610            Element enrich_services_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", lang, uid);
    535611            enrich_services_request.setAttribute(GSXML.INFO_ATT, "serviceList");
    536612            info_message.appendChild(enrich_services_request);
    537613        }
    538        
    539         Element info_response = (Element)this.mr.process(info_message);
     614
     615        Element info_response = (Element) this.mr.process(info_message);
    540616
    541617        // the collection is the first response
    542618        NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    543619        Element format_resp = (Element) responses.item(0);
    544        
    545         Element format_elem = (Element)GSXML.getChildByTagName(format_resp, GSXML.FORMAT_ELEM);
    546         if (format_elem != null) {
     620
     621        Element format_elem = (Element) GSXML.getChildByTagName(format_resp, GSXML.FORMAT_ELEM);
     622        if (format_elem != null)
     623        {
    547624            logger.debug("doc action found a format statement");
    548625            // set teh format type
    549             format_elem.setAttribute(GSXML.TYPE_ATT, "display"); 
     626            format_elem.setAttribute(GSXML.TYPE_ATT, "display");
    550627            page_response.appendChild(this.doc.importNode(format_elem, true));
    551628        }
    552629
    553         if (provide_annotations) {
    554             Element services_resp = (Element)responses.item(1);
     630        if (provide_annotations)
     631        {
     632            Element services_resp = (Element) responses.item(1);
    555633
    556634            // a new message for the mr
    557635            Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    558            
     636
    559637            NodeList e_services = services_resp.getElementsByTagName(GSXML.SERVICE_ELEM);
    560638            boolean service_found = false;
    561             for (int j=0; j<e_services.getLength(); j++) {
    562                 if (((Element)e_services.item(j)).getAttribute(GSXML.TYPE_ATT).equals("enrich")) {
    563                     Element s = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, ((Element)e_services.item(j)).getAttribute(GSXML.NAME_ATT), lang, uid);
     639            for (int j = 0; j < e_services.getLength(); j++)
     640            {
     641                if (((Element) e_services.item(j)).getAttribute(GSXML.TYPE_ATT).equals("enrich"))
     642                {
     643                    Element s = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, ((Element) e_services.item(j)).getAttribute(GSXML.NAME_ATT), lang, uid);
    564644                    enrich_message.appendChild(s);
    565645                    service_found = true;
    566646                }
    567647            }
    568             if (service_found) {
    569                 Element enrich_response = (Element)this.mr.process(enrich_message);
    570                
     648            if (service_found)
     649            {
     650                Element enrich_response = (Element) this.mr.process(enrich_message);
     651
    571652                NodeList e_responses = enrich_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    572653                Element service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
    573                 for (int i=0; i<e_responses.getLength(); i++) {
    574                     Element e_resp = (Element)e_responses.item(i);
    575                     Element e_service = (Element)this.doc.importNode(GSXML.getChildByTagName(e_resp, GSXML.SERVICE_ELEM), true);
     654                for (int i = 0; i < e_responses.getLength(); i++)
     655                {
     656                    Element e_resp = (Element) e_responses.item(i);
     657                    Element e_service = (Element) this.doc.importNode(GSXML.getChildByTagName(e_resp, GSXML.SERVICE_ELEM), true);
    576658                    e_service.setAttribute(GSXML.NAME_ATT, e_resp.getAttribute(GSXML.FROM_ATT));
    577659                    service_list.appendChild(e_service);
     
    581663        } // if provide_annotations
    582664        return true;
    583        
     665
    584666    }
    585667
    586     /** this involves a bit of a hack to get the equivalent query terms - has to requery the query service - uses the last selected service name. (if it ends in query). should this action do the query or should it send a message to the query action? but that will involve lots of extra stuff. also doesn't handle phrases properly - just highlights all the terms found in the text.
    587     */
    588     protected Element highlightQueryTerms(Element request, Element dc_response_doc_content) {
     668    /**
     669     * this involves a bit of a hack to get the equivalent query terms - has to
     670     * requery the query service - uses the last selected service name. (if it
     671     * ends in query). should this action do the query or should it send a
     672     * message to the query action? but that will involve lots of extra stuff.
     673     * also doesn't handle phrases properly - just highlights all the terms found
     674     * in the text.
     675     */
     676    protected Element highlightQueryTerms(Element request, Element dc_response_doc_content)
     677    {
    589678
    590679        // do the query again to get term info
    591         Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     680        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    592681        HashMap params = GSXML.extractParams(cgi_param_list, false);
    593        
    594         HashMap previous_params = (HashMap)params.get("p");
    595         if (previous_params == null) {
     682
     683        HashMap previous_params = (HashMap) params.get("p");
     684        if (previous_params == null)
     685        {
    596686            return dc_response_doc_content;
    597687        }
    598         String service_name = (String)previous_params.get(GSParams.SERVICE);
    599         if (service_name == null || !service_name.endsWith("Query")) { // hack for now - we only do highlighting if we were in a query last - ie not if we were in a browse thingy
     688        String service_name = (String) previous_params.get(GSParams.SERVICE);
     689        if (service_name == null || !service_name.endsWith("Query"))
     690        { // hack for now - we only do highlighting if we were in a query last - ie not if we were in a browse thingy
    600691            logger.debug("invalid service, not doing highlighting");
    601692            return dc_response_doc_content;
    602693        }
    603         String collection = (String)params.get(GSParams.COLLECTION);
     694        String collection = (String) params.get(GSParams.COLLECTION);
    604695        String lang = request.getAttribute(GSXML.LANG_ATT);
    605696        String uid = request.getAttribute(GSXML.USER_ID_ATT);
    606697        String to = GSPath.appendLink(collection, service_name);
    607        
     698
    608699        Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    609700        Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    610701        mr_query_message.appendChild(mr_query_request);
    611        
     702
    612703        // paramList
    613         HashMap service_params = (HashMap)params.get("s1");
    614        
     704        HashMap service_params = (HashMap) params.get("s1");
     705
    615706        Element query_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    616707        GSXML.addParametersToList(this.doc, query_param_list, service_params);
     
    618709
    619710        // do the query
    620         Element mr_query_response = (Element)this.mr.process(mr_query_message);
    621        
    622         String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
     711        Element mr_query_response = (Element) this.mr.process(mr_query_message);
     712
     713        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.TERM_ELEM + GSXML.LIST_MODIFIER);
    623714        Element query_term_list_element = (Element) GSXML.getNodeByPath(mr_query_response, path);
    624         if (query_term_list_element == null) {
     715        if (query_term_list_element == null)
     716        {
    625717            // no term info
    626718            logger.error("No query term information.\n");
     
    630722        String content = GSXML.getNodeText(dc_response_doc_content);
    631723
    632         String metadata_path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     724        String metadata_path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
    633725        Element metadata_list = (Element) GSXML.getNodeByPath(mr_query_response, metadata_path);
    634726
    635727        HashSet query_term_variants = new HashSet();
    636728        NodeList equivalent_terms_nodelist = query_term_list_element.getElementsByTagName("equivTermList");
    637         if(equivalent_terms_nodelist == null || equivalent_terms_nodelist.getLength() == 0)
     729        if (equivalent_terms_nodelist == null || equivalent_terms_nodelist.getLength() == 0)
    638730        {
    639731            NodeList terms_nodelist = query_term_list_element.getElementsByTagName("term");
    640             if(terms_nodelist != null && terms_nodelist.getLength() > 0)
    641             {
    642                 for(int i = 0; i < terms_nodelist.getLength(); i++)
    643                 {
    644                     String termValue = ((Element)terms_nodelist.item(i)).getAttribute("name");
     732            if (terms_nodelist != null && terms_nodelist.getLength() > 0)
     733            {
     734                for (int i = 0; i < terms_nodelist.getLength(); i++)
     735                {
     736                    String termValue = ((Element) terms_nodelist.item(i)).getAttribute("name");
    645737                    String termValueU = null;
    646738                    String termValueL = null;
    647                        
    648                     if(termValue.length() > 1)
     739
     740                    if (termValue.length() > 1)
    649741                    {
    650742                        termValueU = termValue.substring(0, 1).toUpperCase() + termValue.substring(1);
     
    656748                        termValueL = termValue.substring(0, 1).toLowerCase();
    657749                    }
    658                    
     750
    659751                    query_term_variants.add(termValueU);
    660752                    query_term_variants.add(termValueL);
     
    664756        else
    665757        {
    666             for (int i = 0; i < equivalent_terms_nodelist.getLength(); i++) {
     758            for (int i = 0; i < equivalent_terms_nodelist.getLength(); i++)
     759            {
    667760                Element equivalent_terms_element = (Element) equivalent_terms_nodelist.item(i);
    668761                String[] equivalent_terms = GSXML.getAttributeValuesFromList(equivalent_terms_element, GSXML.NAME_ATT);
    669                 for (int j = 0; j < equivalent_terms.length; j++) {
     762                for (int j = 0; j < equivalent_terms.length; j++)
     763                {
    670764                    query_term_variants.add(equivalent_terms[j]);
    671765                }
     
    682776        boolean in_term = false;
    683777        boolean in_phrase = false;
    684         for (int i = 0; i < performed_query.length(); i++) {
     778        for (int i = 0; i < performed_query.length(); i++)
     779        {
    685780            char character = performed_query.charAt(i);
    686781            boolean is_character_letter_or_digit = Character.isLetterOrDigit(character);
    687782
    688783            // Has a query term just started?
    689             if (in_term == false && is_character_letter_or_digit == true) {
     784            if (in_term == false && is_character_letter_or_digit == true)
     785            {
    690786                in_term = true;
    691787                term_start = i;
     
    693789
    694790            // Or has a term just finished?
    695             else if (in_term == true && is_character_letter_or_digit == false) {
     791            else if (in_term == true && is_character_letter_or_digit == false)
     792            {
    696793                in_term = false;
    697794                String term = performed_query.substring(term_start, i);
    698                
     795
    699796                Element term_element = GSXML.getNamedElement(query_term_list_element, GSXML.TERM_ELEM, GSXML.NAME_ATT, term);
    700                 if (term_element != null) {
    701                    
     797                if (term_element != null)
     798                {
     799
    702800                    HashSet phrase_query_p_term_x_variants = new HashSet();
    703                    
     801
    704802                    NodeList term_equivalent_terms_nodelist = term_element.getElementsByTagName("equivTermList");
    705                     if(term_equivalent_terms_nodelist == null || term_equivalent_terms_nodelist.getLength() == 0)
     803                    if (term_equivalent_terms_nodelist == null || term_equivalent_terms_nodelist.getLength() == 0)
    706804                    {
    707805                        String termValueU = null;
    708806                        String termValueL = null;
    709                        
    710                         if(term.length() > 1)
     807
     808                        if (term.length() > 1)
    711809                        {
    712810                            termValueU = term.substring(0, 1).toUpperCase() + term.substring(1);
     
    718816                            termValueL = term.substring(0, 1).toLowerCase();
    719817                        }
    720                        
     818
    721819                        phrase_query_p_term_x_variants.add(termValueU);
    722820                        phrase_query_p_term_x_variants.add(termValueL);
     
    724822                    else
    725823                    {
    726                         for (int j = 0; j < term_equivalent_terms_nodelist.getLength(); j++) {
     824                        for (int j = 0; j < term_equivalent_terms_nodelist.getLength(); j++)
     825                        {
    727826                            Element term_equivalent_terms_element = (Element) term_equivalent_terms_nodelist.item(j);
    728827                            String[] term_equivalent_terms = GSXML.getAttributeValuesFromList(term_equivalent_terms_element, GSXML.NAME_ATT);
    729                             for (int k = 0; k < term_equivalent_terms.length; k++) {
     828                            for (int k = 0; k < term_equivalent_terms.length; k++)
     829                            {
    730830                                phrase_query_p_term_x_variants.add(term_equivalent_terms[k]);
    731831                            }
     
    733833                    }
    734834                    phrase_query_p_term_variants_list.add(phrase_query_p_term_x_variants);
    735                    
    736                     if (in_phrase == false) {
     835
     836                    if (in_phrase == false)
     837                    {
    737838                        phrase_query_term_variants_hierarchy.add(phrase_query_p_term_variants_list);
    738839                        phrase_query_p_term_variants_list = new ArrayList();
     
    741842            }
    742843            // Watch for phrases (surrounded by quotes)
    743             if (character == '\"') {
     844            if (character == '\"')
     845            {
    744846                // Has a phrase just started?
    745                 if (in_phrase == false) {
     847                if (in_phrase == false)
     848                {
    746849                    in_phrase = true;
    747850                }
    748851                // Or has a phrase just finished?
    749                 else if (in_phrase == true) {
     852                else if (in_phrase == true)
     853                {
    750854                    in_phrase = false;
    751855                    phrase_query_term_variants_hierarchy.add(phrase_query_p_term_variants_list);
     
    760864    }
    761865
    762 
    763866    /**
    764     * Highlights query terms in a piece of text.
    765     */
     867     * Highlights query terms in a piece of text.
     868     */
    766869    private Element highlightQueryTermsInternal(String content, HashSet query_term_variants, ArrayList phrase_query_term_variants_hierarchy)
    767870    {
     
    775878        boolean in_word = false;
    776879        boolean preceding_word_matched = false;
    777         for (int i = 0; i < content_characters.length; i++) {
     880        for (int i = 0; i < content_characters.length; i++)
     881        {
    778882            boolean is_character_letter_or_digit = Character.isLetterOrDigit(content_characters[i]);
    779883
    780884            // Has a word just started?
    781             if (in_word == false && is_character_letter_or_digit == true) {
     885            if (in_word == false && is_character_letter_or_digit == true)
     886            {
    782887                in_word = true;
    783888                word_start = i;
     
    785890
    786891            // Or has a word just finished?
    787             else if (in_word == true && is_character_letter_or_digit == false) {
     892            else if (in_word == true && is_character_letter_or_digit == false)
     893            {
    788894                in_word = false;
    789895
    790896                // Check if the word matches any of the query term equivalents
    791897                String word = new String(content_characters, word_start, (i - word_start));
    792                 if (query_term_variants.contains(word)) {
     898                if (query_term_variants.contains(word))
     899                {
    793900                    // We have found a matching word, so remember its location
    794901                    word_matches.add(new WordMatch(word, word_start, i, preceding_word_matched));
    795902                    preceding_word_matched = true;
    796903                }
    797                 else {
     904                else
     905                {
    798906                    preceding_word_matched = false;
    799907                }
     
    802910
    803911        // Don't forget the last word...
    804         if (in_word == true) {
     912        if (in_word == true)
     913        {
    805914            // Check if the word matches any of the query term equivalents
    806915            String word = new String(content_characters, word_start, (content_characters.length - word_start));
    807             if (query_term_variants.contains(word)) {
     916            if (query_term_variants.contains(word))
     917            {
    808918                // We have found a matching word, so remember its location
    809919                word_matches.add(new WordMatch(word, word_start, content_characters.length, preceding_word_matched));
     
    816926        // Deal with phrases now
    817927        ArrayList partial_phrase_matches = new ArrayList();
    818         for (int i = 0; i < word_matches.size(); i++) {
     928        for (int i = 0; i < word_matches.size(); i++)
     929        {
    819930            WordMatch word_match = (WordMatch) word_matches.get(i);
    820931
    821932            // See if any partial phrase matches are extended by this word
    822             if (word_match.preceding_word_matched) {
    823                 for (int j = partial_phrase_matches.size() - 1; j >= 0; j--) {
     933            if (word_match.preceding_word_matched)
     934            {
     935                for (int j = partial_phrase_matches.size() - 1; j >= 0; j--)
     936                {
    824937                    PartialPhraseMatch partial_phrase_match = (PartialPhraseMatch) partial_phrase_matches.remove(j);
    825938                    ArrayList phrase_query_p_term_variants_list = (ArrayList) phrase_query_term_variants_hierarchy.get(partial_phrase_match.query_phrase_number);
    826939                    HashSet phrase_query_p_term_x_variants = (HashSet) phrase_query_p_term_variants_list.get(partial_phrase_match.num_words_matched);
    827                     if (phrase_query_p_term_x_variants.contains(word_match.word)) {
     940                    if (phrase_query_p_term_x_variants.contains(word_match.word))
     941                    {
    828942                        partial_phrase_match.num_words_matched++;
    829943
    830944                        // Has a complete phrase match occurred?
    831                         if (partial_phrase_match.num_words_matched == phrase_query_p_term_variants_list.size()) {
     945                        if (partial_phrase_match.num_words_matched == phrase_query_p_term_variants_list.size())
     946                        {
    832947                            // Check for overlaps by looking at the previous highlight range
    833                             if (!highlight_end_positions.isEmpty()) {
     948                            if (!highlight_end_positions.isEmpty())
     949                            {
    834950                                int last_highlight_index = highlight_end_positions.size() - 1;
    835951                                int last_highlight_end = ((Integer) highlight_end_positions.get(last_highlight_index)).intValue();
    836                                 if (last_highlight_end > partial_phrase_match.start_position) {
     952                                if (last_highlight_end > partial_phrase_match.start_position)
     953                                {
    837954                                    // There is an overlap, so remove the previous phrase match
    838955                                    int last_highlight_start = ((Integer) highlight_start_positions.remove(last_highlight_index)).intValue();
     
    846963                        }
    847964                        // No, but add the partial match back into the list for next time
    848                         else {
     965                        else
     966                        {
    849967                            partial_phrase_matches.add(partial_phrase_match);
    850968                        }
     
    852970                }
    853971            }
    854             else {
     972            else
     973            {
    855974                partial_phrase_matches.clear();
    856975            }
    857976
    858977            // See if this word is at the start of any of the phrases
    859             for (int p = 0; p < phrase_query_term_variants_hierarchy.size(); p++) {
     978            for (int p = 0; p < phrase_query_term_variants_hierarchy.size(); p++)
     979            {
    860980                ArrayList phrase_query_p_term_variants_list = (ArrayList) phrase_query_term_variants_hierarchy.get(p);
    861981                HashSet phrase_query_p_term_1_variants = (HashSet) phrase_query_p_term_variants_list.get(0);
    862                 if (phrase_query_p_term_1_variants.contains(word_match.word)) {
     982                if (phrase_query_p_term_1_variants.contains(word_match.word))
     983                {
    863984                    // If this phrase is just one word long, we have a complete match
    864                     if (phrase_query_p_term_variants_list.size() == 1) {
     985                    if (phrase_query_p_term_variants_list.size() == 1)
     986                    {
    865987                        highlight_start_positions.add(new Integer(word_match.start_position));
    866988                        highlight_end_positions.add(new Integer(word_match.end_position));
    867989                    }
    868990                    // Otherwise we have the start of a potential phrase match
    869                     else {
     991                    else
     992                    {
    870993                        partial_phrase_matches.add(new PartialPhraseMatch(word_match.start_position, p));
    871994                    }
     
    8781001
    8791002        int last_wrote = 0;
    880         for (int i = 0; i < highlight_start_positions.size(); i++) {
     1003        for (int i = 0; i < highlight_start_positions.size(); i++)
     1004        {
    8811005            int highlight_start = ((Integer) highlight_start_positions.get(i)).intValue();
    8821006            int highlight_end = ((Integer) highlight_end_positions.get(i)).intValue();
    8831007
    8841008            // Print anything before the highlight range
    885             if (last_wrote < highlight_start) {
     1009            if (last_wrote < highlight_start)
     1010            {
    8861011                String preceding_text = new String(content_characters, last_wrote, (highlight_start - last_wrote));
    8871012                content_element.appendChild(this.doc.createTextNode(preceding_text));
     
    8891014
    8901015            // Print the highlight text, annotated
    891             if (highlight_end > last_wrote) {
     1016            if (highlight_end > last_wrote)
     1017            {
    8921018                String highlight_text = new String(content_characters, highlight_start, (highlight_end - highlight_start));
    8931019                Element annotation_element = GSXML.createTextElement(this.doc, "annotation", highlight_text);
     
    8991025
    9001026        // Finish off any unwritten text
    901         if (last_wrote < content_characters.length) {
     1027        if (last_wrote < content_characters.length)
     1028        {
    9021029            String remaining_text = new String(content_characters, last_wrote, (content_characters.length - last_wrote));
    9031030            content_element.appendChild(this.doc.createTextNode(remaining_text));
     
    9061033        return content_element;
    9071034    }
    908 
    9091035
    9101036    static private class WordMatch
     
    9241050    }
    9251051
    926 
    9271052    static private class PartialPhraseMatch
    9281053    {
Note: See TracChangeset for help on using the changeset viewer.