use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class XMLParser method importPrefs.
/***************************************************************************
* utilities for Preferences import
**************************************************************************/
static void importPrefs(InputStream in) throws IOException, InvalidPreferencesFormatException {
try {
// load XML document
Document doc = builder.parse(new InputSource(in));
// check preferences' export version
Element preferences;
preferences = doc.getDocumentElement();
String version = preferences.getAttribute("EXTERNAL_XML_VERSION");
if (version != null && Float.parseFloat(version) > XML_VERSION) {
throw new InvalidPreferencesFormatException("Preferences version " + version + " is not supported");
}
// check preferences root's type
Element root = (Element) preferences.getElementsByTagName("root").item(0);
Preferences prefsRoot = null;
String type = root.getAttribute("type");
if (type.equals("user")) {
prefsRoot = Preferences.userRoot();
} else {
prefsRoot = Preferences.systemRoot();
}
// load node
loadNode(prefsRoot, root);
} catch (FactoryConfigurationError e) {
throw new InvalidPreferencesFormatException(e);
} catch (SAXException e) {
throw new InvalidPreferencesFormatException(e);
}
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_Exception.
public void test_ConstructorLjava_lang_Exception() {
Exception e = new Exception();
// case 1: Try to create FactoryConfigurationError
// which is based on Exception without parameters.
FactoryConfigurationError fce = new FactoryConfigurationError(e);
assertNotNull(fce.getMessage());
assertNotNull(fce.getLocalizedMessage());
assertEquals(e.getCause(), fce.getCause());
// case 2: Try to create FactoryConfigurationError
// which is based on Exception with String parameter.
e = new Exception("test message");
fce = new FactoryConfigurationError(e);
assertEquals(e.toString(), fce.getMessage());
assertEquals(e.toString(), fce.getLocalizedMessage());
assertEquals(e.getCause(), fce.getCause());
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class FactoryConfigurationErrorTest method test_getException.
public void test_getException() {
FactoryConfigurationError fce = new FactoryConfigurationError();
assertNull(fce.getException());
fce = new FactoryConfigurationError("test");
assertNull(fce.getException());
Exception e = new Exception("msg");
fce = new FactoryConfigurationError(e);
assertEquals(e, fce.getException());
NullPointerException npe = new NullPointerException();
fce = new FactoryConfigurationError(npe);
assertEquals(npe, fce.getException());
}
use of javax.xml.parsers.FactoryConfigurationError in project bazel by bazelbuild.
the class DensitySpecificManifestProcessor method getSecureDocumentBuilder.
private static DocumentBuilder getSecureDocumentBuilder() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null);
factory.setValidating(false);
factory.setXIncludeAware(false);
for (Map.Entry<String, Boolean> featureAndValue : SECURE_XML_FEATURES.entrySet()) {
try {
factory.setFeature(featureAndValue.getKey(), featureAndValue.getValue());
} catch (ParserConfigurationException e) {
throw new FactoryConfigurationError(e, "Xerces DocumentBuilderFactory doesn't support the required security features: " + e.getMessage());
}
}
return factory.newDocumentBuilder();
}
use of javax.xml.parsers.FactoryConfigurationError in project j2objc by google.
the class XMLReaderManager method getXMLReader.
/**
* Retrieves a cached XMLReader for this thread, or creates a new
* XMLReader, if the existing reader is in use. When the caller no
* longer needs the reader, it must release it with a call to
* {@link #releaseXMLReader}.
*/
public synchronized XMLReader getXMLReader() throws SAXException {
XMLReader reader;
boolean readerInUse;
if (m_readers == null) {
// When the m_readers.get() method is called for the first time
// on a thread, a new XMLReader will automatically be created.
m_readers = new ThreadLocal();
}
if (m_inUse == null) {
m_inUse = new Hashtable();
}
// If the cached reader for this thread is in use, construct a new
// one; otherwise, return the cached reader.
reader = (XMLReader) m_readers.get();
boolean threadHasReader = (reader != null);
if (!threadHasReader || m_inUse.get(reader) == Boolean.TRUE) {
try {
try {
// According to JAXP 1.2 specification, if a SAXSource
// is created using a SAX InputSource the Transformer or
// TransformerFactory creates a reader via the
// XMLReaderFactory if setXMLReader is not used
reader = XMLReaderFactory.createXMLReader();
} catch (Exception e) {
try {
// the XMLReader from JAXP
if (m_parserFactory == null) {
m_parserFactory = SAXParserFactory.newInstance();
m_parserFactory.setNamespaceAware(true);
}
reader = m_parserFactory.newSAXParser().getXMLReader();
} catch (ParserConfigurationException pce) {
// pass along pce
throw pce;
}
}
try {
reader.setFeature(NAMESPACES_FEATURE, true);
reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
} catch (SAXException se) {
// Try to carry on if we've got a parser that
// doesn't know about namespace prefixes.
}
} catch (ParserConfigurationException ex) {
throw new SAXException(ex);
} catch (FactoryConfigurationError ex1) {
throw new SAXException(ex1.toString());
} catch (NoSuchMethodError ex2) {
} catch (AbstractMethodError ame) {
}
// a reader for this thread.
if (!threadHasReader) {
m_readers.set(reader);
m_inUse.put(reader, Boolean.TRUE);
}
} else {
m_inUse.put(reader, Boolean.TRUE);
}
return reader;
}
Aggregations