outputpropertiesfactory.java
来自「JAVA 所有包」· Java 代码 · 共 515 行 · 第 1/2 页
JAVA
515 行
{ if (null == m_xml_properties) // double check { 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 (null == m_html_properties) // double check { fileName = PROP_FILE_HTML; m_html_properties = loadPropertiesFile(fileName, m_xml_properties); } defaultProperties = m_html_properties; } else if (method.equals(Method.TEXT)) { if (null == m_text_properties) // double check { 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(com.sun.org.apache.xml.internal.serializer.Method.UNKNOWN)) { if (null == m_unknown_properties) // double check { 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); } // wrap these cached defaultProperties in a new Property object just so // that the caller of this method can't modify the default values return new Properties(defaultProperties); } /** * 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 \u003a 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. */ static private 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; } /** * Fix up a string in an output properties file according to * the rules of {@link #loadPropertiesFile}. * * @param s non-null reference to string that may need to be fixed up. * @return A new string if fixup occured, otherwise the s argument. */ static private String fixupPropertyString(String s, boolean doClipping) { int index; if (doClipping && s.startsWith(S_XSLT_PREFIX)) { s = s.substring(S_XSLT_PREFIX_LEN); } if (s.startsWith(S_XALAN_PREFIX)) { s = S_BUILTIN_EXTENSIONS_UNIVERSAL + s.substring(S_XALAN_PREFIX_LEN); } if ((index = s.indexOf("\\u003a")) > 0) { String temp = s.substring(index + 6); s = s.substring(0, index) + ":" + temp; } return s; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?