From 3207e986c86c1293f895e58cf2e009f8ed71f5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Fri, 24 Oct 2014 11:28:17 +0000 Subject: [PATCH] - Reimplented SAXParser.parse( uri ) to cover content negotiation --- html/cli.html | 5 +++++ src/fr/inrialpes/exmo/align/cli/ParserPrinter.java | 2 +- src/fr/inrialpes/exmo/align/parser/XMLParser.java | 10 +++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/html/cli.html b/html/cli.html index 72346e4e..74ad43b8 100644 --- a/html/cli.html +++ b/html/cli.html @@ -116,6 +116,11 @@ The utility may be invoked in the following way: <div class="terminal"> $ java -cp lib/procalign.jar fr.inrialpes.exmo.align.cli.ParserPrinter file:examples/rdf/newsample.rdf -r fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor </div> +It should work with files and with URIs, dereferenceable or not: +<div class="terminal"> +$ java -cp lib/procalign.jar fr.inrialpes.exmo.align.cli.ParserPrinter http://alignapi.gforge.inria.fr//tutorial/refalign.rdf +$ java -cp lib/procalign.jar fr.inrialpes.exmo.align.cli.ParserPrinter http://aserv.inrialpes.fr/alid/1317289904908/444 +</div> </p> <h3>Translating queries</h3> diff --git a/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java b/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java index 6f94d580..7d77fd57 100644 --- a/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java +++ b/src/fr/inrialpes/exmo/align/cli/ParserPrinter.java @@ -133,7 +133,7 @@ public class ParserPrinter extends CommonCLI { System.exit(-1); } - //logger.trace("Filename: {}", initName); + logger.trace("Filename: {}", initName); try { // Create parser diff --git a/src/fr/inrialpes/exmo/align/parser/XMLParser.java b/src/fr/inrialpes/exmo/align/parser/XMLParser.java index 3c1ce9df..e2a91281 100644 --- a/src/fr/inrialpes/exmo/align/parser/XMLParser.java +++ b/src/fr/inrialpes/exmo/align/parser/XMLParser.java @@ -39,6 +39,8 @@ import java.io.InputStream; import java.io.File; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; import java.lang.Integer; import java.lang.Double; import java.util.Hashtable; @@ -198,10 +200,16 @@ public class XMLParser extends DefaultHandler { * If the current process has links (import or include) to others documents then they are * parsed. * @param uri URI of the document to parse + * Note: SAXParser has a parse( String uri ) method but it does not do content negotiation + * Hence we have to reimplement it (2014) */ public Alignment parse( String uri ) throws AlignmentException { try { - parser.parse( uri, this ); + // Reimplemented URI parsing because this does not do content negotiation + //parser.parse( uri, this ); + URLConnection connection = new URL( uri ).openConnection(); + connection.setRequestProperty( "Accept", "text/xml, application/rdf+xml" ); + parser.parse( connection.getInputStream(), this ); } catch ( SAXException sex ) { throw new AlignmentException( "Parsing error", sex ); } catch ( IOException ioex ) { -- GitLab