public static SchemaDescription parseResource(final String resourcePath) throws SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl("system resource "+resourcePath); desc.path = resourcePath; desc.streamable = new InputStreamable() { @Override public InputStream openInputStream() { InputStream inputStream = SchemaRegistry.class.getClassLoader().getResourceAsStream(resourcePath); if (inputStream == null) { throw new IllegalStateException("Cannot fetch system resource for schema " + resourcePath); } return inputStream; } }; desc.parseFromInputStream(); return desc; }
public Source getSource() { Source source = null; if (canInputStream()) { InputStream inputStream = openInputStream(); // Return stream source as a first option. It is less effcient, // but it provides information about line numbers source = new StreamSource(inputStream); } else { source = new DOMSource(node); } source.setSystemId(path); return source; }
@Override public String debugDump() { return debugDump(0); }
public static SchemaDescription parseNode(Node node, String sourceDescription) throws SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl(sourceDescription); desc.node = node; desc.fetchBasicInfoFromSchema(); return desc; }
SchemaDescriptionImpl desc = new SchemaDescriptionImpl("schema #" + (number++) + " in system resource " + resourcePath); desc.node = schemaElement; desc.fetchBasicInfoFromSchema(); schemaDescriptions.add(desc); LOGGER.trace("Schema registered from {}", desc.getSourceDescription());
public InputStream openInputStream() { if (!canInputStream()) { throw new IllegalStateException("Schema "+sourceDescription+" cannot provide input stream"); } return streamable.openInputStream(); }
public SchemaDescription loadPrismSchemaDescription(InputStream input, String sourceDescription) throws SchemaException { SchemaDescription desc = SchemaDescriptionImpl.parseInputStream(input, sourceDescription); desc.setPrismSchema(true); registerSchemaDescription(desc); return desc; }
public SchemaDescription loadPrismSchemaFileDescription(File file) throws FileNotFoundException, SchemaException { if (!(file.getName().matches(".*\\.xsd$"))){ LOGGER.trace("Skipping registering {}, because it is not schema definition.", file.getAbsolutePath()); return null; } LOGGER.debug("Loading schema from file {}", file); SchemaDescription desc = SchemaDescriptionImpl.parseFile(file); desc.setPrismSchema(true); registerSchemaDescription(desc); return desc; }
private void parseFromInputStream() throws SchemaException { InputStream inputStream = streamable.openInputStream(); try { node = DOMUtil.parse(inputStream); } catch (IOException e) { throw new SchemaException("Cannot parse schema from " + sourceDescription, e); } fetchBasicInfoFromSchema(); }
private void fetchBasicInfoFromSchema() throws SchemaException { Element rootElement = getDomElement(); if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(DOMUtil.getQName(rootElement))) { String targetNamespace = DOMUtil.getAttribute(rootElement,DOMUtil.XSD_ATTR_TARGET_NAMESPACE); if (targetNamespace != null) { this.namespace = targetNamespace; } else { throw new SchemaException("Schema "+sourceDescription+" does not have targetNamespace attribute"); } } else { throw new SchemaException("Schema "+sourceDescription+" does not start with xsd:schema element"); } }
public static SchemaDescription parseInputStream(final InputStream input, String description) throws SchemaException { if (input == null) { throw new NullPointerException("Input stream must not be null"); } SchemaDescriptionImpl desc = new SchemaDescriptionImpl("inputStream " + description); desc.path = null; desc.streamable = () -> input; desc.parseFromInputStream(); return desc; }
public static SchemaDescription parseFile(final File file) throws FileNotFoundException, SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl("file "+file.getPath()); desc.path = file.getPath(); desc.streamable = new InputStreamable() { @Override public InputStream openInputStream() { InputStream inputStream; try { inputStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new IllegalStateException("Cannot fetch file for schema " + file,e); } return inputStream; } }; desc.parseFromInputStream(); return desc; }