org.milyn.xml.XsdValidator Maven / Gradle / Ivy
The newest version!
/*
* Milyn - Copyright (C) 2006 - 2010
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License (version 2.1) as published by the Free Software
* Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License for more details:
* http://www.gnu.org/licenses/lgpl.txt
*/
package org.milyn.xml;
import org.milyn.assertion.AssertArgument;
import org.milyn.util.ClassUtil;
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.IOException;
import java.util.Collection;
/**
* XSD Validator.
*
* @author [email protected]
*/
public class XsdValidator {
public static final String SCHEMA_FACTORY = XsdValidator.class.getName() + ".SchemaFactory";
private SchemaFactory installedSchemaFactory;
private LSResourceResolver schemaSourceResolver;
private ErrorHandler errorHandler;
private Schema schema;
public void setSchemaFactory(SchemaFactory installedSchemaFactory) {
this.installedSchemaFactory = installedSchemaFactory;
}
public void setSchemaSourceResolver(LSResourceResolver schemaSourceResolver) throws SAXException {
assertSchemaNotInitialized();
SchemaFactory schemaFactory = newSchemaFactory();
this.schemaSourceResolver = schemaSourceResolver;
this.schema = schemaFactory.newSchema();
}
/**
* Set the XSD/Schema Sources.
* @param xsdSources The schema sources.
*/
public void setXSDSources(Collection