use of org.xml.sax.SAXNotRecognizedException in project Payara by payara.
the class GenericParser method newSAXParser.
/**
* Create a <code>SAXParser</code> configured to support XML Scheman and DTD
* @param properties parser specific properties/features
* @return an XML Schema/DTD enabled <code>SAXParser</code>
*/
public static SAXParser newSAXParser(Properties properties) throws ParserConfigurationException, SAXException, SAXNotRecognizedException {
SAXParserFactory factory = (SAXParserFactory) properties.get("SAXParserFactory");
SAXParser parser = factory.newSAXParser();
String schemaLocation = (String) properties.get("schemaLocation");
String schemaLanguage = (String) properties.get("schemaLanguage");
try {
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, parser.getClass().getName() + ": " + e.getMessage() + " not supported.");
}
}
return parser;
}
use of org.xml.sax.SAXNotRecognizedException in project Payara by payara.
the class DeploymentDescriptorFile method getSAXParser.
/**
* @return a SAX Parser to read an XML file (containing
* Deployment Descriptors) into DOL descriptors
*
* @param validating true if the parser should excercise DTD validation
*/
public SAXParser getSAXParser(boolean validating) {
// always use system SAXParser to parse DDs, see IT 8229
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
// set the namespace awareness
spf.setNamespaceAware(true);
// turn validation on for deployment descriptor XML files
spf.setValidating(validating);
if (!validating) {
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
}
// with crimson
if (spf.getClass().getName().indexOf("xerces") != -1) {
spf.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
} else {
DOLUtils.getDefaultLogger().log(Level.WARNING, "modify your java command line to include the -Djava.endorsed.dirs option");
}
try {
if (!validating) {
// if we are not validating, let's not load the DTD
if (getDeploymentDescriptorPath().indexOf(DescriptorConstants.WLS) != -1) {
// and let's only turn it off for weblogic*.xml for now
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
}
}
// Validation part 2a: set the schema language if necessary
spf.setFeature("http://apache.org/xml/features/validation/schema", validating);
SAXParser sp = spf.newSAXParser();
// put the default schema for this deployment file type
String path = getDefaultSchemaSource();
if (path != null) {
sp.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", path);
}
// Set Xerces feature to allow dynamic validation. This prevents
// SAX errors from being reported when no schemaLocation attr
// is seen for a DTD based (J2EE1.3) XML descriptor.
sp.getXMLReader().setFeature("http://apache.org/xml/features/validation/dynamic", validating);
return sp;
} catch (SAXNotRecognizedException x) {
// This can happen if the parser does not support JAXP 1.2
DOLUtils.getDefaultLogger().log(Level.SEVERE, "INFO: JAXP SAXParser property not recognized: " + SaxParserHandler.JAXP_SCHEMA_LANGUAGE);
DOLUtils.getDefaultLogger().log(Level.SEVERE, "Check to see if parser conforms to JAXP 1.2 spec.");
}
} catch (Exception e) {
DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.saxParserError", new Object[] { e.getMessage() });
DOLUtils.getDefaultLogger().log(Level.WARNING, "Error occurred", e);
} finally {
Thread.currentThread().setContextClassLoader(currentLoader);
}
return null;
}
use of org.xml.sax.SAXNotRecognizedException in project iosched by google.
the class SVGParser method parse.
static SVG parse(InputSource data, SVGHandler handler) throws SVGParseException {
try {
final Picture picture = new Picture();
handler.setPicture(picture);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(handler);
xr.setFeature("http://xml.org/sax/features/validation", false);
if (DISALLOW_DOCTYPE_DECL) {
try {
xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
} catch (SAXNotRecognizedException e) {
DISALLOW_DOCTYPE_DECL = false;
}
}
xr.parse(data);
SVG result = new SVG(picture, handler.bounds);
// Skip bounds if it was an empty pic
if (!Float.isInfinite(handler.limits.top)) {
result.setLimits(handler.limits);
}
return result;
} catch (Exception e) {
Log.e(TAG, "Failed to parse SVG.", e);
throw new SVGParseException(e);
}
}
use of org.xml.sax.SAXNotRecognizedException in project robovm by robovm.
the class SAXParserTest method testSetGetProperty.
public void testSetGetProperty() {
// Ordinary case
String validName = "http://xml.org/sax/properties/lexical-handler";
LexicalHandler validValue = new MockHandler(new MethodLogger());
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty(validName, validValue);
assertEquals(validValue, parser.getProperty(validName));
parser.setProperty(validName, null);
assertEquals(null, parser.getProperty(validName));
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
// Unsupported property
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty("foo", "bar");
fail("SAXNotRecognizedException expected");
} catch (SAXNotRecognizedException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
try {
SAXParser parser = spf.newSAXParser();
parser.getProperty("foo");
fail("SAXNotRecognizedException expected");
} catch (SAXNotRecognizedException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
// No name case
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty(null, "bar");
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
try {
SAXParser parser = spf.newSAXParser();
parser.getProperty(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
}
use of org.xml.sax.SAXNotRecognizedException in project robovm by robovm.
the class SAXNotRecognizedExceptionTest method testSAXNotRecognizedException.
public void testSAXNotRecognizedException() {
SAXNotRecognizedException e = new SAXNotRecognizedException();
assertNull(e.getMessage());
}
Aggregations