Ignore:
Timestamp:
2005-05-03T09:50:12+12:00 (19 years ago)
Author:
kjdon
Message:

for all the converter.getDOM calls, now check for null document before using it - hopefully avoid lots of the exceptions that get printed to the screen if something goes wrong

Location:
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java

    r8832 r9798  
    5252    public String process(String xml_in) {
    5353       
    54     Element message = this.converter.getDOM(xml_in).getDocumentElement();
    55    
    56     Element result = process(message);
     54    Document message_doc = this.converter.getDOM(xml_in);
     55    if (message_doc == null) {
     56        System.err.println("Action.process(String) Error: Couldn't parse request");
     57        System.err.println(xml_in);
     58        return null;
     59    }
     60    Element result = process(message_doc.getDocumentElement());
    5761    return this.converter.getString(result);
    5862    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r5403 r9798  
    101101    }
    102102    // get the xml for both files
    103     Element coll_config_elem = this.converter.getDOM(coll_config_file, CONFIG_ENCODING).getDocumentElement();
     103    Document coll_config_doc = this.converter.getDOM(coll_config_file, CONFIG_ENCODING);
     104    Element coll_config_elem = null;
     105    if (coll_config_doc != null) {
     106        coll_config_elem = coll_config_doc.getDocumentElement();
     107    }
    104108    return coll_config_elem;
    105109
     
    116120        return null;
    117121    }
    118     Element build_config_elem = this.converter.getDOM(build_config_file, CONFIG_ENCODING).getDocumentElement();
    119 
     122    Document build_config_doc = this.converter.getDOM(build_config_file, CONFIG_ENCODING);
     123    Element build_config_elem = null;
     124    if (build_config_doc != null) {
     125        build_config_elem = build_config_doc.getDocumentElement();
     126    }
    120127    return build_config_elem;
    121128    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r9433 r9798  
    139139
    140140    Document doc = this.converter.getDOM(config_file, CONFIG_ENCODING);
     141    if (doc == null) {
     142        System.err.println("ServiceCluster: couldn't parse config file "+config_file.getPath());
     143        return false;
     144    }
    141145   
    142146    // get the appropriate service cluster element
     
    147151    return this.configure(sc);
    148152    }
    149  
     153    
    150154   
    151155    public boolean configure(Element service_cluster_info) {
     
    159163        }
    160164    }
    161 
     165   
    162166    // get the display info
    163167    Element display_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER);
     
    528532    }
    529533   
    530     Element site_config_elem  = this.converter.getDOM(configFile).getDocumentElement();
     534    Document site_config_doc  = this.converter.getDOM(configFile);
     535    if (site_config_doc == null) {
     536        System.err.println("ServiceCluster: could not read in site config file: "+configFile.getPath());
     537        return false;
     538    }
     539   
     540    Element site_config_elem = site_config_doc.getDocumentElement();
    531541    Element cluster_config_elem = GSXML.getNamedElement((Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER), GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, this.cluster_name);
    532542    if (cluster_config_elem == null) {
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r9276 r9798  
    133133    this.module_map = new HashMap();
    134134
    135     Element config = this.converter.getDOM(configFile).getDocumentElement();
    136    
    137     Element local_site_name = (Element)GSXML.getChildByTagName(config, GSXML.SITE_NAME_ELEM);
     135    Document config_doc = this.converter.getDOM(configFile);
     136    if (config_doc == null) {
     137System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     138        return false;
     139    }
     140    Element config_elem = config_doc.getDocumentElement();
     141   
     142    Element local_site_name = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_NAME_ELEM);
    138143    if (local_site_name == null) {
    139144        System.err.println("MessageRouter configure error:no site name in config file");
     
    143148    }
    144149   
    145     Element http_address = (Element)GSXML.getChildByTagName(config, GSXML.SITE_HTTP_ADDRESS_ELEM);
     150    Element http_address = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_HTTP_ADDRESS_ELEM);
    146151    if (http_address == null) {
    147152        System.err.println("MessageRouter configure error: no http address  in config file");
     
    151156    }
    152157
    153     Element proxy = (Element)GSXML.getChildByTagName(config, "proxy");
     158    Element proxy = (Element)GSXML.getChildByTagName(config_elem, "proxy");
    154159    if (proxy != null) {
    155160        String host = proxy.getAttribute("host");
     
    180185                     
    181186    // load up the services
    182     Element service_rack_list = (Element)GSXML.getChildByTagName(config, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
     187    Element service_rack_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
    183188    configureServices(service_rack_list);
    184189   
    185190    // load up the service clusters
    186     Element cluster_list = (Element)GSXML.getChildByTagName(config, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);   
     191    Element cluster_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);   
    187192    configureClusters(cluster_list);
    188193
     
    191196
    192197    // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
    193     Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
     198    Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
    194199    configureSites(site_list);
    195200   
     
    603608                    continue;
    604609                }
    605                 site_config_elem  = this.converter.getDOM(configFile).getDocumentElement();
     610                Document site_config_doc = this.converter.getDOM(configFile);
     611                if (site_config_doc == null) {
     612                    System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     613                    continue;
     614                }
     615                site_config_elem  = site_config_doc.getDocumentElement();
    606616                }
    607617                if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
     
    684694    File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name));
    685695    if (init_file.exists()) {
    686         Element init_elem = this.converter.getDOM(init_file).getDocumentElement();
    687         String coll_class_name = init_elem.getAttribute("class");
    688         if (coll_class_name.equals("")) {
    689         c = new Collection();
    690         } else {
    691         try {
    692             c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
    693         } catch (Exception e) {
    694             System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
    695             c = new Collection();
    696         }
    697         }
    698     } else {
    699         // use the defualt collection
     696        Document init_doc = this.converter.getDOM(init_file);
     697        if (init_doc != null) {
     698        Element init_elem = init_doc.getDocumentElement();
     699        if (init_elem != null) {
     700            String coll_class_name = init_elem.getAttribute("class");
     701            if (!coll_class_name.equals("")) {
     702            try {
     703                c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
     704            } catch (Exception e) {
     705                System.out.println("MessageRouter: couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
     706            }
     707            }
     708        }
     709        }
     710    }
     711    if (c==null) { // we haven't found anpther classname to use
    700712        c = new Collection();
    701713    }
     714   
    702715    c.setCollectionName(col_name);
    703716    c.setSiteHome(this.site_home);
     
    720733   
    721734    }
    722 
     735   
    723736    protected boolean activateSite(String site_name) {
    724737    System.out.println("MessageRouter:Activating site: "+site_name+".");
     
    732745        return false;
    733746    }
    734     Element config = this.converter.getDOM(configFile).getDocumentElement();
    735    
    736     Element site_list = (Element)GSXML.getChildByTagName(config, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
     747    Document config_doc = this.converter.getDOM(configFile);
     748    if (config_doc == null) {
     749        System.err.println("MessageRouter: couldn't parse site config file: "+configFile.getPath());
     750        return false;
     751    }
     752    Element config_elem = config_doc.getDocumentElement();
     753   
     754    Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
    737755    if (site_list ==null ) {
    738756        System.err.println("MessageRouter:activateSite, no sites found");
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/core/Receptionist.java

    r8921 r9798  
    8181    }
    8282   
    83     Element config_doc = this.converter.getDOM(interface_config_file).getDocumentElement();
    84     String base_interface = config_doc.getAttribute("baseInterface");
     83    Document config_doc = this.converter.getDOM(interface_config_file);
     84    if (config_doc == null) {
     85        System.err.println("Receptionist: could not parse interface config file: "+interface_config_file.getPath());
     86        return false;
     87    }
     88    Element config_elem = config_doc.getDocumentElement();
     89    String base_interface = config_elem.getAttribute("baseInterface");
    8590    setUpBaseInterface(base_interface);
    86     setUpInterfaceOptions(config_doc);
     91    setUpInterfaceOptions(config_elem);
    8792
    8893    // load up the actions
    89     Element action_list = (Element)GSXML.getChildByTagName(config_doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
     94    Element action_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
    9095    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
    9196
     
    109114    }
    110115
    111     this.language_list = (Element)GSXML.getChildByTagName(config_doc, "languageList");
     116    this.language_list = (Element)GSXML.getChildByTagName(config_elem, "languageList");
    112117    if (language_list == null) {
    113118        System.err.println("Receptionist: didn't find a language list in the config file!!");
     
    229234        base_interfaces.add(base_interface);
    230235        // now see if this has a base interface
    231         Element config_doc = this.converter.getDOM(base_interface_config_file).getDocumentElement();
    232         base_interface = config_doc.getAttribute("baseInterface");
     236        Document config_doc = this.converter.getDOM(base_interface_config_file);
     237        if (config_doc == null) {
     238        System.err.println("Receptionist: could not parse base interface config file: "+base_interface_config_file.getPath());
     239        return false;
     240        }
     241        Element config_elem = config_doc.getDocumentElement();
     242        base_interface = config_elem.getAttribute("baseInterface");
    233243    }
    234244    return true;
    235245    }
    236246
    237     protected boolean setUpInterfaceOptions(Element config_doc) {
    238     Element option_list = (Element)GSXML.getChildByTagName(config_doc, "optionList");
     247    protected boolean setUpInterfaceOptions(Element config_elem) {
     248    Element option_list = (Element)GSXML.getChildByTagName(config_elem, "optionList");
    239249    if (option_list != null) {
    240250        System.err.println("found an option list");
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java

    r9405 r9798  
    5252        return false;
    5353    }
    54    
    55     Element config_doc = this.converter.getDOM(interface_config_file, "utf-8").getDocumentElement();
    56     String base_interface = config_doc.getAttribute("baseInterface");
     54    Document config_doc = this.converter.getDOM(interface_config_file, "utf-8");
     55    if (config_doc == null) {
     56        System.err.println("TransformingReceptionist: could not parse interface config file: "+interface_config_file.getPath());
     57        return false;
     58    }
     59    Element config_elem = config_doc.getDocumentElement();
     60    String base_interface = config_elem.getAttribute("baseInterface");
    5761    setUpBaseInterface(base_interface);
    58     setUpInterfaceOptions(config_doc);
    59 
    60     Element action_list = (Element)GSXML.getChildByTagName(config_doc, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
     62    setUpInterfaceOptions(config_elem);
     63
     64    Element action_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.ACTION_ELEM+GSXML.LIST_MODIFIER);
    6165    NodeList actions = action_list.getElementsByTagName(GSXML.ACTION_ELEM);
    6266
     
    97101       
    98102    }
    99     Element lang_list = (Element)GSXML.getChildByTagName(config_doc, "languageList");
     103    Element lang_list = (Element)GSXML.getChildByTagName(config_elem, "languageList");
    100104    if (lang_list == null) {
    101105        System.err.println("TransformingReceptionist: didn't find a language list in the config file!!");
     
    157161    }
    158162    Document style_doc = this.converter.getDOM(new File(xslt_file), "UTF-8");
     163    if (style_doc == null) {
     164        System.err.println("TransformingReceptionist: cant parse the xslt file needed, so returning the original page!");
     165        return page;
     166       
     167    }
    159168
    160169    // look for the format element in the page response
     
    166175        // need to transform the format info
    167176        String stylesheet_file = GSFile.stylesheetFile((String)this.config_params.get(GSConstants.GSDL3_HOME), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces,   "config_format.xsl");
    168         Document stylesheet = this.converter.getDOM(new File(stylesheet_file));
    169         Document format_doc = this.converter.newDOM();
    170         format_doc.appendChild(format_doc.importNode(format_elem, true));
    171         Element new_format = (Element)this.transformer.transform(stylesheet, format_doc);
     177        Document stylesheet_doc = this.converter.getDOM(new File(stylesheet_file));
     178        if (stylesheet_doc != null) {
     179        Document format_doc = this.converter.newDOM();
     180        format_doc.appendChild(format_doc.importNode(format_elem, true));
     181        Element new_format = (Element)this.transformer.transform(stylesheet_doc, format_doc);
    172182        ///ystem.err.println("new format elem="+this.converter.getPrettyString(new_format));
    173183       
    174184        // add it in to the main stylesheet
    175         GSXSLT.mergeStylesheets(style_doc, new_format);
     185        GSXSLT.mergeStylesheets(style_doc, new_format);
     186        } else {
     187        System.err.println("TransformingReceptionist: couldn't parse the config_format stylesheet, adding the format info as is");
     188        GSXSLT.mergeStylesheets(style_doc, format_elem);
     189        }
    176190        ///ystem.out.println("the converted stylesheet is:");
    177191        ///ystem.out.println(this.converter.getPrettyString(style_doc.getDocumentElement()));
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GATEServices.java.tmp

    r6501 r9798  
    226226
    227227        annotated_text = "<nodeContent>" + annotated_text + "</nodeContent>";
    228         Element annotated_content = this.converter.getDOM(annotated_text).getDocumentElement();
    229         doc_node.replaceChild(doc_node.getOwnerDocument().importNode(annotated_content, true), content);
    230     }
     228        Document annotated_content_doc = this.converter.getDOM(annotated_text);
     229        if (annotated_content_doc != null) {
     230        Element annotated_content = annotated_content_doc.getDocumentElement();
     231        doc_node.replaceChild(doc_node.getOwnerDocument().importNode(annotated_content, true), content);
     232        } else {
     233        System.err.println("GATEServices.processGatePOSTag Error: Couldn't parse annotated text for doc node "+i);
     234        }
     235    }   
    231236
    232237    result.appendChild(this.doc.importNode(doc_node_list, true));
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/IViaProxy.java

    r9529 r9798  
    405405    doc_node.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    406406   
    407     Element content_element = this.converter.getDOM(processed_content.toString()).getDocumentElement();
    408     doc_node.appendChild(this.doc.importNode(content_element, true));
    409    
     407    Document content_doc = this.converter.getDOM(processed_content.toString());
     408    if (content_doc != null) {
     409        Element content_element = content_doc.getDocumentElement();
     410        doc_node.appendChild(this.doc.importNode(content_element, true));
     411    } else {
     412        System.err.println("IViaProxy.getDocument Error: Couldn't parse the node content");
     413    }
    410414    return doc_node;
    411415   
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java

    r9529 r9798  
    9898    processed_content.append("</nodeContent>");
    9999       
    100     Element content_element = this.converter.getDOM(processed_content.toString()).getDocumentElement();
     100    Document content_doc = this.converter.getDOM(processed_content.toString());
     101    if (content_doc == null) {
     102        System.err.println("IViaRetrieve.getNodeContent Error: Couldn't parse node content");
     103        System.err.println(processed_content.toString());
     104        return null;
     105    }
     106   
     107    Element content_element = content_doc.getDocumentElement();
    101108
    102109    return (Element)this.doc.importNode(content_element,true);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/PhindPhraseBrowse.java

    r6490 r9798  
    8989   
    9090    Document dom = this.converter.getDOM(app_info);
     91    if (dom==null) {
     92        System.err.println("PhindPhraseBrowse.configure Error: Couldn't parse applet info");
     93        return false;
     94    }
    9195    Element app_elem = dom.getDocumentElement();
    9296    applet_description.appendChild(this.doc.importNode(app_elem, true));
    93    
     97
    9498    return true;
    9599    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/ServiceRack.java

    r9426 r9798  
    144144   
    145145    Document doc = this.converter.getDOM(xml_in);
    146    
     146    if (doc == null) {
     147        System.err.println("ServiceRack.process(String) Error: Couldn't parse request");
     148        System.err.println(xml_in);
     149        return null;
     150    }
    147151    Element res = process(doc.getDocumentElement());
    148152    return this.converter.getString(res);
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java

    r8347 r9798  
    7575       
    7676    Document dom = converter.getDOM(app_info);
     77    if (dom == null) {
     78        System.err.println("Visualizer.configure Error: Couldn't parse applet info");
     79        return false;
     80    }
    7781    Element app_elem = dom.getDocumentElement();
    7882    applet_description.appendChild(this.doc.importNode(app_elem, true));
Note: See TracChangeset for help on using the changeset viewer.