version 1.39, 2002/08/06 07:39:52
|
version 1.40, 2002/08/06 07:56:45
|
Line 304 public class ARPServlet extends HttpServ
|
Line 304 public class ARPServlet extends HttpServ
|
*@param uri the URI to open |
*@param uri the URI to open |
*@return the content at the URI or null if any error occurs |
*@return the content at the URI or null if any error occurs |
*/ |
*/ |
private String getRDFfromURI (String uri) |
private String getRDFfromURI (String uri, String sError) |
{ |
{ |
try { |
try { |
URL url = new URL(uri); |
URL url = new URL(uri); |
Line 331 public class ARPServlet extends HttpServ
|
Line 331 public class ARPServlet extends HttpServ
|
if (numRead++ >= 195) break; |
if (numRead++ >= 195) break; |
} |
} |
|
|
if (s.equals("")) |
if (s.equals("")) { |
// Nothing was returned |
// Nothing was returned |
|
sError = "Empty document."; |
return null; |
return null; |
|
} |
|
|
// A server could return content but not the RDF/XML that |
// A server could return content but not the RDF/XML that |
// we need. Check the beginning of s and if it looks like |
// we need. Check the beginning of s and if it looks like |
// a generic HTML message, return an error. |
// a generic HTML message, return an error. |
if (s.startsWith("<!DOCTYPE")) |
if (s.startsWith("<!DOCTYPE")) { |
|
sError = "Document looks like HTML, ignored."; |
return null; |
return null; |
|
} |
|
|
String APPFcharset = null; // preliminary 'charset' according to XML APP. F |
String APPFcharset = null; // preliminary 'charset' according to XML APP. F |
int ignoreBytes = 0; |
int ignoreBytes = 0; |
Line 384 public class ARPServlet extends HttpServ
|
Line 388 public class ARPServlet extends HttpServ
|
|
|
String finalCharset; |
String finalCharset; |
if (HTTPcharset != null) { |
if (HTTPcharset != null) { |
if (XMLcharset != null && HTTPcharset != XMLcharset) |
if (XMLcharset != null && HTTPcharset != XMLcharset) { |
|
sError = "Charset conflict: Content-Type: " + contentT + ". XML encoding: " + XMLcharset + "."; |
return null; |
return null; |
|
} |
finalCharset = HTTPcharset; |
finalCharset = HTTPcharset; |
} |
} |
else if (XMLcharset != null) |
else if (XMLcharset != null) |
finalCharset = XMLcharset; |
finalCharset = XMLcharset; |
else |
else |
finalCharset = "UTF-8"; |
finalCharset = "UTF-8"; |
if (finalCharset == "UTF-16" && ignoreBytes != 2) // no BOM! |
if (finalCharset == "UTF-16" && ignoreBytes != 2) { // no BOM! |
|
sError = "Illegal XML: UTF-16 without BOM."; |
return null; |
return null; |
|
} |
|
|
bis.reset(); // move back to start of stream |
bis.reset(); // move back to start of stream |
bis.skip(ignoreBytes); // skip BOM |
bis.skip(ignoreBytes); // skip BOM |
Line 408 public class ARPServlet extends HttpServ
|
Line 416 public class ARPServlet extends HttpServ
|
return s; |
return s; |
|
|
} catch (Exception e) { |
} catch (Exception e) { |
|
sError = "Exception: " + e.getMessage(); |
return null; |
return null; |
} |
} |
} |
} |
Line 1609 System.out.println("SERVLET_TMP_DIR = "
|
Line 1618 System.out.println("SERVLET_TMP_DIR = "
|
URL url; |
URL url; |
url=new URL(sURI); |
url=new URL(sURI); |
in = url.openStream(); |
in = url.openStream(); |
sRDF = getRDFfromURI(sURI); |
sRDF = getRDFfromURI(sURI, sError); |
if (sRDF == null) |
if (sRDF == null) |
sError = "An attempt to load the RDF from URI '" + sURI + "' failed. (The URI may not exist or the server is down.)"; |
sError += "An attempt to load the RDF from URI '" + sURI + "' failed. (The URI may not exist or the server is down.)"; |
} catch (Exception e) { |
} catch (Exception e) { |
sError = "Exception loading RDF from URI '" + sURI + "' failed. (The URI may not exist or the server is down.)"; |
sError = "Exception loading RDF from URI '" + sURI + "' failed. (The URI may not exist or the server is down.)"; |
} |
} |