jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1544549 - in /jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki: server/ validation/ validation2/
Date Fri, 22 Nov 2013 14:22:29 GMT
Author: andy
Date: Fri Nov 22 14:22:29 2013
New Revision: 1544549

URL: http://svn.apache.org/r1544549
Log:
More validators

Added:
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/DataValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/IRIValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/UpdateValidator.java
Removed:
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/DataValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/IRIValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/UpdateValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/ValidatorBase.java
Modified:
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/QueryValidator.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/ValidatorBaseJson.java

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java?rev=1544549&r1=1544548&r2=1544549&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
Fri Nov 22 14:22:29 2013
@@ -34,10 +34,10 @@ import org.apache.jena.fuseki.mgt.Action
 import org.apache.jena.fuseki.mgt.MgtFunctions ;
 import org.apache.jena.fuseki.mgt.PageNames ;
 import org.apache.jena.fuseki.servlets.* ;
-import org.apache.jena.fuseki.validation.DataValidator ;
-import org.apache.jena.fuseki.validation.IRIValidator ;
+import org.apache.jena.fuseki.validation2.DataValidator ;
+import org.apache.jena.fuseki.validation2.IRIValidator ;
 import org.apache.jena.fuseki.validation2.QueryValidator ;
-import org.apache.jena.fuseki.validation.UpdateValidator ;
+import org.apache.jena.fuseki.validation2.UpdateValidator ;
 import org.apache.jena.riot.WebContent ;
 import org.eclipse.jetty.http.MimeTypes ;
 import org.eclipse.jetty.security.* ;
@@ -262,6 +262,7 @@ public class SPARQLServer {
             // Validators
             HttpServlet validateQuery = new QueryValidator() ;
             HttpServlet validateUpdate = new UpdateValidator() ;
+            
             HttpServlet validateData = new DataValidator() ;
             HttpServlet validateIRI = new IRIValidator() ;
 

Added: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/DataValidator.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/DataValidator.java?rev=1544549&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/DataValidator.java
(added)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/DataValidator.java
Fri Nov 22 14:22:29 2013
@@ -0,0 +1,130 @@
+/**
+ * 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.apache.jena.fuseki.validation2;
+
+import static org.apache.jena.riot.SysRIOT.fmtMessage ;
+
+import java.io.StringReader ;
+import java.util.ArrayList ;
+import java.util.List ;
+
+import org.apache.jena.atlas.json.JsonBuilder ;
+import org.apache.jena.atlas.json.JsonObject ;
+import org.apache.jena.riot.* ;
+import org.apache.jena.riot.system.ErrorHandler ;
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
+
+public class DataValidator extends ValidatorBaseJson {
+    public DataValidator() { }
+  
+    static final String jInput           = "input" ;
+
+    static final String paramFormat           = "outputFormat" ;
+    static final String paramIndirection      = "url" ;
+    static final String paramData             = "data" ;
+    static final String paramSyntax           = "languageSyntax" ;
+    @Override
+    protected JsonObject execute(ValidationAction action) {
+        JsonBuilder obj = new JsonBuilder() ;
+        obj.startObject() ;
+        
+        
+        String syntax = getArgOrNull(action, paramSyntax) ;
+        if ( syntax == null || syntax.equals("") )
+            syntax = RDFLanguages.NQUADS.getName() ;
+
+        Lang language = RDFLanguages.shortnameToLang(syntax) ;
+        if ( language == null ) {
+            errorBadRequest("Unknown syntax: " + syntax) ;
+            return null ;
+        }
+
+        String string = getArg(action, paramData) ;
+        StringReader sr = new StringReader(string) ;
+        obj.key(jInput).value(string) ;
+        StreamRDF dest = StreamRDFLib.sinkNull() ;
+        
+        try {
+            // Set error handler!
+            RDFDataMgr.parse(dest, sr, null, language) ;
+        } catch (RiotParseException ex) {
+            obj.key(jErrors) ;
+
+            obj.startArray() ;      // Errors array
+            obj.startObject() ;
+            obj.key(jParseError).value(ex.getMessage()) ;
+            obj.key(jParseErrorLine).value(ex.getLine()) ;
+            obj.key(jParseErrorCol).value(ex.getCol()) ;
+            obj.finishObject() ;
+            obj.finishArray() ;
+            
+            obj.finishObject() ; // Outer object
+            return obj.build().getAsObject() ;
+        } catch (RiotException ex) {
+            obj.key(jErrors) ;
+
+            obj.startArray() ;      // Errors array
+            obj.startObject() ;
+            obj.key(jParseError).value(ex.getMessage()) ;
+            obj.finishObject() ;
+            obj.finishArray() ;
+            
+            obj.finishObject() ; // Outer object
+            return obj.build().getAsObject() ;
+        }
+
+        
+        obj.finishObject() ;
+        return obj.build().getAsObject() ;
+    }
+    @Override
+    protected String validatorName() {
+        return "RDF Data" ;
+    }
+    
+    // Error handler that records messages
+    private static class ErrorHandlerMsg implements ErrorHandler
+    {
+        private List<String> messages = new ArrayList<String>() ;
+
+        ErrorHandlerMsg(List<String> messages) { this.messages = messages; }
+        
+        @Override
+        public void warning(String message, long line, long col)
+        { output(message, line, col, "Warning", "warning") ; }
+    
+        // Attempt to continue.
+        @Override
+        public void error(String message, long line, long col)
+        { output(message, line, col, "Error", "error") ; }
+    
+        @Override
+        public void fatal(String message, long line, long col)
+        { output(message, line, col, "Fatal", "error") ; throw new RiotException(fmtMessage(message,
line, col)) ; }
+        
+        private void output(String message, long line, long col, String typeName, String
className)
+        {
+            String str = fmtMessage(message, line, col) ;
+            messages.add(str) ;
+        }
+    }
+
+}
+

Added: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/IRIValidator.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/IRIValidator.java?rev=1544549&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/IRIValidator.java
(added)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/IRIValidator.java
Fri Nov 22 14:22:29 2013
@@ -0,0 +1,167 @@
+/**
+ * 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.apache.jena.fuseki.validation2;
+
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.atlas.json.JsonBuilder ;
+import org.apache.jena.atlas.json.JsonObject ;
+import org.apache.jena.iri.IRI ;
+import org.apache.jena.iri.IRIFactory ;
+import org.apache.jena.iri.Violation ;
+import org.apache.jena.riot.system.IRIResolver ;
+
+public class IRIValidator extends ValidatorBaseJson {
+    public IRIValidator() { }
+    
+    static IRIFactory iriFactory = IRIResolver.iriFactory ;
+    
+    static final String paramIRI           = "iri" ;
+
+    // Output is an object  { "iris" : [ ] }
+    // { "iri": "" , "error": [], "warnings": [] }
+    static final String jIRIs    = "iris" ;
+    static final String jIRI     = "iri" ;
+
+    @Override
+    protected JsonObject execute(ValidationAction action) {
+        JsonBuilder obj = new JsonBuilder() ;
+        obj.startObject() ;
+        
+        String args[] = getArgs(action, paramIRI) ;
+        if ( args.length == 0 )
+            errorBadRequest("No IRIs supplied");
+        
+        obj.key(jIRIs) ;
+        obj.startArray() ;
+        
+        for ( String iriStr : args )
+        {
+            obj.startObject() ;
+            obj.key(jIRI).value(iriStr) ;
+
+            IRI iri = iriFactory.create(iriStr) ;
+
+
+            List<String> errors = new ArrayList<String>() ;
+            List<String> warnings = new ArrayList<String>() ;
+
+            if ( iri.isRelative() )
+                warnings.add("Relative IRI: "+iriStr) ;
+
+            Iterator<Violation> vIter = iri.violations(true) ;
+            for ( ; vIter.hasNext() ; )
+            {
+                Violation v = vIter.next() ;
+                String str = v.getShortMessage() ;
+                if ( v.isError() )
+                    errors.add(str) ;
+                else
+                    warnings.add(str) ;
+            }
+            
+            obj.key(jErrors) ;
+            obj.startArray() ;
+            for ( String msg : errors )
+                obj.value(msg) ;
+            obj.finishArray() ;
+                
+            obj.key(jWarnings) ;
+            obj.startArray() ;
+            for ( String msg : warnings )
+                obj.value(msg) ;
+            obj.finishArray() ;
+
+            obj.finishObject() ;
+        }
+          
+        
+       obj.finishArray() ;
+        
+        obj.finishObject() ;
+        return obj.build().getAsObject() ;
+    }
+    @Override
+    protected String validatorName() {
+        return "RDF Data" ;
+    }
+}
+
+//static final String paramIRI      = "iri" ;
+////static IRIFactory iriFactory = IRIFactory.iriImplementation() ;
+//static IRIFactory iriFactory = IRIResolver.iriFactory ;
+//
+//@Override
+//protected void execute(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
+//{
+//    try {
+//        String[] args = httpRequest.getParameterValues(paramIRI) ;
+//        ServletOutputStream outStream = httpResponse.getOutputStream() ;
+//        PrintStream stdout = System.out ;
+//        PrintStream stderr = System.err ;
+//        System.setOut(new PrintStream(outStream)) ;
+//        System.setErr(new PrintStream(outStream)) ;
+//
+//        setHeaders(httpResponse) ;
+//
+//        outStream.println("<html>") ;
+//        printHead(outStream, "Jena IRI Validator Report") ;
+//        outStream.println("<body>") ;
+//
+//        outStream.println("<h1>IRI Report</h1>") ;
+//
+//        startFixed(outStream) ;
+//
+//        try {
+//            boolean first = true ;
+//            for ( String iriStr : args )
+//            {
+//                if ( ! first )
+//                    System.out.println() ;
+//                first = false ;
+//
+//                IRI iri = iriFactory.create(iriStr) ;
+//                System.out.println(iriStr + " ==> "+iri) ;
+//                if ( iri.isRelative() )
+//                    System.out.println("Relative IRI: "+iriStr) ;
+//
+//                Iterator<Violation> vIter = iri.violations(true) ;
+//                for ( ; vIter.hasNext() ; )
+//                {
+//                    String str = vIter.next().getShortMessage() ;
+//                    str = htmlQuote(str) ;
+//                    
+//                    System.out.println(str) ;
+//                }
+//            }
+//        } finally 
+//        {
+//            finishFixed(outStream) ;
+//            System.out.flush() ;
+//            System.err.flush() ;
+//            System.setOut(stdout) ;
+//            System.setErr(stdout) ;
+//        }
+//
+//        outStream.println("</body>") ;
+//        outStream.println("</html>") ;
+//    } catch (IOException ex) {}
+//} 

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/QueryValidator.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/QueryValidator.java?rev=1544549&r1=1544548&r2=1544549&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/QueryValidator.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/QueryValidator.java
Fri Nov 22 14:22:29 2013
@@ -49,11 +49,6 @@ public class QueryValidator extends Vali
     static final String jAlgebraOpt      = "algebra-opt" ;
     static final String jAlgebraOptQuads = "algebra-opt-quads" ;
 
-    static final String jErrors          = "errors" ;
-    static final String jParseError      = "parse-error" ;
-    static final String jParseErrorLine  = "parse-error-line" ;
-    static final String jParseErrorCol   = "parse-error-column" ;
-
     @Override
     protected JsonObject execute(ValidationAction action) {
         JsonBuilder obj = new JsonBuilder() ;

Added: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/UpdateValidator.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/UpdateValidator.java?rev=1544549&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/UpdateValidator.java
(added)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/UpdateValidator.java
Fri Nov 22 14:22:29 2013
@@ -0,0 +1,90 @@
+/**
+ * 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.apache.jena.fuseki.validation2;
+
+import org.apache.jena.atlas.io.IndentedLineBuffer ;
+import org.apache.jena.atlas.json.JsonBuilder ;
+import org.apache.jena.atlas.json.JsonObject ;
+
+import com.hp.hpl.jena.query.QueryParseException ;
+import com.hp.hpl.jena.query.Syntax ;
+import com.hp.hpl.jena.update.UpdateFactory ;
+import com.hp.hpl.jena.update.UpdateRequest ;
+
+public class UpdateValidator extends ValidatorBaseJson {
+    public UpdateValidator() {}
+    
+    static final String paramUpdate           = "update" ;
+    static final String paramSyntax           = "languageSyntax" ;
+    
+    static final String jInput           = "input" ;
+    static final String jFormatted       = "formatted" ;
+
+    @Override
+    protected JsonObject execute(ValidationAction action) {
+        JsonBuilder obj = new JsonBuilder() ;
+        obj.startObject() ;
+        
+        final String updateString = getArg(action, paramUpdate) ;
+        String updateSyntax = getArgOrNull(action, paramSyntax) ;
+        if ( updateSyntax == null || updateSyntax.equals("") )
+            updateSyntax = "SPARQL" ;
+        
+        Syntax language = Syntax.lookup(updateSyntax) ;
+        if ( language == null ) {
+            errorBadRequest("Unknown syntax: " + updateSyntax) ;
+            return null ;
+        }
+        
+        obj.key(jInput).value(updateString) ;
+        UpdateRequest request = null ;
+        try {
+            request = UpdateFactory.create(updateString, "http://example/base/", language)
;
+        } catch (QueryParseException ex) {
+            obj.key(jErrors) ;
+            obj.startArray() ;      // Errors array
+            obj.startObject() ;
+            obj.key(jParseError).value(ex.getMessage()) ;
+            obj.key(jParseErrorLine).value(ex.getLine()) ;
+            obj.key(jParseErrorCol).value(ex.getColumn()) ;
+            obj.finishObject() ;
+            obj.finishArray() ;
+            
+            obj.finishObject() ; // Outer object
+            return obj.build().getAsObject() ;
+        }
+        
+        formatted(obj, request) ;
+        
+        obj.finishObject() ;
+        return obj.build().getAsObject() ;
+    }
+
+    private void formatted(JsonBuilder obj, UpdateRequest updateRequest) {
+        IndentedLineBuffer out = new IndentedLineBuffer() ;
+        updateRequest.output(out) ;
+        obj.key(jFormatted).value(out.asString()) ;
+    }
+    
+    @Override
+    protected String validatorName() {
+        return "SPARQL Update" ;
+    }
+}
+

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/ValidatorBaseJson.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/ValidatorBaseJson.java?rev=1544549&r1=1544548&r2=1544549&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/ValidatorBaseJson.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation2/ValidatorBaseJson.java
Fri Nov 22 14:22:29 2013
@@ -42,6 +42,13 @@ import com.hp.hpl.jena.sparql.util.Conte
 /** ValidationBase for JSON out */ 
 public abstract class ValidatorBaseJson extends ServletBase
 {
+    public static final String jErrors          = "errors" ;
+    public static final String jWarnings        = "warning" ;
+
+    public static final String jParseError      = "parse-error" ;
+    public static final String jParseErrorLine  = "parse-error-line" ;
+    public static final String jParseErrorCol   = "parse-error-column" ;
+
     protected static Logger serviceLog = Fuseki.requestLog ;
     public static final String respService      = "X-Service" ;
     
@@ -80,7 +87,6 @@ public abstract class ValidatorBaseJson 
                 responseSendError(response, ex.rc, ex.message) ;
             else
                 responseSendError(response, ex.rc) ;
-            //(null, string, statusCode) ;
         } catch (Throwable th) {
             responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, "Internal Error")
;
         }



Mime
View raw message