Changeset 9813 for branches/ant-install-branch/gsdl3
- Timestamp:
- 2005-05-04T16:12:38+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/IViaRetrieve.java
r9798 r9813 2 2 3 3 // Greenstone classes 4 import org.greenstone.gsdl3.core.GSException; 4 5 import org.greenstone.gsdl3.util.*; 5 6 … … 60 61 61 62 /** gets a document by sending a request to iVia, then processes it and creates a documentNode around the text */ 62 protected Element getNodeContent(String doc_id) { 63 protected Element getNodeContent(String doc_id) 64 throws GSException { 63 65 64 66 String url_string = ivia_server_url+"/cgi-bin/view_record?theme=gsdl3&record_id="+doc_id; … … 66 68 StringBuffer buffer = new StringBuffer(); 67 69 try { 68 BufferedReader reader = makeConnection(url_string);70 BufferedReader reader = Misc.makeHttpConnection(url_string); 69 71 String line; 70 72 while((line = reader.readLine())!= null) { 71 73 buffer.append(line); 72 74 } 73 } catch (Exception e) { 74 System.err.println("IViaRetrieve Error:exception happened"); 75 e.printStackTrace(); 76 } 77 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 78 81 String node_content = buffer.toString(); 79 82 … … 175 178 } 176 179 177 protected BufferedReader makeConnection(String url_string) {178 BufferedReader reader = null;179 try {180 URL url = new URL(url_string);181 HttpURLConnection connection = (HttpURLConnection)url.openConnection();182 InputStream input = connection.getInputStream();183 reader = new BufferedReader(new InputStreamReader(input));184 } catch (java.net.MalformedURLException e) {185 System.err.println("IViaRetrieve: Malformed URL: "+url_string);186 } catch (java.io.IOException e) {187 System.err.println("IViaRetrieve Error: An error occurred during IO to url "+url_string);188 }189 return reader;190 }191 192 180 protected String translateId(String oid){ 193 181 int p = oid.lastIndexOf('.'); … … 221 209 protected Element getMetadataList (String doc_id, 222 210 boolean all_metadata, 223 ArrayList metadata_names){ 211 ArrayList metadata_names) 212 throws GSException { 224 213 225 214 Element meta_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); … … 242 231 String url_string = ivia_server_url+"/cgi-bin/view_record_set?theme=gsdl3&record_id_list="+doc_id+"&field_list="+field_list.toString(); 243 232 try { 244 BufferedReader reader = makeConnection(url_string);233 BufferedReader reader = Misc.makeHttpConnection(url_string); 245 234 String line; 246 235 while ((line = reader.readLine()) != null) { … … 255 244 GSXML.addMetadata(this.doc, meta_list, name, value); 256 245 } 257 } catch (Exception e) { 258 System.err.println("IViaRetrieve Error:exception happened"); 259 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); 260 250 } 261 251 return meta_list;
Note:
See TracChangeset
for help on using the changeset viewer.