sboag       99/12/03 00:43:16

  Modified:    src      makexpath4j makexslt4j
               src/org/apache/xalan/xpath ExtensionFunctionHandler.java
                        XObject.java XPathProcessorImpl.java
                        XSLTJavaClassEngine.java
               src/org/apache/xalan/xpath/dtm DTMLiaison.java
               src/org/apache/xalan/xpath/xml FormatterToXML.java
                        TreeWalker.java XMLParserLiaisonDefault.java
               src/org/apache/xalan/xslt ElemExtensionCall.java
                        ElemLiteralResult.java ElemTemplateElement.java
                        ExtensionNSHandler.java Stylesheet.java
                        StylesheetHandler.java StylesheetRoot.java
                        XSLTEngineImpl.java
  Added:       src/org/apache/xalan/xpath/xml RawCharacterHandler.java
               src/org/apache/xalan/xslt ElemFallback.java
  Log:
  xsl:fallback is now implement, as well as xsl:extension-element-prefixes on 
LREs and extensions, other major work on extensions done.
  
  Revision  Changes    Path
  1.9       +33 -23    xml-xalan/src/makexpath4j
  
  Index: makexpath4j
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/makexpath4j,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- makexpath4j       1999/12/02 06:08:51     1.8
  +++ makexpath4j       1999/12/03 08:43:11     1.9
  @@ -24,28 +24,6 @@
   
   # List of all files to compile for this module
   SRCS = \
  -     $(XMLLIAISONDIR)$(PATHSEP)AttList.java \
  -     $(XMLLIAISONDIR)$(PATHSEP)DefaultErrorHandler.java \
  -     $(XMLLIAISONDIR)$(PATHSEP)FormatterToDOM.java \
  -     $(XMLLIAISONDIR)$(PATHSEP)FormatterToXML.java \
  -     $(XMLLIAISONDIR)$(PATHSEP)FormatterToHTML.java \
  -     $(XMLLIAISONDIR)$(PATHSEP)FormatterToText.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)NameSpace.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)NSInfo.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)PrefixResolver.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)QName.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)TreeWalker.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)WrongParserException.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)XMLParserLiaison.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)XMLParserLiaisonDefault.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)XSLMessages.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)XSLResourceBundle.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)ProblemListener.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)StringToStringTable.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)StringKey.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)StringVector.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)NodeVector.java \
  -  $(XMLLIAISONDIR)$(PATHSEP)ProblemListenerDefault.java \
        $(XPATHDIR)$(PATHSEP)DataProviderAssociation.java \
        $(XPATHDIR)$(PATHSEP)Dispatcher.java \
        $(XPATHDIR)$(PATHSEP)DispatcherFactory.java \
  @@ -129,10 +107,36 @@
        $(DTMDIR)$(PATHSEP)DTMtest.java \
        $(DTMDIR)$(PATHSEP)IntMap.java \
        $(DTMDIR)$(PATHSEP)IntToObjectMap.java
  +     
  +     
  +SRCS2 = \
  +     $(XMLLIAISONDIR)$(PATHSEP)AttList.java \
  +     $(XMLLIAISONDIR)$(PATHSEP)DefaultErrorHandler.java \
  +     $(XMLLIAISONDIR)$(PATHSEP)FormatterToDOM.java \
  +     $(XMLLIAISONDIR)$(PATHSEP)FormatterToXML.java \
  +     $(XMLLIAISONDIR)$(PATHSEP)FormatterToHTML.java \
  +     $(XMLLIAISONDIR)$(PATHSEP)FormatterToText.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)NameSpace.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)NSInfo.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)PrefixResolver.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)QName.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)TreeWalker.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)WrongParserException.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)XMLParserLiaison.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)XMLParserLiaisonDefault.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)XSLMessages.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)XSLResourceBundle.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)ProblemListener.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)StringToStringTable.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)StringKey.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)StringVector.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)NodeVector.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)RawCharacterHandler.java \
  +  $(XMLLIAISONDIR)$(PATHSEP)ProblemListenerDefault.java
   
   OBJS = $(SRCS:%.java=classes/%.class)
   
  -all: sincelast makesubdirs
  +all: sincelast sincelast2 makesubdirs
   
   # Note double-colon targets are treated specially
   clean::
  @@ -143,3 +147,9 @@
        $(SINCE_FILE)
   
   include ../make.include2
  +
  +sincelast2: sincexpath2.last
  +sincexpath2.last: $(SRCS2)
  +     -mkdir $(CLASSESDIR)
  +     $(JAVAC) $(JAVACFLAGS) -classpath "$(EXTRA_CLASSPATH)" $?
  +     touch sincexpath2.last
  \ No newline at end of file
  
  
  
  1.4       +1 -0      xml-xalan/src/makexslt4j
  
  Index: makexslt4j
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/makexslt4j,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- makexslt4j        1999/12/01 01:08:14     1.3
  +++ makexslt4j        1999/12/03 08:43:11     1.4
  @@ -42,6 +42,7 @@
        $(XSLT4JDIR)$(PATHSEP)ElemElement.java \
        $(XSLT4JDIR)$(PATHSEP)ElemEmpty.java \
        $(XSLT4JDIR)$(PATHSEP)ElemExtensionCall.java \
  +     $(XSLT4JDIR)$(PATHSEP)ElemFallback.java \
        $(XSLT4JDIR)$(PATHSEP)ElemForEach.java \
        $(XSLT4JDIR)$(PATHSEP)ElemIf.java \
        $(XSLT4JDIR)$(PATHSEP)ElemLiteralResult.java \
  
  
  
  1.5       +61 -19    
xml-xalan/src/org/apache/xalan/xpath/ExtensionFunctionHandler.java
  
  Index: ExtensionFunctionHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/ExtensionFunctionHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ExtensionFunctionHandler.java     1999/11/28 04:25:05     1.4
  +++ ExtensionFunctionHandler.java     1999/12/03 08:43:12     1.5
  @@ -63,8 +63,6 @@
   import org.w3c.dom.*;
   import org.xml.sax.*;
   
  -import com.ibm.bsf.*;
  -
   /**
    * Class handling an extension namespace for XPath. Provides functions
    * to test a function's existence and call a function
  @@ -74,12 +72,14 @@
   public class ExtensionFunctionHandler 
   {
     protected String namespaceUri;  // uri of the extension namespace
  -  protected String scriptLang;    // scripting language of implementation
  +  protected String scriptLang = "javaclass";    // scripting language of 
implementation
     protected String scriptSrc;     // script source to run (if any)
     protected String scriptSrcURL;  // URL of source of script (if any)
     protected Object javaObject = null;    // object for javaclass engine
  +  protected boolean hasCalledCTor = false;  // we'll be nice and call a ctor 
if they haven't
  +  protected Class classObject = null;  // class object for javaclass engine
     protected Hashtable functions = new Hashtable (); // functions of namespace
  -  protected BSFManager mgr = null; // mgr used to run scripts
  +  protected com.ibm.bsf.BSFManager mgr = null; // mgr used to run scripts
     protected boolean componentStarted; // true when the scripts in a
     // component description (if any) have
     // been run
  @@ -209,26 +209,52 @@
   
       try 
       {
  -      BSFEngine e;
  +      com.ibm.bsf.BSFEngine e;
         Object[] argArray;
         int argStart;
         
         if(null == mgr)
  -        mgr = new BSFManager ();
  +      {
  +        mgr = new com.ibm.bsf.BSFManager ();
  +      }
   
         // we want to use the xslt-javaclass engine to handle the javaclass
         // case 'cause of the funky method selection rules. That engine 
         // expects the first arg to be the object on which to make the call.
  +      boolean isCTorCall = false;
         if (scriptLang.equals ("javaclass")) 
         {
  +        isCTorCall = funcName.equals("new");
           e = mgr.loadScriptingEngine ("xslt-javaclass");
  -        argArray = new Object[args.size () + 1];
  -        argArray[0] = javaObject;
  -        argStart = 1;
  +        if(isCTorCall)
  +        {
  +          argArray = new Object[args.size ()];
  +          argStart = 0;
  +          funcName = this.classObject.getName()+".new";
  +          javaObject = null;
  +          hasCalledCTor = true;
  +        }
  +        else
  +        {
  +          if(!hasCalledCTor)
  +          {
  +            if(null == javaObject)
  +              javaObject = this.classObject.newInstance();
  +            
  +            argArray = new Object[args.size () + 1];
  +            argArray[0] = javaObject;
  +            argStart = 1;
  +          }
  +          else
  +          {
  +            argArray = new Object[args.size ()];
  +            argStart = 0;
  +          }
  +        }
         }
         else 
         {
  -        e = mgr.loadScriptingEngine (scriptLang);
  +        e = ((com.ibm.bsf.BSFManager)mgr).loadScriptingEngine (scriptLang);
           argArray = new Object[args.size ()];
           argStart = 0;
         }
  @@ -241,10 +267,9 @@
                                 (o instanceof XObject) ? ((XObject)o).object 
() : o;
         }
   
  -      // do it
         return e.call (null, funcName, argArray);
       }
  -    catch (BSFException e) 
  +    catch (Exception e) 
       {
         throw new XPathException ("Error with extension in callFunction.", e);
       }
  @@ -255,6 +280,11 @@
     /////////////////////////////////////////////////////////////////////////
     
     /**
  +   * Tell if we've already initialized the bsf engine.
  +   */
  +  protected static boolean bsfInitialized = false;
  +
  +  /**
      * Start the component up by executing any script that needs to run
      * at startup time. This needs to happen before any functions can be
      * called on the component. 
  @@ -263,6 +293,17 @@
      */
     protected void startupComponent () throws  XPathProcessorException 
     {
  +    if(!bsfInitialized)
  +    {
  +      synchronized(com.ibm.bsf.BSFManager.class)
  +      {
  +        bsfInitialized = true;
  +        com.ibm.bsf.BSFManager.registerScriptingEngine ("xslt-javaclass",
  +                                                        
"org.apache.xalan.xpath.XSLTJavaClassEngine",
  +                                                        new String[0]);
  +      }
  +    }
  +
       // special case the javaclass engine - the scriptSrcURL is 
       // the class name to run. If it starts with class: then use the
       // class object with that name instead of init'ing it as the
  @@ -278,21 +319,22 @@
             cname = scriptSrcURL.substring (6);
             isClass = true;
           }
  -        Class cl = Class.forName (cname);
  +        classObject = Class.forName (cname);
           if (isClass) 
           {
  -          javaObject = cl;
  +          javaObject = classObject;
           }
           else
           {
  -          javaObject = cl.newInstance ();
  +          // We'll only do this if they haven't called a ctor.
  +          // javaObject = classObject.newInstance ();
           }
           componentStarted = true;
           return;
         }
         catch (Exception e) 
         {
  -        System.out.println("Extension error: "+e.getMessage ());
  +        // System.out.println("Extension error: "+e.getMessage ());
           throw new XPathProcessorException (e.getMessage (), e);
         }
       }
  @@ -309,15 +351,15 @@
       }
       
       if(null == mgr)
  -      mgr = new BSFManager ();
  +      mgr = new com.ibm.bsf.BSFManager ();
   
       // evaluate the src to load whatever content is in that string to 
       // the engines
       try 
       {
  -      mgr.exec (scriptLang, "LotusXSLScript", -1, -1, scriptSrc);
  +      ((com.ibm.bsf.BSFManager)mgr).exec (scriptLang, "LotusXSLScript", -1, 
-1, scriptSrc);
       }
  -    catch (BSFException bsfe) 
  +    catch (com.ibm.bsf.BSFException bsfe) 
       {
         throw new XPathProcessorException (bsfe.getMessage (), bsfe);
       }
  
  
  
  1.6       +15 -3     xml-xalan/src/org/apache/xalan/xpath/XObject.java
  
  Index: XObject.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/XObject.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XObject.java      1999/11/29 06:25:32     1.5
  +++ XObject.java      1999/12/03 08:43:12     1.6
  @@ -151,10 +151,22 @@
      */
     public DocumentFragment rtree(XPathSupport support)
     {
  -    DocumentFragment result = 
support.getDOMFactory().createDocumentFragment();
  -    Text textNode = support.getDOMFactory().createTextNode(str());
  -    result.appendChild(textNode);
  +    DocumentFragment result = rtree();
  +    if(null == result)
  +    {
  +      result = support.getDOMFactory().createDocumentFragment();
  +      Text textNode = support.getDOMFactory().createTextNode(str());
  +      result.appendChild(textNode);
  +    }
       return result;
  +  }
  +  
  +  /**
  +   * For functions to override.
  +   */
  +  public DocumentFragment rtree()
  +  {
  +    return null;
     }
     
     /**
  
  
  
  1.10      +2 -2      
xml-xalan/src/org/apache/xalan/xpath/XPathProcessorImpl.java
  
  Index: XPathProcessorImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/XPathProcessorImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XPathProcessorImpl.java   1999/12/02 06:04:06     1.9
  +++ XPathProcessorImpl.java   1999/12/03 08:43:12     1.10
  @@ -1193,8 +1193,8 @@
     private static final String FUNC_CONCAT_STRING = "concat";
     //private static final String FUNC_FORMAT_NUMBER_STRING = "format-number";
     private static final String FUNC_SYSTEM_PROPERTY_STRING = 
"system-property";
  -  private static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING = 
"extension-function-available";
  -  private static final String FUNC_EXT_ELEM_AVAILABLE_STRING = 
"extension-element-available";
  +  private static final String FUNC_EXT_FUNCTION_AVAILABLE_STRING = 
"function-available";
  +  private static final String FUNC_EXT_ELEM_AVAILABLE_STRING = 
"element-available";
     private static final String FUNC_SUBSTRING_STRING = "substring";
     private static final String FUNC_STRING_LENGTH_STRING = "string-length";
     private static final String FUNC_UNPARSED_ENTITY_URI_STRING = 
"unparsed-entity-uri";
  
  
  
  1.4       +2 -1      
xml-xalan/src/org/apache/xalan/xpath/XSLTJavaClassEngine.java
  
  Index: XSLTJavaClassEngine.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/XSLTJavaClassEngine.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XSLTJavaClassEngine.java  1999/11/28 04:25:08     1.3
  +++ XSLTJavaClassEngine.java  1999/12/03 08:43:12     1.4
  @@ -209,7 +209,8 @@
               // searching logic is the same of course.
               Constructor c =
                              ReflectionUtils.getConstructor ((Class) object, 
argTypes);
  -            return c.newInstance (methodArgs);
  +            Object obj = c.newInstance (methodArgs);
  +            return obj;
             }
             else 
             {
  
  
  
  1.4       +9 -2      xml-xalan/src/org/apache/xalan/xpath/dtm/DTMLiaison.java
  
  Index: DTMLiaison.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/dtm/DTMLiaison.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DTMLiaison.java   1999/11/25 04:22:06     1.3
  +++ DTMLiaison.java   1999/12/03 08:43:13     1.4
  @@ -159,7 +159,7 @@
           
           if(null != m_entityResolver)
           {
  -          System.out.println("Setting the entity resolver.");
  +          // System.out.println("Setting the entity resolver.");
             parser.setEntityResolver(m_entityResolver);
           }
           
  @@ -174,7 +174,14 @@
           {
             parser.setInputSource(source);
             parseThread = new Thread(parser);
  -          parseThread.start();
  +          try
  +          {
  +            parseThread.start();
  +          }
  +          catch(RuntimeException re)
  +          {
  +            throw new SAXException(re.getMessage());
  +          }
           }
           
           m_document = parser.getDocument();
  
  
  
  1.9       +1 -1      
xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java
  
  Index: FormatterToXML.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/FormatterToXML.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FormatterToXML.java       1999/12/02 06:04:07     1.8
  +++ FormatterToXML.java       1999/12/03 08:43:13     1.9
  @@ -73,7 +73,7 @@
   /**
    * FormatterToXML formats SAX-style events into XML.
    */
  -public class FormatterToXML implements DocumentHandler, LexicalHandler
  +public class FormatterToXML implements DocumentHandler, LexicalHandler, 
RawCharacterHandler
   {
     /** 
      * The writer where the XML will be written.
  
  
  
  1.3       +32 -3     xml-xalan/src/org/apache/xalan/xpath/xml/TreeWalker.java
  
  Index: TreeWalker.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/TreeWalker.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TreeWalker.java   1999/11/27 08:53:24     1.2
  +++ TreeWalker.java   1999/12/03 08:43:13     1.3
  @@ -158,6 +158,8 @@
     }
     */
     
  +  boolean nextIsRaw = false;
  +  
     protected void startNode(Node node)
       throws SAXException 
     {
  @@ -184,8 +186,19 @@
         this.m_formatterListener.startElement (node.getNodeName(), new 
AttList(atts));
         break;
       case Node.PROCESSING_INSTRUCTION_NODE:
  -      ProcessingInstruction pi = (ProcessingInstruction)node;
  -      this.m_formatterListener.processingInstruction(pi.getNodeName(), 
pi.getData());
  +      {
  +        ProcessingInstruction pi = (ProcessingInstruction)node;
  +        String name = pi.getNodeName();
  +        String data = pi.getData();
  +        if(name.equals("xslt-next-is-raw") && 
name.equals("formatter-to-dom"))
  +        {
  +          nextIsRaw = true;
  +        }
  +        else
  +        {
  +          this.m_formatterListener.processingInstruction(pi.getNodeName(), 
pi.getData());
  +        }
  +      }
         break;
       case Node.CDATA_SECTION_NODE:
         {
  @@ -208,7 +221,23 @@
       case Node.TEXT_NODE:
         {
           String data = ((Text)node).getData();
  -        this.m_formatterListener.characters(data.toCharArray(), 0, 
data.length());
  +        if(nextIsRaw)
  +        {
  +          nextIsRaw = false;
  +          if(this.m_formatterListener instanceof RawCharacterHandler)
  +          {
  +            
((RawCharacterHandler)this.m_formatterListener).charactersRaw(data.toCharArray(),
 0, data.length());
  +          }
  +          else
  +          {
  +            System.out.println("Warning: can't output raw characters!");
  +            this.m_formatterListener.characters(data.toCharArray(), 0, 
data.length());
  +          }
  +        }
  +        else
  +        {
  +          this.m_formatterListener.characters(data.toCharArray(), 0, 
data.length());
  +        }
         }
         break;
       case Node.ENTITY_REFERENCE_NODE:
  
  
  
  1.10      +14 -1     
xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java
  
  Index: XMLParserLiaisonDefault.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/XMLParserLiaisonDefault.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLParserLiaisonDefault.java      1999/12/03 01:37:16     1.9
  +++ XMLParserLiaisonDefault.java      1999/12/03 08:43:13     1.10
  @@ -1767,7 +1767,7 @@
       //                    ", func=" + funcName + ") = " + isAvailable);
       return isAvailable;
     }
  -  
  +    
     /**
      * Handle an extension function.
      * @param ns       the URI of namespace in which the function is needed
  @@ -1779,6 +1779,19 @@
     public Object extFunction (String ns, String funcName, Vector argVec)
       throws org.xml.sax.SAXException
     {
  +    if(null == m_extensionFunctionNamespaces.get 
("http://xml.apache.org/xslt/java";))
  +    {
  +      // register the java namespace as being implemented by the 
  +      // xslt-javaclass engine. Note that there's no real code
  +      // per se for this extension as the functions carry the 
  +      // object on which to call etc. and all the logic of breaking
  +      // that up is in the xslt-javaclass engine.
  +      String uri = "http://xml.apache.org/xslt/java";;
  +      ExtensionFunctionHandler fh = new ExtensionFunctionHandler (uri, null, 
"xslt-javaclass", null, null);
  +      
  +      addExtensionNamespace (uri, fh);   
  +    }
  +
       Object result = null;
       if (null != ns)
       {
  
  
  
  1.1                  
xml-xalan/src/org/apache/xalan/xpath/xml/RawCharacterHandler.java
  
  Index: RawCharacterHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  public interface RawCharacterHandler
  {
    public void charactersRaw (char ch[], int start, int length)
      throws org.xml.sax.SAXException;
  }
  
  
  
  1.3       +45 -5     
xml-xalan/src/org/apache/xalan/xslt/ElemExtensionCall.java
  
  Index: ElemExtensionCall.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemExtensionCall.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElemExtensionCall.java    1999/11/30 05:23:52     1.2
  +++ ElemExtensionCall.java    1999/12/03 08:43:14     1.3
  @@ -74,6 +74,8 @@
     AttributeList m_attrs;
     public Vector m_avts = null;
     public StringToStringTable m_excludeResultPrefixes = null;
  +  public String m_extensionElementPrefixes[] = null;
  +  transient boolean isAvailable = false;
   
     public int getXSLToken()
     {
  @@ -90,6 +92,7 @@
       throws SAXException
     {
       super(processor, stylesheetTree, name, atts, lineNumber, columnNumber);
  +        
       this.nsh = nsh;
       this.localPart = localPart;
       m_attrs = new AttributeListImpl(atts);
  @@ -110,9 +113,21 @@
                && ns.equals( m_stylesheet.m_XSLNameSpaceURL ))
             {
               String localName = aname.substring(indexOfNSSep+1);
  -            if(localName.equals(Constants.ATTRNAME_EXCLUDE_RESULT_PREFIXES))
  +            if(localName.equals(Constants.ATTRNAME_EXTENSIONELEMENTPREFIXES))
               {
                 needToProcess = false;
  +              String qnames = atts.getValue(i);
  +              StringTokenizer tokenizer = new StringTokenizer(qnames, " 
\t\n\r", false);
  +              m_extensionElementPrefixes = new 
String[tokenizer.countTokens()];
  +              for(int k = 0; tokenizer.hasMoreTokens(); k++)
  +              {
  +                m_extensionElementPrefixes[k] = tokenizer.nextToken();
  +                m_excludeResultPrefixes = 
m_stylesheet.processExcludeResultPrefixes(m_extensionElementPrefixes[k], null);
  +              }
  +            }
  +            else 
if(localName.equals(Constants.ATTRNAME_EXCLUDE_RESULT_PREFIXES))
  +            {
  +              needToProcess = false;
                 m_excludeResultPrefixes = 
m_stylesheet.processExcludeResultPrefixes(atts.getValue(i), null);
               }
             }
  @@ -134,6 +149,14 @@
       }
   
     }
  +  
  +  /**
  +   * Tell if this extension element is available for execution.
  +   */
  +  public boolean elementIsAvailable()
  +  {
  +    return isAvailable;
  +  }
   
     public void execute(XSLTEngineImpl processor, 
                         Node sourceTree, 
  @@ -145,10 +168,27 @@
              java.io.IOException,
              SAXException
     {
  -    nsh.processElement (localPart, this,
  -                        processor, 
  -                        m_stylesheet,
  -                        sourceTree, sourceNode, mode);
  +    try
  +    {
  +      processor.flushPending();
  +      nsh.processElement (localPart, this,
  +                          processor, 
  +                          m_stylesheet,
  +                          sourceTree, sourceNode, mode);
  +    }
  +    catch(Exception e)
  +    {
  +      String msg = e.getMessage();
  +      processor.message(msg);
  +      isAvailable = false; 
  +      for (ElemTemplateElement child = m_firstChild; child != null; child = 
child.m_nextSibling) 
  +      {
  +        if(child.getXSLToken() == Constants.ELEMNAME_FALLBACK)
  +        {
  +          child.execute(processor, sourceTree, sourceNode, mode);
  +        }
  +      }
  +    }
     }
     
     public String getAttribute(String name)
  
  
  
  1.6       +1 -0      
xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java
  
  Index: ElemLiteralResult.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemLiteralResult.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ElemLiteralResult.java    1999/12/01 22:16:17     1.5
  +++ ElemLiteralResult.java    1999/12/03 08:43:14     1.6
  @@ -118,6 +118,7 @@
                 for(int k = 0; tokenizer.hasMoreTokens(); k++)
                 {
                   m_extensionElementPrefixes[k] = tokenizer.nextToken();
  +                m_excludeResultPrefixes = 
m_stylesheet.processExcludeResultPrefixes(m_extensionElementPrefixes[k], null);
                 }
               }
               else 
if(localName.equals(Constants.ATTRNAME_EXCLUDE_RESULT_PREFIXES))
  
  
  
  1.7       +1 -1      
xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java
  
  Index: ElemTemplateElement.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemTemplateElement.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ElemTemplateElement.java  1999/11/30 22:30:55     1.6
  +++ ElemTemplateElement.java  1999/12/03 08:43:14     1.7
  @@ -151,7 +151,7 @@
      * First child.
      * @serial
      */
  -  private ElemTemplateElement m_firstChild;
  +  protected ElemTemplateElement m_firstChild;
     
     /** Construct a template element instance.
      * 
  
  
  
  1.3       +120 -7    
xml-xalan/src/org/apache/xalan/xslt/ExtensionNSHandler.java
  
  Index: ExtensionNSHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/ExtensionNSHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExtensionNSHandler.java   1999/11/23 04:14:09     1.2
  +++ ExtensionNSHandler.java   1999/12/03 08:43:14     1.3
  @@ -163,7 +163,7 @@
     {
       super.setScript (lang, srcURL, scriptSrc);
       componentDescLoaded = true;
  -  }
  +  }  
   
     /////////////////////////////////////////////////////////////////////////
   
  @@ -243,7 +243,7 @@
         }
         catch (XPathProcessorException e) 
         {
  -        e.printStackTrace ();
  +        // e.printStackTrace ();
           throw new XSLProcessorException (e.getMessage (), e);
         } 
       }
  @@ -261,7 +261,7 @@
       }
       catch (XPathProcessorException e) 
       {
  -      e.printStackTrace ();
  +      // e.printStackTrace ();
         throw new XSLProcessorException (e.getMessage (), e);
       }
   
  @@ -274,7 +274,7 @@
     /////////////////////////////////////////////////////////////////////////
     // Private/Protected Functions
     /////////////////////////////////////////////////////////////////////////
  -
  +  
     /**
      * Start the component up by executing any script that needs to run
      * at startup time. This needs to happen before any functions can be
  @@ -284,6 +284,17 @@
      */
     protected void startupComponent () throws  XPathProcessorException 
     {
  +    if(!bsfInitialized)
  +    {
  +      synchronized(com.ibm.bsf.BSFManager.class)
  +      {
  +        bsfInitialized = true;
  +        com.ibm.bsf.BSFManager.registerScriptingEngine ("xslt-javaclass",
  +                                                        
"org.apache.xalan.xpath.XSLTJavaClassEngine",
  +                                                        new String[0]);
  +      }
  +    }
  +
       if (!componentDescLoaded) 
       {
         try 
  @@ -338,9 +349,18 @@
       URL url = xslp.getURLFromString(namespaceUri,
                                       xslp.m_stylesheetRoot.m_baseIdent);
       // System.out.println("Extension URI: "+url.toString());
  -    xslp.m_parserLiaison.parse(new InputSource(url.toString()));
  -    Document compSpec = xslp.m_parserLiaison.getDocument();
  -    Element componentElement = compSpec.getDocumentElement ();
  +    org.apache.xalan.xpath.xml.XMLParserLiaison liaison = 
xslp.m_parserLiaison;
  +    if(liaison instanceof org.apache.xalan.xpath.dtm.DTMLiaison)
  +    {
  +      // There ought to be a better way.  At least if we know we 
  +      // have the DTM, we ought to have Xerces.
  +      liaison = new org.apache.xalan.xpath.xdom.XercesLiaison();
  +      liaison.setErrorHandler(new ExtErrorHandler(url.toString()));
  +    }
  +    Element componentElement = null;
  +    liaison.parse(new InputSource(url.toString()));
  +    Document compSpec = liaison.getDocument();
  +    componentElement = compSpec.getDocumentElement ();
   
       // determine the functions and elements of this component
       setElements (componentElement.getAttribute ("elements"));
  @@ -397,4 +417,97 @@
       }
       return strBuf.toString();
     }
  +    
  +  
  +  /**
  +   * Implement SAX error handler for default reporting.
  +   */
  +  class ExtErrorHandler implements ErrorHandler 
  +  {
  +    String m_xmlID = null;
  +
  +    public ExtErrorHandler(String identifier)
  +    {
  +      m_xmlID = identifier;
  +    }
  +
  +    /**
  +     * Receive notification of a warning.
  +     *
  +     * <p>SAX parsers will use this method to report conditions that
  +     * are not errors or fatal errors as defined by the XML 1.0
  +     * recommendation.  The default behaviour is to take no action.</p>
  +     *
  +     * <p>The SAX parser must continue to provide normal parsing events
  +     * after invoking this method: it should still be possible for the
  +     * application to process the document through to the end.</p>
  +     *
  +     * @param exception The warning information encapsulated in a
  +     *                  SAX parse exception.
  +     * @exception org.xml.sax.SAXException Any SAX exception, possibly
  +     *            wrapping another exception.
  +     * @see org.xml.sax.SAXParseException 
  +     */
  +    public void warning (SAXParseException exception)
  +      throws SAXException
  +    {
  +      System.out.println("Parser warning: "+exception.getMessage());
  +    }
  +
  +
  +    /**
  +     * Receive notification of a recoverable error.
  +     *
  +     * <p>This corresponds to the definition of "error" in section 1.2
  +     * of the W3C XML 1.0 Recommendation.  For example, a validating
  +     * parser would use this callback to report the violation of a
  +     * validity constraint.  The default behaviour is to take no
  +     * action.</p>
  +     *
  +     * <p>The SAX parser must continue to provide normal parsing events
  +     * after invoking this method: it should still be possible for the
  +     * application to process the document through to the end.  If the
  +     * application cannot do so, then the parser should report a fatal
  +     * error even if the XML 1.0 recommendation does not require it to
  +     * do so.</p>
  +     *
  +     * @param exception The error information encapsulated in a
  +     *                  SAX parse exception.
  +     * @exception org.xml.sax.SAXException Any SAX exception, possibly
  +     *            wrapping another exception.
  +     * @see org.xml.sax.SAXParseException 
  +     */
  +    public void error (SAXParseException exception)
  +      throws SAXException
  +    {
  +      System.out.println("Parser error: "+exception.getMessage());
  +    }
  +
  +    /**
  +     * Receive notification of a non-recoverable error.
  +     *
  +     * <p>This corresponds to the definition of "fatal error" in
  +     * section 1.2 of the W3C XML 1.0 Recommendation.  For example, a
  +     * parser would use this callback to report the violation of a
  +     * well-formedness constraint.</p>
  +     *
  +     * <p>The application must assume that the document is unusable
  +     * after the parser has invoked this method, and should continue
  +     * (if at all) only for the sake of collecting addition error
  +     * messages: in fact, SAX parsers are free to stop reporting any
  +     * other events once this method has been invoked.</p>
  +     *
  +     * @param exception The error information encapsulated in a
  +     *                  SAX parse exception.  
  +     * @exception org.xml.sax.SAXException Any SAX exception, possibly
  +     *            wrapping another exception.
  +     * @see org.xml.sax.SAXParseException
  +     */
  +    public void fatalError (SAXParseException exception)
  +      throws SAXException
  +    {
  +    }
  +
  +  }
  +
   }
  
  
  
  1.12      +11 -22    xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Stylesheet.java   1999/12/02 06:04:08     1.11
  +++ Stylesheet.java   1999/12/03 08:43:14     1.12
  @@ -419,6 +419,15 @@
               return true;
           }
         }
  +      else if(Constants.ELEMNAME_EXTENSIONCALL == elem.getXSLToken())
  +      {
  +        StringToStringTable t = 
((ElemExtensionCall)elem).m_excludeResultPrefixes;
  +        if(null != t)
  +        {
  +          if(t.contains(prefix))
  +            return true;
  +        }
  +      }
         elem = elem.m_parentNode;
         if(null == elem)
         {
  @@ -625,12 +634,7 @@
     {
       m_DecimalFormatDeclarations = v;
     }
  -  
  -  /**
  -   * Tells if the BSF manager needs to be initialized.
  -   */
  -  boolean m_hasExtensions = false;
  -    
  +      
     /**
      * Read the stylesheet from a serialization stream.
      */
  @@ -699,23 +703,8 @@
       m_includeStack = new Stack();
       
m_includeStack.push(processor.m_parserLiaison.getURLFromString(this.m_baseIdent,
 null));
       initXPath(processor, null);
  -    
  -    if(m_hasExtensions)
  -    {
  -      // register the java namespace as being implemented by the 
  -      // xslt-javaclass engine. Note that there's no real code
  -      // per se for this extension as the functions carry the 
  -      // object on which to call etc. and all the logic of breaking
  -      // that up is in the xslt-javaclass engine.
  -      String uri = "http://xml.apache.org/xslt/java";;
  -      ExtensionFunctionHandler fh = 
  -                                   new ExtensionFunctionHandler (uri, null, 
"xslt-javaclass", null, null);
  -      
  -      XPathSupport xld = processor.getExecContext();
  -      xld.addExtensionNamespace (uri, fh);    
  -    }
     }
  -  
  +    
     /**
      * This recursive function is called starting from the 
      * stylesheet root, and tries to find a match for the 
  
  
  
  1.8       +113 -33   
xml-xalan/src/org/apache/xalan/xslt/StylesheetHandler.java
  
  Index: StylesheetHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xslt/StylesheetHandler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StylesheetHandler.java    1999/11/30 22:30:55     1.7
  +++ StylesheetHandler.java    1999/12/03 08:43:14     1.8
  @@ -67,8 +67,6 @@
   import org.apache.xalan.xslt.res.XSLTErrorResources;
   import org.apache.xalan.xpath.xml.XSLMessages;
   
  -import com.ibm.bsf.*;
  -
   /**
    * This class processes a stylesheet via SAX events, and inits
    * the given stylesheet.  If you need to alter the code in here, 
  @@ -134,7 +132,7 @@
     String m_LXSLTScriptLang;
     String m_LXSLTScriptSrcURL;
     ExtensionNSHandler m_LXSLTExtensionNSH;
  -  boolean m_bsfIsInited = false;
  +  // boolean m_bsfIsInited = false;
     // END SANJIVA CODE
     
     /**
  @@ -268,19 +266,7 @@
       }
       return isSpaceAttr;
     }
  -  
  -  private void initBSF()
  -  {
  -    // register the special engine that handles calling into Java objects
  -    // according to the rules of (Lotus)XSLT for method resolution etc.
  -    BSFManager.registerScriptingEngine ("xslt-javaclass",
  -                                        
"org.apache.xalan.xpath.XSLTJavaClassEngine",
  -                                        new String[0]);
  -
  -    m_bsfIsInited = true;
  -    m_stylesheet.m_hasExtensions = true;
  -  }
  -  
  +    
     /**
      * If this is set to true, we've already warned about using the 
      * older XSLT namespace URL.
  @@ -590,9 +576,6 @@
               }
               else 
if(aname.equals(Constants.ATTRNAME_EXTENSIONELEMENTPREFIXES))
               {
  -              if(!m_bsfIsInited)
  -                initBSF();
  -
                 // BEGIN SANJIVA CODE
                 StringTokenizer tokenizer = 
                                            new StringTokenizer (atts.getValue 
(i), " \t\n\r", false);
  @@ -600,12 +583,10 @@
                 {
                   String prefix = tokenizer.nextToken ();
                   // SANJIVA: ask Scott: is the line below correct?
  -                String extns =
  -                              m_stylesheet.getNamespaceForPrefixFromStack 
(prefix);
  +                String extns = m_stylesheet.getNamespaceForPrefixFromStack 
(prefix);
                   if (null == extns) 
                     extns = "";
  -                ExtensionNSHandler nsh = 
  -                                        new ExtensionNSHandler (m_processor, 
extns);
  +                ExtensionNSHandler nsh = new ExtensionNSHandler 
(m_processor, extns);
                   m_stylesheet.addExtensionNamespace (extns, nsh);
                 }
                 // END SANJIVA CODE
  @@ -740,6 +721,12 @@
                               name, atts, lineNumber, columnNumber);
             break;
   
  +        case Constants.ELEMNAME_FALLBACK:
  +          elem = new ElemFallback(m_processor,
  +                            m_stylesheet,
  +                            name, atts, lineNumber, columnNumber);
  +          break;
  +
           case Constants.ELEMNAME_CHOOSE:
             elem = new ElemChoose(m_processor,
                                   m_stylesheet,
  @@ -886,9 +873,6 @@
       else if (!m_inTemplate && (null != ns) &&
                ns.startsWith (m_processor.m_XSLT4JNameSpaceURL))
       {
  -      if(!m_bsfIsInited)
  -        initBSF();
  -
         if (localName.equals ("component")) 
         {
           String prefix = null;
  @@ -929,10 +913,16 @@
           ExtensionNSHandler nsh = m_stylesheet.lookupExtensionNSHandler 
(extns);
           if (nsh == null) 
           {
  -          throw new SAXException 
(XSLMessages.createMessage(XSLTErrorResources.ERROR0075, new Object[]{name, 
prefix})); //"(StylesheetHandler) " + name + 
  -          //" extension namespace prefix '" + prefix + 
  -          //"' unknown");
  +          if (elements != null) 
  +            throw new SAXException 
(XSLMessages.createMessage(XSLTErrorResources.ERROR0075, new Object[]{name, 
prefix})); //"(StylesheetHandler) " + name + 
  +          
  +          if (null == extns) 
  +            extns = "";
  +          nsh = new ExtensionNSHandler (m_processor, extns);
  +          m_stylesheet.addExtensionNamespace (extns, nsh);
           }
  +        
  +        nsh.setScript("javaclass", extns, null); // as default
           if (elements != null) 
           {
             nsh.setElements (elements);
  @@ -987,11 +977,92 @@
           // BEGIN SANJIVA CODE
           // is this an extension element call?
           ExtensionNSHandler nsh = null;
  -        if (ns != null && 
  -            ((nsh = m_stylesheet.lookupExtensionNSHandler (ns)) != null)) 
  +        
  +        if(null != ns)
           {
  -          if(!m_bsfIsInited)
  -            initBSF();
  +          // Yuck, first we have to look at the current attributes for 
  +          // a xsl:extension-element-prefixes attribute.
  +          int nAtts = atts.getLength();
  +          for(int i = 0; i < nAtts; i++)
  +          {
  +            String aname = atts.getName(i);
  +            int indexOfNSSep = aname.indexOf(':');
  +            String prefix;
  +            if(indexOfNSSep > 0)
  +            {
  +              prefix = aname.substring(0, indexOfNSSep);
  +              if(!prefix.equals("xmlns"))
  +              {
  +                String attrNS = m_stylesheet.getNamespaceForPrefixFromStack 
(prefix);
  +                if((null != attrNS) 
  +                   && attrNS.equals( m_stylesheet.m_XSLNameSpaceURL ))
  +                {
  +
  +                  String nm = aname.substring(indexOfNSSep+1);
  +                  if(nm.equals(Constants.ATTRNAME_EXTENSIONELEMENTPREFIXES))
  +                  {
  +                    String qnames = atts.getValue(i);
  +                    StringTokenizer tokenizer = new StringTokenizer(qnames, 
" \t\n\r", false);
  +                    for(int k = 0; tokenizer.hasMoreTokens(); k++)
  +                    {
  +                      String extnsPrefix = tokenizer.nextToken();
  +                      String extns = 
m_stylesheet.getNamespaceForPrefixFromStack (extnsPrefix);
  +                      if((ns != null) && ns.equals(extns))
  +                      {
  +                        nsh = new ExtensionNSHandler (m_processor, extns);
  +                        break;
  +                      }
  +                    }
  +                  }
  +                }
  +              }
  +            }
  +          }
  +          // now we have to look up the stack...
  +          if(null == nsh)
  +          {
  +            ElemTemplateElement parent = (ElemTemplateElement)m_elems.peek();
  +            while(null != parent)
  +            {
  +              int tok = parent.getXSLToken();
  +              String[] extensionElementPrefixes = null;
  +              if(Constants.ELEMNAME_EXTENSIONCALL == tok)
  +              {
  +                ElemExtensionCall extcall = (ElemExtensionCall)parent;
  +                extensionElementPrefixes = 
extcall.m_extensionElementPrefixes;
  +                
  +              }
  +              else if(Constants.ELEMNAME_LITERALRESULT == tok)
  +              {
  +                ElemLiteralResult extcall = (ElemLiteralResult)parent;
  +                extensionElementPrefixes = 
extcall.m_extensionElementPrefixes;
  +              }
  +              if(null != extensionElementPrefixes)
  +              {
  +                int n = extensionElementPrefixes.length;
  +                for(int i = 0; i < n; i++)
  +                {
  +                  String extnsPrefix = extensionElementPrefixes[i];
  +                  String extns = m_stylesheet.getNamespaceForPrefixFromStack 
(extnsPrefix);
  +                  if((ns != null) && ns.equals(extns))
  +                  {
  +                    nsh = new ExtensionNSHandler (m_processor, extns);
  +                    break;
  +                  }
  +                }
  +              }
  +              parent = parent.m_parentNode;
  +            }
  +          }
  +        }
  +        
  +        if ((ns != null) && (null == nsh)) 
  +        {
  +          nsh = m_stylesheet.lookupExtensionNSHandler(ns);
  +        }
  +        
  +        if (nsh != null) 
  +        {
             elem = new ElemExtensionCall (m_processor,
                                           m_stylesheet,
                                           nsh,
  @@ -1292,6 +1363,15 @@
         m_LXSLTExtensionNSH.setScript (m_LXSLTScriptLang, m_LXSLTScriptSrcURL,
                                        m_LXSLTScriptBody.toString ());
   
  +      // reset state
  +      m_inLXSLTScript = false;
  +      m_LXSLTScriptLang = null;
  +      m_LXSLTScriptSrcURL = null;
  +      m_LXSLTScriptBody = null;
  +      m_LXSLTExtensionNSH = null;
  +    }
  +    else if(null != m_LXSLTExtensionNSH)
  +    {
         // reset state
         m_inLXSLTScript = false;
         m_LXSLTScriptLang = null;
  
  
  
  1.12      +1 -1      xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/StylesheetRoot.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StylesheetRoot.java       1999/11/28 10:26:22     1.11
  +++ StylesheetRoot.java       1999/12/03 08:43:14     1.12
  @@ -93,7 +93,7 @@
      * attribute sets.
      */
     transient Stack m_attrSetStack = null;
  -  
  +    
     static final String DEFAULT_ENCODING = "UTF-8";
       
     /**
  
  
  
  1.17      +4 -88     xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java
  
  Index: XSLTEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- XSLTEngineImpl.java       1999/12/02 06:04:08     1.16
  +++ XSLTEngineImpl.java       1999/12/03 08:43:14     1.17
  @@ -1962,40 +1962,11 @@
       DocumentFragment docFrag = obj.rtree(support);
       NodeList nl = docFrag.getChildNodes();
       int nChildren = nl.getLength();
  +    TreeWalker tw = new TreeWalker(m_flistener);
       for(int i = 0; i < nChildren; i++)
       {
  -      Node pos = nl.item(i);
  -      Node top = pos;
  -      while(null != pos)
  -      {
  -        flushPending();
  -        cloneToResultTree( m_stylesheetRoot, pos, false, false, true );
  -        Node nextNode = pos.getFirstChild();
  -        while(null == nextNode)
  -        {
  -          if(Node.ELEMENT_NODE == pos.getNodeType())
  -          {
  -            m_resultTreeHandler.endElement(pos.getNodeName());
  -          }
  -          if(top == pos)
  -            break;
  -          nextNode = pos.getNextSibling();
  -          if(null == nextNode)
  -          {
  -            pos = pos.getParentNode();
  -            if((top == pos) || (null == pos))
  -            {
  -              if((null != pos) && (Node.ELEMENT_NODE == pos.getNodeType()))
  -              {
  -                m_resultTreeHandler.endElement(pos.getNodeName());
  -              }
  -              nextNode = null;
  -              break;
  -            }
  -          }
  -        }
  -        pos = nextNode;
  -      }
  +      flushPending(); // I think.
  +      tw.traverse(nl.item(i));
       }
     }
   
  @@ -3159,61 +3130,6 @@
       }
     }
   
  -  /**
  -   * Get the textual contents of the node. If the node
  -   * is an element, apply whitespace stripping rules,
  -   * though I'm not sure if this is right (I'll fix
  -   * or declare victory when I review the entire
  -   * whitespace handling).
  -   */
  -  String getNodeData(Node node)
  -    throws org.xml.sax.SAXException
  -  {
  -    String data = null;
  -    switch(node.getNodeType())
  -    {
  -    case Node.DOCUMENT_FRAGMENT_NODE:
  -    case Node.DOCUMENT_NODE:
  -    case Node.ELEMENT_NODE:
  -      for(Node child = node.getFirstChild(); null != child; 
child=child.getNextSibling())
  -      {
  -        String nodeData = getNodeData(child);
  -        if((null != nodeData) && (nodeData.length() > 0))
  -        {
  -          data = (null == data) ? nodeData : (data + nodeData);
  -        }
  -      }
  -      break;
  -    case Node.TEXT_NODE:
  -    case Node.CDATA_SECTION_NODE:
  -      // Apply the same whitespace rules that you apply to
  -      // fixing the whitespace when m_stripWhiteSpace == true.
  -      // Don't know if this is OK.
  -      if(shouldStripSourceNode(node))
  -      {
  -        if(!m_parserLiaison.isIgnorableWhitespace((Text)node))
  -        {
  -          // data = fixWhiteSpace(((Text)node).getData(), false, false, 
true);
  -          data = getNormalizedText((Text)node);
  -        }
  -      }
  -      else
  -      {
  -        data = ((Text)node).getData();
  -      }
  -      break;
  -    case Node.ATTRIBUTE_NODE:
  -      data = node.getNodeValue();
  -      break;
  -    default:
  -      // ignore
  -      break;
  -    }
  -
  -    return data;
  -  }
  -
  -
   
     /**
      * Given a tag name, an attribute name, and
  @@ -4052,7 +3968,7 @@
      * Class to bottleneck the SAX output events for the
      * result tree.
      */
  -  class ResultTreeHandler implements DocumentHandler
  +  class ResultTreeHandler implements DocumentHandler, RawCharacterHandler
     {
   
       /**
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xslt/ElemFallback.java
  
  Index: ElemFallback.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xslt;
  
  import org.w3c.dom.*;
  import org.xml.sax.*;
  import org.apache.xalan.xpath.*;
  import org.apache.xalan.xslt.trace.SelectionEvent;
  import org.apache.xalan.xpath.xml.QName;
  import org.apache.xalan.xslt.res.XSLTErrorResources;
  
  public class ElemFallback extends ElemTemplateElement
  {
    public int getXSLToken()
    {
      return Constants.ELEMNAME_FALLBACK;
    }
    
    public ElemFallback (XSLTEngineImpl processor,
                        Stylesheet stylesheetTree,
                        String name, 
                    AttributeList atts,
                    int lineNumber, int columnNumber)
      throws SAXException
    {
      super(processor, stylesheetTree, name, atts, lineNumber, columnNumber);
      int nAttrs = atts.getLength();
      for(int i = 0; i < nAttrs; i++)
      {
        String aname = atts.getName(i);
        int tok = getAttrTok(aname);
        switch(tok)
        {
        case Constants.TATTRNAME_XMLSPACE:
          processSpaceAttr(atts, i);
          break;
        default:
          if(!isAttrOK(tok, aname, atts, i))
          {
            processor.error(XSLTErrorResources.ERROR0002, new Object[] {name, 
aname}); //name+" has an illegal attribute: "+aname);
          }
        }
      }
    }
  
    public void execute(XSLTEngineImpl processor, 
                        Node sourceTree, 
                        Node sourceNode,
                        QName mode)
      throws XSLProcessorException, 
             java.net.MalformedURLException, 
             java.io.FileNotFoundException, 
             java.io.IOException,
             SAXException
    {    
      if(Constants.ELEMNAME_EXTENSIONCALL == m_parentNode.getXSLToken())
      {
        ElemExtensionCall parent = (ElemExtensionCall)m_parentNode; 
        if(!parent.elementIsAvailable())
        {
          super.execute(processor, sourceTree, sourceNode, mode);
          XPathSupport execContext = processor.getXMLProcessorLiaison();
          executeChildren(processor, sourceTree, 
                          sourceNode, mode);
        }
      }
      else
      {
        // Should never happen
        System.out.println("Error!  parent of xsl:fallback must be an extension 
element!");
      }
    }
  }
  
  
  

Reply via email to