Ignore:
Timestamp:
2005-05-16T11:02:50+12:00 (19 years ago)
Author:
kjdon
Message:

merged from branch ant-install-branch: merge 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java

    r9289 r9874  
    22
    33// Greenstone classes
    4 import org.greenstone.gdbm.*;
     4import org.greenstone.gsdl3.core.GSException;
    55import org.greenstone.gsdl3.util.*;
    66
     
    6161       
    6262    /** gets a document by sending a request to iVia, then processes it and creates a documentNode around the text */
    63     protected Element getNodeContent(String doc_id) {
     63    protected Element getNodeContent(String doc_id)
     64    throws GSException {
    6465
    6566    String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id;
     
    6768    StringBuffer buffer = new StringBuffer();
    6869    try {
    69         BufferedReader reader = makeConnection(url_string);
     70        BufferedReader reader = Misc.makeHttpConnection(url_string);
    7071            String line;
    7172        while((line = reader.readLine())!= null) {
    7273        buffer.append(line);
    7374        }
    74     } catch (Exception e) {
    75         System.err.println("IViaRetrieve Error:exception happened");
    76         e.printStackTrace();
    77     }
    78    
     75    } catch (java.net.MalformedURLException e) {
     76        throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM);
     77    } catch (java.io.IOException e) {
     78        throw new GSException("IOException during connection to "+url_string+": "+e.toString(),GSXML.ERROR_TYPE_SYSTEM);
     79    }
     80
    7981    String node_content = buffer.toString();
    8082
     
    99101    processed_content.append("</nodeContent>");
    100102       
    101     Element content_element = this.converter.getDOM(processed_content.toString()).getDocumentElement();
     103    Document content_doc = this.converter.getDOM(processed_content.toString());
     104    if (content_doc == null) {
     105        System.err.println("IViaRetrieve.getNodeContent Error: Couldn't parse node content");
     106        System.err.println(processed_content.toString());
     107        return null;
     108    }
     109   
     110    Element content_element = content_doc.getDocumentElement();
    102111
    103112    return (Element)this.doc.importNode(content_element,true);
     
    169178    }
    170179
    171     protected BufferedReader makeConnection(String url_string) {
    172     BufferedReader reader = null;
    173     try {
    174         URL url = new URL(url_string);
    175         HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    176         InputStream input = connection.getInputStream();
    177         reader = new BufferedReader(new InputStreamReader(input)); 
    178     } catch (java.net.MalformedURLException e) {
    179         System.err.println("IViaRetrieve: Malformed URL: "+url_string);
    180     } catch (java.io.IOException e) {
    181         System.err.println("IViaRetrieve Error: An error occurred during IO to url "+url_string);
    182     }
    183     return reader;
    184     }
    185 
    186180    protected String translateId(String oid){
    187181    int p = oid.lastIndexOf('.');
     
    215209    protected Element getMetadataList (String doc_id,
    216210                       boolean all_metadata,
    217                        ArrayList metadata_names){
     211                       ArrayList metadata_names)
     212    throws GSException {
    218213   
    219214    Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     
    236231    String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString();
    237232    try {
    238         BufferedReader reader = makeConnection(url_string);
     233        BufferedReader reader = Misc.makeHttpConnection(url_string);
    239234        String line;
    240235        while  ((line = reader.readLine()) != null) {
     
    249244        GSXML.addMetadata(this.doc, meta_list, name, value);
    250245        }
    251     } catch (Exception e) {
    252         System.err.println("IViaRetrieve Error:exception happened");
    253         e.printStackTrace();
     246    } catch (java.net.MalformedURLException e) {
     247        throw new GSException("Malformed URL: "+url_string, GSXML.ERROR_TYPE_SYSTEM);
     248    } catch (java.io.IOException e) {
     249        throw new GSException("IOException: "+e.toString(), GSXML.ERROR_TYPE_SYSTEM);
    254250    }
    255251    return meta_list;
Note: See TracChangeset for help on using the changeset viewer.