Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 96064 invoked by uid 500); 6 Dec 2002 19:52:31 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 96050 invoked from network); 6 Dec 2002 19:52:31 -0000 Date: 6 Dec 2002 19:52:30 -0000 Message-ID: <20021206195230.48851.qmail@icarus.apache.org> From: ilene@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/java/src/org/apache/xalan/templates ElemPI.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ilene 2002/12/06 11:52:30 Modified: java/src/org/apache/xpath Tag: xslt20 NodeSetDTM.java NodeSet.java java/src/org/apache/xalan/transformer Tag: xslt20 TransformerImpl.java java/src/org/apache/xalan/processor Tag: xslt20 StylesheetHandler.java TransformerFactoryImpl.java java/src/org/apache/xalan/templates Tag: xslt20 ElemPI.java Log: Propogating changes from main branch... Eliminating some potential race conditions in StylesheetHandler and TransformerFactoryImpl by moving some of the initialization from the constructors into static initializers. Adding patch for 13863. Replacing some hard coded strings in NodeSet and NodeSetDTM. Updating ElemPI with patch from 5013...forgot to update this file in my previous commit. Revision Changes Path No revision No revision 1.10.2.1.2.2 +2 -2 xml-xalan/java/src/org/apache/xpath/NodeSetDTM.java Index: NodeSetDTM.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/NodeSetDTM.java,v retrieving revision 1.10.2.1.2.1 retrieving revision 1.10.2.1.2.2 diff -u -r1.10.2.1.2.1 -r1.10.2.1.2.2 --- NodeSetDTM.java 11 Nov 2002 19:51:17 -0000 1.10.2.1.2.1 +++ NodeSetDTM.java 6 Dec 2002 19:52:29 -0000 1.10.2.1.2.2 @@ -455,7 +455,7 @@ if (!m_cacheNodes) throw new RuntimeException( - "This NodeSetDTM can not iterate to a previous node!"); + XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null)); //"This NodeSetDTM can not iterate to a previous node!"); if ((m_next - 1) > 0) { @@ -522,7 +522,7 @@ if (!m_cacheNodes) throw new RuntimeException( - "This NodeSetDTM can not do indexing or counting functions!"); + XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null)); //"This NodeSetDTM can not do indexing or counting functions!"); if ((index >= 0) && (m_next < m_firstFree)) m_next = index; 1.15.2.1.2.1 +2 -2 xml-xalan/java/src/org/apache/xpath/NodeSet.java Index: NodeSet.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/NodeSet.java,v retrieving revision 1.15.2.1 retrieving revision 1.15.2.1.2.1 diff -u -r1.15.2.1 -r1.15.2.1.2.1 --- NodeSet.java 14 Aug 2002 20:06:56 -0000 1.15.2.1 +++ NodeSet.java 6 Dec 2002 19:52:29 -0000 1.15.2.1.2.1 @@ -307,7 +307,7 @@ if (!m_cacheNodes) throw new RuntimeException( - "This NodeSet can not iterate to a previous node!"); + XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_ITERATE, null)); //"This NodeSet can not iterate to a previous node!"); if ((m_next - 1) > 0) { @@ -362,7 +362,7 @@ if (!m_cacheNodes) throw new RuntimeException( - "This NodeSet can not do indexing or counting functions!"); + XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NODESET_CANNOT_INDEX, null)); //"This NodeSet can not do indexing or counting functions!"); if ((index >= 0) && (m_next < m_firstFree)) m_next = index; No revision No revision 1.133.2.1.2.3 +7 -0 xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java Index: TransformerImpl.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v retrieving revision 1.133.2.1.2.2 retrieving revision 1.133.2.1.2.3 diff -u -r1.133.2.1.2.2 -r1.133.2.1.2.3 --- TransformerImpl.java 25 Nov 2002 22:15:07 -0000 1.133.2.1.2.2 +++ TransformerImpl.java 6 Dec 2002 19:52:29 -0000 1.133.2.1.2.3 @@ -624,6 +624,13 @@ try { + // Patch for bugzilla #13863. If we don't reset the namespaceContext + // then we will get a NullPointerException if transformer is reused + // (for stylesheets that use xsl:key). Not sure if this should go + // here or in reset(). -is + if(getXPathContext().getNamespaceContext() == null){ + getXPathContext().setNamespaceContext(getStylesheet()); + } String base = source.getSystemId(); // If no systemID of the source, use the base of the stylesheet. No revision No revision 1.53.2.1.2.2 +25 -46 xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java Index: StylesheetHandler.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java,v retrieving revision 1.53.2.1.2.1 retrieving revision 1.53.2.1.2.2 diff -u -r1.53.2.1.2.1 -r1.53.2.1.2.2 --- StylesheetHandler.java 16 Aug 2002 21:23:47 -0000 1.53.2.1.2.1 +++ StylesheetHandler.java 6 Dec 2002 19:52:30 -0000 1.53.2.1.2.2 @@ -56,9 +56,7 @@ */ package org.apache.xalan.processor; -import java.util.EmptyStackException; import java.util.Stack; -import java.util.Vector; import javax.xml.transform.ErrorListener; import javax.xml.transform.SourceLocator; @@ -66,6 +64,7 @@ import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.sax.TemplatesHandler; + import org.apache.xalan.extensions.ExpressionVisitor; import org.apache.xalan.res.XSLMessages; import org.apache.xalan.res.XSLTErrorResources; @@ -88,8 +87,6 @@ import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.NamespaceSupport; @@ -104,6 +101,26 @@ implements TemplatesHandler, PrefixResolver, NodeConsumer { + static { + Function func = new org.apache.xalan.templates.FuncDocument(); + + SimpleNode.m_builtInFunctions.put(new QName("document"), func); + + // func = new org.apache.xalan.templates.FuncKey(); + // FunctionTable.installFunction("key", func); + func = new org.apache.xalan.templates.FuncFormatNumb(); + + SimpleNode.m_builtInFunctions.put(new QName("format-number"), func); + + func = new org.apache.xalan.templates.FuncCurrentGroup(); + + SimpleNode.m_builtInFunctions.put(new QName("current-group"), func); + + func = new org.apache.xalan.templates.FuncRegexGroup(); + + SimpleNode.m_builtInFunctions.put(new QName("regex-group"), func); + } + /** * Create a StylesheetHandler object, creating a root stylesheet * as the target. @@ -122,50 +139,12 @@ } /** - * Static flag to let us know if the XPath functions table - * has been initialized. - */ - private static boolean m_xpathFunctionsInited = false; - - /** * Do common initialization. * * @param processor non-null reference to the transformer factory that owns this handler. */ void init(TransformerFactoryImpl processor) { - - // Not sure about double-check of this flag, but - // it seems safe... - if (false == m_xpathFunctionsInited) - { - synchronized (this) - { - if (false == m_xpathFunctionsInited) - { - m_xpathFunctionsInited = true; - - Function func = new org.apache.xalan.templates.FuncDocument(); - - SimpleNode.m_builtInFunctions.put(new QName("document"), func); - - // func = new org.apache.xalan.templates.FuncKey(); - // FunctionTable.installFunction("key", func); - func = new org.apache.xalan.templates.FuncFormatNumb(); - - SimpleNode.m_builtInFunctions.put(new QName("format-number"), func); - - func = new org.apache.xalan.templates.FuncCurrentGroup(); - - SimpleNode.m_builtInFunctions.put(new QName("current-group"), func); - - func = new org.apache.xalan.templates.FuncRegexGroup(); - - SimpleNode.m_builtInFunctions.put(new QName("regex-group"), func); - } - } - } - m_stylesheetProcessor = processor; // Set the initial content handler. @@ -420,8 +399,8 @@ } if (null == elemProcessor) - error(rawName + " is not allowed in this position in the stylesheet!", - null); + error(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_ALLOWED_IN_POSITION, new Object[]{rawName}),null);//rawName + " is not allowed in this position in the stylesheet!", + return elemProcessor; } @@ -738,8 +717,8 @@ // If it's whitespace, just ignore it, otherwise flag an error. if (!XMLCharacterRecognizer.isWhiteSpace(ch, start, length)) error( - "Non-whitespace text is not allowed in this position in the stylesheet!", - null); + XSLMessages.createMessage(XSLTErrorResources.ER_NONWHITESPACE_NOT_ALLOWED_IN_POSITION, null),null);//"Non-whitespace text is not allowed in this position in the stylesheet!", + } else elemProcessor.characters(this, ch, start, length); 1.42.4.1 +5 -16 xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java Index: TransformerFactoryImpl.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v retrieving revision 1.42 retrieving revision 1.42.4.1 diff -u -r1.42 -r1.42.4.1 --- TransformerFactoryImpl.java 7 Jun 2002 17:13:54 -0000 1.42 +++ TransformerFactoryImpl.java 6 Dec 2002 19:52:30 -0000 1.42.4.1 @@ -121,16 +121,12 @@ public static String XSLT_PROPERTIES = "org/apache/xalan/res/XSLTInfo.properties"; - /** Flag tells if the properties file has been loaded to the system */ - private static boolean isInited = false; - - /** + /** * Constructor TransformerFactoryImpl * */ public TransformerFactoryImpl() { - loadPropertyFileToSystem(XSLT_PROPERTIES); } /** a zero length Class array used in loadPropertyFileToSystem() */ @@ -149,15 +145,10 @@ public static final String FEATURE_SOURCE_LOCATION = XalanProperties.SOURCE_LOCATION; /** - * Retrieve a propery bundle from a specified file and load it + * Retrieve a propery bundle from XSLT_PROPERTIES and load it * int the System properties. - * - * @param file The properties file to be processed. */ - private static void loadPropertyFileToSystem(String file) - { - - if (false == isInited) + static { try { @@ -171,7 +162,7 @@ java.lang.reflect.Method getCCL = Thread.class.getMethod("getContextClassLoader", NO_CLASSES); if (getCCL != null) { ClassLoader contextClassLoader = (ClassLoader) getCCL.invoke(Thread.currentThread(), NO_OBJS); - is = contextClassLoader.getResourceAsStream(file); // file should be already fully specified + is = contextClassLoader.getResourceAsStream(XSLT_PROPERTIES); // file should be already fully specified } } catch (Exception e) {} @@ -180,7 +171,7 @@ // NOTE! For the below getResourceAsStream in Sun JDK 1.1.8M // we apparently must add the leading slash character - I // don't know why, but if it's not there, we throw an NPE from the below loading - is = TransformerFactoryImpl.class.getResourceAsStream("/" + file); // file should be already fully specified + is = TransformerFactoryImpl.class.getResourceAsStream("/" + XSLT_PROPERTIES); // file should be already fully specified } // get a buffered version @@ -204,7 +195,6 @@ System.setProperties(systemProps); - isInited = true; } catch (Exception ex){} } @@ -213,7 +203,6 @@ // In this case the caller is required to have // the needed attributes already defined. - } } } No revision No revision 1.14.2.1.2.1 +17 -5 xml-xalan/java/src/org/apache/xalan/templates/ElemPI.java Index: ElemPI.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemPI.java,v retrieving revision 1.14.2.1 retrieving revision 1.14.2.1.2.1 diff -u -r1.14.2.1 -r1.14.2.1.2.1 --- ElemPI.java 14 Aug 2002 19:21:28 -0000 1.14.2.1 +++ ElemPI.java 6 Dec 2002 19:52:30 -0000 1.14.2.1.2.1 @@ -173,16 +173,28 @@ XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); - String piName = m_name_atv.evaluate(xctxt, sourceNode, this); + + String piName = m_name_atv == null ? null : m_name_atv.evaluate(xctxt, sourceNode, this); + + // Ignore processing instruction if name is null + if (piName == null) return; if (piName.equalsIgnoreCase("xml")) { - error(XSLTErrorResources.ER_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML); //"processing-instruction name can not be 'xml'"); + transformer.getMsgMgr().warn( + this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML, + new Object[]{ Constants.ATTRNAME_NAME, piName }); + return; } - else if (!isValidNCName(piName)) + + // Only check if an avt was used (ie. this wasn't checked at compose time.) + // Ignore processing instruction, if invalid + else if ((!m_name_atv.isSimple()) && (!isValidNCName(piName))) { - error(XSLTErrorResources.ER_PROCESSINGINSTRUCTION_NOTVALID_NCNAME, - new Object[]{ piName }); //"processing-instruction name must be a valid NCName: "+piName); + transformer.getMsgMgr().warn( + this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NOTVALID_NCNAME, + new Object[]{ Constants.ATTRNAME_NAME, piName }); + return; } // Note the content model is: --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: xalan-cvs-help@xml.apache.org