jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1359086 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer: FormatterElement.java QuerySerializer.java
Date Mon, 09 Jul 2012 11:54:56 GMT
Author: andy
Date: Mon Jul  9 11:54:55 2012
New Revision: 1359086

URL: http://svn.apache.org/viewvc?rev=1359086&view=rev
Log:
Fix formatting of VALUES clauses on output.

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java?rev=1359086&r1=1359085&r2=1359086&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/FormatterElement.java
Mon Jul  9 11:54:55 2012
@@ -30,12 +30,9 @@ import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.sparql.core.BasicPattern ;
 import com.hp.hpl.jena.sparql.core.PathBlock ;
 import com.hp.hpl.jena.sparql.core.TriplePath ;
-import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.engine.binding.Binding ;
 import com.hp.hpl.jena.sparql.expr.Expr ;
 import com.hp.hpl.jena.sparql.path.PathWriter ;
 import com.hp.hpl.jena.sparql.syntax.* ;
-import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
 
 public class FormatterElement extends FormatterBase
@@ -231,64 +228,7 @@ public class FormatterElement extends Fo
     @Override
     public void visit(ElementData el)
     {
-        // QuerySrializer.outputDataBlock.
-        
-        List<Var> variables = el.getVars() ;
-        out.print("VALUES ") ;
-        if ( variables.size() == 1 )
-        {
-            // Short form.
-            out.print("?") ;
-            out.print(variables.get(0).getVarName()) ;
-            out.print(" {") ;
-            out.incIndent() ;
-            for ( Binding valueRow : el.getRows() )
-            {
-                // A value may be null for UNDEF
-                for ( Var var : variables )
-                {
-                    out.print(" ") ;
-                    Node value = valueRow.get(var) ; 
-                    if ( value == null )
-                        out.print("UNDEF") ;
-                    else
-                        out.print(FmtUtils.stringForNode(value, context)) ;
-                }
-            }
-            out.decIndent() ;
-            out.print("}") ;
-            return ;
-        }
-        // Long form.
-        out.print("(") ;
-        for ( Var v : variables )
-        {
-            out.print(" ") ;
-            out.print(v) ;
-        }
-        out.print(" )") ;
-        out.print(" {") ;
-        out.incIndent() ;
-        for ( Binding valueRow : el.getRows() )
-        {
-            out.println() ;
-            // A value may be null for UNDEF
-            out.print("(") ;
-            for ( Var var : variables )
-            {
-                out.print(" ") ;
-                Node value = valueRow.get(var) ; 
-                if ( value == null )
-                    out.print("UNDEF") ;
-                else
-                    out.print(FmtUtils.stringForNode(value, context)) ;
-            }
-            out.print(" )") ;
-        }
-        out.decIndent() ;
-        out.ensureStartOfLine() ;
-        out.print("}") ;
-        
+        QuerySerializer.outputDataBlock(out, el.getVars(), el.getRows(), context.getPrologue())
;
     }
 
     @Override

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java?rev=1359086&r1=1359085&r2=1359086&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/serializer/QuerySerializer.java
Mon Jul  9 11:54:55 2012
@@ -259,25 +259,51 @@ public class QuerySerializer implements 
     {
         if ( query.hasValues() )
         {
-            out.print("VALUES") ;
             outputDataBlock(out, query.getValuesVariables(), query.getValuesData(), query)
;
+            out.newline() ;
         }
     }
 
-    private static void outputDataBlock(IndentedWriter out, List<Var> variables, List<Binding>
values, Query query)
+    public static void outputDataBlock(IndentedWriter out, List<Var> variables, List<Binding>
values, Prologue prologue)
     {
+        out.print("VALUES ") ;
+        if ( variables.size() == 1 )
+        {
+            // Short form.
+            out.print("?") ;
+            out.print(variables.get(0).getVarName()) ;
+            out.print(" {") ;
+            out.incIndent() ;
+            for ( Binding valueRow : values )
+            {
+                // A value may be null for UNDEF
+                for ( Var var : variables )
+                {
+                    out.print(" ") ;
+                    Node value = valueRow.get(var) ; 
+                    if ( value == null )
+                        out.print("UNDEF") ;
+                    else
+                        out.print(FmtUtils.stringForNode(value, prologue)) ;
+                }
+            }
+            out.decIndent() ;
+            out.print(" }") ;
+            return ;
+        }
+        // Long form.
+        out.print("(") ;
         for ( Var v : variables )
         {
             out.print(" ") ;
             out.print(v) ;
         }
-        out.println();
-
-        out.print("{") ;
+        out.print(" )") ;
+        out.print(" {") ;
         out.incIndent() ;
-        out.println() ;
         for ( Binding valueRow : values )
         {
+            out.println() ;
             // A value may be null for UNDEF
             out.print("(") ;
             for ( Var var : variables )
@@ -287,13 +313,13 @@ public class QuerySerializer implements 
                 if ( value == null )
                     out.print("UNDEF") ;
                 else
-                    out.print(FmtUtils.stringForNode(value, query)) ;
+                    out.print(FmtUtils.stringForNode(value, prologue)) ;
             }
-            out.println(" )") ;
+            out.print(" )") ;
         }
         out.decIndent() ;
+        out.ensureStartOfLine() ;
         out.print("}") ;
-        out.println() ;
     }
     
 



Mime
View raw message