[x3d-public] Follow up, ticket to expand conversion code into JSON validator (pure Java).

John Carlson yottzumm at gmail.com
Thu Feb 17 05:47:13 PST 2022


Here is the complete validation code and sample command line usages:

# Note: Git Bash command line inside Windows Terminal:

$ javac -cp .:/home/coderextreme/pythonSAI/X3DJSAIL.4.0.full.jar
Validate.java

$ find ../../../data -name '*.json' | xargs java -cp
.:/home/coderextreme/pythonSAI/X3DJSAIL.4.0.full.jar Validate |egrep
Exception

$ find /c/x3d-code/www.web3d.org/x3d/content/examples/ -name '*.json' |
xargs java -cp .:/home/coderextreme/pythonSAI/X3DJSAIL.4.0.full.jar
Validate |egrep -v '^Info|^Validating'

# or just run validate.sh to run both Ajv and Validate.java

$ bash validate.sh

Code follows.  Please integrate into an ant build.xml and I will copy to
x3dschema (or you may accept my invite to
https://github.com/coderextreme/x3dschema, or just look at build.xml there)
with the changes to the build.xml. I don't know how to properly pass
multiple files to a program. I am stuck right now.  If you need to review
X3DJSONLD.java, I understand. I see the below needs try/catch to continue
after an exception.  I will add that to x3dschema.

import org.w3c.dom.Document;
import javax.json.JsonObject;
import java.io.File;
import org.web3d.x3d.jsail.X3DLoaderDOM;
import org.web3d.x3d.jsail.Core.X3D;

public class Validate {
        public static void main(String [] args) throws Exception {
                for (int i = 0; i < args.length; i++) {
                        X3DJSONLD loader = new X3DJSONLD();
                        X3DLoaderDOM xmlLoader = new X3DLoaderDOM();

                        JsonObject jsobj = loader.readJsonFile(new
File(args[i]));
                        Document document =
loader.loadJsonIntoDocument(jsobj);

                        X3D X3D0 =
(X3D)xmlLoader.toX3dModelInstance(document);
                        System.out.println("Validating "+args[i]);
                        String validationResults = X3D0.validationReport();
                        if (validationResults.startsWith("\n")) {
                                System.out.println();

System.out.println(validationResults.trim());
                        }
                }
        }
}

On Thu, Feb 17, 2022 at 3:57 AM John Carlson <yottzumm at gmail.com> wrote:

> We don't need a JSON Schema validator to validate JSON documents when we
> have X3DJSONLD.java and X3DJSAIL:
>
> See:
>
> https://sourceforge.net/p/x3d/tickets/18/
>
> You may use the code with the Apache 2.0 license. I have already given you
> the rights to use X3DJSONLD.java, and you suggested that you would rename
> the file, which is OK!
>
> I'm not seeing other dependencies beyond JDK (JSON library?)
>
> So can we drop X3D JSON schema, except for X3DJSONLD website?
>
> Anyone skilled at creating Java validators (which all the Java examples
> that I know of in the X3D examples archives are) should be able to craft
> this code into a JSON validator.   I don't know how to do ant/build.xml
> that well.  I can help with the Java, but I would direct you do any Java
> example in the archive as an example of a validator, a snippet included
> below from Hello, World:
>
> 		X3DJSONLD loader = new X3DJSONLD();
> 		JsonObject jsobj = loader.readJsonFile(new File("examples/HelloWorldProgramOutput.json"));
> 		Document document = loader.loadJsonIntoDocument(jsobj);
> 		X3DLoaderDOM  xmlLoader = new X3DLoaderDOM();
> 		X3D X3D0 = (X3D)xmlLoader.toX3dModelInstance(document);
>
> 		String validationResults = X3D0.validationReport();
>                 if (validationResults.startsWith("\n")) {
>                         System.out.println();
> 			System.out.println(validationResults.trim());
> 		}
>
>
> I'm hopefully going to leave the rest of the details to you (passing command line args), but I will help as needed!
>
>
> No more bitching about "No JSON schema draft," please!
>
>
> John
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20220217/bbfedf83/attachment.html>


More information about the x3d-public mailing list