You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by My...@lotus.com on 2000/08/14 21:06:42 UTC

Re: PATCH: Jaxp support

Hello Costin,
I just checked in your patch to XalanJ1. If you don't mind, could you
double check that things work the way they should on your end before we
include it in the next build?
Please let me know if you run into any problems. Thanks a lot!

Myriam




costin@costin.dnt.ro on 08/11/2000 05:51:10 PM

Please respond to xalan-dev@xml.apache.org

To:   "xalan-dev@xml.apache.org" <xa...@xml.apache.org>
cc:    (bcc: Myriam Midy/CAM/Lotus)
Subject:  PATCH: Jaxp support

Hi,

This is a new Liaison that use javax.xml to parse. It's not
complete - xerces is still needed to compile, but at runtime
it is possible to use only xalan.jar and a jaxp parser ( with support
for SAX2 ). You also need org.apache.xml.serialize in your classpath
( it is independent of xerces ).

Note that xalan + xerces will be faster - but without this fix
the idea of Liaison doesn't work ( since xerces is
hardcoded ).

There are few other changes that are needed to build
xalan without xerces.

( Crimson doesn't work right now - some fixes are required
in SAX2 impl. )

If you think it's usefull please check it in.

Costin

Index: src/org/apache/xalan/xslt/XSLTEngineImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v

retrieving revision 1.65
diff -u -r1.65 XSLTEngineImpl.java
--- src/org/apache/xalan/xslt/XSLTEngineImpl.java 2000/08/08 01:33:33
1.65
+++ src/org/apache/xalan/xslt/XSLTEngineImpl.java 2000/08/11 21:21:51
@@ -490,30 +490,40 @@
    // DTM - DTM - Do nothing, We're OK
    // Xerces DOM - DTM - error, you can't have DTM as a result
    // Xerces DOM - Xerces DOM - switch to Xerces Liaison
-
-
-    if((null != resultNode) && (resultNode instanceof
org.apache.xerces.dom.NodeImpl) &&
-       (m_parserLiaison instanceof
org.apache.xalan.xpath.dtm.DTMLiaison))
-    {
-      if((null != sourceNode)
-         && (!(sourceNode instanceof org.apache.xerces.dom.NodeImpl)))
-      {
-        throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_MIX_XERCESDOM,

null)); //"Can not mix non Xerces-DOM input with Xerces-DOM output!");
-      }
+
+    // common condition
+    if(! "org.apache.xalan.xpath.dtm.DTMLiaison".equals(
m_parserLiaison.getClass().getName()))
+      return;
+
+    String specialNote="org.apache.xerces.dom.NodeImpl";
+
+    boolean specialResult=false;
+    if( resultNode != null && specialNote.equals(
resultNode.getClass().getName()))
+      specialResult=true;
+
+    boolean specialSource=false;
+    if( sourceNode != null && specialNote.equals(
sourceNode.getClass().getName()))
+      specialSource=true;

+    if( specialResult && ! specialSource && sourceNode!= null )
+      throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.
+             ER_CANNOT_MIX_XERCESDOM, null));
+      //"Can not mix non Xerces-DOM input with Xerces-DOM output!");
+
+    if( specialResult ) { // either sourceNote==null or specialSource
+      // XXX class.forName ?
       XMLParserLiaison newLiaison = new
org.apache.xalan.xpath.xdom.XercesLiaison();

newLiaison.copyFromOtherLiaison((XMLParserLiaisonDefault)m_parserLiaison);

       setExecContext(newLiaison);
+      return;
     }
-    else if((null != sourceNode)&& (sourceNode instanceof
org.apache.xerces.dom.NodeImpl) &&
-       (m_parserLiaison instanceof
org.apache.xalan.xpath.dtm.DTMLiaison))
-    {
-      if((null != resultNode)
-         && (!(resultNode instanceof org.apache.xerces.dom.NodeImpl)))
-      {
-        throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_CANNOT_MIX_XERCESDOM,

null)); //"Can not mix Xerces-DOM input with non Xerces-DOM output!");
-      }
-
+
+    if( specialSource && ! specialResult && resultNode!=null )
+        throw new
SAXException(XSLMessages.createMessage(XSLTErrorResources.
+        ER_CANNOT_MIX_XERCESDOM, null));
+    //"Can not mix Xerces-DOM input with non Xerces-DOM output!");
+
+    if( specialSource ) { // either specialResult or resultNode==null
       XMLParserLiaison newLiaison = new
org.apache.xalan.xpath.xdom.XercesLiaison();

newLiaison.copyFromOtherLiaison((XMLParserLiaisonDefault)m_parserLiaison);

       setExecContext(newLiaison);

package org.apache.xalan.xpath.xml;

import java.io.*;
import java.net.URL;

import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;

import org.apache.xalan.xpath.xml.*;
import org.apache.xalan.xpath.*;


/**
 *  Allow use of a generic JAXP parser with Xalan.
 */
public class JaxpLiaison extends XMLParserLiaisonDefault
{
    // later.
    String domFactoryName=null;
    String saxFactoryName=null;

    public JaxpLiaison()
    {
    }

    // debug
    static final int debug=0;
    void d( String s) {
           System.out.println("JaxpLiaison: " + s );
    }

    // -------------------- Liason implementation --------------------

    public String getParserDescription()
    {
           return "Jaxp";
    }

    public void checkNode(Node node)
           throws SAXException
    {
           if( debug>0) d("Calling checkNode");
    }

    public boolean supportsSAX()
    {
           if(debug>0) d("Calling supportsSAX");
           return true;
    }

    public void parse (InputSource source)
           throws SAXException, IOException
    {
           try {
               if( m_docHandler != null ) {

                     SAXParserFactory sf=null;
                     //if( saxFactoryName == null)
                     sf=SAXParserFactory.newInstance();
                     //                   else
                     //
sf=SAXParserFactory.newInstance(saxFactoryName);

                     sf.setNamespaceAware( true );
                     SAXParser saxP=sf.newSAXParser();

                     Parser p=saxP.getParser();

                     if( debug>0) d("Parse " + m_docHandler +
                                      " " + m_DTDHandler+
                                      " " + m_errorHandler +
                                      " " + m_entityResolver);
                     p.setDocumentHandler( m_docHandler);

                     if(null != m_DTDHandler) {
                         p.setDTDHandler(m_DTDHandler);
                     }

                     if(null != m_errorHandler) {
                         p.setErrorHandler(m_errorHandler);
                     }  else {
                         String ident = source.getSystemId();
                         if( ident==null ) ident=source.toString();
                         p.setErrorHandler(new DefaultErrorHandler(ident));
                     }

                     if(null != m_entityResolver) {
                         p.setEntityResolver(m_entityResolver);
                     }

                     p.parse(source);
                     // XXX XXX Workaround - without this stylesheed
handler will
                     // remain set
                     m_docHandler=null;
               } else {
                     if(debug>0) d("XalanJaxpLiaison: dom parse " +
m_docHandler +
                                     " " + m_entityResolver + " " +
m_errorHandler);
                     DocumentBuilderFactory df=null;
                     //                   if( domFactoryName==null )
                     df=DocumentBuilderFactory.newInstance();
                     // else
                     //
df=DocumentBuilderFactory.newInstance(domFactoryName);
                     df.setNamespaceAware( true );
                     DocumentBuilder docB=df.newDocumentBuilder();

                     if (m_entityResolver != null) {
                         docB.setEntityResolver(m_entityResolver);
                     }

                     if (m_errorHandler != null) {
                         docB.setErrorHandler(m_errorHandler);
                     }


                     m_document= docB.parse(source);
               }
           } catch(Exception e ) {
               e.printStackTrace();
           }
    }

    public Document getDocument()
    {
           if(debug>0) d( "getDocument() " + m_document);
           return m_document;
    }

    /**
     * Create an empty DOM Document.  Mainly used for creating an
     * output document.  Implementation of XMLParserLiaison
     * interface method.
     */
    public Document createDocument()
    {
           if(debug>0) d( "createDocument() " );
           try {
               DocumentBuilderFactory df=DocumentBuilderFactory.newInstance
();
               DocumentBuilder docB=df.newDocumentBuilder();
               return docB.newDocument();
           } catch( Exception ex ) {
               ex.printStackTrace();
               return null;
           }
    }

    public Element getElementByID(String id, Document doc)
    {
           if(debug>-1) d("GetElemByID");
           return null;
    }
}






Re: xpath.Process problem or am I doing something wrong?

Posted by Gary L Peskin <ga...@firstech.com>.
Michael --

Thanks for the clarification.  I really haven't looked into this too
much.  It looks like parseXML was deprecated in XPathSupport because no
one else was using it anymore.  You might want to have a look in the
XPathAPI.java source in samples\ApplyXPath.  This is the class that
actually does the work for ApplyXPath.  It looks like it just takes a
Node which would work for you maybe.

Like I said, I haven't really studied this but the techniques in
XPathAPI might give you some insight to a workaround or proper
implementation.

Gary

Michael Shapiro wrote:
> 
> Gary,
> 
> Thank you very much.
> 
> Yes, I could use ApplyXPath and the high level API it's presenting but my
> real task is somewhat different.
> I'm trying to put a thin DOM layer around some tree-like structured object
> that has it's own accessors and mutators.
> The first thing I'd like to implement is something similar to
> xpath.Process.main. ApplyXPath example is using DOMParser directly that's
> why it's less useful in my case.
> 
> Thanks again,
> 
> Michael

Re: xpath.Process problem or am I doing something wrong?

Posted by Michael Shapiro <mi...@creativescience.com>.
Gary,

Thank you very much.

Yes, I could use ApplyXPath and the high level API it's presenting but my
real task is somewhat different.
I'm trying to put a thin DOM layer around some tree-like structured object
that has it's own accessors and mutators.
The first thing I'd like to implement is something similar to
xpath.Process.main. ApplyXPath example is using DOMParser directly that's
why it's less useful in my case.

Thanks again,

Michael


----- Original Message -----
From: "Gary L Peskin" <ga...@firstech.com>
To: <xa...@xml.apache.org>
Sent: Thursday, August 17, 2000 7:10 PM
Subject: Re: xpath.Process problem or am I doing something wrong?


> Michael --
>
> You are correct that this is the problem.  I haven't looked into fixing
> Process.main to go to parse where it seems like it should go.  However,
> you can accomplish what you want with the following command line:
>
> java ApplyXPath c:\test.xml /
>
> This is explained at http://xml.apache.org/xalan/samples.html#xpath
>
> Also, you'll need to change the comma in version="1,0" to a period.
>
> HTH,
> Gary
>
> Michael Shapiro wrote:
> >
> > Sorry in advance for the [most probably] stupid question.
> >
> > I'm trying to use XPathProcessor and I ran into the problem.
> >
> > Here is the problem:
> >
> > c:\>java org.apache.xalan.xpath.Process file:///C:\test.xml -select "/"
> > Parsing XML:
> > java.lang.NullPointerException:
> >         at
> >
org.apache.xalan.xpath.SimpleNodeLocator.findRoot(SimpleNodeLocator.java:114
> > 5)
> >         at org.apache.xalan.xpath.SimpleNodeLocator.step(Compiled Code)
> >         at
> >
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java
> > :321)
> >         at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
> >         at org.apache.xalan.xpath.XPath.execute(XPath.java:1381)
> >         at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
> >         at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
> >         at org.apache.xalan.xpath.XPath.execute(XPath.java:274)
> >         at org.apache.xalan.xpath.Process.main(Compiled Code)
> >
> > The test.xml file content is:
> > <?xml version="1,0"?>
> > <a>
> >     <b/>
> > </a>
> >
> > After spending sometime on the source code study I found that somehow
the
> >     doc = callbacks.parseXML(url, null, null);
> > goes to XPathSupportDefault that always returns null
> >
> > I think it should go to xerces parser (through XMLParserLiason) but in
> > reallity it goes to XPathSupportDefult that has a parseXML method
returning
> > null.
> >
> > Any advice would be greatly appriciated.
> >
> > Michael
>


Re: xpath.Process problem or am I doing something wrong?

Posted by Gary L Peskin <ga...@firstech.com>.
Michael --

You are correct that this is the problem.  I haven't looked into fixing
Process.main to go to parse where it seems like it should go.  However,
you can accomplish what you want with the following command line:

	java ApplyXPath c:\test.xml /

This is explained at http://xml.apache.org/xalan/samples.html#xpath

Also, you'll need to change the comma in version="1,0" to a period.

HTH,
Gary

Michael Shapiro wrote:
> 
> Sorry in advance for the [most probably] stupid question.
> 
> I'm trying to use XPathProcessor and I ran into the problem.
> 
> Here is the problem:
> 
> c:\>java org.apache.xalan.xpath.Process file:///C:\test.xml -select "/"
> Parsing XML:
> java.lang.NullPointerException:
>         at
> org.apache.xalan.xpath.SimpleNodeLocator.findRoot(SimpleNodeLocator.java:114
> 5)
>         at org.apache.xalan.xpath.SimpleNodeLocator.step(Compiled Code)
>         at
> org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java
> :321)
>         at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
>         at org.apache.xalan.xpath.XPath.execute(XPath.java:1381)
>         at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
>         at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
>         at org.apache.xalan.xpath.XPath.execute(XPath.java:274)
>         at org.apache.xalan.xpath.Process.main(Compiled Code)
> 
> The test.xml file content is:
> <?xml version="1,0"?>
> <a>
>     <b/>
> </a>
> 
> After spending sometime on the source code study I found that somehow the
>     doc = callbacks.parseXML(url, null, null);
> goes to XPathSupportDefault that always returns null
> 
> I think it should go to xerces parser (through XMLParserLiason) but in
> reallity it goes to XPathSupportDefult that has a parseXML method returning
> null.
> 
> Any advice would be greatly appriciated.
> 
> Michael

xpath.Process problem or am I doing something wrong?

Posted by Michael Shapiro <mi...@creativescience.com>.
Sorry in advance for the [most probably] stupid question.

I'm trying to use XPathProcessor and I ran into the problem.

Here is the problem:

c:\>java org.apache.xalan.xpath.Process file:///C:\test.xml -select "/"
Parsing XML:
java.lang.NullPointerException:
        at
org.apache.xalan.xpath.SimpleNodeLocator.findRoot(SimpleNodeLocator.java:114
5)
        at org.apache.xalan.xpath.SimpleNodeLocator.step(Compiled Code)
        at
org.apache.xalan.xpath.SimpleNodeLocator.locationPath(SimpleNodeLocator.java
:321)
        at org.apache.xalan.xpath.XPath.locationPath(XPath.java:964)
        at org.apache.xalan.xpath.XPath.execute(XPath.java:1381)
        at org.apache.xalan.xpath.XPath.execute(XPath.java:1354)
        at org.apache.xalan.xpath.XPath.execute(XPath.java:311)
        at org.apache.xalan.xpath.XPath.execute(XPath.java:274)
        at org.apache.xalan.xpath.Process.main(Compiled Code)

The test.xml file content is:
<?xml version="1,0"?>
<a>
    <b/>
</a>

After spending sometime on the source code study I found that somehow the
    doc = callbacks.parseXML(url, null, null);
goes to XPathSupportDefault that always returns null

I think it should go to xerces parser (through XMLParserLiason) but in
reallity it goes to XPathSupportDefult that has a parseXML method returning
null.

Any advice would be greatly appriciated.

Michael