org.citygml4j.xml.schema.SchemaHandler Java Examples

The following examples show how to use org.citygml4j.xml.schema.SchemaHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InterpretingSchema.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "parsing ADE schema file CityGML-SubsurfaceADE-0_9_0.xsd");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.parseSchema(new File("datasets/schemas/CityGML-SubsurfaceADE-0_9_0.xsd"));

	// using com.sun.xml.xsom.impl.util.SchemaWriter		
	// as the documentation of SchemaWriter says, SchemaWriter is not intended 
	// to be a fully-fledged round-trippable schema writer.
	System.out.println(df.format(new Date()) + "creating SchemaWriter instance to interpret ADE schema");
	Files.createDirectories(Paths.get("output"));

	SchemaWriter writer = new SchemaWriter(new PrintWriter(new File("output/CityGML-SubsurfaceADE-0_9_0.xml")));
	Schema schema = schemaHandler.getSchema("http://www.citygml.org/ade/sub/0.9.0");

	System.out.println(df.format(new Date()) + "writing ADE schema file CityGML-SubsurfaceADE-0_9_0.xml");
	writer.schema(schema.getXSSchema());
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #2
Source File: XMLElementChecker.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
XMLElementChecker(SchemaHandler schemaHandler, 
		FeatureReadMode featureReadMode, 
		boolean keepInlineAppearance,
		boolean parseSchema,
		boolean failOnMissingADESchema,
		List<QName> excludes,
		List<QName> featureProperties) {
	this.schemaHandler = schemaHandler;
	this.featureReadMode = featureReadMode;
	this.keepInlineAppearance = keepInlineAppearance;
	this.parseSchema = parseSchema;
	this.failOnMissingADESchema = failOnMissingADESchema;

	initExcludes(prepareNameList(excludes, true));		
	if (featureReadMode == FeatureReadMode.SPLIT_PER_COLLECTION_MEMBER)
		initCollectionSplitProperties(prepareNameList(featureProperties, false));
}
 
Example #3
Source File: JAXBInputFactory.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public JAXBInputFactory(CityGMLBuilder builder, SchemaHandler schemaHandler) {
	this.builder = builder;
	this.schemaHandler = schemaHandler;

	xmlInputFactory = XMLInputFactory.newInstance();
	xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);

	gmlIdManager = DefaultGMLIdManager.getInstance();
	validationEventHandler = null;
	featureReadMode = FeatureReadMode.NO_SPLIT;
	excludes = new ArrayList<>();
	splitAtFeatureProperties = new ArrayList<>();
	keepInlineAppearance = true;
	parseSchema = true;
	failOnMissingADESchema = true;
}
 
Example #4
Source File: CityGMLValidatorFactory.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeContext(Config config) throws ValidationException {
    try {
        SchemaHandler schemaHandler = SchemaHandler.newInstance();
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(schemaHandler.getSchemaSources());
        validator = schema.newValidator();
    } catch (SAXException e) {
        throw new ValidationException("Failed to create CityGML schema context.", e);
    }

    validationHandler = new ValidationErrorHandler(config);
}
 
Example #5
Source File: CityGMLBuilder.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public synchronized SchemaHandler getDefaultSchemaHandler() throws CityGMLBuilderException {
	if (schemaHandler == null) {
		try {
			schemaHandler = SchemaHandler.newInstance();
		} catch (SAXException e) {
			throw new CityGMLBuilderException("Failed to build default schema handler.", e);
		}
	}

	return schemaHandler;
}
 
Example #6
Source File: ValidationSchemaHandler.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public void setSchemaHandler(SchemaHandler schemaHandler) {
	if (schemaHandler == null)
		throw new IllegalArgumentException("schema handler may not be null.");

	this.schemaHandler = schemaHandler;
	size.set(-1);
}
 
Example #7
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBOutputFactory(CityGMLBuilder builder, ModuleContext moduleContext, SchemaHandler schemaHandler) {
	this.builder = builder;
	this.schemaHandler = schemaHandler;
	this.moduleContext = moduleContext;

	gmlIdManager = DefaultGMLIdManager.getInstance();
	featureWriteMode = FeatureWriteMode.NO_SPLIT;
	excludes = new HashSet<>();
	keepInlineAppearance = true;
	splitCopy = true;
}
 
Example #8
Source File: JAXBUnmarshaller.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public JAXBUnmarshaller(CityGMLBuilder builder, SchemaHandler schemaHandler) {
	this.builder = builder;
	this.schemaHandler = schemaHandler;

	citygml = new CityGMLUnmarshaller(this);
	gml = new GMLUnmarshaller(this);
	xal = new XALUnmarshaller();
	ade = new ADEUnmarshaller(this);

	try {
		dataTypeFactory = DatatypeFactory.newInstance();
	} catch (DatatypeConfigurationException e) {
		throw new RuntimeException("Failed to create DatatypeFactory.", e);
	}
}
 
Example #9
Source File: ObjectTreeValidation.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	// creating example (and simple) CityGML object tree
	System.out.println(df.format(new Date()) + "creating simple city model with invalid content");
	Building building = new Building();
	
	// set invalid gml:id
	building.setId("1st-Building");
	
	// set empty and thus invalid generic attribute set
	building.addGenericAttribute(new GenericAttributeSet());
	
	CityModel cityModel = new CityModel();
	cityModel.addCityObjectMember(new CityObjectMember(building));
	
	System.out.println(df.format(new Date()) + "creating citygml4j Validator and validating city model against CityGML 2.0.0");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	Validator validator = builder.createValidator(schemaHandler);
	
	validator.setValidationEventHandler(new ValidationEventHandler() {			
		public boolean handleEvent(ValidationEvent event) {
			System.out.println(event.getMessage());
			return true;
		}
	});		
	
	validator.validate(cityModel, CityGMLVersion.v2_0_0);
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #10
Source File: ReadingRemoteADE.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
static void checkADE(SchemaHandler schemaHandler, Element element, ElementDecl parent, int level) {		
	System.out.print(indent(level) + element.getLocalName());

	Schema schema = schemaHandler.getSchema(element.getNamespaceURI());
	ElementDecl decl = null;

	if (schema != null) {
		decl = schema.getElementDecl(element.getLocalName(), parent);
		if (decl != null) {

			if (decl.isCityObject())
				System.out.print(" [CITYOBJECT]");
			else if (decl.isFeature())
				System.out.print(" [FEATURE]");
			else if (decl.isGeometry())
				System.out.print(" [GEOMETRY]");
			else if (decl.isFeatureProperty())
				System.out.print(" [FEATURE_PROPERTY]");
			else if (decl.isGeometryProperty())
				System.out.print(" [GEOMETRY_PROPERTY]");

			XSType type = decl.getXSElementDecl().getType();
			System.out.println(": " + type.getName() + "{" + type.getTargetNamespace() + "}");
		}
	}

	parent = decl;

	NodeList children = element.getChildNodes();
	for (int i = 0; i < children.getLength(); i++) {
		Node child = children.item(i);
		if (child.getNodeType() == Node.ELEMENT_NODE)
			checkADE(schemaHandler, (Element)child, parent, level + 1);	
	}

	if (element.getFirstChild().getNodeType() == Node.TEXT_NODE)
		System.out.println(indent(level) + "--> " + element.getFirstChild().getNodeValue());
}
 
Example #11
Source File: ReadingLocalADE.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
static void checkADE(SchemaHandler schemaHandler, Element element, ElementDecl parent, int level) {		
	System.out.print(indent(level) + element.getLocalName());

	Schema schema = schemaHandler.getSchema(element.getNamespaceURI());
	ElementDecl decl = null;

	if (schema != null) {
		decl = schema.getElementDecl(element.getLocalName(), parent);
		if (decl != null) {

			if (decl.isCityObject())
				System.out.print(" [CITYOBJECT]");
			else if (decl.isFeature())
				System.out.print(" [FEATURE]");
			else if (decl.isGeometry())
				System.out.print(" [GEOMETRY]");
			else if (decl.isFeatureProperty())
				System.out.print(" [FEATURE_PROPERTY]");
			else if (decl.isGeometryProperty())
				System.out.print(" [GEOMETRY_PROPERTY]");

			XSType type = decl.getXSElementDecl().getType();
			System.out.println(": " + type.getName() + "{" + type.getTargetNamespace() + "}");
		}
	}

	parent = decl;

	NodeList children = element.getChildNodes();
	for (int i = 0; i < children.getLength(); i++) {
		Node child = children.item(i);
		if (child.getNodeType() == Node.ELEMENT_NODE)
			checkADE(schemaHandler, (Element)child, parent, level + 1);	
	}

	if (element.getFirstChild().getNodeType() == Node.TEXT_NODE)
		System.out.println(indent(level) + "--> " + element.getFirstChild().getNodeValue());
}
 
Example #12
Source File: WrongSchemaLocation.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();

	System.out.println(df.format(new Date()) + "setting up schema handler");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.setSchemaEntityResolver(new SchemaEntityResolver());
	schemaHandler.setErrorHandler(new SchemaParseErrorHandler());
	
	// register false schema location in order to provoke a schema parse error
	schemaHandler.registerSchemaLocation("http://www.citygml.org/ade/noise_de/2.0", 
			new File("/nowhere/nofile.xsd"));

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD0_Railway_NoiseADE_v200.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_v200.gml"));
	
	while (reader.hasNext()) {
		CityGML citygml = reader.nextFeature();
		
		if (citygml instanceof AbstractFeature)
			System.out.println("Found CityGML: " + citygml.getCityGMLClass());
		else if (citygml instanceof ADEGenericElement)
			System.out.println("Found ADE: " + ((ADEGenericElement)citygml).getContent().getLocalName());
	}
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #13
Source File: MissingSchemaReference.java    From citygml4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();

	System.out.println(df.format(new Date()) + "setting up schema handler");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.setSchemaEntityResolver(new SchemaEntityResolver());
	schemaHandler.setErrorHandler(new SchemaParseErrorHandler());

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD0_Railway_NoiseADE_missing_ADE_reference_v200.gml");
	System.out.println(df.format(new Date()) + "note: the input document is lacking a reference to the ADE schema document");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.SPLIT_PER_FEATURE);
	
	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD0_Railway_NoiseADE_missing_ADE_reference_v200.gml"));
	
	while (reader.hasNext()) {
		CityGML citygml = reader.nextFeature();
		
		if (citygml instanceof AbstractFeature)
			System.out.println("Found CityGML: " + citygml.getCityGMLClass());
		else if (citygml instanceof ADEGenericElement)
			System.out.println("Found ADE: " + ((ADEGenericElement)citygml).getContent().getLocalName());
	}
	
	reader.close();
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #14
Source File: ObjectTreeValidationUsingSplitter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	/*
	 * PLEASE NOTE, that you receive less errors if the in-memory objects
	 * derived from the input document are validated than if the input document
	 * itself is validated.
	 * reason: citygml4j tries to reconstruct a valid object tree from the
	 * input document. Generally, this means
	 * 1) Invalid order of XML elements will be corrected automatically (see ADDRESS element)
	 * 2) Invalid text values of XML elements cannot be automatically corrected
	 *    and thus will be reported (see, e.g., gml:id of BUILDING element)
	 * 3) Invalid XML child elements will be omitted in the object tree (see CLOSURESURFACE element)
	 * 
	 * Due to 3) you should always make sure to generate object trees from 
	 * valid CityGML documents!
	 */
	
	SimpleDateFormat df = new SimpleDateFormat("[HH:mm:ss] "); 

	System.out.println(df.format(new Date()) + "setting up citygml4j context and CityGML builder");
	CityGMLContext ctx = CityGMLContext.getInstance();
	CityGMLBuilder builder = ctx.createCityGMLBuilder();
	
	System.out.println(df.format(new Date()) + "parsing ADE schema file CityGML-SubsurfaceADE-0_9_0.xsd");
	SchemaHandler schemaHandler = SchemaHandler.newInstance();
	schemaHandler.parseSchema(new File("datasets/schemas/CityGML-SubsurfaceADE-0_9_0.xsd"));

	System.out.println(df.format(new Date()) + "reading ADE-enriched CityGML file LOD2_SubsurfaceStructureADE_invalid_v100.gml");
	CityGMLInputFactory in = builder.createCityGMLInputFactory(schemaHandler);
	in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.NO_SPLIT);

	CityGMLReader reader = in.createCityGMLReader(new File("datasets/LOD2_SubsurfaceStructureADE_invalid_v100.gml"));
	CityGML citygml = reader.nextFeature();		
	reader.close();
	
	System.out.println(df.format(new Date()) + "creating citygml4j Validator");
	Validator validator = builder.createValidator(schemaHandler);		
	validator.setValidationEventHandler(event -> {
           System.out.println("\t" + event.getMessage());
           return true;
       });
	
	System.out.println(df.format(new Date()) + "creating citygml4j FeatureSplitter and splitting document into single features");
	FeatureSplitter splitter = new FeatureSplitter()
			.setSchemaHandler(schemaHandler)
			.setSplitMode(FeatureSplitMode.SPLIT_PER_FEATURE)
			.splitCopy(true);
	
	System.out.println(df.format(new Date()) + "iterating over splitting result and validating features against CityGML 1.0.0");
	for (CityGML feature : splitter.split(citygml)) {
		
		String type;
		if (feature instanceof ADEGenericElement){
			Element element = ((ADEGenericElement)feature).getContent();
			type = element.getPrefix() + ':' + element.getLocalName();
		} else
			type = feature.getCityGMLClass().toString();
		
		System.out.println("Validating " + type);
		validator.validate(feature, CityGMLVersion.v1_0_0);
	}
	
	System.out.println(df.format(new Date()) + "sample citygml4j application successfully finished");
}
 
Example #15
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setSchemaHandler(SchemaHandler schemaHandler) {
	if (schemaHandler == null)
		throw new IllegalArgumentException("schema handler may not be null.");

	this.schemaHandler = schemaHandler;
}
 
Example #16
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return schemaHandler;
}
 
Example #17
Source File: JAXBOutputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public JAXBOutputFactory(CityGMLBuilder builder, SchemaHandler schemaHandler) {
	this(builder, new ModuleContext(), schemaHandler);
}
 
Example #18
Source File: JAXBInputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return schemaHandler;
}
 
Example #19
Source File: JAXBInputFactory.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setSchemaHandler(SchemaHandler schemaHandler) {
	if (schemaHandler == null)
		throw new IllegalArgumentException("schema handler may not be null.");

	this.schemaHandler = schemaHandler;
}
 
Example #20
Source File: ValidationSchemaHandler.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return schemaHandler;
}
 
Example #21
Source File: ValidationSchemaHandler.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public ValidationSchemaHandler(SchemaHandler schemaHandler) {
	this.schemaHandler = schemaHandler;
	schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
}
 
Example #22
Source File: JAXBValidator.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public void setSchemaHandler(SchemaHandler schemaHandler) {
	if (schemaHandler == null)
		throw new IllegalArgumentException("schema handler may not be null.");

	validationSchemaHandler.setSchemaHandler(schemaHandler);
}
 
Example #23
Source File: JAXBValidator.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return validationSchemaHandler.getSchemaHandler();
}
 
Example #24
Source File: JAXBValidator.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public JAXBValidator(CityGMLBuilder builder, SchemaHandler schemaHandler) {
	this.builder = builder;
	validationSchemaHandler = new ValidationSchemaHandler(schemaHandler);
}
 
Example #25
Source File: JAXBUnmarshaller.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return schemaHandler;
}
 
Example #26
Source File: CityGMLBuilder.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public Validator createValidator(SchemaHandler schemaHandler) {
	return new JAXBValidator(this, schemaHandler);
}
 
Example #27
Source File: CityGMLBuilder.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public CityGMLOutputFactory createCityGMLOutputFactory(SchemaHandler schemaHandler) {
	return new JAXBOutputFactory(this, schemaHandler);
}
 
Example #28
Source File: CityGMLBuilder.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public CityGMLOutputFactory createCityGMLOutputFactory(ModuleContext moduleContext, SchemaHandler schemaHandler) {
	return new JAXBOutputFactory(this, moduleContext, schemaHandler);
}
 
Example #29
Source File: FeatureSplitter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public FeatureSplitter setSchemaHandler(SchemaHandler schemaHandler) {
	splitter.setSchemaHandler(schemaHandler);
	return this;
}
 
Example #30
Source File: FeatureSplitter.java    From citygml4j with Apache License 2.0 4 votes vote down vote up
public SchemaHandler getSchemaHandler() {
	return splitter.getSchemaHandler();
}