use of org.apache.xml.serializer.utils.WrappedRuntimeException in project robovm by robovm.
the class ToStream method serialize.
/**
* Serializes the DOM node. Throws an exception only if an I/O
* exception occured while serializing.
*
* @param node Node to serialize.
* @throws IOException An I/O exception occured while serializing
*/
public void serialize(Node node) throws IOException {
try {
TreeWalker walker = new TreeWalker(this);
walker.traverse(node);
} catch (org.xml.sax.SAXException se) {
throw new WrappedRuntimeException(se);
}
}
use of org.apache.xml.serializer.utils.WrappedRuntimeException in project robovm by robovm.
the class DOM3SerializerImpl method serializeDOM3.
/**
* Serializes the Level 3 DOM node by creating an instance of DOM3TreeWalker
* which traverses the DOM tree and invokes handler events to serialize
* the DOM NOde. Throws an exception only if an I/O exception occured
* while serializing.
* This interface is a public API.
*
* @param node the Level 3 DOM node to serialize
* @throws IOException if an I/O exception occured while serializing
*/
public void serializeDOM3(Node node) throws IOException {
try {
DOM3TreeWalker walker = new DOM3TreeWalker(fSerializationHandler, fErrorHandler, fSerializerFilter, fNewLine);
walker.traverse(node);
} catch (org.xml.sax.SAXException se) {
throw new WrappedRuntimeException(se);
}
}
use of org.apache.xml.serializer.utils.WrappedRuntimeException in project robovm by robovm.
the class CharInfo method getCharInfo.
/**
* Factory that reads in a resource file that describes the mapping of
* characters to entity references.
*
* Resource files must be encoded in UTF-8 and have a format like:
* <pre>
* # First char # is a comment
* Entity numericValue
* quot 34
* amp 38
* </pre>
* (Note: Why don't we just switch to .properties files? Oct-01 -sc)
*
* @param entitiesResource Name of entities resource file that should
* be loaded, which describes that mapping of characters to entity references.
* @param method the output method type, which should be one of "xml", "html", "text"...
*
* @xsl.usage internal
*/
static CharInfo getCharInfo(String entitiesFileName, String method) {
CharInfo charInfo = (CharInfo) m_getCharInfoCache.get(entitiesFileName);
if (charInfo != null) {
return mutableCopyOf(charInfo);
}
// try to load it internally - cache
try {
charInfo = getCharInfoBasedOnPrivilege(entitiesFileName, method, true);
// Put the common copy of charInfo in the cache, but return
// a copy of it.
m_getCharInfoCache.put(entitiesFileName, charInfo);
return mutableCopyOf(charInfo);
} catch (Exception e) {
}
// try to load it externally - do not cache
try {
return getCharInfoBasedOnPrivilege(entitiesFileName, method, false);
} catch (Exception e) {
}
String absoluteEntitiesFileName;
if (entitiesFileName.indexOf(':') < 0) {
absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURIFromRelative(entitiesFileName);
} else {
try {
absoluteEntitiesFileName = SystemIDResolver.getAbsoluteURI(entitiesFileName, null);
} catch (TransformerException te) {
throw new WrappedRuntimeException(te);
}
}
return getCharInfoBasedOnPrivilege(entitiesFileName, method, false);
}
use of org.apache.xml.serializer.utils.WrappedRuntimeException in project robovm by robovm.
the class OutputPropertiesFactory method getDefaultMethodProperties.
/**
* Creates an empty OutputProperties with the property key/value defaults specified by
* a property file. The method argument is used to construct a string of
* the form output_[method].properties (for instance, output_html.properties).
* The output_xml.properties file is always used as the base.
*
* <p>Anything other than 'text', 'xml', and 'html', will
* use the output_xml.properties file.</p>
*
* @param method non-null reference to method name.
*
* @return Properties object that holds the defaults for the given method.
*/
public static final Properties getDefaultMethodProperties(String method) {
String fileName = null;
Properties defaultProperties = null;
// http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html
try {
synchronized (m_synch_object) {
if (// double check
null == m_xml_properties) {
fileName = PROP_FILE_XML;
m_xml_properties = loadPropertiesFile(fileName, null);
}
}
if (method.equals(Method.XML)) {
defaultProperties = m_xml_properties;
} else if (method.equals(Method.HTML)) {
if (// double check
null == m_html_properties) {
fileName = PROP_FILE_HTML;
m_html_properties = loadPropertiesFile(fileName, m_xml_properties);
}
defaultProperties = m_html_properties;
} else if (method.equals(Method.TEXT)) {
if (// double check
null == m_text_properties) {
fileName = PROP_FILE_TEXT;
m_text_properties = loadPropertiesFile(fileName, m_xml_properties);
if (null == m_text_properties.getProperty(OutputKeys.ENCODING)) {
String mimeEncoding = Encodings.getMimeEncoding(null);
m_text_properties.put(OutputKeys.ENCODING, mimeEncoding);
}
}
defaultProperties = m_text_properties;
} else if (method.equals(Method.UNKNOWN)) {
if (// double check
null == m_unknown_properties) {
fileName = PROP_FILE_UNKNOWN;
m_unknown_properties = loadPropertiesFile(fileName, m_xml_properties);
}
defaultProperties = m_unknown_properties;
} else {
// TODO: Calculate res file from name.
defaultProperties = m_xml_properties;
}
} catch (IOException ioe) {
throw new WrappedRuntimeException(Utils.messages.createMessage(MsgKey.ER_COULD_NOT_LOAD_METHOD_PROPERTY, new Object[] { fileName, method }), ioe);
}
// that the caller of this method can't modify the default values
return new Properties(defaultProperties);
}
use of org.apache.xml.serializer.utils.WrappedRuntimeException in project robovm by robovm.
the class OutputPropertiesFactory method loadPropertiesFile.
/**
* Load the properties file from a resource stream. If a
* key name such as "org.apache.xslt.xxx", fix up the start of
* string to be a curly namespace. If a key name starts with
* "xslt.output.xxx", clip off "xslt.output.". If a key name *or* a
* key value is discovered, check for : in the text, and
* fix it up to be ":", since earlier versions of the JDK do not
* handle the escape sequence (at least in key names).
*
* @param resourceName non-null reference to resource name.
* @param defaults Default properties, which may be null.
*/
private static Properties loadPropertiesFile(final String resourceName, Properties defaults) throws IOException {
// This static method should eventually be moved to a thread-specific class
// so that we can cache the ContextClassLoader and bottleneck all properties file
// loading throughout Xalan.
Properties props = new Properties(defaults);
InputStream is = null;
BufferedInputStream bis = null;
try {
if (ACCESS_CONTROLLER_CLASS != null) {
is = (InputStream) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return OutputPropertiesFactory.class.getResourceAsStream(resourceName);
}
});
} else {
// User may be using older JDK ( JDK < 1.2 )
is = OutputPropertiesFactory.class.getResourceAsStream(resourceName);
}
bis = new BufferedInputStream(is);
props.load(bis);
} catch (IOException ioe) {
if (defaults == null) {
throw ioe;
} else {
throw new WrappedRuntimeException(Utils.messages.createMessage(MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] { resourceName }), ioe);
//"Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ", ioe);
}
} catch (SecurityException se) {
// Repeat IOException handling for sandbox/applet case -sc
if (defaults == null) {
throw se;
} else {
throw new WrappedRuntimeException(Utils.messages.createMessage(MsgKey.ER_COULD_NOT_LOAD_RESOURCE, new Object[] { resourceName }), se);
//"Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the defaults ", se);
}
} finally {
if (bis != null) {
bis.close();
}
if (is != null) {
is.close();
}
}
// Note that we're working at the HashTable level here,
// and not at the Properties level! This is important
// because we don't want to modify the default properties.
// NB: If fixupPropertyString ends up changing the property
// name or value, we need to remove the old key and re-add
// with the new key and value. However, then our Enumeration
// could lose its place in the HashTable. So, we first
// clone the HashTable and enumerate over that since the
// clone will not change. When we migrate to Collections,
// this code should be revisited and cleaned up to use
// an Iterator which may (or may not) alleviate the need for
// the clone. Many thanks to Padraig O'hIceadha
// <padraig@gradient.ie> for finding this problem. Bugzilla 2000.
Enumeration keys = ((Properties) props.clone()).keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
// Now check if the given key was specified as a
// System property. If so, the system property
// overides the default value in the propery file.
String value = null;
try {
value = System.getProperty(key);
} catch (SecurityException se) {
// No-op for sandbox/applet case, leave null -sc
}
if (value == null)
value = (String) props.get(key);
String newKey = fixupPropertyString(key, true);
String newValue = null;
try {
newValue = System.getProperty(newKey);
} catch (SecurityException se) {
// No-op for sandbox/applet case, leave null -sc
}
if (newValue == null)
newValue = fixupPropertyString(value, false);
else
newValue = fixupPropertyString(newValue, false);
if (key != newKey || value != newValue) {
props.remove(key);
props.put(newKey, newValue);
}
}
return props;
}
Aggregations