You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/09/08 13:07:52 UTC
jena git commit: Better error handling for a Lang that is not
registered for writing.
Repository: jena
Updated Branches:
refs/heads/master 9d5f675a8 -> 9f27e0a5c
Better error handling for a Lang that is not registered for writing.
Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/9f27e0a5
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/9f27e0a5
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/9f27e0a5
Branch: refs/heads/master
Commit: 9f27e0a5cacb393935c40661b7bdcd2f96268d2f
Parents: 9d5f675
Author: Andy Seaborne <an...@apache.org>
Authored: Thu Sep 8 14:07:31 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Thu Sep 8 14:07:31 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/jena/riot/RDFDataMgr.java | 28 +++++++++++++-------
1 file changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jena/blob/9f27e0a5/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
index 7713389..667a41f 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/RDFDataMgr.java
@@ -907,11 +907,19 @@ public class RDFDataMgr
return uri ;
}
- /** Default lang - usually left as unknow so that extended content negotation happens */
+ /** Default lang - usually left as unknown so that extended content negotation happens */
private static Lang defaultLang(String uri) {
return null;
}
+ /** Map {@link Lang} to {@link RDFFormat}, or throw an exception. */
+ private static RDFFormat langToFormatOrException(Lang lang) {
+ RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ if ( serialization == null )
+ throw new RiotException("No output format for "+lang) ;
+ return serialization ;
+ }
+
/** Determine the Lang, given the URI target, any content type header string and a hint */
public static Lang determineLang(String target, String ctStr, Lang hintLang) {
ContentType ct = WebContent.determineCT(ctStr, hintLang, target) ;
@@ -989,10 +997,10 @@ public class RDFDataMgr
* @param lang Language for the seralization.
*/
public static void write(OutputStream out, Graph graph, Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
write(out, graph, serialization);
}
-
+
/** Write the graph to the output stream in the default serialization for the language.
* @param out OutputStream
* @param graph Graph to write
@@ -1009,7 +1017,7 @@ public class RDFDataMgr
*/
public static void write(StringWriter out, Graph graph, Lang lang) {
// Only known reasonable use of a Writer
- write$(out, graph, RDFWriterRegistry.defaultSerialization(lang));
+ write$(out, graph, langToFormatOrException(lang));
}
/** Write the graph to the output stream in the default serialization for the language.
@@ -1020,7 +1028,7 @@ public class RDFDataMgr
*/
@Deprecated
public static void write(Writer out, Graph graph, Lang lang) {
- write$(out, graph, RDFWriterRegistry.defaultSerialization(lang));
+ write$(out, graph, langToFormatOrException(lang));
}
/** Write the graph to the output stream in the default serialization for the language.
@@ -1077,7 +1085,7 @@ public class RDFDataMgr
* @param lang Language for the seralization.
*/
public static void write(StringWriter out, Dataset dataset, Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
write$(out, dataset.asDatasetGraph(), serialization);
}
@@ -1098,7 +1106,7 @@ public class RDFDataMgr
* @param lang Language for the seralization.
*/
public static void write(OutputStream out, DatasetGraph dataset, Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
write(out, dataset, serialization);
}
@@ -1117,7 +1125,7 @@ public class RDFDataMgr
* @param lang Language for the seralization.
*/
public static void write(StringWriter out, DatasetGraph dataset, Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
write(out, dataset, serialization);
}
@@ -1162,7 +1170,7 @@ public class RDFDataMgr
* @return WriterGraphRIOT
*/
public static WriterGraphRIOT createGraphWriter(Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
return createGraphWriter$(serialization);
}
@@ -1179,7 +1187,7 @@ public class RDFDataMgr
* @return WriterGraphRIOT
*/
public static WriterDatasetRIOT createDatasetWriter(Lang lang) {
- RDFFormat serialization = RDFWriterRegistry.defaultSerialization(lang);
+ RDFFormat serialization = langToFormatOrException(lang);
return createDatasetWriter$(serialization);
}