Java Examples for org.w3c.dom.ls.LSResourceResolver
The following java examples will help you to understand the usage of org.w3c.dom.ls.LSResourceResolver. These source code samples are taken from different open source projects.
Example 1
| Project: wicket-stuff-markup-validator-master File: ValidatorImpl.java View source code |
private void doValidate(SAXSource source, ContentHandler contentHandler, LexicalHandler lexicalHandler, DTDHandler dtdHandler) throws SAXException, IOException {
XMLReader xr = source.getXMLReader();
if (xr == null) {
LSResourceResolver resourceResolver = handler.getResourceResolver();
if (cachedXMLReader != null && cachedResourceResolver == resourceResolver)
xr = cachedXMLReader;
else {
Resolver resolver = null;
if (resourceResolver != null)
resolver = LS.createResolver(resourceResolver);
xr = new SAXResolver(resolver).createXMLReader();
cachedXMLReader = xr;
cachedResourceResolver = resourceResolver;
}
}
handler.setContentHandler(contentHandler);
handler.setDTDHandler(dtdHandler);
// always set the lexical handler to avoid problems when reusing the XMLReader
try {
xr.setProperty(LEXICAL_HANDLER_PROPERTY, lexicalHandler);
} catch (SAXNotRecognizedException e) {
} catch (SAXNotSupportedException e) {
}
xr.setContentHandler(handler);
xr.setDTDHandler(handler);
ErrorHandler eh = handler.getErrorHandler();
if (eh == null)
eh = new DraconianErrorHandler();
xr.setErrorHandler(eh);
if (needReset)
handler.reset();
else
needReset = true;
xr.parse(source.getInputSource());
}Example 2
| Project: android-gradle-plugin-master File: ValidateTestCase.java View source code |
/**
* Validates an XSD stream against the w3.org XSD schema.
*/
protected void validateXsd(InputStream repoXsdStream) throws SAXException, IOException {
final Class<? extends ValidateTestCase> clazz = this.getClass();
InputStream xsdXsdStream = clazz.getResourceAsStream("/com/android/sdklib/testdata/www.w3.org/2001/XMLSchema.xsd");
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(String type, String namespaceURI, final String publicId, final String systemId, final String baseURI) {
if (systemId != null) {
String resName = "/com/android/sdklib/testdata/www.w3.org/2001/";
int pos = systemId.lastIndexOf('/');
if (pos < 0) {
resName += systemId;
} else {
resName += systemId.substring(pos + 1);
}
final InputStream stream = clazz.getResourceAsStream(resName);
if (stream == null) {
fail("XSD validation requires missing file: " + resName);
}
return new LSInput() {
@SuppressWarnings("hiding")
@Override
public void setSystemId(String systemId) {
}
@Override
public void setStringData(String stringData) {
}
@SuppressWarnings("hiding")
@Override
public void setPublicId(String publicId) {
}
@Override
public void setEncoding(String encoding) {
}
@Override
public void setCharacterStream(Reader characterStream) {
}
@Override
public void setCertifiedText(boolean certifiedText) {
}
@Override
public void setByteStream(InputStream byteStream) {
}
@SuppressWarnings("hiding")
@Override
public void setBaseURI(String baseURI) {
}
@Override
public String getSystemId() {
return systemId;
}
@Override
public String getStringData() {
return null;
}
@Override
public String getPublicId() {
return publicId;
}
@Override
public String getEncoding() {
return null;
}
@Override
public Reader getCharacterStream() {
return null;
}
@Override
public boolean getCertifiedText() {
return false;
}
@Override
public InputStream getByteStream() {
return stream;
}
@Override
public String getBaseURI() {
return baseURI;
}
};
}
return null;
}
});
Schema schema = factory.newSchema(new StreamSource(xsdXsdStream));
Validator validator = schema.newValidator();
CaptureErrorHandler handler = new CaptureErrorHandler();
validator.setErrorHandler(handler);
validator.validate(new StreamSource(repoXsdStream));
handler.verify();
}Example 3
| Project: android-platform-tools-base-master File: ValidateTestCase.java View source code |
/**
* Validates an XSD stream against the w3.org XSD schema.
*/
protected void validateXsd(InputStream repoXsdStream) throws SAXException, IOException {
final Class<? extends ValidateTestCase> clazz = this.getClass();
InputStream xsdXsdStream = clazz.getResourceAsStream("/com/android/sdklib/testdata/www.w3.org/2001/XMLSchema.xsd");
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(String type, String namespaceURI, final String publicId, final String systemId, final String baseURI) {
if (systemId != null) {
String resName = "/com/android/sdklib/testdata/www.w3.org/2001/";
int pos = systemId.lastIndexOf('/');
if (pos < 0) {
resName += systemId;
} else {
resName += systemId.substring(pos + 1);
}
final InputStream stream = clazz.getResourceAsStream(resName);
if (stream == null) {
fail("XSD validation requires missing file: " + resName);
}
return new LSInput() {
@SuppressWarnings("hiding")
@Override
public void setSystemId(String systemId) {
}
@Override
public void setStringData(String stringData) {
}
@SuppressWarnings("hiding")
@Override
public void setPublicId(String publicId) {
}
@Override
public void setEncoding(String encoding) {
}
@Override
public void setCharacterStream(Reader characterStream) {
}
@Override
public void setCertifiedText(boolean certifiedText) {
}
@Override
public void setByteStream(InputStream byteStream) {
}
@SuppressWarnings("hiding")
@Override
public void setBaseURI(String baseURI) {
}
@Override
public String getSystemId() {
return systemId;
}
@Override
public String getStringData() {
return null;
}
@Override
public String getPublicId() {
return publicId;
}
@Override
public String getEncoding() {
return null;
}
@Override
public Reader getCharacterStream() {
return null;
}
@Override
public boolean getCertifiedText() {
return false;
}
@Override
public InputStream getByteStream() {
return stream;
}
@Override
public String getBaseURI() {
return baseURI;
}
};
}
return null;
}
});
Schema schema = factory.newSchema(new StreamSource(xsdXsdStream));
Validator validator = schema.newValidator();
CaptureErrorHandler handler = new CaptureErrorHandler();
validator.setErrorHandler(handler);
validator.validate(new StreamSource(repoXsdStream));
handler.verify();
}Example 4
| Project: camel-master File: ValidatorWithResourceResolverRouteTest.java View source code |
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
// we have to do it here, because we need the context created first
CatalogManager.getStaticManager().setIgnoreMissingProperties(true);
CatalogResolver catalogResolver = new CatalogResolver(true);
URL catalogUrl = ResourceHelper.resolveMandatoryResourceAsUrl(context.getClassResolver(), "org/apache/camel/component/validator/catalog.cat");
catalogResolver.getCatalog().parseCatalog(catalogUrl);
LSResourceResolver resourceResolver = new CatalogLSResourceResolver(catalogResolver);
JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
registry.bind("resourceResolver", resourceResolver);
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").doTry().to("validator:org/apache/camel/component/validator/report.xsd?resourceResolver=#resourceResolver").to("mock:valid").doCatch(ValidationException.class).to("mock:invalid").doFinally().to("mock:finally").end();
}
};
}Example 5
| Project: nazgul_core-master File: JaxbUtils.java View source code |
/**
* Acquires a JAXB Schema from the provided JAXBContext.
*
* @param ctx The context for which am XSD should be constructed.
* @return A tuple holding the constructed XSD from the provided JAXBContext, and
* the LSResourceResolver synthesized during the way.
* @throws NullPointerException if ctx was {@code null}.
* @throws IllegalArgumentException if a JAXB-related exception occurred while extracting the schema.
*/
public static Tuple<Schema, LSResourceResolver> generateTransientXSD(@NotNull final JAXBContext ctx) throws NullPointerException, IllegalArgumentException {
// Check sanity
Validate.notNull(ctx, "ctx");
final SortedMap<String, ByteArrayOutputStream> namespace2SchemaMap = new TreeMap<String, ByteArrayOutputStream>();
try {
ctx.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(final String namespaceUri, final String suggestedFileName) throws IOException {
// to avoid using the default ("") namespace.
if (namespaceUri.isEmpty()) {
log.warn("Received empty namespaceUri while resolving a generated schema. " + "Did you forget to add a @XmlType(namespace = \"... something ...\") annotation " + "to your class?");
}
// Create the result ByteArrayOutputStream
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final StreamResult toReturn = new StreamResult(out);
toReturn.setSystemId("");
// Map the namespaceUri to the schemaResult.
namespace2SchemaMap.put(namespaceUri, out);
// All done.
return toReturn;
}
});
} catch (IOException e) {
throw new IllegalArgumentException("Could not acquire Schema snippets.", e);
}
// Convert to an array of StreamSource.
final MappedSchemaResourceResolver resourceResolver = new MappedSchemaResourceResolver();
final StreamSource[] schemaSources = new StreamSource[namespace2SchemaMap.size()];
int counter = 0;
for (Map.Entry<String, ByteArrayOutputStream> current : namespace2SchemaMap.entrySet()) {
final byte[] schemaSnippetAsBytes = current.getValue().toByteArray();
resourceResolver.addNamespace2SchemaEntry(current.getKey(), new String(schemaSnippetAsBytes));
if (log.isDebugEnabled()) {
log.info("Generated schema [" + (counter + 1) + "/" + schemaSources.length + "]:\n " + new String(schemaSnippetAsBytes));
}
// Copy the schema source to the schemaSources array.
schemaSources[counter] = new StreamSource(new ByteArrayInputStream(schemaSnippetAsBytes), "");
// Increase the counter
counter++;
}
try {
// All done.
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(resourceResolver);
final Schema transientSchema = schemaFactory.newSchema(schemaSources);
// All done.
return new Tuple<Schema, LSResourceResolver>(transientSchema, resourceResolver);
} catch (final SAXException e) {
throw new IllegalArgumentException("Could not create Schema from snippets.", e);
}
}Example 6
| Project: openjdk-master File: XMLSchemaLoader.java View source code |
/* (non-Javadoc)
* @see DOMConfiguration#setParameter(String, Object)
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
if (name.equals("validate") && state) {
return;
}
try {
setFeature(name, state);
} catch (Exception e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
return;
}
if (name.equals(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
setErrorHandler(fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
return;
}
if (name.equals(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver) {
try {
fResourceResolver = new DOMEntityResolverWrapper((LSResourceResolver) value);
setEntityResolver(fResourceResolver);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
return;
}
try {
setProperty(name, value);
} catch (Exception ex) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
}Example 7
| Project: cdi-tck-master File: EjbJarDescriptorBuilderTest.java View source code |
@Test
public void testDescriptorIsValid() throws ParserConfigurationException, SAXException, DescriptorExportException, IOException {
EjbJarDescriptor ejbJarDescriptor = new EjbJarDescriptorBuilder().messageDrivenBeans(newMessageDriven("TestQueue", QueueMessageDrivenBean.class.getName()).addActivationConfigProperty("acknowledgeMode", "Auto-acknowledge").addActivationConfigProperty("destinationType", "javax.jms.Queue").addActivationConfigProperty("destinationLookup", "test_queue"), newMessageDriven("TestTopic", TopicMessageDrivenBean.class.getName()).addActivationConfigProperty("acknowledgeMode", "Auto-acknowledge").addActivationConfigProperty("destinationType", "javax.jms.Topic").addActivationConfigProperty("destinationLookup", "test_topic")).build();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
try {
if (systemId.startsWith("http")) {
// Ugly workaround for xml.xsd
systemId = StringUtils.substringAfterLast(systemId, "/");
}
return new Input(publicId, systemId, new FileInputStream(new File("src/test/resources/xsd", systemId)));
} catch (FileNotFoundException e) {
throw new IllegalStateException();
}
}
});
schemaFactory.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) throws SAXException {
}
@Override
public void fatalError(SAXParseException exception) throws SAXException {
throw exception;
}
@Override
public void error(SAXParseException exception) throws SAXException {
throw exception;
}
});
Source schemaFile = new StreamSource(new FileInputStream(new File("src/test/resources/xsd", "ejb-jar_3_1.xsd")));
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new ByteArrayInputStream(ejbJarDescriptor.exportAsString().getBytes())));
}Example 8
| Project: classlib6-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
fConfiguration.setFeature(name.toLowerCase(Locale.ENGLISH), state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
//parameter is not recognized
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
}Example 9
| Project: cxf-master File: JAXBDataBinding.java View source code |
public void validateSchema(Element ele, String uri, final OASISCatalogManager catalog, final SchemaCollection schemaCollection) throws ToolException {
SchemaFactory schemaFact = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFact.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String s = JAXBDataBinding.mapSchemaLocation(systemId, baseURI, catalog);
//System.out.println(namespaceURI + " " + systemId + " " + baseURI + " " + s);
if (s == null) {
XmlSchema sc = schemaCollection.getSchemaByTargetNamespace(namespaceURI);
StringWriter writer = new StringWriter();
sc.write(writer);
InputSource src = new InputSource(new StringReader(writer.toString()));
src.setSystemId(sc.getSourceURI());
return new LSInputSAXWrapper(src);
}
return new LSInputSAXWrapper(new InputSource(s));
}
});
DOMSource domSrc = new DOMSource(ele, uri);
try {
schemaFact.newSchema(domSrc);
} catch (SAXException e) {
if (e.getLocalizedMessage().indexOf("src-resolve.4.2") > -1) {
} else {
throw new ToolException("Schema Error : " + e.getLocalizedMessage(), e);
}
}
}Example 10
| Project: ikvm-openjdk-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
fConfiguration.setFeature(name.toLowerCase(Locale.ENGLISH), state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
//parameter is not recognized
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
}Example 11
| Project: ManagedRuntimeInitiative-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
fConfiguration.setFeature(name.toLowerCase(Locale.ENGLISH), state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
//parameter is not recognized
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
}Example 12
| Project: oxAuth-master File: FacesConfigPopulator.java View source code |
/**
* Validates *.faces-config.xml file
*
* @param xml
* @return
*/
private boolean isValidFacesConfig(InputStream xml) {
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
InputStream xsd = this.getClass().getResourceAsStream(FACES_2_2_XSD);
Schema schema = factory.newSchema(new StreamSource(xsd));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(xml));
return true;
} catch (Exception ex) {
return false;
}
}Example 13
| Project: Shindig-master File: XSDValidator.java View source code |
/**
* Validate a xml input stream against a supplied schema.
*
* @param xml
* a stream containing the xml
* @param schema
* a stream containing the schema
* @return a list of errors or warnings, a 0 lenght string if none.
*/
public static String validate(InputStream xml, InputStream schema) {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
final StringBuilder errors = new StringBuilder();
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA);
Schema s = schemaFactory.newSchema(new StreamSource(schema));
Validator validator = s.newValidator();
final LSResourceResolver lsr = validator.getResourceResolver();
validator.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String arg0, String arg1, String arg2, String arg3, String arg4) {
log.info("resolveResource(" + arg0 + "," + arg1 + "," + arg2 + "," + arg3 + "," + arg4 + ")");
return lsr.resolveResource(arg0, arg1, arg2, arg3, arg4);
}
});
validator.validate(new StreamSource(xml));
} catch (IOException e) {
} catch (SAXException e) {
errors.append(e.getMessage()).append("\n");
}
return errors.toString();
}Example 14
| Project: aries-master File: SimpleNamespaceHandlerSet.java View source code |
public Schema getSchema() throws SAXException, IOException {
if (schema == null) {
final List<StreamSource> schemaSources = new ArrayList<StreamSource>();
final List<InputStream> streams = new ArrayList<InputStream>();
try {
InputStream is = getClass().getResourceAsStream("/org/apache/aries/blueprint/blueprint.xsd");
streams.add(is);
schemaSources.add(new StreamSource(is));
for (URI uri : namespaces.keySet()) {
is = namespaces.get(uri).openStream();
streams.add(is);
schemaSources.add(new StreamSource(is));
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespace, String publicId, String systemId, String baseURI) {
try {
URL namespaceURL = namespaces.get(URI.create(namespace));
if (systemId != null && namespaceURL != null) {
URI systemIdUri = namespaceURL.toURI();
if (!URI.create(systemId).isAbsolute()) {
systemIdUri = systemIdUri.resolve(systemId);
}
if (!systemIdUri.isAbsolute() && "jar".equals(namespaceURL.getProtocol())) {
String urlString = namespaceURL.toString();
int jarFragmentIndex = urlString.lastIndexOf('!');
if (jarFragmentIndex > 0 && jarFragmentIndex < urlString.length() - 1) {
String jarUrlOnly = urlString.substring(0, jarFragmentIndex);
String oldFragment = urlString.substring(jarFragmentIndex + 1);
String newFragment = URI.create(oldFragment).resolve(systemId).toString();
String newJarUri = jarUrlOnly + '!' + newFragment;
systemIdUri = URI.create(newJarUri);
}
}
InputStream resourceStream = systemIdUri.toURL().openStream();
return new LSInputImpl(publicId, systemId, resourceStream);
}
} catch (Exception ex) {
}
return null;
}
});
schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
} finally {
for (InputStream is : streams) {
is.close();
}
}
}
return schema;
}Example 15
| Project: Consent2Share-master File: XmlValidation.java View source code |
/**
* Creates the schema.
*
* @param xsdInputStream
* the xsd input stream
* @param resourceResolver
* the resource resolver
* @return the schema
* @throws XmlSchemaFailureException
* the xml schema failure exception
*/
private Schema createSchema(InputStream xsdInputStream, LSResourceResolver resourceResolver) throws XmlSchemaFailureException {
final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Source schemaSource = new StreamSource(xsdInputStream);
if (resourceResolver != null) {
factory.setResourceResolver(resourceResolver);
}
Schema schema;
try {
schema = factory.newSchema(schemaSource);
} catch (final SAXException e) {
logger.error(e.getMessage());
throw new XmlSchemaFailureException(e);
}
return schema;
}Example 16
| Project: gatein-shindig-master File: XSDValidator.java View source code |
/**
* Validate a xml input stream against a supplied schema.
*
* @param xml
* a stream containing the xml
* @param schema
* a stream containing the schema
* @return a list of errors or warnings, a 0 lenght string if none.
*/
public static String validate(InputStream xml, InputStream schema) {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
final StringBuilder errors = new StringBuilder();
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA);
Schema s = schemaFactory.newSchema(new StreamSource(schema));
Validator validator = s.newValidator();
final LSResourceResolver lsr = validator.getResourceResolver();
validator.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String arg0, String arg1, String arg2, String arg3, String arg4) {
log.info("resolveResource(" + arg0 + ',' + arg1 + ',' + arg2 + ',' + arg3 + ',' + arg4 + ')');
return lsr.resolveResource(arg0, arg1, arg2, arg3, arg4);
}
});
validator.validate(new StreamSource(xml));
} catch (IOException e) {
} catch (SAXException e) {
errors.append(e.getMessage()).append('\n');
}
return errors.toString();
}Example 17
| Project: iaf-master File: JavaxXmlValidator.java View source code |
protected String validate(Source source, IPipeLineSession session) throws XmlValidatorException, ConfigurationException, PipeRunException {
init();
String schemasId = schemasProvider.getSchemasId();
if (schemasId == null) {
schemasId = schemasProvider.getSchemasId(session);
getSchemaObject(schemasId, schemasProvider.getSchemas(session));
}
Schema xsd = javaxSchemas.get(schemasId);
try {
Validator validator = xsd.newValidator();
validator.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String s, String s1, String s2, String s3, String s4) {
System.out.println("--");
//To change body of implemented methods Settings | File Templates.
return null;
}
});
validator.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException e) throws SAXException {
LOG.warn(e.getMessage());
}
public void error(SAXParseException e) throws SAXException {
LOG.error(e.getMessage());
}
public void fatalError(SAXParseException e) throws SAXException {
LOG.error(e.getMessage());
}
});
//validator.setFeature("http://xml.org/sax/features/namespace-prefixes", true); /// DOESNT" WORK any more?
validator.validate(source);
} catch (SAXException e) {
throw new XmlValidatorException(e.getClass() + " " + e.getMessage());
} catch (IOException e) {
throw new XmlValidatorException(e.getMessage(), e);
}
return XML_VALIDATOR_VALID_MONITOR_EVENT;
}Example 18
| Project: jaxb-master File: SchemaCompilerImpl.java View source code |
public JAXBModelImpl bind() {
// this also takes care of the binding files given in the -episode option.
for (InputSource is : opts.getBindFiles()) parseSchema(is);
// internalization
SCDBasedBindingSet scdBasedBindingSet = forest.transform(opts.isExtensionMode());
if (!NO_CORRECTNESS_CHECK) {
// correctness check
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, opts.disableXmlSecurity);
// taken from SchemaConstraintChecker, TODO XXX FIXME UGLY
if (opts.entityResolver != null) {
sf.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
try {
// XSOM passes the namespace URI to the publicID parameter.
// we do the same here .
InputSource is = opts.entityResolver.resolveEntity(namespaceURI, systemId);
if (is == null)
return null;
return new LSInputSAXWrapper(is);
} catch (SAXException e) {
return null;
} catch (IOException e) {
return null;
}
}
});
}
sf.setErrorHandler(new DowngradingErrorHandler(this));
forest.weakSchemaCorrectnessCheck(sf);
if (hadError)
// error in the correctness check. abort now
return null;
}
JCodeModel codeModel = new JCodeModel();
ModelLoader gl = new ModelLoader(opts, codeModel, this);
try {
XSSchemaSet result = gl.createXSOM(forest, scdBasedBindingSet);
if (result == null)
return null;
// we need info about each field, so we go ahead and generate the
// skeleton at this point.
// REVISIT: we should separate FieldRenderer and FieldAccessor
// so that accessors can be used before we build the code.
Model model = gl.annotateXMLSchema(result);
if (model == null)
return null;
// if we have any error by now, abort
if (hadError)
return null;
model.setPackageLevelAnnotations(opts.packageLevelAnnotations);
Outline context = model.generateCode(opts, this);
if (context == null)
return null;
if (hadError)
return null;
return new JAXBModelImpl(context);
} catch (SAXException e) {
return null;
}
}Example 19
| Project: service-proxy-master File: ResolverMap.java View source code |
public LSResourceResolver toLSResourceResolver() { return new LSResourceResolver() { @Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { if (systemId == null) return null; try { if (!systemId.contains("://")) systemId = new URI(baseURI).resolve(systemId).toString(); return new LSInputImpl(publicId, systemId, resolve(systemId)); } catch (Exception e) { throw new RuntimeException(e); } } }; }
Example 20
| Project: archive-ddf-spatial-master File: TestFeatureCollectionMessageBodyWriter.java View source code |
@Test
public void testWriteToGeneratesGMLConformantXml() throws IOException, WebApplicationException, SAXException {
FeatureCollectionMessageBodyWriter wtr = new FeatureCollectionMessageBodyWriter();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
wtr.writeTo(getWfsFeatureCollection(), null, null, null, null, null, stream);
String actual = stream.toString();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
private Map<String, String> schemaLocations;
private Map<String, LSInput> inputs;
{
inputs = new HashMap<String, LSInput>();
schemaLocations = new HashMap<String, String>();
schemaLocations.put("xml.xsd", "/w3/1999/xml.xsd");
schemaLocations.put("xlink.xsd", "/w3/1999/xlink.xsd");
schemaLocations.put("geometry.xsd", "/gml/2.1.2/geometry.xsd");
schemaLocations.put("feature.xsd", "/gml/2.1.2/feature.xsd");
schemaLocations.put("gml.xsd", "/gml/2.1.2/gml.xsd");
schemaLocations.put("expr.xsd", "/filter/1.0.0/expr.xsd");
schemaLocations.put("filter.xsd", "/filter/1.0.0/filter.xsd");
schemaLocations.put("filterCapabilities.xsd", "/filter/1.0.0/filterCapabilties.xsd");
schemaLocations.put("WFS-capabilities.xsd", "/wfs/1.0.0/WFS-capabilities.xsd");
schemaLocations.put("OGC-exception.xsd", "/wfs/1.0.0/OGC-exception.xsd");
schemaLocations.put("WFS-basic.xsd", "/wfs/1.0.0/WFS-basic.xsd");
schemaLocations.put("WFS-transaction.xsd", "/wfs/1.0.0/WFS-transaction.xsd");
schemaLocations.put("wfs.xsd", "/wfs/1.0.0/wfs.xsd");
}
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String fileName = new java.io.File(systemId).getName();
if (inputs.containsKey(fileName)) {
return inputs.get(fileName);
}
LSInput input = new DOMInputImpl();
InputStream is = getClass().getResourceAsStream(schemaLocations.get(fileName));
input.setByteStream(is);
input.setBaseURI(baseURI);
input.setSystemId(systemId);
inputs.put(fileName, input);
return input;
}
});
Source wfsSchemaSource = new StreamSource(getClass().getResourceAsStream("/wfs/1.0.0/wfs.xsd"));
Source testSchemaSource = new StreamSource(getClass().getResourceAsStream("/schema.xsd"));
Schema schema = schemaFactory.newSchema(new Source[] { wfsSchemaSource, testSchemaSource });
try {
schema.newValidator().validate(new StreamSource(new StringReader(actual)));
} catch (Exception e) {
fail("Generated GML Response does not conform to WFS Schema" + e.getMessage());
}
}Example 21
| Project: ddf-catalog-master File: TestFeatureCollectionMessageBodyWriter.java View source code |
@Test
public void testWriteToGeneratesGMLConformantXml() throws IOException, WebApplicationException, SAXException {
FeatureCollectionMessageBodyWriter wtr = new FeatureCollectionMessageBodyWriter();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
wtr.writeTo(getWfsFeatureCollection(), null, null, null, null, null, stream);
String actual = stream.toString();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
private Map<String, String> schemaLocations;
private Map<String, LSInput> inputs;
{
inputs = new HashMap<String, LSInput>();
schemaLocations = new HashMap<String, String>();
schemaLocations.put("xml.xsd", "/w3/1999/xml.xsd");
schemaLocations.put("xlink.xsd", "/w3/1999/xlink.xsd");
schemaLocations.put("geometry.xsd", "/gml/2.1.2/geometry.xsd");
schemaLocations.put("feature.xsd", "/gml/2.1.2/feature.xsd");
schemaLocations.put("gml.xsd", "/gml/2.1.2/gml.xsd");
schemaLocations.put("expr.xsd", "/filter/1.0.0/expr.xsd");
schemaLocations.put("filter.xsd", "/filter/1.0.0/filter.xsd");
schemaLocations.put("filterCapabilities.xsd", "/filter/1.0.0/filterCapabilties.xsd");
schemaLocations.put("WFS-capabilities.xsd", "/wfs/1.0.0/WFS-capabilities.xsd");
schemaLocations.put("OGC-exception.xsd", "/wfs/1.0.0/OGC-exception.xsd");
schemaLocations.put("WFS-basic.xsd", "/wfs/1.0.0/WFS-basic.xsd");
schemaLocations.put("WFS-transaction.xsd", "/wfs/1.0.0/WFS-transaction.xsd");
schemaLocations.put("wfs.xsd", "/wfs/1.0.0/wfs.xsd");
}
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String fileName = new java.io.File(systemId).getName();
if (inputs.containsKey(fileName)) {
return inputs.get(fileName);
}
LSInput input = new DOMInputImpl();
InputStream is = getClass().getResourceAsStream(schemaLocations.get(fileName));
input.setByteStream(is);
input.setBaseURI(baseURI);
input.setSystemId(systemId);
inputs.put(fileName, input);
return input;
}
});
Source wfsSchemaSource = new StreamSource(getClass().getResourceAsStream("/wfs/1.0.0/wfs.xsd"));
Source testSchemaSource = new StreamSource(getClass().getResourceAsStream("/schema.xsd"));
Schema schema = schemaFactory.newSchema(new Source[] { wfsSchemaSource, testSchemaSource });
try {
schema.newValidator().validate(new StreamSource(new StringReader(actual)));
} catch (Exception e) {
fail("Generated GML Response does not conform to WFS Schema" + e.getMessage());
}
}Example 22
| Project: fcrepo-master File: SchemaValidator.java View source code |
void validate(Context context, DsTypeModel typeModel, Datastream objectDatastream, Validation validation, DOReader contentmodelReader, Date asOfDateTime, ExternalContentManager m_exExternalContentManager) throws ServerException {
List<Extension> extensions = typeModel.getExtension();
List<List<String>> schemaStreamsToProblemsMap = new ArrayList<List<String>>();
for (Extension extension : extensions) {
String name = extension.getName();
Element reference = null;
Source source = null;
if (!"SCHEMA".equals(name)) {
//ignore non schema extensions
continue;
}
List<Element> contents = extension.getAny();
for (Element content : contents) {
//find the reference
String tagname = content.getTagName();
if (tagname.equals("reference")) {
reference = content;
break;
}
}
if (reference == null) {
//if no reference
boolean found = false;
for (Element content : contents) {
if (content.getNodeType() == Element.ELEMENT_NODE) {
//parse the inline schema
source = new DOMSource(content);
found = true;
break;
}
}
if (!found) {
//empty tag
List<String> validationProblems = validation.getDatastreamProblems(objectDatastream.DatastreamID);
validationProblems.add(Errors.schemaNotFound(contentmodelReader.GetObjectPID()));
validation.setValid(false);
}
} else {
String type = reference.getAttribute("type");
String value = reference.getAttribute("value");
if ("datastream".equalsIgnoreCase(type)) {
Datastream schemaDS = contentmodelReader.GetDatastream(value, asOfDateTime);
if (schemaDS == null) {
//No schema datastream, ignore and continue
continue;
}
InputStream schemaStream;
schemaStream = schemaDS.getContentStream();
source = new StreamSource(schemaStream);
} else if ("url".equalsIgnoreCase(type)) {
InputStream schemaStream;
ContentManagerParams params = new ContentManagerParams(value);
MIMETypedStream externalContent = m_exExternalContentManager.getExternalContent(params);
schemaStream = externalContent.getStream();
source = new StreamSource(schemaStream);
} else {
//reference used, but type not recognized
List<String> validationProblems = validation.getDatastreamProblems(objectDatastream.DatastreamID);
validationProblems.add(Errors.schemaNotFound(contentmodelReader.GetObjectPID()));
validation.setValid(false);
continue;
}
}
LSResourceResolver resourceResolver = new ResourceResolver(contentmodelReader, asOfDateTime);
Schema schema;
try {
schema = parseAsSchema(source, resourceResolver);
} catch (SAXException e) {
List<String> validationProblems = validation.getDatastreamProblems(objectDatastream.DatastreamID);
validationProblems.add(Errors.schemaCannotParse(contentmodelReader.GetObjectPID(), objectDatastream.DatastreamID, e));
validation.setValid(false);
continue;
}
List<String> problems = checkSchema(objectDatastream.getContentStream(), schema, contentmodelReader.GetObjectPID(), objectDatastream.DatastreamID);
schemaStreamsToProblemsMap.add(problems);
if (problems.isEmpty()) {
//produce no errors, do not bother validating against the others.
break;
}
}
boolean foundProblem = false;
for (List<String> problems : schemaStreamsToProblemsMap) {
if (!problems.isEmpty()) {
foundProblem = true;
break;
}
}
if (foundProblem) {
validation.setValid(false);
List<String> validationProblems = validation.getDatastreamProblems(objectDatastream.DatastreamID);
for (List<String> problems : schemaStreamsToProblemsMap) {
validationProblems.addAll(problems);
}
}
}Example 23
| Project: geoserver-master File: CapabilitiesSystemTest.java View source code |
/**
* As for section 7.2.4.1, ensures the GeCapabilities document validates against its schema
*/
@Test
public void testValidateCapabilitiesXML() throws Exception {
final Document dom = getAsDOM("ows?service=WMS&version=1.3.0&request=GetCapabilities");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
URL schemaLocation = getClass().getResource("/schemas/wms/1.3.0/capabilities_1_3_0.xsd");
factory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
if (namespaceURI.equals("http://www.w3.org/1999/xlink")) {
try {
LSInput input = ((DOMImplementationLS) dom.getImplementation()).createLSInput();
URL xlink = getClass().getResource("/schemas/xlink/1999/xlink.xsd");
systemId = xlink.toURI().toASCIIString();
input.setPublicId(publicId);
input.setSystemId(systemId);
return input;
} catch (Exception e) {
return null;
}
} else if (XML.NAMESPACE.equals(namespaceURI)) {
try {
LSInput input = ((DOMImplementationLS) dom.getImplementation()).createLSInput();
URL xml = XML.class.getResource("xml.xsd");
systemId = xml.toURI().toASCIIString();
input.setPublicId(publicId);
input.setSystemId(systemId);
return input;
} catch (Exception e) {
return null;
}
} else {
return null;
}
}
});
Schema schema = factory.newSchema(schemaLocation);
Validator validator = schema.newValidator();
Source source = new DOMSource(dom);
try {
validator.validate(source);
assertTrue(true);
} catch (SAXException ex) {
LOGGER.log(Level.WARNING, "WMS 1.3.0 capabilities validation error", ex);
print(dom);
fail("WMS 1.3.0 capabilities validation error: " + ex.getMessage());
}
}Example 24
| Project: geoserver_trunk-master File: CapabilitiesSystemTest.java View source code |
/**
* As for section 7.2.4.1, ensures the GeCapabilities document validates against its schema
*/
public void testValidateCapabilitiesXML() throws Exception {
Document dom = getAsDOM("ows?service=WMS&version=1.3.0&request=GetCapabilities");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
URL schemaLocation = getClass().getResource("/schemas/wms/1.3.0/capabilities_1_3_0.xsd");
factory.setResourceResolver(new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
if (namespaceURI.equals("http://www.w3.org/1999/xlink")) {
try {
URL xlink = getClass().getResource("/schemas/xlink/1.0.0/xlinks.xsd");
systemId = xlink.toURI().toASCIIString();
DOMInputImpl input = new DOMInputImpl(publicId, systemId, null);
return input;
} catch (Exception e) {
return null;
}
} else {
return null;
}
}
});
Schema schema = factory.newSchema(schemaLocation);
Validator validator = schema.newValidator();
Source source = new DOMSource(dom);
try {
validator.validate(source);
assertTrue(true);
} catch (SAXException ex) {
LOGGER.log(Level.WARNING, "WMS 1.3.0 capabilities validation error", ex);
print(dom);
fail("WMS 1.3.0 capabilities validation error: " + ex.getMessage());
}
}Example 25
| Project: p2abcengine-master File: XmlUtils.java View source code |
private static Schema getSchema() {
if (abc4trustSchema == null) {
// this XSD includes original + ui json + pilot specifid + test
InputStream xmlSchema_all = XmlUtils.class.getResourceAsStream("/xsd/schema-include-all.xsd");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// only include xsd once
final HashSet<String> seen = new HashSet<String>();
// resolver will create 'one' scheame with all definitions...
schemaFactory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
if (!seen.add(systemId)) {
return null;
}
final InputStream xmlSchema_included = XmlUtils.class.getResourceAsStream("/xsd/" + systemId);
return new LSInput() {
@Override
public void setSystemId(String systemId) {
}
@Override
public void setStringData(String stringData) {
}
@Override
public void setPublicId(String publicId) {
}
@Override
public void setEncoding(String encoding) {
}
@Override
public void setCharacterStream(Reader characterStream) {
}
@Override
public void setCertifiedText(boolean certifiedText) {
}
@Override
public void setByteStream(InputStream byteStream) {
}
@Override
public void setBaseURI(String baseURI) {
}
@Override
public String getSystemId() {
return systemId;
}
@Override
public String getStringData() {
return null;
}
@Override
public String getPublicId() {
return publicId;
}
@Override
public String getEncoding() {
return null;
}
@Override
public Reader getCharacterStream() {
return null;
}
@Override
public boolean getCertifiedText() {
return false;
}
@Override
public InputStream getByteStream() {
return xmlSchema_included;
}
@Override
public String getBaseURI() {
return null;
}
};
}
});
try {
abc4trustSchema = schemaFactory.newSchema(new StreamSource(xmlSchema_all));
} catch (SAXException e) {
throw new RuntimeException("Cannot load abc4trust schema: " + e.getMessage());
}
}
return abc4trustSchema;
}Example 26
| Project: rmf-master File: AbstractTestCase.java View source code |
protected void validateAgainstSchema(String filename) throws Exception {
final String schemaFolderName = "../org.eclipse.rmf.reqif10/schema/";
StreamSource[] schemaDocuments = new StreamSource[] { new StreamSource("../org.eclipse.rmf.reqif10/schema/reqif.xsd") };
Source instanceDocument = new StreamSource(filename);
// the resolver is required to map the schema references to the reqif sub schema files to the local locations
LSResourceResolver resolver = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
String schemaFileName;
if (null != systemId) {
int slashIndex = systemId.lastIndexOf("/");
if (-1 == slashIndex) {
schemaFileName = systemId;
} else if (slashIndex == systemId.length() + 1) {
schemaFileName = null;
} else {
schemaFileName = systemId.substring(slashIndex);
}
} else {
schemaFileName = null;
}
InputStream inputStream;
try {
inputStream = new FileInputStream(schemaFolderName + schemaFileName);
} catch (FileNotFoundException ex) {
return null;
}
return new Input(publicId, systemId, inputStream);
}
};
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
sf.setResourceResolver(resolver);
Schema s = sf.newSchema(schemaDocuments);
Validator v = s.newValidator();
v.validate(instanceDocument);
}Example 27
| Project: eid-applet-master File: XAdESSignatureFacetTest.java View source code |
@Test
public void testSignEnvelopingDocument() throws Exception {
// setup
EnvelopedSignatureFacet envelopedSignatureFacet = new EnvelopedSignatureFacet();
KeyInfoSignatureFacet keyInfoSignatureFacet = new KeyInfoSignatureFacet(true, false, false);
SignaturePolicyService signaturePolicyService = null;
// SignaturePolicyService signaturePolicyService = new
// ExplicitSignaturePolicyService(
// "urn:test", "hello world".getBytes(), "description",
// "http://here.com");
XAdESSignatureFacet xadesSignatureFacet = new XAdESSignatureFacet(signaturePolicyService);
TimeStampService mockTimeStampService = EasyMock.createMock(TimeStampService.class);
RevocationDataService mockRevocationDataService = EasyMock.createMock(RevocationDataService.class);
XAdESXLSignatureFacet xadesXLSignatureFacet = new XAdESXLSignatureFacet(mockTimeStampService, mockRevocationDataService);
XmlSignatureTestService testedInstance = new XmlSignatureTestService(envelopedSignatureFacet, keyInfoSignatureFacet, xadesSignatureFacet, xadesXLSignatureFacet);
KeyPair keyPair = PkiTestUtils.generateKeyPair();
DateTime notBefore = new DateTime();
DateTime notAfter = notBefore.plusYears(1);
X509Certificate certificate = PkiTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null, new KeyUsage(KeyUsage.nonRepudiation));
List<X509Certificate> certificateChain = new LinkedList<X509Certificate>();
/*
* We need at least 2 certificates for the XAdES-C complete certificate
* refs construction.
*/
certificateChain.add(certificate);
certificateChain.add(certificate);
RevocationData revocationData = new RevocationData();
final X509CRL crl = PkiTestUtils.generateCrl(certificate, keyPair.getPrivate());
revocationData.addCRL(crl);
OCSPResp ocspResp = PkiTestUtils.createOcspResp(certificate, false, certificate, certificate, keyPair.getPrivate(), "SHA1withRSA");
revocationData.addOCSP(ocspResp.getEncoded());
// expectations
EasyMock.expect(mockTimeStampService.timeStamp(EasyMock.anyObject(byte[].class), EasyMock.anyObject(RevocationData.class))).andStubAnswer(new IAnswer<byte[]>() {
public byte[] answer() throws Throwable {
Object[] arguments = EasyMock.getCurrentArguments();
RevocationData revocationData = (RevocationData) arguments[1];
revocationData.addCRL(crl);
return "time-stamp-token".getBytes();
}
});
EasyMock.expect(mockRevocationDataService.getRevocationData(EasyMock.eq(certificateChain))).andStubReturn(revocationData);
// prepare
EasyMock.replay(mockTimeStampService, mockRevocationDataService);
// operate
DigestInfo digestInfo = testedInstance.preSign(null, certificateChain, null, null, null);
// verify
assertNotNull(digestInfo);
assertEquals("SHA-1", digestInfo.digestAlgo);
assertNotNull(digestInfo.digestValue);
TemporaryTestDataStorage temporaryDataStorage = (TemporaryTestDataStorage) testedInstance.getTemporaryDataStorage();
assertNotNull(temporaryDataStorage);
InputStream tempInputStream = temporaryDataStorage.getTempInputStream();
assertNotNull(tempInputStream);
Document tmpDocument = PkiTestUtils.loadDocument(tempInputStream);
LOG.debug("tmp document: " + PkiTestUtils.toString(tmpDocument));
Element nsElement = tmpDocument.createElement("ns");
nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS);
nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:xades", "http://uri.etsi.org/01903/v1.3.2#");
Node digestValueNode = XPathAPI.selectSingleNode(tmpDocument, "//ds:DigestValue", nsElement);
assertNotNull(digestValueNode);
String digestValueTextContent = digestValueNode.getTextContent();
LOG.debug("digest value text content: " + digestValueTextContent);
assertFalse(digestValueTextContent.isEmpty());
/*
* Sign the received XML signature digest value.
*/
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPrivate());
byte[] digestInfoValue = ArrayUtils.addAll(PkiTestUtils.SHA1_DIGEST_INFO_PREFIX, digestInfo.digestValue);
byte[] signatureValue = cipher.doFinal(digestInfoValue);
/*
* Operate: postSign
*/
testedInstance.postSign(signatureValue, certificateChain);
// verify
EasyMock.verify(mockTimeStampService, mockRevocationDataService);
byte[] signedDocumentData = testedInstance.getSignedDocumentData();
assertNotNull(signedDocumentData);
Document signedDocument = PkiTestUtils.loadDocument(new ByteArrayInputStream(signedDocumentData));
LOG.debug("signed document: " + PkiTestUtils.toString(signedDocument));
NodeList signatureNodeList = signedDocument.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");
assertEquals(1, signatureNodeList.getLength());
Element signatureNode = (Element) signatureNodeList.item(0);
// work-around for Java 7
Element signedPropertiesElement = (Element) signatureNode.getElementsByTagNameNS(XAdESXLSignatureFacet.XADES_NAMESPACE, "SignedProperties").item(0);
signedPropertiesElement.setIdAttribute("Id", true);
DOMValidateContext domValidateContext = new DOMValidateContext(KeySelector.singletonKeySelector(keyPair.getPublic()), signatureNode);
XMLSignatureFactory xmlSignatureFactory = XMLSignatureFactory.getInstance();
XMLSignature xmlSignature = xmlSignatureFactory.unmarshalXMLSignature(domValidateContext);
boolean validity = xmlSignature.validate(domValidateContext);
assertTrue(validity);
File tmpFile = File.createTempFile("xades-x-l-", ".xml");
FileUtils.writeStringToFile(tmpFile, PkiTestUtils.toString(signedDocument));
LOG.debug("tmp file: " + tmpFile.getAbsolutePath());
Node resultNode = XPathAPI.selectSingleNode(signedDocument, "ds:Signature/ds:Object/xades:QualifyingProperties/xades:SignedProperties/xades:SignedSignatureProperties/xades:SigningCertificate/xades:Cert/xades:CertDigest/ds:DigestValue", nsElement);
assertNotNull(resultNode);
// also test whether the XAdES extension is in line with the XAdES XML
// Schema.
// stax-api 1.0.1 prevents us from using
// "XMLConstants.W3C_XML_SCHEMA_NS_URI"
Node qualifyingPropertiesNode = XPathAPI.selectSingleNode(signedDocument, "ds:Signature/ds:Object/xades:QualifyingProperties", nsElement);
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
LSResourceResolver xadesResourceResolver = new XAdESLSResourceResolver();
factory.setResourceResolver(xadesResourceResolver);
InputStream schemaInputStream = XAdESSignatureFacetTest.class.getResourceAsStream("/XAdESv141.xsd");
Source schemaSource = new StreamSource(schemaInputStream);
Schema schema = factory.newSchema(schemaSource);
Validator validator = schema.newValidator();
// DOMResult gives some DOMException...
validator.validate(new DOMSource(qualifyingPropertiesNode));
StreamSource streamSource = new StreamSource(tmpFile.toURI().toString());
ByteArrayOutputStream resultOutputStream = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(resultOutputStream);
// validator.validate(streamSource, streamResult);
LOG.debug("result: " + resultOutputStream);
}Example 28
| Project: jaxws-master File: AbstractSchemaValidationTube.java View source code |
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, final String systemId, final String baseURI) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "type={0} namespaceURI={1} publicId={2} systemId={3} baseURI={4}", new Object[] { type, namespaceURI, publicId, systemId, baseURI });
}
try {
final SDDocument doc;
if (systemId == null) {
doc = nsMapping.get(namespaceURI);
} else {
URI rel = (baseURI != null) ? new URI(baseURI).resolve(systemId) : new URI(systemId);
doc = docs.get(rel.toString());
}
if (doc != null) {
return new LSInput() {
@Override
public Reader getCharacterStream() {
return null;
}
@Override
public void setCharacterStream(Reader characterStream) {
throw new UnsupportedOperationException();
}
@Override
public InputStream getByteStream() {
ByteArrayBuffer bab = new ByteArrayBuffer();
try {
doc.writeTo(null, resolver, bab);
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
return bab.newInputStream();
}
@Override
public void setByteStream(InputStream byteStream) {
throw new UnsupportedOperationException();
}
@Override
public String getStringData() {
return null;
}
@Override
public void setStringData(String stringData) {
throw new UnsupportedOperationException();
}
@Override
public String getSystemId() {
return doc.getURL().toExternalForm();
}
@Override
public void setSystemId(String systemId) {
throw new UnsupportedOperationException();
}
@Override
public String getPublicId() {
return null;
}
@Override
public void setPublicId(String publicId) {
throw new UnsupportedOperationException();
}
@Override
public String getBaseURI() {
return doc.getURL().toExternalForm();
}
@Override
public void setBaseURI(String baseURI) {
throw new UnsupportedOperationException();
}
@Override
public String getEncoding() {
return null;
}
@Override
public void setEncoding(String encoding) {
throw new UnsupportedOperationException();
}
@Override
public boolean getCertifiedText() {
return false;
}
@Override
public void setCertifiedText(boolean certifiedText) {
throw new UnsupportedOperationException();
}
};
}
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Exception in LSResourceResolver impl", e);
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Don''t know about systemId={0} baseURI={1}", new Object[] { systemId, baseURI });
}
return null;
}Example 29
| Project: mojarra-master File: DbfFactory.java View source code |
/**
* Load the schema for the given schema id.
*
* @param schemaMap the schema map.
* @param schemaId the schema id.
*/
private static void loadSchema(Map<FacesSchema, Schema> schemaMap, FacesSchema schemaId) {
URL url;
URLConnection conn;
InputStream in;
SchemaFactory factory;
File f;
Schema schema;
try {
switch(schemaId) {
case FACES_12:
url = DbfFactory.class.getResource(FACES_1_2_XSD);
if (url == null) {
// try to load from the file
f = new File(FACES_1_2_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facesconfig_1_2.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACES_11:
url = DbfFactory.class.getResource(FACES_1_1_XSD);
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACES_21:
url = DbfFactory.class.getResource(FACES_2_1_XSD);
if (url == null) {
// try to load from the file
f = new File(FACES_2_1_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facesconfig_2_1.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACES_22:
url = DbfFactory.class.getResource(FACES_2_2_XSD);
if (url == null) {
// try to load from the file
f = new File(FACES_2_2_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facesconfig_2_2.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACES_23:
url = DbfFactory.class.getResource(FACES_2_3_XSD);
if (url == null) {
// try to load from the file
f = new File(FACES_2_3_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facesconfig_2_3.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACES_20:
url = DbfFactory.class.getResource(FACES_2_0_XSD);
if (url == null) {
// try to load from the file
f = new File(FACES_2_0_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facesconfig_2_0.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACELET_TAGLIB_20:
url = DbfFactory.class.getResource(FACELET_TAGLIB_2_0_XSD);
if (url == null) {
// try to load from the file
f = new File(FACELET_TAGLIB_2_0_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facelettaglibrary_2_0.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
case FACELET_TAGLIB_22:
url = DbfFactory.class.getResource(FACELET_TAGLIB_2_2_XSD);
if (url == null) {
// try to load from the file
f = new File(FACELET_TAGLIB_2_2_XSD_FILE);
if (!f.exists()) {
throw new IllegalStateException("Unable to find web-facelettaglibrary_2_2.xsd");
}
url = f.toURI().toURL();
}
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
factory = Util.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
schema = factory.newSchema(new StreamSource(in));
schemaMap.put(schemaId, schema);
break;
default:
throw new ConfigurationException("Unrecognized Faces Version: " + schemaId.toString());
}
} catch (IllegalStateExceptionIOException | SAXException | ConfigurationException | e) {
throw new ConfigurationException(e);
}
}Example 30
| Project: wss4j-master File: WSSec.java View source code |
public static Schema loadWSSecuritySchemas() throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("schemas/XMLSchema.dtd", WSSec.class));
return concreteLSInput;
} else if ("XMLSchema.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("schemas/XMLSchema.dtd", WSSec.class));
return concreteLSInput;
} else if ("datatypes.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("schemas/datatypes.dtd", WSSec.class));
return concreteLSInput;
} else if ("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("schemas/xmldsig-core-schema.xsd", WSSec.class));
return concreteLSInput;
} else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("schemas/xml.xsd", WSSec.class));
return concreteLSInput;
}
return null;
}
});
Schema schema = schemaFactory.newSchema(new Source[] { new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/xml.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/soap-1.1.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/soap-1.2.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/exc-c14n.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/xmldsig-core-schema.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/xenc-schema.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/xenc-schema-11.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/xmldsig11-schema.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/oasis-200401-wss-wssecurity-utility-1.0.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/oasis-200401-wss-wssecurity-secext-1.0.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/oasis-wss-wssecurity-secext-1.1.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/ws-secureconversation-200502.xsd", WSSec.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("schemas/ws-secureconversation-1.3.xsd", WSSec.class)) });
return schema;
}Example 31
| Project: JDK-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
String normalizedName;
if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
} else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
fConfiguration.setFeature(normalizedName, state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// Try to set the property.
String normalizedName = name.toLowerCase(Locale.ENGLISH);
try {
fConfiguration.setProperty(normalizedName, value);
return;
} catch (XMLConfigurationException e) {
}
// If this is a boolean parameter a type mismatch should be thrown.
try {
if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
}
fConfiguration.getFeature(normalizedName);
throw newTypeMismatchError(name);
} catch (XMLConfigurationException e) {
}
// Parameter is not recognized
throw newFeatureNotFoundError(name);
}
}
}Example 32
| Project: jdk7u-jaxp-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
String normalizedName;
if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
} else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
fConfiguration.setFeature(normalizedName, state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// Try to set the property.
String normalizedName = name.toLowerCase(Locale.ENGLISH);
try {
fConfiguration.setProperty(normalizedName, value);
return;
} catch (XMLConfigurationException e) {
}
// If this is a boolean parameter a type mismatch should be thrown.
try {
if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
}
fConfiguration.getFeature(normalizedName);
throw newTypeMismatchError(name);
} catch (XMLConfigurationException e) {
}
// Parameter is not recognized
throw newFeatureNotFoundError(name);
}
}
}Example 33
| Project: boilerpipe-android-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
throw newFeatureNotSupportedError(name);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
throw newFeatureNotSupportedError(name);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
//MF
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "mf.org.apache.xerces.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
String normalizedName;
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
} else if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
} else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
fConfiguration.setFeature(normalizedName, state);
}
} catch (XMLConfigurationException e) {
throw newFeatureNotFoundError(name);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
throw newTypeMismatchError(name);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
throw newTypeMismatchError(name);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
ArrayList locations = new ArrayList();
locations.add(t.nextToken());
while (t.hasMoreTokens()) {
locations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, locations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
throw newTypeMismatchError(name);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
throw newTypeMismatchError(name);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// Try to set the property.
String normalizedName = name.toLowerCase(Locale.ENGLISH);
try {
fConfiguration.setProperty(normalizedName, value);
return;
} catch (XMLConfigurationException e) {
}
// If this is a boolean parameter a type mismatch should be thrown.
try {
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
} else if (name.equals(NAMESPACE_GROWTH)) {
normalizedName = NAMESPACE_GROWTH;
} else if (name.equals(TOLERATE_DUPLICATES)) {
normalizedName = TOLERATE_DUPLICATES;
}
fConfiguration.getFeature(normalizedName);
throw newTypeMismatchError(name);
} catch (XMLConfigurationException e) {
}
// Parameter is not recognized
throw newFeatureNotFoundError(name);
}
}
}Example 34
| Project: JFugue-for-Android-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "org.apache.xerces.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
fConfiguration.setFeature(name.toLowerCase(Locale.ENGLISH), state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// REVISIT: check if this is a boolean parameter -- type mismatch should be thrown.
//parameter is not recognized
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
}Example 35
| Project: topic-modeling-master File: DOMParserImpl.java View source code |
/**
* Set parameters and properties
*/
public void setParameter(String name, Object value) throws DOMException {
if (value instanceof Boolean) {
boolean state = ((Boolean) value).booleanValue();
try {
if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {
fConfiguration.setFeature(NORMALIZE_DATA, state);
} else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_DISALLOW_DOCTYPE)) {
fConfiguration.setFeature(DISALLOW_DOCTYPE_DECL_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_SUPPORTED_MEDIATYPES_ONLY) || name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS) || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION) || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)) {
if (state) {
// true is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting those features to false is no-op
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {
fConfiguration.setFeature(NAMESPACES, state);
} else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {
// Setting false has no effect.
if (state) {
// true: namespaces, namespace-declarations,
// comments, element-content-whitespace
fConfiguration.setFeature(NAMESPACES, true);
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, true);
fConfiguration.setFeature(INCLUDE_COMMENTS_FEATURE, true);
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, true);
// false: validate-if-schema, entities,
// datatype-normalization, cdata-sections
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
fConfiguration.setFeature(CREATE_ENTITY_REF_NODES, false);
fConfiguration.setFeature(NORMALIZE_DATA, false);
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {
fConfiguration.setFeature(CREATE_CDATA_NODES_FEATURE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)) {
fConfiguration.setFeature(Constants.DOM_NAMESPACE_DECLARATIONS, state);
} else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED) || name.equalsIgnoreCase(Constants.DOM_IGNORE_UNKNOWN_CHARACTER_DENORMALIZATIONS)) {
if (!state) {
// false is not supported
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_SUPPORTED", new Object[] { name });
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
// setting these features to true is no-op
// REVISIT: implement "namespace-declaration" feature
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {
fConfiguration.setFeature(VALIDATION_FEATURE, state);
if (fSchemaType != Constants.NS_DTD) {
fConfiguration.setFeature(XMLSCHEMA, state);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, state);
}
if (state) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)) {
fConfiguration.setFeature(DYNAMIC_VALIDATION, state);
// Note: validation and dynamic validation are mutually exclusive
if (state) {
fConfiguration.setFeature(VALIDATION_FEATURE, false);
}
} else if (name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {
fConfiguration.setFeature(INCLUDE_IGNORABLE_WHITESPACE, state);
} else if (name.equalsIgnoreCase(Constants.DOM_PSVI)) {
//XSModel - turn on PSVI augmentation
fConfiguration.setFeature(PSVI_AUGMENT, true);
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, "org.apache.xerces.dom.PSVIDocumentImpl");
} else {
// Constants.DOM_CHARSET_OVERRIDES_XML_ENCODING feature,
// Constants.DOM_SPLIT_CDATA feature,
// or any Xerces feature
String normalizedName;
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
} else {
normalizedName = name.toLowerCase(Locale.ENGLISH);
}
fConfiguration.setFeature(normalizedName, state);
}
} catch (XMLConfigurationException e) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
} else {
// set properties
if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {
if (value instanceof DOMErrorHandler || value == null) {
try {
fErrorHandler = new DOMErrorHandlerWrapper((DOMErrorHandler) value);
fConfiguration.setProperty(ERROR_HANDLER, fErrorHandler);
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {
if (value instanceof LSResourceResolver || value == null) {
try {
fConfiguration.setProperty(ENTITY_RESOLVER, new DOMEntityResolverWrapper((LSResourceResolver) value));
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
fSchemaLocation = null;
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, null);
} else {
fSchemaLocation = (String) value;
// map DOM schema-location to JAXP schemaSource property
// tokenize location string
StringTokenizer t = new StringTokenizer(fSchemaLocation, " \n\t\r");
if (t.hasMoreTokens()) {
fSchemaLocations.clear();
fSchemaLocations.add(t.nextToken());
while (t.hasMoreTokens()) {
fSchemaLocations.add(t.nextToken());
}
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, fSchemaLocations.toArray());
} else {
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE, value);
}
}
} catch (XMLConfigurationException e) {
}
} else {
// REVISIT: type mismatch
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {
if (value instanceof String || value == null) {
try {
if (value == null) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, null);
fSchemaType = null;
} else if (value.equals(Constants.NS_XMLSCHEMA)) {
// turn on schema features
fConfiguration.setFeature(XMLSCHEMA, true);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, true);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_XMLSCHEMA);
fSchemaType = Constants.NS_XMLSCHEMA;
} else if (value.equals(Constants.NS_DTD)) {
// turn off schema features
fConfiguration.setFeature(XMLSCHEMA, false);
fConfiguration.setFeature(XMLSCHEMA_FULL_CHECKING, false);
// map to JAXP schemaLanguage
fConfiguration.setProperty(Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE, Constants.NS_DTD);
fSchemaType = Constants.NS_DTD;
}
} catch (XMLConfigurationException e) {
}
} else {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
}
} else if (name.equalsIgnoreCase(DOCUMENT_CLASS_NAME)) {
fConfiguration.setProperty(DOCUMENT_CLASS_NAME, value);
} else {
// Try to set the property.
String normalizedName = name.toLowerCase(Locale.ENGLISH);
try {
fConfiguration.setProperty(normalizedName, value);
return;
} catch (XMLConfigurationException e) {
}
// If this is a boolean parameter a type mismatch should be thrown.
try {
// mixed case so requires special treatment.
if (name.equalsIgnoreCase(HONOUR_ALL_SCHEMALOCATIONS)) {
normalizedName = HONOUR_ALL_SCHEMALOCATIONS;
}
fConfiguration.getFeature(normalizedName);
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "TYPE_MISMATCH_ERR", new Object[] { name });
throw new DOMException(DOMException.TYPE_MISMATCH_ERR, msg);
} catch (XMLConfigurationException e) {
}
// Parameter is not recognized
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name });
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
}
}Example 36
| Project: expath-pkg-java-master File: PkgJaxpConfigurer.java View source code |
@Override
public void configSchemaFactory(SchemaFactory factory) {
LSResourceResolver r = new PkgLSResourceResolver(myRepo, URISpace.XSD);
factory.setResourceResolver(r);
}Example 37
| Project: JamVM-PH-master File: GrammarValidator.java View source code |
public LSResourceResolver getResourceResolver() {
return resourceResolver;
}Example 38
| Project: smooks-master File: XsdValidator.java View source code |
public void setSchemaSourceResolver(LSResourceResolver schemaSourceResolver) throws SAXException {
assertSchemaNotInitialized();
SchemaFactory schemaFactory = newSchemaFactory();
this.schemaSourceResolver = schemaSourceResolver;
this.schema = schemaFactory.newSchema();
}Example 39
| Project: eclipse-optimus-master File: XMLFileTransformationMaskDataSource.java View source code |
@Override
public LSResourceResolver getResourceResolver() {
return null;
}Example 40
| Project: werval-master File: SchemaFactoryRelaxNG.java View source code |
@Override
public void setResourceResolver(LSResourceResolver resourceResolver) {
delegate.setResourceResolver(resourceResolver);
}Example 41
| Project: JCGO-master File: XMLSchemaValidatorHandler.java View source code |
public LSResourceResolver getResourceResolver() {
return resourceResolver;
}Example 42
| Project: spring-framework-master File: Jaxb2Marshaller.java View source code |
/** * Set the resource resolver, as used to load the schema resources. * @see SchemaFactory#setResourceResolver(org.w3c.dom.ls.LSResourceResolver) * @see #setSchema(Resource) * @see #setSchemas(Resource[]) */ public void setSchemaResourceResolver(LSResourceResolver schemaResourceResolver) { this.schemaResourceResolver = schemaResourceResolver; }
Example 43
| Project: eclipselink.runtime-master File: XMLMappingTestCases.java View source code |
@Override
public void setResourceResolver(LSResourceResolver resourceResolver) {
}