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 2011/08/29 16:03:05 UTC
svn commit: r1162821 - in /incubator/jena/Jena2/ARQ/trunk: src-dev/dev/
src-test/org/openjena/riot/out/ src/org/openjena/riot/out/
Author: andy
Date: Mon Aug 29 14:03:05 2011
New Revision: 1162821
URL: http://svn.apache.org/viewvc?rev=1162821&view=rev
Log:
Node formatting output -- write to a writer, avoid string intermediaries
Added:
incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java (with props)
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java (with props)
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java (with props)
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java (with props)
Modified:
incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestOutput.java
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterBase.java
incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/SinkTripleOutput.java
Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java?rev=1162821&r1=1162820&r2=1162821&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java Mon Aug 29 14:03:05 2011
@@ -9,44 +9,28 @@
package dev;
import java.io.FileInputStream ;
-import java.io.IOException ;
import java.io.InputStream ;
-import java.io.OutputStream ;
-import java.net.URLEncoder ;
-import java.util.ArrayList ;
-import java.util.HashMap ;
import java.util.Iterator ;
-import java.util.List ;
-import java.util.Map ;
import java.util.NoSuchElementException ;
import java.util.concurrent.ArrayBlockingQueue ;
import java.util.concurrent.BlockingQueue ;
import java.util.concurrent.ExecutorService ;
import java.util.concurrent.Executors ;
-import org.apache.http.HttpResponse ;
import org.openjena.atlas.io.IndentedWriter ;
-import org.openjena.atlas.iterator.Iter ;
import org.openjena.atlas.json.JSON ;
import org.openjena.atlas.json.JsonValue ;
import org.openjena.atlas.lib.Lib ;
import org.openjena.atlas.lib.Sink ;
import org.openjena.atlas.lib.StrUtils ;
import org.openjena.atlas.logging.Log ;
-import org.openjena.atlas.web.MediaType ;
import org.openjena.riot.ErrorHandlerFactory ;
import org.openjena.riot.RiotReader ;
-import org.openjena.riot.WebContent ;
import org.openjena.riot.checker.CheckerIRI ;
import org.openjena.riot.pipeline.normalize.CanonicalizeLiteral ;
import org.openjena.riot.tokens.Token ;
import org.openjena.riot.tokens.Tokenizer ;
import org.openjena.riot.tokens.TokenizerFactory ;
-import org.openjena.riot.web.ContentProducer ;
-import org.openjena.riot.web.HttpCaptureResponse ;
-import org.openjena.riot.web.HttpOp ;
-import org.openjena.riot.web.HttpResponseHandler ;
-import org.openjena.riot.web.HttpResponseLib ;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
import com.hp.hpl.jena.datatypes.xsd.XSDDuration ;
@@ -63,7 +47,6 @@ import com.hp.hpl.jena.query.QueryExecut
import com.hp.hpl.jena.query.QueryFactory ;
import com.hp.hpl.jena.query.QuerySolutionMap ;
import com.hp.hpl.jena.query.ResultSet ;
-import com.hp.hpl.jena.query.ResultSetFactory ;
import com.hp.hpl.jena.query.ResultSetFormatter ;
import com.hp.hpl.jena.rdf.model.AnonId ;
import com.hp.hpl.jena.rdf.model.Model ;
@@ -90,7 +73,6 @@ import com.hp.hpl.jena.sparql.function.F
import com.hp.hpl.jena.sparql.function.FunctionEnvBase ;
import com.hp.hpl.jena.sparql.function.FunctionRegistry ;
import com.hp.hpl.jena.sparql.graph.NodeTransform ;
-import com.hp.hpl.jena.sparql.resultset.ResultsFormat ;
import com.hp.hpl.jena.sparql.sse.SSE ;
import com.hp.hpl.jena.sparql.util.ExprUtils ;
import com.hp.hpl.jena.sparql.util.FmtUtils ;
Added: incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java?rev=1162821&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java Mon Aug 29 14:03:05 2011
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openjena.riot.out;
+
+import java.io.StringWriter ;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.riot.system.PrefixMap ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.util.NodeFactory ;
+
+public class TestNodeFmt extends BaseTest
+{
+ private static String base = "http://example/base" ;
+ private static PrefixMap prefixMap = new PrefixMap() ;
+ static {
+ prefixMap.add(":", "http://example/p") ;
+ prefixMap.add("ex", "http://example/ex/") ;
+ }
+ private static NodeFormatter nodeFormatterNT = new NodeFormatterNT() ;
+ private static NodeFormatter nodeFormatterTTL = new NodeFormatterTTL(base, prefixMap) ;
+
+ public static void test(NodeFormatter nodeFormatter, String str)
+ {
+ test(nodeFormatter, str, str) ;
+ }
+
+ public static void test(NodeFormatter nodeFormatter, String nStr , String str)
+ {
+ Node n = NodeFactory.parseNode(nStr) ;
+ test(nodeFormatter, n, str) ;
+ }
+
+ public static void test(NodeFormatter nodeFormatter, Node n , String str)
+ {
+ StringWriter sw = new StringWriter() ;
+ nodeFormatter.format(sw, n) ;
+ String str2 = sw.toString() ;
+ assertEquals(str, str2) ;
+ }
+
+ @Test public void nodefmt_nt_01() { test(nodeFormatterNT, "?x") ; }
+ @Test public void nodefmt_nt_02() { test(nodeFormatterNT, "?xyz") ; }
+ @Test public void nodefmt_nt_03() { test(nodeFormatterNT, Var.alloc(""), "?") ; }
+ @Test public void nodefmt_nt_04() { test(nodeFormatterNT, Var.alloc("?"), "??") ; }
+
+ @Test public void nodefmt_nt_05() { test(nodeFormatterNT, "\"abc\"") ; }
+ @Test public void nodefmt_nt_06() { test(nodeFormatterNT, "\"\"") ; }
+ @Test public void nodefmt_nt_07() { test(nodeFormatterNT, "\"abc\"@en") ; }
+ @Test public void nodefmt_nt_08() { test(nodeFormatterNT, "\"123\"^^<http://www.w3.org/2001/XMLSchema#integer>" ) ; }
+ @Test public void nodefmt_nt_09() { test(nodeFormatterNT, Node.ANY, "ANY") ; }
+
+ @Test public void nodefmt_ttl_01() { test(nodeFormatterTTL, "?x") ; }
+ @Test public void nodefmt_ttl_02() { test(nodeFormatterTTL, "?xyz") ; }
+ @Test public void nodefmt_ttl_03() { test(nodeFormatterTTL, Var.alloc(""), "?") ; }
+ @Test public void nodefmt_ttl_04() { test(nodeFormatterTTL, Var.alloc("?"), "??") ; }
+
+ @Test public void nodefmt_ttl_05() { test(nodeFormatterTTL, "\"abc\"") ; }
+ @Test public void nodefmt_ttl_06() { test(nodeFormatterTTL, "\"\"") ; }
+ @Test public void nodefmt_ttl_07() { test(nodeFormatterTTL, "\"abc\"@en") ; }
+ @Test public void nodefmt_ttl_08() { test(nodeFormatterTTL, Node.ANY, "ANY") ; }
+
+ @Test public void nodefmt_ttl_11() { test(nodeFormatterTTL, "<http://example.org/resources>") ; } // No match
+ @Test public void nodefmt_ttl_12() { test(nodeFormatterTTL, "<http://example/ex/>", "ex:") ; }
+ @Test public void nodefmt_ttl_13() { test(nodeFormatterTTL, "<http://example/ex/abc>", "ex:abc") ; }
+ @Test public void nodefmt_ttl_14() { test(nodeFormatterTTL, "<http://example/ex/ab/c>", "<http://example/ex/ab/c>") ; }
+ @Test public void nodefmt_ttl_15() { test(nodeFormatterTTL, "<http://example/p>", ":") ; }
+ @Test public void nodefmt_ttl_16() { test(nodeFormatterTTL, "<http://example/p#a>", "<http://example/p#a>") ; }
+
+ @Test public void prefixedname_01() { testPrefix("", "") ; }
+
+ private void testPrefix(String prefix, String local)
+ {
+ assertTrue(NodeFormatterTTL.safeForPrefix(prefix)) ;
+ assertTrue(NodeFormatterTTL.safeForPrefixLocalname(local)) ;
+ }
+
+ // Turtle numbers
+ @Test public void nodefmt_ttl_30() { test(nodeFormatterTTL, "'123'^^<http://www.w3.org/2001/XMLSchema#integer>", "123") ; }
+ @Test public void nodefmt_ttl_31() { test(nodeFormatterTTL, "'123.0'^^<http://www.w3.org/2001/XMLSchema#integer>", "\"123.0\"^^<http://www.w3.org/2001/XMLSchema#integer>") ; }
+ @Test public void nodefmt_ttl_32() { test(nodeFormatterTTL, "''^^<http://www.w3.org/2001/XMLSchema#integer>", "\"\"^^<http://www.w3.org/2001/XMLSchema#integer>") ; }
+ @Test public void nodefmt_ttl_33() { test(nodeFormatterTTL, "'abc'^^<http://www.w3.org/2001/XMLSchema#integer>", "\"abc\"^^<http://www.w3.org/2001/XMLSchema#integer>") ; }
+ @Test public void nodefmt_ttl_34() { test(nodeFormatterTTL, "'+123'^^<http://www.w3.org/2001/XMLSchema#integer>", "+123") ; }
+ @Test public void nodefmt_ttl_35() { test(nodeFormatterTTL, "'-1'^^<http://www.w3.org/2001/XMLSchema#integer>", "-1") ; }
+
+ // Add .123 and 123.
+ @Test public void nodefmt_ttl_40() { test(nodeFormatterTTL, "'123'^^<http://www.w3.org/2001/XMLSchema#decimal>", "\"123\"^^<http://www.w3.org/2001/XMLSchema#decimal>") ; }
+ @Test public void nodefmt_ttl_41() { test(nodeFormatterTTL, "'123.0'^^<http://www.w3.org/2001/XMLSchema#decimal>", "123.0") ; }
+ @Test public void nodefmt_ttl_42() { test(nodeFormatterTTL, "''^^<http://www.w3.org/2001/XMLSchema#decimal>", "\"\"^^<http://www.w3.org/2001/XMLSchema#decimal>") ; }
+ @Test public void nodefmt_ttl_43() { test(nodeFormatterTTL, "'abc'^^<http://www.w3.org/2001/XMLSchema#decimal>", "\"abc\"^^<http://www.w3.org/2001/XMLSchema#decimal>") ; }
+ @Test public void nodefmt_ttl_44() { test(nodeFormatterTTL, "'+123.0'^^<http://www.w3.org/2001/XMLSchema#decimal>", "+123.0") ; }
+ @Test public void nodefmt_ttl_45() { test(nodeFormatterTTL, "'-1.0'^^<http://www.w3.org/2001/XMLSchema#decimal>", "-1.0") ; }
+ @Test public void nodefmt_ttl_46() { test(nodeFormatterTTL, "'.1'^^<http://www.w3.org/2001/XMLSchema#decimal>", ".1") ; }
+ @Test public void nodefmt_ttl_47() { test(nodeFormatterTTL, "'-.1'^^<http://www.w3.org/2001/XMLSchema#decimal>", "-.1") ; }
+ @Test public void nodefmt_ttl_48() { test(nodeFormatterTTL, "\"1.\"^^<http://www.w3.org/2001/XMLSchema#decimal>", "\"1.\"^^<http://www.w3.org/2001/XMLSchema#decimal>") ; }
+
+ // Doubles.
+ // Add .123 and 123.
+ @Test public void nodefmt_ttl_50() { test(nodeFormatterTTL, "'123'^^<http://www.w3.org/2001/XMLSchema#double>", "\"123\"^^<http://www.w3.org/2001/XMLSchema#double>") ; }
+ @Test public void nodefmt_ttl_51() { test(nodeFormatterTTL, "'123.0'^^<http://www.w3.org/2001/XMLSchema#double>", "\"123.0\"^^<http://www.w3.org/2001/XMLSchema#double>") ; }
+ @Test public void nodefmt_ttl_52() { test(nodeFormatterTTL, "'123.0e0'^^<http://www.w3.org/2001/XMLSchema#double>", "123.0e0") ; }
+ @Test public void nodefmt_ttl_53() { test(nodeFormatterTTL, "'123e0'^^<http://www.w3.org/2001/XMLSchema#double>", "123e0") ; }
+ @Test public void nodefmt_ttl_54() { test(nodeFormatterTTL, "'.1e0'^^<http://www.w3.org/2001/XMLSchema#double>", ".1e0") ; }
+
+ @Test public void nodefmt_ttl_55() { test(nodeFormatterTTL, "'123.0e+10'^^<http://www.w3.org/2001/XMLSchema#double>", "123.0e+10") ; }
+ @Test public void nodefmt_ttl_56() { test(nodeFormatterTTL, "'123.0e-10'^^<http://www.w3.org/2001/XMLSchema#double>", "123.0e-10") ; }
+
+ @Test public void nodefmt_ttl_57() { test(nodeFormatterTTL, "''^^<http://www.w3.org/2001/XMLSchema#double>", "\"\"^^<http://www.w3.org/2001/XMLSchema#double>") ; }
+ @Test public void nodefmt_ttl_58() { test(nodeFormatterTTL, "'+123.0e-10'^^<http://www.w3.org/2001/XMLSchema#double>", "+123.0e-10") ; }
+ @Test public void nodefmt_ttl_59() { test(nodeFormatterTTL, "'-123.0e-10'^^<http://www.w3.org/2001/XMLSchema#double>", "-123.0e-10") ; }
+}
+
Propchange: incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestNodeFmt.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestOutput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestOutput.java?rev=1162821&r1=1162820&r2=1162821&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestOutput.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-test/org/openjena/riot/out/TestOutput.java Mon Aug 29 14:03:05 2011
@@ -23,6 +23,7 @@ import com.hp.hpl.jena.sparql.util.NodeF
// Nodes, escapes, prefix mapping.
public class TestOutput extends BaseTest
{
+ public TestOutput() {}
static Prologue prologue = new Prologue() ;
static {
prologue.getPrefixMap().add("", "http://example/") ;
Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterBase.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterBase.java?rev=1162821&r1=1162820&r2=1162821&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterBase.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterBase.java Mon Aug 29 14:03:05 2011
@@ -6,14 +6,19 @@
package org.openjena.riot.out;
+import java.io.IOException ;
import java.io.Writer ;
+import org.openjena.atlas.io.IO ;
+
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
+/** Provide implementations of the operations of NodeFormatter in terms
+ * of core operations for each node type.
+ */
public abstract class NodeFormatterBase implements NodeFormatter
{
-
//@Override
public void format(Writer w, Node n)
{
@@ -25,6 +30,9 @@ public abstract class NodeFormatterBase
formatLiteral(w, n) ;
else if ( n.isVariable() )
formatVar(w, n) ;
+ else if ( Node.ANY.equals(n) )
+ try { w.write("ANY") ; }
+ catch (IOException ex) { IO.exception(ex) ; }
else
throw new ARQInternalErrorException("Unknow node type: "+n) ;
}
Added: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java?rev=1162821&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java Mon Aug 29 14:03:05 2011
@@ -0,0 +1,97 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openjena.riot.out;
+
+import java.io.IOException ;
+import java.io.Writer ;
+
+import org.openjena.atlas.io.IO ;
+
+public class NodeFormatterNT extends NodeFormatterBase
+{
+ // Formatting for NTriples
+ // Turtles extends this class to intercept forms it can do better.
+
+ public NodeFormatterNT() {}
+
+ //@Override
+ public void formatURI(Writer w, String uriStr)
+ {
+ try {
+ w.write('<') ;
+ w.write(uriStr) ;
+ w.write('>') ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+
+ //@Override
+ public void formatVar(Writer w, String name)
+ {
+ try {
+ w.write('?') ;
+ w.write(name) ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+
+ //@Override
+ public void formatBNode(Writer w, String label)
+ {
+ try {
+ w.write("_:") ;
+ String lab = NodeFmtLib.encodeBNodeLabel(label) ;
+ w.write(label) ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+
+ //@Override
+ public void formatLitString(Writer w, String lex)
+ {
+ try {
+ writeEscaped(w, lex) ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+
+ private void writeEscaped(Writer w,String lex) throws IOException
+ {
+ w.write('"') ;
+ w.write(lex) ; // DO BETTER
+ w.write('"') ;
+ }
+
+ //@Override
+ public void formatLitLang(Writer w, String lex, String langTag)
+ {
+ try {
+ writeEscaped(w, lex) ;
+ w.write('@') ;
+ w.write(langTag) ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+
+ //@Override
+ public void formatLitDT(Writer w, String lex, String datatypeURI)
+ {
+ try {
+ writeEscaped(w, lex) ;
+ w.write("^^") ;
+ formatURI(w, datatypeURI) ;
+ } catch (IOException ex) { IO.exception(ex) ; }
+ }
+}
+
Propchange: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterNT.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java?rev=1162821&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java Mon Aug 29 14:03:05 2011
@@ -0,0 +1,309 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openjena.riot.out;
+
+import java.io.IOException ;
+import java.io.Writer ;
+
+import org.openjena.atlas.io.IO ;
+import org.openjena.atlas.lib.Pair ;
+import org.openjena.riot.system.PrefixMap ;
+import org.openjena.riot.system.RiotChars ;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+
+public class NodeFormatterTTL extends NodeFormatterNT
+{
+ private final NodeToLabel nodeToLabel = NodeToLabel.createBNodeByLabelEncoded() ;
+ private final PrefixMap prefixMap ;
+ private final String baseIRI ;
+
+ public NodeFormatterTTL(String baseIRI , PrefixMap prefixMap) //OutputPolicy outputPolicy)
+ {
+ this.prefixMap = prefixMap ;
+ this.baseIRI = baseIRI ;
+ }
+
+ @Override
+ public void formatURI(Writer w, String uriStr)
+ {
+ try {
+ Pair<String, String> pName = prefixMap.abbrev(uriStr) ;
+ // Check if legal
+ if ( pName != null )
+ {
+ // Check legal - need to check legal, not for illegal.
+ String pref = pName.getLeft() ;
+ String ln = pName.getRight() ;
+ if ( safeForPrefix(pref) && safeForPrefixLocalname(ln) )
+ {
+ w.write(pName.getLeft()) ;
+ w.write(':') ;
+ w.write(pName.getRight()) ;
+ return ;
+ }
+ }
+ } catch (IOException ex) { IO.exception(ex) ; }
+ super.formatURI(w, uriStr) ;
+ }
+
+/*private-testing*/ static boolean safeForPrefix(String str)
+ {
+ int N = str.length() ;
+ if ( N == 0 ) return true ;
+ int idx = 0 ;
+ idx = skip1_PN_CHARS_BASE(str, idx) ;
+ if ( idx == -1 ) return false ;
+ idx = skipAny_PN_CHARS_or_DOT(str, idx) ;
+ if ( idx == -1 ) return false ;
+ if ( idx == N ) return true ;
+ idx = skip1_PN_CHARS(str, idx) ;
+ if ( idx == -1 ) return false ;
+ return ( idx == N ) ;
+ }
+
+// @Override
+// public void formatVar(Writer w, String name)
+
+// @Override
+// public void formatBNode(Writer w, String label)
+
+// @Override
+// public void formatLitString(Writer w, String lex)
+
+// @Override
+// public void formatLitLang(Writer w, String lex, String langTag)
+
+ /* PN_CHARS_BASE includes escapes.
+ *
+ * PN_CHARS_BASE ::= [A-Z] | [a-z] | [#00C0-#00D6] | [#00D8-#00F6] | [#00F8-#02FF] | [#0370-#037D] | [#037F-#1FFF]
+ * | [#200C-#200D] | [#2070-#218F] | [#2C00-#2FEF] | [#3001-#D7FF] | [#F900-#FDCF] | [#FDF0-#FFFD] | [#10000-#EFFFF]
+ * | UCHAR
+ * PN_CHARS_U ::= PN_CHARS_BASE | "_"
+ * PN_CHARS ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
+ * PN_PREFIX ::= PN_CHARS_BASE ( ( PN_CHARS | "." )* PN_CHARS )?
+ * PN_LOCAL ::= ( PN_CHARS_U | [0-9] ) ( ( PN_CHARS | "." )* PN_CHARS )?
+ */
+
+ /*private-testing*/ static boolean safeForPrefixLocalname(String str)
+ {
+ int N = str.length() ;
+ if ( N == 0 ) return true ;
+ int idx = 0 ;
+ idx = skip1_PN_CHARS_U_or_029(str, idx) ;
+ if ( idx == -1 ) return false ;
+ idx = skipAny_PN_CHARS_or_DOT(str, idx) ;
+ if ( idx == -1 ) return false ;
+ if ( idx == N ) return true ;
+ idx = skip1_PN_CHARS(str, idx) ;
+ return ( idx == N ) ;
+
+// int N = str.length();
+// if ( N == 0 )
+// return true ;
+// // Test first and last.
+// //char chFirst = str.charAt(0) ;
+// int startIdx = 0 ;
+//
+// char chLast = str.charAt(N-1) ;
+// if ( ! RiotChars.isA2ZN(chLast) &&
+// chLast != '_' )
+// return false ;
+// int lastIdx = N-2 ;
+//
+// for ( int i = startIdx ; i <= lastIdx ; i++ )
+// {
+// char ch = str.charAt(i) ;
+// if ( ! RiotChars.isA2ZN(ch) &&
+// ch != '_' &&
+// ch != '.' )
+// return false ;
+// }
+// return true ;
+ }
+
+ private static boolean is_PN_CHARS_BASE(int ch) { return RiotChars.isAlpha(ch) ; }
+ private static boolean is_PN_CHARS_U(int ch) { return is_PN_CHARS_BASE(ch) || ch == '_' ; }
+ private static boolean is_PN_CHARS(int ch) { return is_PN_CHARS_U(ch) || ch == '-' || RiotChars.isDigit(ch) || isCharsExtra(ch) ; }
+
+ public static boolean isCharsExtra(int ch)
+ {
+ return ch == '\u00B7' || RiotChars.range(ch, '\u0300', '\u036F') || RiotChars.range(ch, '\u203F', '\u2040') ;
+ }
+
+ private static int skip1_PN_CHARS_U_or_029(String str, int idx)
+ {
+ char ch = str.charAt(idx) ;
+ if ( is_PN_CHARS_U(ch) ) return idx+1 ;
+ if ( RiotChars.isDigit(ch) ) return idx+1 ;
+ return -1 ;
+ }
+
+ private static int skip1_PN_CHARS_BASE(String str, int idx)
+ {
+ char ch = str.charAt(idx) ;
+ if ( is_PN_CHARS_BASE(ch) ) return idx+1 ;
+ return -1 ;
+ }
+
+ private static int skipAny_PN_CHARS_or_DOT(String str, int idx)
+ {
+ int N = str.length() ;
+ for ( int i = idx ; i < N ; i++ )
+ {
+ char ch = str.charAt(i) ;
+ if ( ! is_PN_CHARS(ch) && ch != '.' ) return i ;
+ }
+ return N ;
+ }
+
+ private static int skip1_PN_CHARS(String str, int idx)
+ {
+ char ch = str.charAt(idx) ;
+ if ( is_PN_CHARS(ch) ) return idx+1 ;
+ return -1 ;
+ }
+
+ @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) )
+ {
+ w.write(lex) ;
+ return ;
+ }
+ }
+ else if ( dtInteger.equals(datatypeURI) )
+ {
+ if ( validInteger(lex) )
+ {
+ w.write(lex) ;
+ return ;
+ }
+ }
+ if ( dtDouble.equals(datatypeURI) )
+ {
+ if ( validDouble(lex) )
+ {
+ w.write(lex) ;
+ return ;
+ }
+ }
+ } catch (IOException ex) { IO.exception(ex) ; }
+
+ super.formatLitDT(w, lex, datatypeURI) ;
+ }
+
+
+ private static boolean validInteger(String lex)
+ {
+ int N = lex.length() ;
+ if ( N == 0 ) return false ;
+ int idx = 0 ;
+
+ idx = skipSign(lex, idx) ;
+ idx = skipDigits(lex, idx) ;
+ return ( idx == N ) ;
+ }
+
+ private static boolean validDecimal(String lex)
+ {
+ // case : "." illegal.
+ int N = lex.length() ;
+ if ( N <= 1 ) return false ;
+ int idx = 0 ;
+
+ idx = skipSign(lex, idx) ;
+ idx = skipDigits(lex, idx) ; // Maybe none.
+
+ // DOT required.
+ if ( idx >= N ) return false ;
+
+ char ch = lex.charAt(idx) ;
+ if ( ch != '.' ) return false ;
+ idx++ ;
+ // Digit required.
+ if ( idx >= N ) return false ;
+ idx = skipDigits(lex, idx) ;
+ return ( idx == N ) ;
+ }
+
+ private static boolean validDouble(String lex)
+ {
+ int N = lex.length() ;
+ if ( N == 0 ) return false ;
+ int idx = 0 ;
+
+ idx = skipSign(lex, idx) ;
+ idx = skipDigits(lex, idx) ;
+ // Exponent required.
+ if ( idx >= N ) return false ;
+ char ch = lex.charAt(idx) ;
+ if ( ch == '.' )
+ {
+ idx++ ;
+ if ( idx >= N ) return false ;
+ idx = skipDigits(lex, idx) ;
+ if ( idx >= N ) return false ;
+ }
+ // "e" or "E"
+ ch = lex.charAt(idx) ;
+ if ( ch != 'e' && ch != 'E' ) return false ;
+ idx++ ;
+ if ( idx >= N ) return false ;
+ idx = skipSign(lex, idx) ;
+ if ( idx >= N ) return false ; // At least one digit.
+ idx = skipDigits(lex, idx) ;
+ return ( idx == N ) ;
+ }
+
+ /** Skip digits [0-9] and return the index just after the digits,
+ * which may be beyond the length of the string.
+ * May skip zero.
+ */
+ private static int skipDigits(String str, int start)
+ {
+ int N = str.length() ;
+ for ( int i = start ; i < N ; i++ )
+ {
+ char ch = str.charAt(i) ;
+ if ( ! RiotChars.isDigit(ch) )
+ return i ;
+ }
+ return N ;
+ }
+
+ /** Skip any plus or minus */
+ private static int skipSign(String str, int idx)
+ {
+ int N = str.length() ;
+ char ch = str.charAt(idx) ;
+ if ( ch == '+' || ch == '-' )
+ return idx + 1 ;
+ return idx ;
+ }
+}
+
Propchange: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java?rev=1162821&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java Mon Aug 29 14:03:05 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openjena.riot.out;
+
+import org.openjena.riot.system.PrefixMap ;
+
+public class OutputPolicy
+{
+ final NodeToLabel nodeToLabel ;
+ final PrefixMap prefixMap ;
+ final String baseIRI ;
+
+ public OutputPolicy(NodeToLabel nodeToLabel,
+ String baseIRI,
+ PrefixMap prefixMap)
+ {
+ this.nodeToLabel = nodeToLabel ;
+ this.baseIRI = baseIRI ;
+ this.prefixMap = prefixMap ;
+ }
+}
+
Propchange: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/OutputPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/SinkTripleOutput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/SinkTripleOutput.java?rev=1162821&r1=1162820&r2=1162821&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/SinkTripleOutput.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/SinkTripleOutput.java Mon Aug 29 14:03:05 2011
@@ -59,10 +59,6 @@ public class SinkTripleOutput implements
out.flush() ;
}
- private Node lastS = null ;
- private Node lastP = null ;
- private Node lastO = null ;
-
public void send(Triple triple)
{
Node s = triple.getSubject() ;