sboag 01/03/26 13:35:47 Modified: java/src/org/apache/xalan/templates OutputProperties.java Log: Patches submitted by Patrick Moore <[EMAIL PROTECTED]> on 03/15/2001 01:25 PM: This proposed change does a number of things: 1. Problem: HTML output method does not uses XML output properties as default. In both org/apache/xalan/templates/output_html.properties and in the java doc for org/apache/xalan/templates/OutputProperties#getDefaultMethodProperties(Strin g) It specifically states that all OutputProperties use the output_xml.properties as a base. In the code this is not true for html. This is now changed to match the comments 2. Problem: unclear IOException. If there was a problem loading the XML properties file. The wrapped exception now will say which file was trying to be loaded. If the file did not exist I was getting a very strange "Stream closed" IOException message. 3. Problem: the streams were not closed after reading the property file. Fixed. 4. Problem: the double-check locking mechanism does not work in Java (see bug #919) <http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html> 5. QUESTION: now if there is a default properties (i.e. output_xml.properties has been loaded) but the expected properties file does not exist a error message will be printed to System.err and the processing will continuing using just the default properties (output_xml.properties) I felt that this is the best behavior. (comment by sboag: I think it's better to throw a runtime exception in this case. but we can discuss this over time. For now the patch was modified to do the runtime exception). Revision Changes Path 1.13 +36 -28 xml-xalan/java/src/org/apache/xalan/templates/OutputProperties.java Index: OutputProperties.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/OutputProperties.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- OutputProperties.java 2001/03/18 09:26:58 1.12 +++ OutputProperties.java 2001/03/26 21:35:46 1.13 @@ -182,11 +182,28 @@ { Properties props = new Properties(defaults); - InputStream is = OutputProperties.class.getResourceAsStream( - resourceName); - BufferedInputStream bis = new BufferedInputStream(is); - + InputStream is = null; + BufferedInputStream bis = null; + try { + is = OutputProperties.class.getResourceAsStream(resourceName); + bis = new BufferedInputStream(is); props.load(bis); + } catch (IOException ioe) { + if ( defaults == null ) { + throw ioe; + } + else + { + throw new WrappedRuntimeException("Could not load '"+resourceName+"' (check CLASSPATH) using just the defaults ", ioe); + } + } 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 @@ -234,19 +251,18 @@ */ static public Properties getDefaultMethodProperties(String method) { - + String fileName = null; Properties defaultProperties = null; - + // According to this article : Double-check locking does not work + // http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-toolbox.html try { - if (null == m_xml_properties) // fast check + synchronized (m_synch_object) { - synchronized (m_synch_object) + if (null == m_xml_properties) // double check { - if (null == m_xml_properties) // double check - { - m_xml_properties = loadPropertiesFile("output_xml.properties", null); - } + fileName = "output_xml.properties"; + m_xml_properties = loadPropertiesFile(fileName, null); } } @@ -256,38 +272,28 @@ } else if (method.equals(Method.HTML)) { - if (null == m_html_properties) // fast check - { - synchronized (m_synch_object) - { if (null == m_html_properties) // double check { - m_html_properties = loadPropertiesFile("output_html.properties", + fileName = "output_html.properties"; + m_html_properties = loadPropertiesFile(fileName, m_xml_properties); } - } - } defaultProperties = m_html_properties; } else if (method.equals(Method.Text)) { - if (null == m_text_properties) // fast check - { - synchronized (m_synch_object) - { if (null == m_text_properties) // double check { - m_text_properties = loadPropertiesFile("output_text.properties", - null); + fileName = "output_text.properties"; + m_text_properties = loadPropertiesFile(fileName, + m_xml_properties); if(null == m_text_properties.getProperty(OutputKeys.ENCODING)) { String mimeEncoding = org.apache.xalan.serialize.Encodings.getMimeEncoding(null); m_text_properties.put(OutputKeys.ENCODING, mimeEncoding); } } - } - } defaultProperties = m_text_properties; } @@ -300,7 +306,9 @@ } catch (IOException ioe) { - throw new org.apache.xml.utils.WrappedRuntimeException(ioe); + throw new WrappedRuntimeException( + "Output method is "+method+" could not load "+fileName+" (check CLASSPATH)", + ioe); } return defaultProperties;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
