This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new c14b9d9db3 GH-2250: Determine likely syntax using source URI
c14b9d9db3 is described below
commit c14b9d9db396662d442654b51854363162958445
Author: Andy Seaborne <[email protected]>
AuthorDate: Tue Feb 6 16:36:58 2024 +0000
GH-2250: Determine likely syntax using source URI
---
.../main/java/org/apache/jena/riot/RDFParser.java | 27 ++++++++++++++++------
.../org/apache/jena/sparql/util/DatasetUtils.java | 2 +-
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFParser.java
b/jena-arq/src/main/java/org/apache/jena/riot/RDFParser.java
index 7ac679a379..8bde96cdb6 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFParser.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFParser.java
@@ -379,25 +379,38 @@ public class RDFParser {
private void parseURI(StreamRDF destination) {
// Source by uri or path.
try (TypedInputStream input = openTypedInputStream(uri, path)) {
- ReaderRIOT reader;
+ ReaderRIOT readerRiot;
ContentType ct;
if ( forceLang != null ) {
ReaderRIOTFactory r = RDFParserRegistry.getFactory(forceLang);
if ( r == null )
throw new RiotException("No parser registered for
language: " + forceLang);
ct = forceLang.getContentType();
- reader = createReader(r, forceLang);
+ readerRiot = createReader(r, forceLang);
} else {
// No forced language.
- // Conneg and hint, ignoring text/plain.
- ct = WebContent.determineCT(input.getContentType(), hintLang,
baseURI);
+ // Determine the syntax based on
+ // Content-type, ignoring text/plain
+ // hintLanguage
+ // Any pathname extension from file or URI.
+ //
+ // Prefer the uri being read for more information, or oath,
and the base if all else fails.
+
+ String target;
+ if ( uri != null )
+ target = uri;
+ else if ( path != null )
+ target = path.toString();
+ else
+ target = baseURI;
+ ct = WebContent.determineCT(input.getContentType(), hintLang,
target);
if ( ct == null )
throw new RiotException("Failed to determine the content
type: (URI=" + baseURI + " : stream=" + input.getContentType()+")");
- reader = createReader(ct);
- if ( reader == null )
+ readerRiot = createReader(ct);
+ if ( readerRiot == null )
throw new RiotException("No parser registered for content
type: " + ct.getContentTypeStr());
}
- read(reader, input, null, baseURI, context, ct, destination);
+ read(readerRiot, input, null, baseURI, context, ct, destination);
}
}
diff --git
a/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
b/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
index a0476ea448..e61d25e1d5 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/DatasetUtils.java
@@ -206,7 +206,7 @@ public class DatasetUtils
for ( Iterator<String> iter = namedSourceList.iterator() ;
iter.hasNext() ; ) {
String sourceURI = iter.next();
String absURI = baseURI(sourceURI, absBaseURI);
- // Read to a tmp graph in case of syntax errors.
+ // Read into a tmp graph in case of syntax errors.
Graph gTmp = GraphFactory.createJenaDefaultGraph();
RDFDataMgr.read(gTmp, sourceURI, absBaseURI, null);
Node gn = NodeFactory.createURI(sourceURI);