- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java
r9289 r9874 2 2 3 3 // Greenstone classes 4 import org.greenstone.g dbm.*;4 import org.greenstone.gsdl3.core.GSException; 5 5 import org.greenstone.gsdl3.util.*; 6 6 … … 61 61 62 62 /** 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 { 64 65 65 66 String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id; … … 67 68 StringBuffer buffer = new StringBuffer(); 68 69 try { 69 BufferedReader reader = makeConnection(url_string);70 BufferedReader reader = Misc.makeHttpConnection(url_string); 70 71 String line; 71 72 while((line = reader.readLine())!= null) { 72 73 buffer.append(line); 73 74 } 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 79 81 String node_content = buffer.toString(); 80 82 … … 99 101 processed_content.append("</nodeContent>"); 100 102 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(); 102 111 103 112 return (Element)this.doc.importNode(content_element,true); … … 169 178 } 170 179 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 186 180 protected String translateId(String oid){ 187 181 int p = oid.lastIndexOf('.'); … … 215 209 protected Element getMetadataList (String doc_id, 216 210 boolean all_metadata, 217 ArrayList metadata_names){ 211 ArrayList metadata_names) 212 throws GSException { 218 213 219 214 Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); … … 236 231 String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString(); 237 232 try { 238 BufferedReader reader = makeConnection(url_string);233 BufferedReader reader = Misc.makeHttpConnection(url_string); 239 234 String line; 240 235 while ((line = reader.readLine()) != null) { … … 249 244 GSXML.addMetadata(this.doc, meta_list, name, value); 250 245 } 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); 254 250 } 255 251 return meta_list;
Note:
See TracChangeset
for help on using the changeset viewer.