sboag 01/05/26 20:05:17 Modified: java/src/org/apache/xalan/extensions Tag: DTM_EXP ExtensionHandler.java ExtensionHandlerGeneral.java MethodResolver.java java/src/org/apache/xalan/processor Tag: DTM_EXP ProcessorInclude.java TransformerFactoryImpl.java XSLTElementProcessor.java XSLTSchema.java java/src/org/apache/xalan/res Tag: DTM_EXP XSLTErrorResources.java java/src/org/apache/xalan/serialize Tag: DTM_EXP CharInfo.java java/src/org/apache/xalan/templates Tag: DTM_EXP ElemChoose.java ElemCopy.java ElemValueOf.java OutputProperties.java java/src/org/apache/xalan/transformer Tag: DTM_EXP ResultTreeHandler.java TransformSnapshotImpl.java TransformerIdentityImpl.java TransformerImpl.java TreeWalker2Result.java java/src/org/apache/xalan/xslt Tag: DTM_EXP Process.java java/src/org/apache/xml/utils Tag: DTM_EXP TreeWalker.java java/src/org/apache/xpath Tag: DTM_EXP XPath.java XPathAPI.java java/src/org/apache/xpath/axes Tag: DTM_EXP DescendantIterator.java java/src/org/apache/xpath/functions Tag: DTM_EXP FuncCurrent.java FuncExtFunction.java FuncSystemProperty.java java/src/org/apache/xpath/objects Tag: DTM_EXP XObject.java XString.java Log: Myriam's merges from the main branch. Revision Changes Path No revision No revision 1.12.2.2 +1 -1 xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandler.java Index: ExtensionHandler.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandler.java,v retrieving revision 1.12.2.1 retrieving revision 1.12.2.2 diff -u -r1.12.2.1 -r1.12.2.2 --- ExtensionHandler.java 2001/04/10 18:44:36 1.12.2.1 +++ ExtensionHandler.java 2001/05/27 03:05:12 1.12.2.2 @@ -116,7 +116,7 @@ * * @param className Name of the class to load */ - static Class getClassForName(String className) + public static Class getClassForName(String className) throws ClassNotFoundException { Class result = null; 1.10.2.3 +4 -2 xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java Index: ExtensionHandlerGeneral.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/ExtensionHandlerGeneral.java,v retrieving revision 1.10.2.2 retrieving revision 1.10.2.3 diff -u -r1.10.2.2 -r1.10.2.3 --- ExtensionHandlerGeneral.java 2001/05/06 02:09:22 1.10.2.2 +++ ExtensionHandlerGeneral.java 2001/05/27 03:05:12 1.10.2.3 @@ -138,11 +138,13 @@ { try { - managerClass = Class.forName(BSF_MANAGER); + //managerClass = Class.forName(BSF_MANAGER); + managerClass = ExtensionHandler.getClassForName(BSF_MANAGER); mgrLoadScriptingEngine = managerClass.getMethod("loadScriptingEngine", new Class[]{ String.class }); - Class engineClass = Class.forName(BSF_ENGINE); + //Class engineClass = Class.forName(BSF_ENGINE); + Class engineClass = ExtensionHandler.getClassForName(BSF_ENGINE); engineExec = engineClass.getMethod("exec", new Class[]{ String.class, Integer.TYPE, 1.19.2.3 +71 -46 xml-xalan/java/src/org/apache/xalan/extensions/MethodResolver.java Index: MethodResolver.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/extensions/MethodResolver.java,v retrieving revision 1.19.2.2 retrieving revision 1.19.2.3 diff -u -r1.19.2.2 -r1.19.2.3 --- MethodResolver.java 2001/05/06 02:09:22 1.19.2.2 +++ MethodResolver.java 2001/05/27 03:05:12 1.19.2.3 @@ -338,7 +338,6 @@ Method bestMethod = null; Method[] methods = classObj.getMethods(); int nMethods = methods.length; - int bestScore = Integer.MAX_VALUE; int bestScoreCount = 0; for(int i = 0; i < nMethods; i++) { @@ -348,33 +347,13 @@ { Class[] paramTypes = method.getParameterTypes(); if ( (paramTypes.length == 2) - && paramTypes[1].isAssignableFrom(org.apache.xalan.templates.ElemExtensionCall.class) ) + && paramTypes[1].isAssignableFrom(org.apache.xalan.templates.ElemExtensionCall.class) + && paramTypes[0].isAssignableFrom(org.apache.xalan.extensions.XSLProcessorContext.class) ) { - int score = -1; - if (paramTypes[0].isAssignableFrom( - org.apache.xalan.extensions.XSLProcessorContext.class)) - { - score = 10; - } - /******* - else if (paramTypes[0].isAssignableFrom( - org.apace.xalan.xslt.XSLProcessorContext.class)) - { - score = 5; - } - ********/ - else - continue; - - if (score < bestScore) - { - // System.out.println("Assigning best method: "+method); + if ( ++bestScoreCount == 1 ) bestMethod = method; - bestScore = score; - bestScoreCount = 1; - } - else if (score == bestScore) - bestScoreCount++; + else + break; } } } @@ -630,15 +609,53 @@ { // If we get here, we haven't made a match on this parameter using // the ConversionInfo array. We now try to handle the object -> object - // mapping which we can't handle through the array mechanism. + // mapping which we can't handle through the array mechanism. To do this, + // we must determine the class of the argument passed from the stylesheet. + + // If we were passed a subclass of XObject, representing one of the actual + // XSLT types, and we are here, we reject this extension method as a candidate + // because a match should have been made using the ConversionInfo array. If we + // were passed an XObject that encapsulates a non-XSLT type or we + // were passed a non-XSLT type directly, we continue. + + // The current implementation (contributed by Kelly Campbell <[EMAIL PROTECTED]>) + // checks to see if we were passed an XObject from the XSLT stylesheet. If not, + // we use the class of the object that was passed and make sure that it will + // map to the class type of the parameter in the extension function. + // If we were passed an XObject, we attempt to get the class of the actual + // object encapsulated inside the XObject. If the encapsulated object is null, + // we judge this method as a match but give it a low score. + // If the encapsulated object is not null, we use its type to determine + // whether this java method is a valid match for this extension function call. + // This approach eliminates the NullPointerException in the earlier implementation + // that resulted from passing an XObject encapsulating the null java object. + // TODO: This needs to be improved to assign relative scores to subclasses, - // etc. I plan to do this very soon. Gary Peskin 29-Oct-2000. + // etc. if (XObject.CLASS_UNKNOWN == xsltClassType) { - Class realClass = (xsltObj instanceof XObject) - ? ((XObject) xsltObj).object().getClass() - : xsltObj.getClass(); + Class realClass = null; + + if (xsltObj instanceof XObject) + { + Object realObj = ((XObject) xsltObj).object(); + if (null != realObj) + { + realClass = realObj.getClass(); + } + else + { + // do the same as if we were passed XObject.CLASS_NULL + score += 10; + continue; + } + } + else + { + realClass = xsltObj.getClass(); + } + if (javaClass.isAssignableFrom(realClass)) { score += 0; // TODO: To be assigned based on subclass "distance" @@ -827,22 +844,30 @@ } // end if if(xsltObj instanceof XObject) - // At this point, we have a raw java object. - if(javaClass == java.lang.String.class) - { - return xsltObj.toString(); - } - else if(javaClass.isPrimitive()) - { - // Assume a number conversion - XString xstr = new XString(xsltObj.toString()); - double num = xstr.num(); - return convertDoubleToNumber(num, javaClass); - } - else if(javaClass == java.lang.Class.class) + // At this point, we have a raw java object, not an XObject. + if (null != xsltObj) { - return xsltObj.getClass(); - } + if(javaClass == java.lang.String.class) + { + return xsltObj.toString(); + } + else if(javaClass.isPrimitive()) + { + // Assume a number conversion + XString xstr = new XString(xsltObj.toString()); + double num = xstr.num(); + return convertDoubleToNumber(num, javaClass); + } + else if(javaClass == java.lang.Class.class) + { + return xsltObj.getClass(); + } + else + { + // Just pass the object directly, and hope for the best. + return xsltObj; + } + } else { // Just pass the object directly, and hope for the best. No revision No revision 1.17.2.1 +1 -1 xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java Index: ProcessorInclude.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorInclude.java,v retrieving revision 1.17 retrieving revision 1.17.2.1 diff -u -r1.17 -r1.17.2.1 --- ProcessorInclude.java 2001/03/12 02:12:43 1.17 +++ ProcessorInclude.java 2001/05/27 03:05:12 1.17.2.1 @@ -230,7 +230,7 @@ if (null != source && source instanceof DOMSource) { Node node = ((DOMSource)source).getNode(); - TreeWalker walker = new TreeWalker(handler, new org.apache.xpath.DOM2Helper()); + TreeWalker walker = new TreeWalker(handler, new org.apache.xpath.DOM2Helper(), source.getSystemId()); try { 1.28.2.2 +27 -7 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.28.2.1 retrieving revision 1.28.2.2 diff -u -r1.28.2.1 -r1.28.2.2 --- TransformerFactoryImpl.java 2001/05/06 02:09:23 1.28.2.1 +++ TransformerFactoryImpl.java 2001/05/27 03:05:12 1.28.2.2 @@ -128,6 +128,12 @@ loadPropertyFileToSystem(XSLT_PROPERTIES); } + /** a zero length Class array used in loadPropertyFileToSystem() */ + private static final Class[] NO_CLASSES = new Class[0]; + + /** a zero length Object array used in loadPropertyFileToSystem() */ + private static final Object[] NO_OBJS = new Object[0]; + /** * Retrieve a propery bundle from a specified file and load it * int the System properties. @@ -141,13 +147,24 @@ { try { - InputStream is; + InputStream is = null; try { Properties props = new Properties(); + + try { + 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("org/apache/xalan/processor/" + file); + } + } + catch (Exception e) {} - is = TransformerFactoryImpl.class.getResourceAsStream(file); + if (is == null) { + is = TransformerFactoryImpl.class.getResourceAsStream(file); + } // get a buffered version BufferedInputStream bis = new BufferedInputStream(is); @@ -190,7 +207,7 @@ try { TemplatesHandler builder = newTemplatesHandler(); - TreeWalker walker = new TreeWalker(builder, new org.apache.xpath.DOM2Helper()); + TreeWalker walker = new TreeWalker(builder, new org.apache.xpath.DOM2Helper(), builder.getSystemId()); walker.traverse(node); @@ -224,11 +241,11 @@ // Assume it's already been reported to the error listener. throw tce; } - catch (TransformerException tce) + /* catch (TransformerException tce) { // Assume it's already been reported to the error listener. throw new TransformerConfigurationException(tce.getMessage(), tce); - } + }*/ catch (Exception e) { if (m_errorListener != null) @@ -356,7 +373,7 @@ { if (null != node) { - TreeWalker walker = new TreeWalker(handler, new org.apache.xpath.DOM2Helper()); + TreeWalker walker = new TreeWalker(handler, new org.apache.xpath.DOM2Helper(), baseID); walker.traverse(node); } @@ -589,6 +606,7 @@ try { TransformerImpl transformer = (TransformerImpl) templates.newTransformer(); + transformer.setURIResolver(m_uriResolver); TransformerHandler th = (TransformerHandler) transformer.getInputContentHandler(true); @@ -674,7 +692,9 @@ that, and returns null. */ if( tmpl==null ) return null; - return tmpl.newTransformer(); + Transformer transformer = tmpl.newTransformer(); + transformer.setURIResolver(m_uriResolver); + return transformer; } catch( TransformerConfigurationException ex ) { if( m_errorListener != null ) { try { 1.10.2.1 +3 -0 xml-xalan/java/src/org/apache/xalan/processor/XSLTElementProcessor.java Index: XSLTElementProcessor.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/XSLTElementProcessor.java,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -r1.10 -r1.10.2.1 --- XSLTElementProcessor.java 2001/03/29 22:39:33 1.10 +++ XSLTElementProcessor.java 2001/05/27 03:05:13 1.10.2.1 @@ -223,6 +223,9 @@ { if (m_savedLastOrder != null && !m_savedLastOrder.empty()) getElemDef().setLastOrder(m_savedLastOrder.pop()); + + if (!getElemDef().getRequiredFound()) + handler.error(XSLTErrorResources.ER_REQUIRED_ELEM_NOT_FOUND, new Object[]{getElemDef().getRequiredElem()}, null); } /** 1.19.2.1 +1 -1 xml-xalan/java/src/org/apache/xalan/processor/XSLTSchema.java Index: XSLTSchema.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/XSLTSchema.java,v retrieving revision 1.19 retrieving revision 1.19.2.1 diff -u -r1.19 -r1.19.2.1 --- XSLTSchema.java 2001/03/29 22:39:33 1.19 +++ XSLTSchema.java 2001/05/27 03:05:13 1.19.2.1 @@ -560,7 +560,7 @@ new XSLTAttributeDef[]{ hrefAttr }, new ProcessorInclude(), null /* class object */, - 2, true); + 20, true); XSLTElementDef[] topLevelElements = new XSLTElementDef[]{ includeDef, importDef, // resultElement, No revision No revision 1.17.2.1 +10 -1 xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java Index: XSLTErrorResources.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java,v retrieving revision 1.17 retrieving revision 1.17.2.1 diff -u -r1.17 -r1.17.2.1 --- XSLTErrorResources.java 2001/03/13 19:54:58 1.17 +++ XSLTErrorResources.java 2001/05/27 03:05:13 1.17.2.1 @@ -86,7 +86,7 @@ public static final String WARNING_SUFFIX = "WR"; /** Maximum error messages, this is needed to keep track of the number of messages. */ - public static final int MAX_CODE = 109; + public static final int MAX_CODE = 110; /** Maximum warnings, this is needed to keep track of the number of warnings. */ public static final int MAX_WARNING = 26; @@ -1091,6 +1091,15 @@ { contents[ER_CLASS_NOT_FOUND_FOR_OPTION][1] = "Class file not found for option {0}"; + } + + /** Required Element not found */ + public static final int ER_REQUIRED_ELEM_NOT_FOUND = 110; + + static + { + contents[ER_REQUIRED_ELEM_NOT_FOUND][1] = + "Required Element not found: {0}"; } No revision No revision 1.4.2.1 +19 -1 xml-xalan/java/src/org/apache/xalan/serialize/CharInfo.java Index: CharInfo.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/CharInfo.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- CharInfo.java 2001/01/07 03:39:19 1.4 +++ CharInfo.java 2001/05/27 03:05:13 1.4.2.1 @@ -101,6 +101,13 @@ /** The carriage return character, which the parser should always normalize. */ public static char S_CARRIAGERETURN = 0x0D; + /** a zero length Class array used in the constructor */ + private static final Class[] NO_CLASSES = new Class[0]; + + /** a zero length Object array used in the constructor */ + private static final Object[] NO_OBJS = new Object[0]; + + /** * Constructor that reads in a resource file that describes the mapping of * characters to entity references. @@ -121,7 +128,18 @@ try { - is = CharInfo.class.getResourceAsStream(entitiesResource); + + try { + 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("org/apache/xalan/serialize/" + entitiesResource); + } + } + catch (Exception e) {} + + if (is == null) + is = CharInfo.class.getResourceAsStream(entitiesResource); if (is == null) { No revision No revision 1.9.2.2 +1 -1 xml-xalan/java/src/org/apache/xalan/templates/ElemChoose.java Index: ElemChoose.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemChoose.java,v retrieving revision 1.9.2.1 retrieving revision 1.9.2.2 diff -u -r1.9.2.1 -r1.9.2.2 --- ElemChoose.java 2001/04/10 18:44:46 1.9.2.1 +++ ElemChoose.java 2001/05/27 03:05:13 1.9.2.2 @@ -144,7 +144,7 @@ XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); XObject test = when.getTest().execute(transformer.getXPathContext(), - sourceNode, this); + sourceNode, when); if (TransformerImpl.S_DEBUG) transformer.getTraceManager().fireSelectedEvent(sourceNode, when, 1.12.2.2 +7 -1 xml-xalan/java/src/org/apache/xalan/templates/ElemCopy.java Index: ElemCopy.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemCopy.java,v retrieving revision 1.12.2.1 retrieving revision 1.12.2.2 diff -u -r1.12.2.1 -r1.12.2.2 --- ElemCopy.java 2001/04/10 18:44:46 1.12.2.1 +++ ElemCopy.java 2001/05/27 03:05:13 1.12.2.2 @@ -134,10 +134,12 @@ TransformerImpl transformer) throws TransformerException { + XPathContext xctxt = transformer.getXPathContext(); + try { - XPathContext xctxt = transformer.getXPathContext(); int sourceNode = xctxt.getCurrentNode(); + xctxt.pushCurrentNode(sourceNode); DTM dtm = xctxt.getDTM(sourceNode); short nodeType = dtm.getNodeType(sourceNode); @@ -177,6 +179,10 @@ catch(org.xml.sax.SAXException se) { throw new TransformerException(se); + } + finally + { + xctxt.popCurrentNode(); } } } 1.13.2.4 +11 -2 xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java Index: ElemValueOf.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemValueOf.java,v retrieving revision 1.13.2.3 retrieving revision 1.13.2.4 diff -u -r1.13.2.3 -r1.13.2.4 --- ElemValueOf.java 2001/05/19 07:05:43 1.13.2.3 +++ ElemValueOf.java 2001/05/27 03:05:14 1.13.2.4 @@ -234,13 +234,15 @@ throws TransformerException { + XPathContext xctxt = transformer.getXPathContext(); + boolean didPushCurrent = false; try { if (TransformerImpl.S_DEBUG) transformer.getTraceManager().fireTraceEvent(this); - XPathContext xctxt = transformer.getXPathContext(); - int sourceNode = xctxt.getCurrentNode(); + + int sourceNode = xctxt.getCurrentNode(); int child; XObject value; @@ -271,6 +273,8 @@ XMLString s; if(DTM.NULL != child) { + xctxt.pushCurrentNode(child); + didPushCurrent = true; DTM dtm = xctxt.getDTM(child); ResultTreeHandler rth = transformer.getResultTreeHandler(); if (m_disableOutputEscaping) @@ -306,6 +310,11 @@ catch(SAXException se) { throw new TransformerException(se); + } + finally + { + if (didPushCurrent) + xctxt.popCurrentNode(); } } 1.13.2.1 +59 -11 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.13 retrieving revision 1.13.2.1 diff -u -r1.13 -r1.13.2.1 --- OutputProperties.java 2001/03/26 21:35:46 1.13 +++ OutputProperties.java 2001/05/27 03:05:14 1.13.2.1 @@ -73,6 +73,7 @@ import org.apache.xml.utils.FastStringBuffer; import org.apache.xml.utils.WrappedRuntimeException; import org.apache.xalan.serialize.Method; +import org.apache.xalan.extensions.ExtensionHandler; import javax.xml.transform.TransformerException; import javax.xml.transform.OutputKeys; @@ -180,23 +181,51 @@ static private Properties loadPropertiesFile(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 { - is = OutputProperties.class.getResourceAsStream(resourceName); + try { + 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("org/apache/xalan/templates/" + resourceName); + } + } + catch (Exception e) {} + + if ( is == null ) { + is = OutputProperties.class.getResourceAsStream(resourceName); + } + bis = new BufferedInputStream(is); - props.load(bis); - } catch (IOException ioe) { + 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); + else { + throw new WrappedRuntimeException("Could not load '"+resourceName+"' (check CLASSPATH), now using just the defaults ", ioe); } - } finally { + } + catch (SecurityException se) { + // Repeat IOException handling for sandbox/applet case -sc + if ( defaults == null ) { + throw se; + } + else { + throw new WrappedRuntimeException("Could not load '"+resourceName+"' (check CLASSPATH, applet security), now using just the defaults ", se); + } + } + finally { if ( bis != null ) { bis.close(); } @@ -215,13 +244,25 @@ // 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; - if ((value = System.getProperty(key)) == null) + 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; - if ((newValue = System.getProperty(newKey)) == null) + 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); @@ -1011,4 +1052,11 @@ /** Synchronization object for lazy initialization of the above tables. */ private static Integer m_synch_object = new Integer(1); + + /** a zero length Class array used in loadPropertiesFile() */ + private static final Class[] NO_CLASSES = new Class[0]; + + /** a zero length Object array used in loadPropertiesFile() */ + private static final Object[] NO_OBJS = new Object[0]; + } No revision No revision 1.37.2.8 +5 -0 xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java Index: ResultTreeHandler.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v retrieving revision 1.37.2.7 retrieving revision 1.37.2.8 diff -u -r1.37.2.7 -r1.37.2.8 --- ResultTreeHandler.java 2001/05/22 05:48:44 1.37.2.7 +++ ResultTreeHandler.java 2001/05/27 03:05:14 1.37.2.8 @@ -1146,6 +1146,11 @@ m_startElement.setIsTransformClient(m_contentHandler instanceof TransformerClient); m_startElement.setContentHandler(m_contentHandler); m_startDoc.setContentHandler(m_contentHandler); + + if (m_contentHandler instanceof LexicalHandler) + m_lexicalHandler = (LexicalHandler) m_contentHandler; + else + m_lexicalHandler = null; reInitEvents(); } 1.1.2.2 +35 -20 xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java Index: TransformSnapshotImpl.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformSnapshotImpl.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- TransformSnapshotImpl.java 2001/05/06 02:09:35 1.1.2.1 +++ TransformSnapshotImpl.java 2001/05/27 03:05:14 1.1.2.2 @@ -2,8 +2,10 @@ import org.apache.xpath.XPathContext; import org.apache.xpath.VariableStack; +import org.apache.xpath.axes.ContextNodeList; import org.apache.xml.utils.NodeVector; import org.apache.xml.utils.BoolStack; +import org.apache.xml.dtm.DTMIterator; import java.util.Stack; import org.xml.sax.helpers.NamespaceSupport; import java.util.Enumeration; @@ -30,9 +32,14 @@ private NodeVector m_currentExpressionNodes; /** - * The current context node list. + * The current context node lists stack. */ private Stack m_contextNodeLists; + + /** + * The current context node list. + */ + private ContextNodeList m_contextNodeList; /** * Stack of AxesIterators. @@ -125,14 +132,17 @@ m_currentNodes = (NodeVector)xpc.getCurrentNodeStack().clone(); m_currentExpressionNodes = (NodeVector)xpc.getCurrentExpressionNodeStack().clone(); m_contextNodeLists = (Stack)xpc.getContextNodeListsStack().clone(); + if (!m_contextNodeLists.empty()) + m_contextNodeList = (ContextNodeList)xpc.getContextNodeList().clone(); m_axesIteratorStack = (Stack)xpc.getAxesIteratorStackStacks().clone(); m_currentTemplateRuleIsNull = (BoolStack)transformer.m_currentTemplateRuleIsNull.clone(); m_currentTemplateElements = (NodeVector)transformer.m_currentTemplateElements.clone(); m_currentMatchTemplates = (Stack)transformer.m_currentMatchTemplates.clone(); m_currentMatchNodes = (NodeVector)transformer.m_currentMatchedNodes.clone(); - m_countersTable = (CountersTable)transformer.m_countersTable.clone(); - m_attrSetStack = (Stack)transformer.m_attrSetStack.clone(); + m_countersTable = (CountersTable)transformer.getCountersTable().clone(); + if (transformer.m_attrSetStack != null) + m_attrSetStack = (Stack)transformer.m_attrSetStack.clone(); } catch(CloneNotSupportedException cnse) { @@ -147,29 +157,33 @@ // Are all these clones deep enough? ResultTreeHandler rtf = transformer.getResultTreeHandler(); - - rtf.m_startElement = (QueuedStartElement)m_startElement.clone(); - rtf.m_startDoc = (QueuedStartDocument)m_startDoc.clone(); - rtf.m_eventCount = m_eventCount; - - // yuck. No clone. Hope this is good enough. - rtf.m_nsSupport = new NamespaceSupport(); - Enumeration prefixes = m_nsSupport.getPrefixes(); - while(prefixes.hasMoreElements()) - { - String prefix = (String)prefixes.nextElement(); - String uri = m_nsSupport.getURI(prefix); - rtf.m_nsSupport.declarePrefix(prefix, uri); - } - - rtf.m_nsContextPushed = m_nsContextPushed; + if (rtf != null) + { + rtf.m_startElement = (QueuedStartElement)m_startElement.clone(); + rtf.m_startDoc = (QueuedStartDocument)m_startDoc.clone(); + rtf.m_eventCount = 1; //1 for start document event! m_eventCount; + + // yuck. No clone. Hope this is good enough. + rtf.m_nsSupport = new NamespaceSupport(); + Enumeration prefixes = m_nsSupport.getPrefixes(); + while(prefixes.hasMoreElements()) + { + String prefix = (String)prefixes.nextElement(); + String uri = m_nsSupport.getURI(prefix); + rtf.m_nsSupport.declarePrefix(prefix, uri); + } + + rtf.m_nsContextPushed = m_nsContextPushed; + } XPathContext xpc = transformer.getXPathContext(); xpc.setVarStack((VariableStack)m_variableStacks.clone()); xpc.setCurrentNodeStack((NodeVector)m_currentNodes.clone()); xpc.setCurrentExpressionNodeStack((NodeVector)m_currentExpressionNodes.clone()); xpc.setContextNodeListsStack((Stack)m_contextNodeLists.clone()); + if (m_contextNodeList != null) + xpc.pushContextNodeList((DTMIterator)m_contextNodeList.clone()); xpc.setAxesIteratorStackStacks((Stack)m_axesIteratorStack.clone()); transformer.m_currentTemplateRuleIsNull = (BoolStack)m_currentTemplateRuleIsNull.clone(); @@ -177,7 +191,8 @@ transformer.m_currentMatchTemplates = (Stack)m_currentMatchTemplates.clone(); transformer.m_currentMatchedNodes = (NodeVector)m_currentMatchNodes.clone(); transformer.m_countersTable = (CountersTable)m_countersTable.clone(); - transformer.m_attrSetStack = (Stack)m_attrSetStack.clone(); + if (m_attrSetStack != null) + transformer.m_attrSetStack = (Stack)m_attrSetStack.clone(); } catch(CloneNotSupportedException cnse) { 1.10.2.1 +2 -3 xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java Index: TransformerIdentityImpl.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerIdentityImpl.java,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -r1.10 -r1.10.2.1 --- TransformerIdentityImpl.java 2001/03/12 02:12:52 1.10 +++ TransformerIdentityImpl.java 2001/05/27 03:05:14 1.10.2.1 @@ -273,8 +273,7 @@ if (m_resultContentHandler instanceof DeclHandler) m_resultDeclHandler = (DeclHandler) m_resultContentHandler; - if (null == m_resultLexicalHandler - && m_resultContentHandler instanceof LexicalHandler) + if (m_resultContentHandler instanceof LexicalHandler) m_resultLexicalHandler = (LexicalHandler) m_resultContentHandler; } @@ -319,7 +318,7 @@ } else { - TreeWalker walker = new TreeWalker(this, new org.apache.xpath.DOM2Helper()); + TreeWalker walker = new TreeWalker(this, new org.apache.xpath.DOM2Helper(), m_systemID); walker.traverse(dNode); } } 1.90.2.13 +159 -35 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.90.2.12 retrieving revision 1.90.2.13 diff -u -r1.90.2.12 -r1.90.2.13 --- TransformerImpl.java 2001/05/22 05:48:44 1.90.2.12 +++ TransformerImpl.java 2001/05/27 03:05:14 1.90.2.13 @@ -125,6 +125,7 @@ import org.xml.sax.InputSource; import javax.xml.transform.TransformerException; import org.xml.sax.XMLReader; +import org.xml.sax.SAXException; import org.xml.sax.XMLFilter; import org.xml.sax.Locator; import org.xml.sax.helpers.XMLReaderFactory; @@ -134,6 +135,7 @@ import org.xml.sax.SAXNotSupportedException; import javax.xml.transform.ErrorListener; + // TRaX Imports import javax.xml.transform.Source; import javax.xml.transform.Result; @@ -357,6 +359,13 @@ /** Flag to to tell if the tranformer needs to be reset. */ private boolean m_hasBeenReset = false; + + private boolean m_shouldReset = true; + + public void setShouldReset(boolean shouldReset) + { + m_shouldReset = shouldReset; + } /** * A stack of current template modes. @@ -386,7 +395,7 @@ */ public void reset() { - if(!m_hasBeenReset) + if(!m_hasBeenReset && m_shouldReset) { m_hasBeenReset = true; @@ -547,7 +556,8 @@ String msg = spe.getMessage(); SAXSourceLocator loc = new SAXSourceLocator(spe); - m_errorHandler.fatalError(new TransformerException( msg, loc )); + //m_errorHandler.fatalError(new TransformerException( msg, loc )); + m_errorHandler.fatalError(new TransformerException( spe )); } catch(org.xml.sax.SAXException se) { @@ -1523,6 +1533,7 @@ // in scope, when really only the current stylesheet's // global variables should be in scope. Have to think on // this more... + XObject xobj; XPathContext xctxt = getXPathContext(); VariableStack vs = xctxt.getVarStack(); StylesheetRoot sr = getStylesheet(); @@ -1541,11 +1552,17 @@ { previouslyDeclared.setIsVisible(true); } + else + { + xobj = new XUnresolvedVariable(v, contextNode, + this, vs.getSearchStartOrTop(), 0, true); + previouslyDeclared.setVal(xobj); + } continue; } // XObject xobj = v.getValue(this, contextNode); - XObject xobj = new XUnresolvedVariable(v, contextNode, + xobj = new XUnresolvedVariable(v, contextNode, this, vs.getSearchStartOrTop(), 0, true); vs.pushVariable(v.getName(), xobj); @@ -1836,24 +1853,38 @@ { maxImportLevel = -1; } - - // Find the XSL template that is the best match for the - // element. - XPathContext xctxt = getXPathContext(); - PrefixResolver savedPrefixResolver = xctxt.getNamespaceContext(); - - try - { - xctxt.setNamespaceContext(xslInstruction); - QName mode = this.getMode(); - template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, maxImportLevel, - m_quietConflictWarnings); - } - finally - { - xctxt.setNamespaceContext(savedPrefixResolver); - } + // If we're trying an xsl:apply-imports at the top level (ie there are no + // imported stylesheets), we need to indicate that there is no matching template. + // The above logic will calculate a maxImportLevel of -1 which indicates + // that we should find any template. This is because a value of -1 for + // maxImportLevel has a special meaning. But we don't want that. + // We want to match -no- templates. See bugzilla bug 1170. + + if (isApplyImports && (maxImportLevel == -1)) + { + template = null; + } + else + { + // Find the XSL template that is the best match for the + // element. + XPathContext xctxt = getXPathContext(); + PrefixResolver savedPrefixResolver = xctxt.getNamespaceContext(); + + try + { + xctxt.setNamespaceContext(xslInstruction); + + QName mode = this.getMode(); + template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, maxImportLevel, + m_quietConflictWarnings); + } + finally + { + xctxt.setNamespaceContext(savedPrefixResolver); + } + } // If that didn't locate a node, fall back to a default template rule. // See http://www.w3.org/TR/xslt#built-in-rule. @@ -2329,7 +2360,8 @@ try { - return getXPathContext().getContextNodeList().cloneWithReset(); + DTMIterator cnl = getXPathContext().getContextNodeList(); + return (cnl == null)? null : (DTMIterator)cnl.cloneWithReset(); } catch (CloneNotSupportedException cnse) { @@ -2712,19 +2744,97 @@ //////////////////////// // Implement Runnable // //////////////////////// - - /** - * Create a thread for the transform. This can be overridden by derived - * implementations to provide their own thread, for thread pooling and the - * like. - * - * @return thread suitable to use for the transformation. - */ - public Thread createTransformThread() - { - Thread t = new Thread(this); - // System.out.println("created thread: "+t.getName()); - return t; + + /** Base thread controler for xalan. Must be overriden with + a derived class to support thread pooling. + + All thread-related stuff is in this class. + */ + public static class ThreadControler { + + /** Will get a thread from the pool, execute the task + * and return the thread to the pool. + * + * The return value is used only to wait for completion + * + * @param priority if >0 the task will run with the given priority + * ( doesn't seem to be used in xalan, since it's allways the default ) + * @returns The thread that is running the task, can be used + * to wait for completion + */ + public Thread run( Runnable task, int priority ) { + Thread t=new Thread(task); + t.start(); +// if( priority > 0 ) +// t.setPriority( priority ); + return t; + } + + + /** + * Wait until the task is completed on the worker + * thread. + */ + public void waitThread( Thread worker, Runnable task ) + throws InterruptedException + { + // This should wait until the transformThread is considered not alive. + worker.join(); + } + } + + static ThreadControler tpool=new ThreadControler(); + + /** Change the ThreadControler that will be used to + * manage the transform threads. + */ + public static void setThreadControler( ThreadControler tp ) { + tpool=tp; + } + + /** Called by SourceTreeHandler to start the transformation + * in a separate thread + */ + public void runTransformThread( int priority ) { + // used in SourceTreeHandler + Thread t=tpool.run( this, priority ); + this.setTransformThread( t ); + } + + /** Called by this.transform() if isParserEventsOnMain()==false. + * Similar with runTransformThread(), but no priority is set + * and setTransformThread is not set. + */ + public void runTransformThread( ) { + tpool.run( this, -1); + } + + /** Used by SourceTreeHandler to wait until the transform + * completes + */ + public void waitTransformThread() throws SAXException { + // This is called to make sure the task is done. + // It is possible that the thread has been reused - + // but for a different transformation. ( what if we + // recycle the transformer ? Not a problem since this is + // still in use. ) + Thread transformThread = this.getTransformThread(); + if (null != transformThread) + { + try + { + tpool.waitThread( transformThread, this ); + + if(!this.hasTransformThreadErrorCatcher()) + { + Exception e = this.getExceptionThrown(); + if(null != e) + throw new org.xml.sax.SAXException(e); + } + this.setTransformThread(null); + } + catch (InterruptedException ie){} + } } /** @@ -2913,8 +3023,22 @@ * from the snapshot point. */ public void executeFromSnapshot(TransformSnapshot ts) + throws TransformerException + { + ElemTemplateElement template = getMatchedTemplate(); + int child = getMatchedNode(); + pushElemTemplateElement(template); //needed?? + m_xcontext.pushCurrentNode(child); //needed?? + this.executeChildTemplates(template, true); // getResultTreeHandler()); + } + + /** + * This will execute the following XSLT instructions + * from the snapshot point. + */ + public void resetToStylesheet(TransformSnapshot ts) { - ((TransformSnapshotImpl)ts).apply(this); + ((TransformSnapshotImpl)ts).apply(this); } public void stopTransformation() 1.9.2.5 +68 -37 xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java Index: TreeWalker2Result.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TreeWalker2Result.java,v retrieving revision 1.9.2.4 retrieving revision 1.9.2.5 diff -u -r1.9.2.4 -r1.9.2.5 --- TreeWalker2Result.java 2001/05/23 02:55:37 1.9.2.4 +++ TreeWalker2Result.java 2001/05/27 03:05:15 1.9.2.5 @@ -56,7 +56,7 @@ */ package org.apache.xalan.transformer; -//import org.w3c.dom.*; +import org.w3c.dom.Node; import org.apache.xml.dtm.DTM; import org.xml.sax.*; @@ -65,6 +65,7 @@ import org.apache.xml.utils.MutableAttrListImpl; import org.apache.xalan.templates.ElemTemplateElement; import org.apache.xpath.DOMHelper; +import org.apache.xpath.XPathContext; /** * <meta name="usage" content="internal"/> @@ -113,6 +114,23 @@ super.traverse(pos); } + + /** + * End processing of given node + * + * + * @param node Node we just finished processing + * + * @throws org.xml.sax.SAXException + */ + protected void endNode(int node) throws org.xml.sax.SAXException + { + super.endNode(node); + if(DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) + { + m_transformer.getXPathContext().popCurrentNode(); + } + } /** * Start traversal of the tree at the given node @@ -125,45 +143,58 @@ protected void startNode(int node) throws org.xml.sax.SAXException { + XPathContext xcntxt = m_transformer.getXPathContext(); try { - if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) - { - String elemName = m_dtm.getNodeName(node); - String localName = m_dtm.getLocalName(node); - String namespace = m_dtm.getNamespaceURI(node); - - m_handler.startElement(namespace, localName, elemName, null); - - if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) - { - boolean hasNSDecls = false; - DTM dtm = m_dtm; - for (int ns = dtm.getFirstNamespaceNode(node, true); - DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true)) - { - m_handler.ensureNamespaceDeclDeclared(dtm, ns); - } - - if(hasNSDecls) - { - m_handler.addNSDeclsToAttrs(); - } - - for (int attr = dtm.getFirstAttribute(node); - DTM.NULL != attr; attr = dtm.getNextAttribute(attr)) - { - m_handler.addAttribute(attr); - } - - } - } - else - { - super.startNode(node); - } - } + if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) + { + xcntxt.pushCurrentNode(node); + + if(m_startNode != node) + { + super.startNode(node); + } + else + { + String elemName = m_dtm.getNodeName(node); + String localName = m_dtm.getLocalName(node); + String namespace = m_dtm.getNamespaceURI(node); + + //xcntxt.pushCurrentNode(node); + m_handler.startElement(namespace, localName, elemName, null); + + if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) + { + boolean hasNSDecls = false; + DTM dtm = m_dtm; + for (int ns = dtm.getFirstNamespaceNode(node, true); + DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true)) + { + m_handler.ensureNamespaceDeclDeclared(dtm, ns); + } + + if(hasNSDecls) + { + m_handler.addNSDeclsToAttrs(); + } + + for (int attr = dtm.getFirstAttribute(node); + DTM.NULL != attr; attr = dtm.getNextAttribute(attr)) + { + m_handler.addAttribute(attr); + } + } + } + + } + else + { + xcntxt.pushCurrentNode(node); + super.startNode(node); + xcntxt.popCurrentNode(); + } + } catch(javax.xml.transform.TransformerException te) { throw new org.xml.sax.SAXException(te); No revision No revision 1.32.2.3 +13 -10 xml-xalan/java/src/org/apache/xalan/xslt/Process.java Index: Process.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v retrieving revision 1.32.2.2 retrieving revision 1.32.2.3 diff -u -r1.32.2.2 -r1.32.2.3 --- Process.java 2001/05/19 07:05:45 1.32.2.2 +++ Process.java 2001/05/27 03:05:15 1.32.2.3 @@ -171,15 +171,19 @@ System.out.println(resbundle.getString("optionENTITYRESOLVER")); //" [-ENTITYRESOLVER full class name (EntityResolver to be used to resolve entities)]"); System.out.println(resbundle.getString("optionCONTENTHANDLER")); //" [-CONTENTHANDLER full class name (ContentHandler to be used to serialize output)]"); } - - /** Default properties file */ - static String XSLT_PROPERTIES = "/org/apache/xalan/res/XSLTInfo.properties"; - + /** - * Command line interfact to transform the XML according to - * the instructions found in the XSL stylesheet. - * <p>To set stylesheet parameters from the command line, use -PARAM name expression. If - * you want to set the parameter to a string value, enclose the string in single quotes (') to + * Command line interface to transform an XML document according to + * the instructions found in an XSL stylesheet. + * <p>The Process class provides basic functionality for + * performing transformations from the command line. To see a + * list of arguments supported, call with zero arguments.</p> + * <p>To set stylesheet parameters from the command line, use + * <code>-PARAM name expression</code>. If you want to set the + * parameter to a string value, simply pass the string value + * as-is, and it will be interpreted as a string. (Note: if + * the value has spaces in it, you may need to quote it depending + * on your shell environment).</p> * * @param argv Input parameters from command line */ @@ -204,7 +208,6 @@ org.apache.xml.utils.res.XResourceBundle.ERROR_RESOURCES)); String flavor = "s2s"; - // loadPropertyFileToSystem(XSLT_PROPERTIES); if (argv.length < 1) { printArgOptions(resbundle); @@ -578,7 +581,7 @@ if (null != outFileName) { - strResult = new StreamResult(new File(outFileName)); + strResult = new StreamResult(new FileOutputStream(outFileName)); } else { No revision No revision 1.7.2.3 +41 -1 xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java Index: TreeWalker.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/TreeWalker.java,v retrieving revision 1.7.2.2 retrieving revision 1.7.2.3 diff -u -r1.7.2.2 -r1.7.2.3 --- TreeWalker.java 2001/05/16 05:33:22 1.7.2.2 +++ TreeWalker.java 2001/05/27 03:05:15 1.7.2.3 @@ -60,6 +60,7 @@ import org.xml.sax.*; import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.LocatorImpl; import org.apache.xpath.DOM2Helper; import org.apache.xpath.DOMHelper; @@ -81,6 +82,9 @@ /** DomHelper for this TreeWalker */ protected DOMHelper m_dh; + + /** Locator object for this TreeWalker */ + private LocatorImpl m_locator = new LocatorImpl(); /** * Get the ContentHandler used for the tree walk. @@ -101,6 +105,23 @@ { m_contentHandler = ch; } + + /** + * Constructor. + * @param contentHandler The implemention of the + * @param systemId System identifier for the document. + * contentHandler operation (toXMLString, digest, ...) + */ + public TreeWalker(ContentHandler contentHandler, DOMHelper dh, String systemId) + { + this.m_contentHandler = contentHandler; + m_contentHandler.setDocumentLocator(m_locator); + if (systemId != null) + m_locator.setSystemId(systemId); + else + m_locator.setSystemId(System.getProperty("user.dir")); + m_dh = dh; + } /** * Constructor. @@ -110,6 +131,8 @@ public TreeWalker(ContentHandler contentHandler, DOMHelper dh) { this.m_contentHandler = contentHandler; + m_contentHandler.setDocumentLocator(m_locator); + m_locator.setSystemId(System.getProperty("user.dir")); m_dh = dh; } @@ -121,6 +144,9 @@ public TreeWalker(ContentHandler contentHandler) { this.m_contentHandler = contentHandler; + if (m_contentHandler != null) + m_contentHandler.setDocumentLocator(m_locator); + m_locator.setSystemId(System.getProperty("user.dir")); m_dh = new org.apache.xpath.DOM2Helper(); } @@ -242,6 +268,20 @@ { ((NodeConsumer) m_contentHandler).setOriginatingNode(node); } + + if (node instanceof Locator) + { + Locator loc = (Locator)node; + m_locator.setColumnNumber(loc.getColumnNumber()); + m_locator.setLineNumber(loc.getLineNumber()); + m_locator.setPublicId(loc.getPublicId()); + m_locator.setSystemId(loc.getSystemId()); + } + else + { + m_locator.setColumnNumber(0); + m_locator.setLineNumber(0); + } switch (node.getNodeType()) { @@ -341,7 +381,7 @@ break; case Node.TEXT_NODE : { - String data = ((Text) node).getData(); + //String data = ((Text) node).getData(); if (nextIsRaw) { No revision No revision 1.18.2.4 +1 -1 xml-xalan/java/src/org/apache/xpath/XPath.java Index: XPath.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPath.java,v retrieving revision 1.18.2.3 retrieving revision 1.18.2.4 diff -u -r1.18.2.3 -r1.18.2.4 --- XPath.java 2001/05/19 07:05:49 1.18.2.3 +++ XPath.java 2001/05/27 03:05:15 1.18.2.4 @@ -243,7 +243,7 @@ * @param contextNode The node that "." expresses. * @param namespaceContext The context in which namespaces in the * XPath are supposed to be expanded. - + * * @return The result of the XPath or null if callbacks are used. * @throws TransformerException thrown if * the error condition is severe enough to halt processing. 1.9.2.2 +15 -4 xml-xalan/java/src/org/apache/xpath/XPathAPI.java Index: XPathAPI.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/XPathAPI.java,v retrieving revision 1.9.2.1 retrieving revision 1.9.2.2 diff -u -r1.9.2.1 -r1.9.2.2 --- XPathAPI.java 2001/04/10 18:45:11 1.9.2.1 +++ XPathAPI.java 2001/05/27 03:05:15 1.9.2.2 @@ -71,6 +71,11 @@ import org.apache.xml.utils.PrefixResolver; import org.apache.xpath.objects.XObject; +import org.apache.xml.dtm.DTM; +import org.apache.xml.dtm.ref.DTMNodeIterator; +import org.apache.xml.dtm.ref.DTMManagerDefault; + + /** * The methods in this class are convenience methods into the * low-level XPath API. @@ -160,8 +165,9 @@ // Have the XObject return its result as a NodeSet. // %TBD% Convert to DOM nodeset -// return list.nodeset(); - return null; + + return new DTMNodeIterator(list.nodeset()); + } /** @@ -276,7 +282,9 @@ // Execute the XPath, and have it return the result // %TBD% Need to convert contextNode to a DTM node // return xpath.execute(xpathSupport, contextNode, prefixResolver); - return null; + int ctxtNode; + ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); + return xpath.execute(xpathSupport, ctxtNode, prefixResolver); } /** @@ -317,6 +325,9 @@ // Execute the XPath, and have it return the result // %TBD% Need to convert contextNode to a DTM node // return xpath.execute(new XPathContext(), contextNode, prefixResolver); - return null; + int ctxtNode; + XPathContext xpathSupport = new XPathContext(); + ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode); + return xpath.execute(xpathSupport, ctxtNode, prefixResolver); } } No revision No revision 1.8.2.6 +9 -4 xml-xalan/java/src/org/apache/xpath/axes/DescendantIterator.java Index: DescendantIterator.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/DescendantIterator.java,v retrieving revision 1.8.2.5 retrieving revision 1.8.2.6 diff -u -r1.8.2.5 -r1.8.2.6 --- DescendantIterator.java 2001/05/27 02:28:49 1.8.2.5 +++ DescendantIterator.java 2001/05/27 03:05:16 1.8.2.6 @@ -99,19 +99,24 @@ int ops[] = compiler.getOpMap(); int firstStepPos = compiler.getFirstChildPos(opPos); int stepType = ops[firstStepPos]; + /** Bit is on if any of the walkers contain a child step. */ + final int BIT_CHILD = (0x00001000 << 4); - m_orSelf = (OpCodes.FROM_DESCENDANTS_OR_SELF == stepType); + if (OpCodes.FROM_DESCENDANTS_OR_SELF == stepType) + m_orSelf = (BIT_CHILD == (analysis & BIT_CHILD)) ? false : true; if (OpCodes.FROM_SELF == stepType) { - m_orSelf = true; + m_orSelf = (BIT_CHILD == (analysis & BIT_CHILD)) ? false : true; firstStepPos += 8; } else if(OpCodes.FROM_ROOT == stepType) { m_fromRoot = true; - m_orSelf = true; + m_orSelf = (BIT_CHILD == (analysis & BIT_CHILD)) ? false : true; firstStepPos += 8; } + else + m_orSelf = false; int whatToShow = compiler.getWhatToShow(firstStepPos); @@ -210,7 +215,7 @@ // The start context can either be the location path context node, // or the root node. - if (getSelf && m_fromRoot) + if (m_fromRoot) { if(m_cdtm.getNodeType(m_context) == DTM.DOCUMENT_NODE) pos = m_context; No revision No revision 1.5.2.5 +5 -9 xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java Index: FuncCurrent.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncCurrent.java,v retrieving revision 1.5.2.4 retrieving revision 1.5.2.5 diff -u -r1.5.2.4 -r1.5.2.5 --- FuncCurrent.java 2001/05/25 17:36:56 1.5.2.4 +++ FuncCurrent.java 2001/05/27 03:05:16 1.5.2.5 @@ -72,6 +72,7 @@ import org.apache.xpath.axes.PredicatedNodeTest; import org.apache.xpath.axes.LocPathIterator; import org.apache.xpath.axes.ContextNodeList; +import org.apache.xpath.axes.SubContextList; /** * <meta name="usage" content="advanced"/> @@ -92,20 +93,15 @@ { // If we're in a predicate, then this will return non-null. - Object subContextList = xctxt.getSubContextList(); + //PredicatedNodeTest iter = (PredicatedNodeTest) xctxt.getSubContextList(); + SubContextList iter = xctxt.getSubContextList(); int currentNode; - // %TBD% Hack city... - if (null != subContextList && subContextList instanceof PredicatedNodeTest) + if (null != iter && iter instanceof PredicatedNodeTest) { - PredicatedNodeTest iter = (PredicatedNodeTest) xctxt.getSubContextList(); - LocPathIterator lpi = iter.getLocPathIterator(); + LocPathIterator lpi = ((PredicatedNodeTest)iter).getLocPathIterator(); currentNode = lpi.getCurrentContextNode(); - } - else if(xctxt.getIteratorRoot() != DTM.NULL) - { - currentNode = xctxt.getIteratorRoot(); } else { 1.7.2.3 +12 -10 xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunction.java Index: FuncExtFunction.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncExtFunction.java,v retrieving revision 1.7.2.2 retrieving revision 1.7.2.3 diff -u -r1.7.2.2 -r1.7.2.3 --- FuncExtFunction.java 2001/05/17 05:38:50 1.7.2.2 +++ FuncExtFunction.java 2001/05/27 03:05:16 1.7.2.3 @@ -63,6 +63,8 @@ import org.apache.xpath.objects.*; import org.apache.xalan.extensions.ExtensionsTable; +import org.apache.xml.dtm.DTMIterator; + //import org.w3c.dom.Node; import org.w3c.dom.DocumentFragment; import org.w3c.dom.traversal.NodeIterator; @@ -164,19 +166,19 @@ result = ((Boolean) val).booleanValue() ? XBoolean.S_TRUE : XBoolean.S_FALSE; } - else if (val instanceof Double) + else if (val instanceof Number) { - result = new XNumber(((Double) val).doubleValue()); + result = new XNumber(((Number) val).doubleValue()); } // %TBD% -// else if (val instanceof DocumentFragment) -// { -// result = new XRTreeFrag((DocumentFragment) val); -// } -// else if (val instanceof NodeIterator) -// { -// result = new XNodeSet((NodeIterator) val); -// } + // else if (val instanceof DocumentFragment) + // { + // result = new XRTreeFrag(val, xctxt); + // } + else if (val instanceof DTMIterator) + { + result = new XNodeSet((DTMIterator) val); + } else if (val instanceof org.w3c.dom.Node) { result = new XNodeSet(xctxt.getDTMHandleFromNode((org.w3c.dom.Node)val), 1.8.2.2 +19 -2 xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java Index: FuncSystemProperty.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncSystemProperty.java,v retrieving revision 1.8.2.1 retrieving revision 1.8.2.2 diff -u -r1.8.2.1 -r1.8.2.2 --- FuncSystemProperty.java 2001/04/10 18:45:33 1.8.2.1 +++ FuncSystemProperty.java 2001/05/27 03:05:16 1.8.2.2 @@ -85,7 +85,14 @@ /** The name of the property file where the name will be stored. */ static String XSLT_PROPERTIES = "/org/apache/xalan/res/XSLTInfo.properties"; + + /** a zero length Class array used in loadPropertyFile() */ + private static final Class[] NO_CLASSES = new Class[0]; + /** a zero length Object array used in loadPropertyFile() */ + private static final Object[] NO_OBJS = new Object[0]; + + /** * Execute the function. The function must return * a valid object. @@ -205,11 +212,21 @@ public void loadPropertyFile(String file, Properties target) { - InputStream is; + InputStream is = null; try { - is = getClass().getResourceAsStream(file); + try { + 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("org/apache/xpath/functions/" + file); + } + } + catch (Exception e) {} + + if (is == null); + is = FuncSystemProperty.class.getResourceAsStream(file); // get a buffered version BufferedInputStream bis = new BufferedInputStream(is); No revision No revision 1.8.2.6 +9 -2 xml-xalan/java/src/org/apache/xpath/objects/XObject.java Index: XObject.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XObject.java,v retrieving revision 1.8.2.5 retrieving revision 1.8.2.6 diff -u -r1.8.2.5 -r1.8.2.6 --- XObject.java 2001/05/19 07:05:57 1.8.2.5 +++ XObject.java 2001/05/27 03:05:16 1.8.2.6 @@ -268,7 +268,7 @@ */ public String str() { - return m_obj.toString(); + return (m_obj != null) ? m_obj.toString() : "null"; } /** @@ -518,7 +518,14 @@ if (obj2.getType() == XObject.CLASS_NODESET) return obj2.equals(this); - return m_obj.equals(obj2.m_obj); + if (null != m_obj) + { + return m_obj.equals(obj2.m_obj); + } + else + { + return obj2.m_obj == null; + } } /** 1.6.2.5 +1 -1 xml-xalan/java/src/org/apache/xpath/objects/XString.java Index: XString.java =================================================================== RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/objects/XString.java,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -u -r1.6.2.4 -r1.6.2.5 --- XString.java 2001/05/19 07:05:58 1.6.2.4 +++ XString.java 2001/05/27 03:05:16 1.6.2.5 @@ -537,7 +537,7 @@ */ public int compareToIgnoreCase(XMLString str) { - return str().compareToIgnoreCase(str.toString()); + return xstr().compareToIgnoreCase(str); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]