use of javax.xml.parsers.FactoryConfigurationError in project j2objc by google.
the class DocumentBuilderFactoryTest method test_newInstance.
/* public void test_isSetXIncludeAware() {
dbf.setXIncludeAware(true);
assertTrue(dbf.isXIncludeAware());
dbf.setXIncludeAware(false);
assertFalse(dbf.isXIncludeAware());
}
*/
/**
* 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 j2objc by google.
the class FactoryConfigurationErrorTest method test_ConstructorLjava_lang_ExceptionLjava_lang_String.
public void test_ConstructorLjava_lang_ExceptionLjava_lang_String() {
Exception e = new Exception();
// case 1: Try to create FactoryConfigurationError
// which is based on Exception without parameters.
FactoryConfigurationError fce = new FactoryConfigurationError(e, "msg");
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, "msg");
assertEquals("msg", fce.getMessage());
assertEquals("msg", fce.getLocalizedMessage());
assertEquals(e.getCause(), fce.getCause());
}
use of javax.xml.parsers.FactoryConfigurationError in project j2objc by google.
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 j2objc by google.
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 XobotOS by xamarin.
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);
}
}
Aggregations