You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Heath James <he...@sees.bangor.ac.uk> on 2000/10/26 15:58:06 UTC

An error or am I missing the point?

I'm really embarrassed to have to appeal for help on this one, but after
years of using java, it comes to this ....

I'm trying to construct a really simple applet that will process a given
xml file against an xsl file. Both files are represented by urls.

I'm extending the XSLTProcessorApplet class as it says in the
instructions. I have an apache web server running on the local machine,
so the xml and xsl files are both in the correct path, and available. 

When the transformXmlToHtml method is executed, it comes up with a
NullPointerException.

The source code, and the error message is attached. 

Am I simply being dumb or is there some trick that I'm not aware of, for
getting this to work. 

Please reply to my email address: heath@sees.bangor.ac.uk

Thanks very much for your time!

HJ.

--
SOURCE CODE

import org.apache.xalan.xslt.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class hjApplet extends
org.apache.xalan.xslt.client.XSLTProcessorApplet {

    String docURL = null;
    String styleURL = null;

    public hjApplet() {
	super();
	System.err.println("INITn FINISHED!!");
    }

    public void init() {
	if ((docURL = getParameter("DocumentURL")) == null) {
	    System.err.println("Cannot read document URL!!");
	    System.exit(1);
	}
	setDocumentURL(docURL);
	System.err.println("doc = "+docURL);
	if ((styleURL = getParameter("StyleURL")) == null) {
	    System.err.println("Cannot read style URL!!");
	    System.exit(1);
	}
	setStyleURL(styleURL);
	System.err.println("style = "+styleURL);
    }

    public void start() {
	InputStream xmlIS = null;
	InputStream xslIS = null;

	try {
	    setDocumentURL(docURL);
	    setStyleURL(styleURL);

  		// Not really needed, but for peace of mind ...
		// Make sure the urls supplied as parameters are valid 
		// and their contents readable
	    URL dURL = new URL(docURL); 
	    xmlIS = dURL.openStream();
	    System.err.println("xmlIS = "+xmlIS);
	    URL sURL = new URL(styleURL);
	    xslIS = sURL.openStream();
	    System.err.println("xslIS = "+xslIS);

	    String result = null;
	    result = getStyleTreeAsText();
	    System.err.println("result = " +result);
		// The above code works, as you can see from the
		// output

	    System.err.println("About to transform xml -> html");
	    result = transformToHtml(docURL, styleURL);
	    System.err.println("new result = "+result);
		// The transformToHtml() line above consistently
		// produces a Null Pointer Error, even when it is
		// possible to [individually] read the xml and xsl
		// documents

	} catch (Exception e) {
	    System.err.println("Caught an exception: "+e);
	    e.printStackTrace();
	    System.exit(1);
	}

	
    }

}

--

ERROR OUTPUT

The output below occurs when the program is run within Netscape. The
error is occuring on the transformToHtml(docURL, styleURL) line.

<xsl:stylesheet>
...
</xsl:stylesheet>

Caught an exception: java.lang.NullPointerException

java.lang.NullPointerException

  at
org.apache.xalan.xslt.client.XSLTProcessorApplet.getHtmlText(Compiled
Code)

* at
org.apache.xalan.xslt.client.XSLTProcessorApplet.transformToHtml(Compiled
Code)

  at hjApplet.start(Compiled Code)

  at
netscape.applet.DerivedAppletFrame$StartAppletEvent.dispatch(Compiled
Code)

  at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled
Code)

  at java.awt.EventDispatchThread.run(Compiled Code)

  at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)

netscape.security.AppletSecurityException: security.checkexit: 1

  at java.lang.Throwable.<init>(Compiled Code)

  at java.lang.Exception.<init>(Compiled Code)

  at java.lang.RuntimeException.<init>(Compiled Code)

  at java.lang.SecurityException.<init>(Compiled Code)

  at netscape.security.AppletSecurityException.<init>(Compiled Code)

  at netscape.security.AppletSecurityException.<init>(Compiled Code)

  at netscape.security.AppletSecurity.checkExit(Compiled Code)

  at java.lang.SecurityManager.checkExit(Compiled Code)

  at java.lang.Runtime.exit(Compiled Code)

  at java.lang.System.exit(Compiled Code)

  at hjApplet.start(Compiled Code)

* at
netscape.applet.DerivedAppletFrame$StartAppletEvent.dispatch(Compiled
Code)

  at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled
Code)

  at java.awt.EventDispatchThread.run(Compiled Code)

  at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)



-- 
Dr Heath A. James, Lecturer
School of Informatics, University of Wales
Dean Street, Bangor, Gwynedd, UK LL57 1UT
Email: heath@sees.bangor.ac.uk
Mobile: 07771 746 900

Re: An error or am I missing the point?

Posted by Gary L Peskin <ga...@firstech.com>.
Please see my comments below.

Gary

Heath James wrote:
> And, I've since tried to run the original code, after copying the whole
> xalan distribution to the www directory of my department's web server.
> The files are acessible, as the four-framed web page comes up, even
> showing the xml and xsl files' contents. However, when I hit the
> transform button, the only output in the right hand side is "null" and
> the java console produces the text below.  Any hints?
> 
> Thanks,
> 
> HJ
>
> netscape.security.AppletSecurityException: security.class from local
> disk trying to access url:
> http://saturn.sees.bangor.ac.uk/~heath/xalan/samples/AppletXMLtoHTML/s1ToHTML.xsl
>   at java.lang.Throwable.<init>(Compiled Code)
>   at java.lang.Exception.<init>(Compiled Code)
>   at org.xml.sax.SAXException.<init>(Compiled Code)
>   at org.apache.xerces.framework.XMLParser.parse(Compiled Code)
>   at
> org.apache.xalan.client.XSLTProcessorApplet.doTransformation(Compiled
> Code)
>   at
> org.apache.xalan.client.XSLTProcessorApplet.processTransformation(Compiled
> Code)
> * at org.apache.xalan.client.XSLTProcessorApplet.access$3(Compiled Code)
>   at
> org.apache.xalan.client.XSLTProcessorApplet$TrustedAgent.run(Compiled
> Code)
>   at java.lang.Thread.run(Compiled Code)

Heath --

I've copied this to the Xalan list because I think that it will have
interest there.

I'm not an applet person, as I've said before.  I've been learning about
applets all morning and I still don't know too much.  However, here is
what I do know:

-On my Netscape (4.75), I'm using the built-in java VM which shows on
the java console as "Netscape Communications Corporation -- Java
1.1.5".  When I click on transform, I get almost the same results as you
do.  Actually, my security exception is thrown from
getSourceTreeFromInput so it happens a little earlier than yours does. 
However, I'm accessing a local file (file://) whereas you're accessing
via http:// so that might make the difference.  I also get the xml and
xsl source showing and "null" in the rightmost window.

-On my Internet Explorer 5.50.4134.0600, the java console shows
"Microsoft (R) VM for Java, 5.0 Release 5.0.0.3309".  When I click on
transform, I get the transformed document in the rightmost pane but the
xml and xsl panes are blank except for the headings.  The java console
shows two security exceptions for each document.  They are
"com.ms.security.SecurityExceptionEx[Unknown]: cannot access file ..." 
This is happening in the writeSource() and writeStylesheet() methods in
client.html in getSourceTreeAsText() and getStyleTreeAsText().

-It's clear from the results that each applet is sometimes able to read
the files and sometimes not depending on how it goes about it.

-It seems like in the olden days when this was originally written and
presumably working that if you made a child thread, this child thread
would somehow be specially authorized and bypass/evade some (or all) of
the applet sandbox restrictions.  I could only find oblique references
to this.  However, the comment in XSLTProcessorApplet preceeding the
declaration of the TrustedAgent inner class is:

  /**
   * This class maintains a worker thread that that is
   * trusted and can do things like access data.  You need
   * this because the thread that is called by the browser
   * is not trusted and can't access data from the URLs.
   */

This doesn't seem to be the case anymore.

-From reading the Netscape and MS sites, it seems that each have been
doing more and more towards applet security in the various releases. 
This seems, to me, to have resulted in the bizarre situation that the
security model is different for each browser and each release of that
browser.

-We know that you can access the files from Netscape because they show
up in the two left panes.  Therefore, it must be possible to construct
an applet that will work properly.  Perhaps you'd like to fiddle with
the source and contribute your working results back to the project. 
I've sort of lost interest in applets altogether after this episode.

-This example doesn't seem to fare any better under XalanJ2.

Re: An error or am I missing the point?

Posted by Gary L Peskin <ga...@firstech.com>.
Heath James wrote:
> I'm trying to construct a really simple applet that will process a given
> xml file against an xsl file. Both files are represented by urls.
> 
> I'm extending the XSLTProcessorApplet class as it says in the
> instructions.

Well, not really.  It means to include XSLTProcessorApplet in an
<APPLET...> or equivalent tag in your web page.  Like in the samples
directory.  If you look at the source for it
(org.apache.xalan.xslt.client.XSLTProcessorApplet) you'll see that the
init() and start() methods do the work.  You're just overriding those
methods but not invoking them.

You don't really need to code all of this stuff.  XSLTProcessorApplet is
not a base class, meant to be derived from, but a "complete"
implementation.

> When the transformXmlToHtml method is executed, it comes up with a
> NullPointerException.

Yes, your implementation is incomplete.

> Am I simply being dumb or is there some trick that I'm not aware of, for
> getting this to work.

Not dumb.  The instructions could be improved.

HTH,
Gary