Changeset 24985

Show
Ignore:
Timestamp:
26.01.2012 11:30:41 (7 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

Files:
1 modified

Legend:

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

    r23360 r24985  
    55 
    66// XML classes 
    7 import org.w3c.dom.Node;  
    8 import org.w3c.dom.Element;  
    9 import org.w3c.dom.Document;  
     7import org.w3c.dom.Node; 
     8import org.w3c.dom.Element; 
     9import org.w3c.dom.Document; 
    1010 
    1111// other java stuff 
     
    2020import java.io.*; 
    2121import org.xml.sax.*; 
    22 import javax.xml.parsers.SAXParserFactory;  
     22import javax.xml.parsers.SAXParserFactory; 
    2323import javax.xml.parsers.ParserConfigurationException; 
    2424import javax.xml.parsers.SAXParser; 
     
    2929import org.apache.log4j.*; 
    3030 
    31 public class SystemAction extends Action { 
    32      
    33       static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName()); 
     31public class SystemAction extends Action 
     32{ 
    3433 
    35     String tempVal = ""; 
     34    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName()); 
    3635 
    37     /** process a request */ 
    38     public Node process (Node message_node) { 
    39      
    40     Element message = this.converter.nodeToElement(message_node); 
     36    String tempVal = ""; 
    4137 
    42     // assume only one request 
    43     Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
    44      
    45     String subaction = request.getAttribute(GSXML.SUBACTION_ATT); 
    46     String lang = request.getAttribute(GSXML.LANG_ATT); 
    47     String uid = request.getAttribute(GSXML.USER_ID_ATT); 
    48     // get the param list 
    49     Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
    50     HashMap params = GSXML.extractParams(cgi_param_list, false); 
     38    /** process a request */ 
     39    public Node process(Node message_node) 
     40    { 
    5141 
    52     Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    53      
    54     String coll = (String)params.get(GSParams.SYSTEM_CLUSTER); 
     42        Element message = this.converter.nodeToElement(message_node); 
    5543 
    56     String to = ""; 
    57     if (coll!=null && !coll.equals("")) { 
    58         to = coll; 
     44        // assume only one request 
     45        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
     46 
     47        String subaction = request.getAttribute(GSXML.SUBACTION_ATT); 
     48        String lang = request.getAttribute(GSXML.LANG_ATT); 
     49        String uid = request.getAttribute(GSXML.USER_ID_ATT); 
     50        // get the param list 
     51        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     52        HashMap params = GSXML.extractParams(cgi_param_list, false); 
     53 
     54        Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     55 
     56        String coll = (String) params.get(GSParams.SYSTEM_CLUSTER); 
     57 
     58        String to = ""; 
     59        if (coll != null && !coll.equals("")) 
     60        { 
     61            to = coll; 
     62        } 
     63 
     64        Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     65        Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, to, lang, uid); 
     66        mr_request_message.appendChild(mr_request); 
     67 
     68        Element system = this.doc.createElement(GSXML.SYSTEM_ELEM); 
     69        mr_request.appendChild(system); 
     70 
     71        // will need to change the following if can do more than one system request at once 
     72        if (subaction.equals("c")) 
     73        { // configure 
     74            system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE); 
     75            String info = (String) params.get(GSParams.SYSTEM_SUBSET); 
     76            system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info); 
     77        } 
     78        else 
     79        { 
     80            String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME); 
     81            String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE); 
     82 
     83            system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name); 
     84            system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type); 
     85 
     86            if (subaction.equals("d")) 
     87            { // delete 
     88                system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE); 
     89 
     90            } 
     91            else if (subaction.equals("a")) 
     92            { // add 
     93                system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE); 
     94            } 
     95            else 
     96            { 
     97                // create the default response 
     98                // for now just have an error 
     99                logger.error("bad subaction type"); 
     100                Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 
     101                result.appendChild(page_response); 
     102 
     103                return result; 
     104            } 
     105        } 
     106 
     107        Node response_message = this.mr.process(mr_request_message); 
     108 
     109        result.appendChild(GSXML.duplicateWithNewName(this.doc, (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true)); 
     110        return result; 
     111 
    59112    } 
    60113 
    61     Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    62     Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, to, lang, uid); 
    63     mr_request_message.appendChild(mr_request); 
    64      
    65     Element system = this.doc.createElement(GSXML.SYSTEM_ELEM); 
    66     mr_request.appendChild(system); 
    67      
    68     // will need to change the following if can do more than one system request at once 
    69     if (subaction.equals("c")) { // configure 
    70         system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE); 
    71         String info = (String)params.get(GSParams.SYSTEM_SUBSET); 
    72         system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info); 
    73     } 
    74     else { 
    75         String name = (String)params.get(GSParams.SYSTEM_MODULE_NAME); 
    76         String type = (String)params.get(GSParams.SYSTEM_MODULE_TYPE); 
    77  
    78         system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name); 
    79         system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type); 
    80          
    81         if (subaction.equals("d")) { // delete 
    82         system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE); 
    83  
    84         } else if (subaction.equals("a")) { // add 
    85         system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE); 
    86         } else { 
    87         // create the default response 
    88         // for now just have an error 
    89         logger.error("bad subaction type"); 
    90         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 
    91         result.appendChild(page_response); 
    92      
    93         return result; 
    94         } 
    95     } 
    96  
    97     Node response_message = this.mr.process(mr_request_message); 
    98      
    99     result.appendChild(GSXML.duplicateWithNewName(this.doc, (Element)GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true)); 
    100     return result; 
    101      
    102     } 
    103  
    104114}