下面列出了org.w3c.dom.TypeInfo#javax.xml.validation.ValidatorHandler 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
protected static ValidatorHandler createValidatorForSchemaFiles(String... schemaFiles) throws TechnicalConnectorException {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
try {
Source[] sources = new Source[0];
for(int i = 0; i < schemaFiles.length; ++i) {
String schemaFile = schemaFiles[i];
InputStream in = SchemaValidatorHandler.class.getResourceAsStream(schemaFile);
if (in == null) {
throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_XML_INVALID, new Object[]{"Unable to find schemaFile " + schemaFile});
}
if (schemaFiles.length == 1) {
sources = (Source[])((Source[])ArrayUtils.add(sources, new StreamSource(SchemaValidatorHandler.class.getResource(schemaFile).toExternalForm())));
} else {
Source source = new StreamSource(in);
sources = (Source[])((Source[])ArrayUtils.add(sources, source));
}
}
return schemaFactory.newSchema(sources).newValidatorHandler();
} catch (Exception var7) {
throw handleException(var7);
}
}
protected static ValidatorHandler createValidatorForSchemaFiles(String... schemaFiles) throws TechnicalConnectorException {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
try {
Source[] sources = new Source[0];
for(int i = 0; i < schemaFiles.length; ++i) {
String schemaFile = schemaFiles[i];
InputStream in = SchemaValidatorHandler.class.getResourceAsStream(schemaFile);
if (in == null) {
throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_XML_INVALID, new Object[]{"Unable to find schemaFile " + schemaFile});
}
if (schemaFiles.length == 1) {
sources = (Source[])((Source[])ArrayUtils.add(sources, new StreamSource(SchemaValidatorHandler.class.getResource(schemaFile).toExternalForm())));
} else {
Source source = new StreamSource(in);
sources = (Source[])((Source[])ArrayUtils.add(sources, source));
}
}
return schemaFactory.newSchema(sources).newValidatorHandler();
} catch (Exception var7) {
throw handleException(var7);
}
}
protected static ValidatorHandler createValidatorForSchemaFiles(String... schemaFiles) throws TechnicalConnectorException {
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
try {
Source[] sources = new Source[0];
for(int i = 0; i < schemaFiles.length; ++i) {
String schemaFile = schemaFiles[i];
InputStream in = SchemaValidatorHandler.class.getResourceAsStream(schemaFile);
if (in == null) {
throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_XML_INVALID, new Object[]{"Unable to find schemaFile " + schemaFile});
}
if (schemaFiles.length == 1) {
sources = (Source[])((Source[])ArrayUtils.add(sources, new StreamSource(SchemaValidatorHandler.class.getResource(schemaFile).toExternalForm())));
} else {
Source source = new StreamSource(in);
sources = (Source[])((Source[])ArrayUtils.add(sources, source));
}
}
return schemaFactory.newSchema(sources).newValidatorHandler();
} catch (Exception var7) {
throw handleException(var7);
}
}
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
public static String translate(JsonStructure json, URL schemaURL, boolean compactJsonArrays, String rootElement, boolean strictSyntax, boolean deepSearch, String targetNamespace, Map<String,Object> overrideValues) throws SAXException, IOException {
ValidatorHandler validatorHandler = getValidatorHandler(schemaURL);
List<XSModel> schemaInformation = getSchemaInformation(schemaURL);
// create the validator, setup the chain
Json2Xml j2x = new Json2Xml(validatorHandler,schemaInformation,compactJsonArrays,rootElement,strictSyntax);
if (overrideValues!=null) {
j2x.setOverrideValues(overrideValues);
}
if (targetNamespace!=null) {
//if (DEBUG) System.out.println("setting targetNamespace ["+targetNamespace+"]");
j2x.setTargetNamespace(targetNamespace);
}
j2x.setDeepSearch(deepSearch);
return j2x.translate(json);
}
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
private void parseAndValidate(InputStream input, Schema schema) throws XmlParseException, IOException {
ValidatorHandler vHandler = schema.newValidatorHandler();
vHandler.setContentHandler(this);
vHandler.setErrorHandler(this);
InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
is.setEncoding("UTF-8");
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(vHandler);
parser.setErrorHandler(this);
vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
parser.parse(is);
} catch (SAXException e) {
throw new XmlParseException(e.getMessage(), e);
}
}
public ValidatorHandler newValidator() {
synchronized(this) {
if(schema==null) {
try {
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
schema = allowExternalAccess(sf, "file", false).newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
public String validate(Object input, IPipeLineSession session, String logPrefix, ValidatorHandler validatorHandler, XMLFilterImpl filter, ValidationContext context) throws XmlValidatorException, PipeRunException, ConfigurationException {
if (filter != null) {
// If a filter is present, connect its output to the context.contentHandler.
// It is assumed that the filter input is already properly connected.
filter.setContentHandler(context.getContentHandler());
filter.setErrorHandler(context.getErrorHandler());
} else {
validatorHandler.setContentHandler(context.getContentHandler());
}
validatorHandler.setErrorHandler(context.getErrorHandler());
InputSource is = getInputSource(Message.asMessage(input));
return validate(is, validatorHandler, session, context);
}
/**
* Applies the additional binding customizations.
*/
public void apply(XSSchemaSet schema, ErrorReceiver errorReceiver) {
if(topLevel!=null) {
this.errorReceiver = errorReceiver;
Unmarshaller u = BindInfo.getCustomizationUnmarshaller();
this.unmarshaller = u.getUnmarshallerHandler();
ValidatorHandler v = BindInfo.bindingFileSchema.newValidator();
v.setErrorHandler(errorReceiver);
loader = new ForkContentHandler(v,unmarshaller);
topLevel.applyAll(schema.getSchemas());
this.loader = null;
this.unmarshaller = null;
this.errorReceiver = null;
}
}
/**
* Parses an xml config file and returns a Config object.
*
* @param xmlFile
* The xml config file which is passed by the user to annotation processing
* @return
* A non null Config object
*/
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
XMLReader reader;
try {
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
reader = factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
// in practice this will never happen
throw new Error(e);
}
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
// set up validator
ValidatorHandler validator = configSchema.newValidator();
validator.setErrorHandler(errorHandler);
// the validator will receive events first, then the parser.
reader.setContentHandler(new ForkContentHandler(validator,runtime));
reader.setErrorHandler(errorHandler);
Config config = new Config(runtime);
runtime.setRootHandler(config);
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
runtime.reset();
return config;
}
public static void validate(Source source, boolean xop, String... schemaLocations) throws TechnicalConnectorException {
try {
XOPValidationHandler handler = new XOPValidationHandler(xop);
ValidatorHandler validator = createValidatorForSchemaFiles(schemaLocations);
ErrorCollectorHandler collector = new ErrorCollectorHandler(handler);
validator.setErrorHandler(collector);
SAXParser parser = SAF.newSAXParser();
parser.parse(convert(source), new ForkContentHandler(new ContentHandler[]{handler, validator}));
handleValidationResult(collector);
} catch (Exception var7) {
throw handleException(var7);
}
}
public static void validate(Source source, boolean xop, String... schemaLocations) throws TechnicalConnectorException {
try {
XOPValidationHandler handler = new XOPValidationHandler(xop);
ValidatorHandler validator = createValidatorForSchemaFiles(schemaLocations);
ErrorCollectorHandler collector = new ErrorCollectorHandler(handler);
validator.setErrorHandler(collector);
SAXParser parser = SAF.newSAXParser();
parser.parse(convert(source), new ForkContentHandler(new ContentHandler[]{handler, validator}));
handleValidationResult(collector);
} catch (Exception var7) {
throw handleException(var7);
}
}
public static void validate(Source source, boolean xop, String... schemaLocations) throws TechnicalConnectorException {
try {
XOPValidationHandler handler = new XOPValidationHandler(xop);
ValidatorHandler validator = createValidatorForSchemaFiles(schemaLocations);
ErrorCollectorHandler collector = new ErrorCollectorHandler(handler);
validator.setErrorHandler(collector);
SAXParser parser = SAF.newSAXParser();
parser.parse(convert(source), new ForkContentHandler(new ContentHandler[]{handler, validator}));
handleValidationResult(collector);
} catch (Exception var7) {
throw handleException(var7);
}
}
public static void validate(Source source, boolean xop, String... schemaLocations) throws TechnicalConnectorException {
try {
XOPValidationHandler handler = new XOPValidationHandler(xop);
ValidatorHandler validator = createValidatorForSchemaFiles(schemaLocations);
ErrorCollectorHandler collector = new ErrorCollectorHandler(handler);
validator.setErrorHandler(collector);
SAXParser parser = SAF.newSAXParser();
parser.parse(convert(source), new ForkContentHandler(new ContentHandler[]{handler, validator}));
handleValidationResult(collector);
} catch (Exception var7) {
throw handleException(var7);
}
}
/**
* Parses an xml config file and returns a Config object.
*
* @param xmlFile
* The xml config file which is passed by the user to annotation processing
* @return
* A non null Config object
*/
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
XMLReader reader;
try {
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
reader = factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
// in practice this will never happen
throw new Error(e);
}
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
// set up validator
ValidatorHandler validator = configSchema.newValidator();
validator.setErrorHandler(errorHandler);
// the validator will receive events first, then the parser.
reader.setContentHandler(new ForkContentHandler(validator,runtime));
reader.setErrorHandler(errorHandler);
Config config = new Config(runtime);
runtime.setRootHandler(config);
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
runtime.reset();
return config;
}
/**
* Parses an xml config file and returns a Config object.
*
* @param xmlFile
* The xml config file which is passed by the user to annotation processing
* @return
* A non null Config object
*/
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
XMLReader reader;
try {
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
reader = factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
// in practice this will never happen
throw new Error(e);
}
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
// set up validator
ValidatorHandler validator = configSchema.newValidator();
validator.setErrorHandler(errorHandler);
// the validator will receive events first, then the parser.
reader.setContentHandler(new ForkContentHandler(validator,runtime));
reader.setErrorHandler(errorHandler);
Config config = new Config(runtime);
runtime.setRootHandler(config);
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
runtime.reset();
return config;
}
/**
* Parses an xml config file and returns a Config object.
*
* @param xmlFile
* The xml config file which is passed by the user to annotation processing
* @return
* A non null Config object
*/
private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
XMLReader reader;
try {
SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
reader = factory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException e) {
// in practice this will never happen
throw new Error(e);
}
NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
// set up validator
ValidatorHandler validator = configSchema.newValidator();
validator.setErrorHandler(errorHandler);
// the validator will receive events first, then the parser.
reader.setContentHandler(new ForkContentHandler(validator,runtime));
reader.setErrorHandler(errorHandler);
Config config = new Config(runtime);
runtime.setRootHandler(config);
reader.parse(new InputSource(xmlFile.toURL().toExternalForm()));
runtime.reset();
return config;
}
protected PipeForward validate(String messageToValidate, IPipeLineSession session, boolean responseMode) throws XmlValidatorException, PipeRunException, ConfigurationException {
ValidationContext context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
ValidatorHandler validatorHandler = validator.getValidatorHandler(session, context);
XMLFilterImpl storeRootFilter = StringUtils.isNotEmpty(getRootElementSessionKey()) ? new RootElementToSessionKeyFilter(session, getRootElementSessionKey(), getRootNamespaceSessionKey(), null) : null;
if (storeRootFilter!=null) {
validatorHandler.setContentHandler(storeRootFilter);
}
String resultEvent = validator.validate(messageToValidate, session, getLogPrefix(session), validatorHandler, storeRootFilter, context);
return determineForward(resultEvent, session, responseMode);
}
public ValidatorHandler newValidator() {
if (schema==null) {
synchronized (this) {
if (schema == null) {
ResourceResolver resourceResolver = null;
try (InputStream is = clazz.getResourceAsStream(resourceName)) {
StreamSource source = new StreamSource(is);
source.setSystemId(resourceName);
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
if (createResolver) {
resourceResolver = new ResourceResolver(clazz);
schemaFactory.setResourceResolver(resourceResolver);
}
schema = schemaFactory.newSchema(source);
} catch (IOException | SAXException e) {
InternalError ie = new InternalError(e.getMessage());
ie.initCause(e);
throw ie;
} finally {
if (resourceResolver != null) resourceResolver.closeStreams();
}
}
}
}
return schema.newValidatorHandler();
}
public String validate(InputSource inputSource, ValidatorHandler validatorHandler, IPipeLineSession session, ValidationContext context) throws XmlValidatorException {
try {
XmlUtils.parseXml(inputSource, validatorHandler, context.getErrorHandler());
} catch (IOException | SAXException e) {
return finalizeValidation(context, session, e);
}
return finalizeValidation(context, session, null);
}