use of java.util.InvalidPropertiesFormatException in project jena by apache.
the class Metadata method read.
// Protect all classloader choosing -- sometimes systems mess with even the system class loader.
private static void read(Properties properties, String resourceName) {
// Armour-plate this - classloaders and using them can be blocked by some environments.
try {
ClassLoader classLoader = null;
try {
classLoader = SystemUtils.chooseClassLoader();
} catch (ARQException ex) {
}
if (classLoader == null) {
try {
classLoader = Metadata.class.getClassLoader();
} catch (ARQException ex) {
}
}
if (classLoader == null) {
Log.error(Metadata.class, "No classloader");
return;
}
InputStream in = classLoader.getResourceAsStream(resourceName);
if (in == null)
// In development, there is no properties file.
return;
try {
properties.loadFromXML(in);
} catch (InvalidPropertiesFormatException ex) {
throw new ARQException("Invalid properties file", ex);
} catch (IOException ex) {
throw new ARQException("Metadata ==> IOException", ex);
}
} catch (Throwable ex) {
Log.error(Metadata.class, "Unexpected Thorwable", ex);
return;
}
}
use of java.util.InvalidPropertiesFormatException in project Bytecoder by mirkosertic.
the class PropertiesDefaultHandler method load.
public void load(Properties props, InputStream in) throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException {
this.properties = props;
try {
SAXParser parser = new SAXParserImpl();
parser.parse(in, this);
} catch (SAXException saxe) {
throw new InvalidPropertiesFormatException(saxe);
}
/**
* String xmlVersion = propertiesElement.getAttribute("version"); if
* (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
* InvalidPropertiesFormatException( "Exported Properties file format
* version " + xmlVersion + " is not supported. This java installation
* can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
* " may need to install a newer version of JDK.");
*/
}
use of java.util.InvalidPropertiesFormatException in project ofbiz-framework by apache.
the class UtilProperties method xmlToProperties.
/**
* Convert XML property file to Properties instance. This method will convert
* both the Java XML properties file format and the OFBiz custom XML
* properties file format.
*
* <p>The format of the custom XML properties file is:</p>
* <pre>
* {@code
* <resource>
* <property key="key">
* <value xml:lang="locale 1">Some value</value>
* <value xml:lang="locale 2">Some value</value>
* ...
* </property>
* ...
* </resource>
* }
* </pre>
* where <em>"locale 1", "locale 2"</em> are valid xml:lang values..
*
* @param in XML file InputStream
* @param locale The desired locale
* @param properties Optional Properties object to populate
* @return Properties instance or null if not found
*/
public static Properties xmlToProperties(InputStream in, Locale locale, Properties properties) throws IOException, InvalidPropertiesFormatException {
if (in == null) {
throw new IllegalArgumentException("InputStream cannot be null");
}
Document doc = null;
try {
doc = UtilXml.readXmlDocument(in, true, "XML Properties file");
in.close();
} catch (Exception e) {
Debug.logWarning(e, "XML file for locale " + locale + " could not be loaded.", module);
in.close();
return null;
}
Element resourceElement = doc.getDocumentElement();
List<? extends Element> propertyList = UtilXml.childElementList(resourceElement, "property");
if (UtilValidate.isNotEmpty(propertyList)) {
// Custom XML properties file format
if (locale == null) {
throw new IllegalArgumentException("locale cannot be null");
}
String localeString = locale.toString();
String correctedLocaleString = localeString.replace('_', '-');
for (Element property : propertyList) {
// Support old way of specifying xml:lang value.
// Old way: en_AU, new way: en-AU
Element value = UtilXml.firstChildElement(property, "value", "xml:lang", correctedLocaleString);
if (value == null) {
value = UtilXml.firstChildElement(property, "value", "xml:lang", localeString);
}
if (value != null) {
if (properties == null) {
properties = new Properties();
}
String valueString = UtilXml.elementValue(value);
if (valueString != null) {
properties.put(property.getAttribute("key"), valueString);
}
}
}
return properties;
}
propertyList = UtilXml.childElementList(resourceElement, "entry");
if (UtilValidate.isEmpty(propertyList)) {
throw new InvalidPropertiesFormatException("XML properties file invalid or empty");
}
// Java XML properties file format
for (Element property : propertyList) {
String value = UtilXml.elementValue(property);
if (value != null) {
if (properties == null) {
properties = new Properties();
}
properties.put(property.getAttribute("key"), value);
}
}
return properties;
}
use of java.util.InvalidPropertiesFormatException in project jena by apache.
the class Metadata method read.
// Protect all classloader choosing -- sometimes systems mess with even the system
// class loader.
private static void read(Properties properties, String resourceName) {
// environments.
try {
ClassLoader classLoader = null;
try {
classLoader = SystemUtils.chooseClassLoader();
} catch (AtlasException ex) {
}
if (classLoader == null) {
try {
classLoader = Metadata.class.getClassLoader();
} catch (AtlasException ex) {
}
}
if (classLoader == null) {
Log.error(Metadata.class, "No classloader");
return;
}
InputStream in = classLoader.getResourceAsStream(resourceName);
if (in == null)
return;
try {
properties.loadFromXML(in);
} catch (InvalidPropertiesFormatException ex) {
throw new JenaException("Invalid properties file", ex);
} catch (IOException ex) {
throw new RuntimeIOException("Metadata ==> IOException", ex);
}
} catch (Throwable ex) {
Log.error(Metadata.class, "Unexpected Throwable", ex);
return;
}
}
use of java.util.InvalidPropertiesFormatException in project j2objc by google.
the class PropertiesXmlLoader method load.
public void load(final Properties p, InputStream in) throws IOException, InvalidPropertiesFormatException {
if (in == null) {
throw new NullPointerException("in == null");
}
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(new DefaultHandler() {
private String key;
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
key = null;
if (qName.equals("entry")) {
key = attributes.getValue("key");
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (key != null) {
String value = new String(ch, start, length);
p.put(key, value);
key = null;
}
}
});
reader.parse(new InputSource(in));
} catch (SAXException e) {
throw new InvalidPropertiesFormatException(e);
}
}
Aggregations