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 2012/04/30 15:27:13 UTC
svn commit: r1332191 - in /incubator/jena/Jena2/ARQ/trunk/src:
main/java/com/hp/hpl/jena/sparql/util/ main/java/org/openjena/riot/out/
test/java/org/openjena/riot/out/
Author: andy
Date: Mon Apr 30 13:27:12 2012
New Revision: 1332191
URL: http://svn.apache.org/viewvc?rev=1332191&view=rev
Log:
Fix bug: Don't output "False" (bare word) as the lexical form of an XSD boolean if that was the original lexical form -- the legal lexical forms are "false", "true", "0" and "1" only so using "False"^^xsd:boolean is not a valid literal.
Modified:
incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/NodeFormatterTTL.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/OutputLangUtils.java
incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestNodeFmt.java
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java?rev=1332191&r1=1332190&r2=1332191&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/util/FmtUtils.java Mon Apr 30 13:27:12 2012
@@ -270,8 +270,13 @@ public class FmtUtils
if ( datatype.equals(XSD.xboolean.getURI()) )
{
- if ( s.equalsIgnoreCase("true") ) return s ;
- if ( s.equalsIgnoreCase("false") ) return s ;
+ // Pragmatics: if the data wrote "1"^^xsd:boolean, keep that form.
+ // The lexical form must be lower case.
+// if ( s.equals("true") || s.equals("1") ) return s ;
+// if ( s.equals("false") || s.equals("0") ) return s ;
+ if ( s.equals("true") ) return s ;
+ if ( s.equals("false") ) return s ;
+
}
// Not a recognized form.
}
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/NodeFormatterTTL.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/NodeFormatterTTL.java?rev=1332191&r1=1332190&r2=1332191&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/NodeFormatterTTL.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/NodeFormatterTTL.java Mon Apr 30 13:27:12 2012
@@ -215,14 +215,15 @@ public class NodeFormatterTTL extends No
return -1 ;
}
+ private static final String dtDecimal = XSDDatatype.XSDdecimal.getURI() ;
+ private static final String dtInteger = XSDDatatype.XSDinteger.getURI() ;
+ private static final String dtDouble = XSDDatatype.XSDdouble.getURI() ;
+ private static final String dtBoolean = XSDDatatype.XSDboolean.getURI() ;
+
@Override
public void formatLitDT(Writer w, String lex, String datatypeURI)
{
try {
- String dtDecimal = XSDDatatype.XSDdecimal.getURI() ;
- String dtInteger = XSDDatatype.XSDinteger.getURI() ;
- String dtDouble = XSDDatatype.XSDdouble.getURI() ;
-
if ( dtDecimal.equals(datatypeURI) )
{
if ( validDecimal(lex) )
@@ -247,6 +248,16 @@ public class NodeFormatterTTL extends No
return ;
}
}
+ // Boolean
+ if ( dtBoolean.equals(datatypeURI) )
+ {
+ // We leave "0" and "1" as-is assumign that if written like that, there was a reason.
+ if ( lex.equals("true") || lex.equals("false") )
+ {
+ w.write(lex) ;
+ return ;
+ }
+ }
} catch (IOException ex) { IO.exception(ex) ; }
super.formatLitDT(w, lex, datatypeURI) ;
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/OutputLangUtils.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/OutputLangUtils.java?rev=1332191&r1=1332190&r2=1332191&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/OutputLangUtils.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/OutputLangUtils.java Mon Apr 30 13:27:12 2012
@@ -45,7 +45,7 @@ public class OutputLangUtils
// "Prologue" is an input concept - whats the equivalent for output?
// Prefix mapping + base URI abbreviation.
- // TODO Use NodeFmtLib (objectified) in output(Writer, node,*)
+ // TODO Use NodeFormatters / NodeFmtLib (objectified) in output(Writer, node,*)
// Make an object so it can have per-instance flags
// ASCII vs UTF-8
Modified: incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestNodeFmt.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestNodeFmt.java?rev=1332191&r1=1332190&r2=1332191&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestNodeFmt.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/riot/out/TestNodeFmt.java Mon Apr 30 13:27:12 2012
@@ -140,4 +140,16 @@ public class TestNodeFmt extends BaseTes
@Test public void nodefmt_ttl_60() { test(nodeFormatterTTL, "'-123.e-10'^^<http://www.w3.org/2001/XMLSchema#double>", "-123.e-10") ; }
@Test public void nodefmt_ttl_61() { test(nodeFormatterTTL, "'.1e-10'^^<http://www.w3.org/2001/XMLSchema#double>", ".1e-10") ; }
@Test public void nodefmt_ttl_62() { test(nodeFormatterTTL, "'.e9'^^<http://www.w3.org/2001/XMLSchema#double>", "\".e9\"^^<http://www.w3.org/2001/XMLSchema#double>") ; }
+
+ // Booleans
+ @Test public void nodefmt_ttl_70() { test(nodeFormatterTTL, "'true'^^<http://www.w3.org/2001/XMLSchema#boolean>", "true") ; }
+ @Test public void nodefmt_ttl_71() { test(nodeFormatterTTL, "'1'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"1\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
+
+ @Test public void nodefmt_ttl_72() { test(nodeFormatterTTL, "'false'^^<http://www.w3.org/2001/XMLSchema#boolean>", "false") ; }
+ @Test public void nodefmt_ttl_73() { test(nodeFormatterTTL, "'0'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"0\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
+
+ // Illegal lexical form.
+ @Test public void nodefmt_ttl_74() { test(nodeFormatterTTL, "'False'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"False\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
+ @Test public void nodefmt_ttl_75() { test(nodeFormatterTTL, "'True'^^<http://www.w3.org/2001/XMLSchema#boolean>", "\"True\"^^<http://www.w3.org/2001/XMLSchema#boolean>") ; }
+
}