use of javax.xml.parsers.FactoryConfigurationError in project j2objc by google.
the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_String.
public void test_ConstructorLjava_lang_String() {
FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
assertEquals("Oops!", fce.getMessage());
assertEquals("Oops!", fce.getLocalizedMessage());
assertNull(fce.getCause());
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
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;
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class SAXParserFactoryTest method test_newInstance.
@KnownFailure("Dalvik doesn't honor system properties when choosing a SAX implementation")
public void test_newInstance() {
try {
SAXParserFactory dtf = SAXParserFactory.newInstance();
assertNotNull("New Instance of DatatypeFactory is null", dtf);
System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.harmony.xml.parsers.SAXParserFactoryImpl");
SAXParserFactory spf1 = SAXParserFactory.newInstance();
assertTrue(spf1 instanceof org.apache.harmony.xml.parsers.SAXParserFactoryImpl);
String key = "javax.xml.parsers.SAXParserFactory = org.apache.harmony.xml.parsers.SAXParserFactoryImpl";
ByteArrayInputStream bis = new ByteArrayInputStream(key.getBytes());
Properties prop = System.getProperties();
prop.load(bis);
SAXParserFactory spf2 = SAXParserFactory.newInstance();
assertTrue(spf2 instanceof org.apache.harmony.xml.parsers.SAXParserFactoryImpl);
System.setProperty("javax.xml.parsers.SAXParserFactory", "");
try {
SAXParserFactory.newInstance();
fail("Expected FactoryConfigurationError was not thrown");
} catch (FactoryConfigurationError e) {
// expected
}
} catch (IOException ioe) {
fail("Unexpected exception " + ioe.toString());
}
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class DocumentBuilderFactoryTest method test_newInstance.
/**
* javax.xml.parsers.DocumentBuilderFactory#newInstance().
*/
public void test_newInstance() {
String className = null;
try {
// case 1: Try to obtain a new instance of factory by default.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
assertNotNull(dbf);
// case 2: Try to create a new instance of factory using
// property DATATYPEFACTORY_PROPERTY
className = System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl");
dbf = DocumentBuilderFactory.newInstance();
assertNotNull(dbf);
assertTrue(dbf instanceof org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl);
// case 3: Try to create a new instance of factory using Property
String keyValuePair = "javax.xml.parsers.DocumentBuilderFactory" + "=" + "org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl";
ByteArrayInputStream bis = new ByteArrayInputStream(keyValuePair.getBytes());
Properties prop = System.getProperties();
prop.load(bis);
dbf = DocumentBuilderFactory.newInstance();
assertNotNull(dbf);
assertTrue(dbf instanceof org.apache.harmony.xml.parsers.DocumentBuilderFactoryImpl);
// case 4: Check FactoryConfiguration error
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "");
try {
DocumentBuilderFactory.newInstance();
} catch (FactoryConfigurationError fce) {
// expected
}
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
} finally {
// because of this test modifies it.
if (className == null) {
System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
} else {
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", className);
}
}
}
use of javax.xml.parsers.FactoryConfigurationError in project robovm by robovm.
the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_String.
public void test_ConstructorLjava_lang_String() {
FactoryConfigurationError fce = new FactoryConfigurationError("Oops!");
assertEquals("Oops!", fce.getMessage());
assertEquals("Oops!", fce.getLocalizedMessage());
assertNull(fce.getCause());
}
Aggregations