Search in sources :

Example 1 with InputStreamInput

use of org.whole.lang.xml.util.InputStreamInput in project whole by wholeplatform.

the class XsdRegistry method deploySchemaForSchema.

protected void deploySchemaForSchema() {
    String location = "XMLSchema.xsd";
    MappingStrategyRegistry.instance().putMappingModel(new SchemaMapping().create());
    // FIXME replace with real schema for schema model with annotations
    InputStream is = getClass().getResourceAsStream(location);
    Schema schemaForSchema = SchemaUtils.load(new InputStreamInput(is));
    putSchema(location, schemaForSchema, true);
}
Also used : InputStream(java.io.InputStream) SchemaMapping(org.whole.lang.xsd.codebase.SchemaMapping) Schema(org.whole.lang.xsd.model.Schema) InputStreamInput(org.whole.lang.xml.util.InputStreamInput)

Example 2 with InputStreamInput

use of org.whole.lang.xml.util.InputStreamInput in project whole by wholeplatform.

the class XsdRegistry method predeploySchemas.

protected void predeploySchemas(String... locations) {
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    args.wDefValue("predeployed", true);
    args.wDefValue("fileName", "");
    args.wDefValue("fileExtension", "");
    args.wDefValue("fileNameWithExtension", "");
    args.wDefValue("fileLocationURI", "");
    for (String location : locations) {
        String fileNameWithExtension = location.replaceFirst("^.*/", "");
        String filename = fileNameWithExtension.replaceFirst("\\.[^\\.]*$", "");
        args.wSetValue("fileName", filename);
        args.wSetValue("fileExtension", fileNameWithExtension.substring(filename.length() + 1));
        args.wSetValue("fileNameWithExtension", fileNameWithExtension);
        args.wSetValue("fileLocationURI", getClass().getResource(location).toExternalForm());
        InputStream is = getClass().getResourceAsStream(location);
        Schema schema = SchemaUtils.load(new InputStreamInput(is));
        InterpreterOperation.interpret(schema, args);
    }
}
Also used : InputStream(java.io.InputStream) Schema(org.whole.lang.xsd.model.Schema) IBindingManager(org.whole.lang.bindings.IBindingManager) InputStreamInput(org.whole.lang.xml.util.InputStreamInput)

Example 3 with InputStreamInput

use of org.whole.lang.xml.util.InputStreamInput in project whole by wholeplatform.

the class SchemaUtils method resolve.

// /* was LSInput, workaround for Android compatibility */
// private static InputStreamInput resolve(String namespaceURI, String schemaLocationURI, String folderLocation) {
// return resolve(namespaceURI, schemaLocationURI, folderLocation, null);
// }
/* was LSInput, workaround for Android compatibility */
private static InputStreamInput resolve(String namespaceURI, String schemaLocationURI, String folderLocation, /* was LSResourceResolver, workaround for Android compatibility */
ResourceResolver lsResourceResolver) {
    try {
        // try to resolve using provided LSResourceResolver
        URI schemaLocation = new URI(schemaLocationURI);
        URI folder = new File(folderLocation).toURI();
        if (lsResourceResolver != null) {
            /* was LSInput, workaround for Android compatibility */
            InputStreamInput lsInput = lsResourceResolver.resolveResource(NamespaceUtils.XSD_NAMESPACE_URI, namespaceURI, null, schemaLocationURI, schemaLocation.isAbsolute() ? null : folder.toASCIIString());
            if (lsInput != null)
                return lsInput;
        }
        // try to resolve directly using provided schemaLocation
        schemaLocation = folder.resolve(schemaLocation);
        URLConnection connection = schemaLocation.toURL().openConnection();
        InputStream is = connection.getInputStream();
        return new InputStreamInput(is);
    } catch (Exception e) {
    // fail silently
    }
    return null;
}
Also used : InputStream(java.io.InputStream) InputStreamInput(org.whole.lang.xml.util.InputStreamInput) URI(java.net.URI) File(java.io.File) URLConnection(java.net.URLConnection)

Aggregations

InputStream (java.io.InputStream)3 InputStreamInput (org.whole.lang.xml.util.InputStreamInput)3 Schema (org.whole.lang.xsd.model.Schema)2 File (java.io.File)1 URI (java.net.URI)1 URLConnection (java.net.URLConnection)1 IBindingManager (org.whole.lang.bindings.IBindingManager)1 SchemaMapping (org.whole.lang.xsd.codebase.SchemaMapping)1