You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Cary A. Bran" <re...@verizon.net> on 2001/03/07 07:04:48 UTC

Applet and Xalan

Hello,

I am having problems using Xalan from within an applet.  The problem
manifests itself whenever I make a call to the newTemplates() function.  I
am using forte to develop the applet and it runs fine under debug execution,
but under runtime execution it fails.  I have downloaded the latest
TrasformerFactory.java file (the one with exception handling for the
user.dir exception) and am still having problems.  The scenario is I have 2
documents 1 XML, 1XSL, that I am getting from the applets local directory
(this should not cause any problems - and they both load fine into Document
objects). The error comes when I try to create a templates object using a
DOMSource for the XSL document basically it looks like this:

	DOMSource xslSource = new DOMSource(xslDoc); //where xslDoc is a Document
object

	//here is where it runs into trouble - mind you this is only occurs for
applets under runtime mode
	Templates templates = transformerFactory.newTemplates(xslSource);

I didn't show the TransformerFactory instance creation but it does occur.  I
have traced the code and it looks like the error is occurring in the
OutputProperties.java loadPropertiesFile method.  There appears to be a
problem getting the resource name when calling
OutputProperties.class.getResourceAsStream(resourceName). The resultant
InputStream from this call is null causes everything else to barf.

Is this a known issue?  Is there a work around for using Xalan with applets
that won't require signing the applet or turning down the security settings
in IE for it to function?

Any help would be much appreciated!

Thanks,

Cary A. Bran

Cisco Systems.
Seattle, WA


RE: Applet and Xalan

Posted by "Cary A. Bran" <re...@verizon.net>.
Greetings all,

It appears that my problems are coming from the OutputProperties.java file
loadPropertiesFile method whenever it tries to load a properties file: e.g.
InputStream =OutputProperties.class.getResourceAsStream(resourceName);

- When this is executed with the security constraints of the applet sandbox
it causes an IO exception because it is trying to find the file by accessing
system resources.
The exception occurs here:
BufferedInputStream bis = new BufferedInputStream(is);  - is, the input
stream is null.

To work around this, I manually set default properties (the ones contained
within output_xml.properties, output_text.properties, and
output_html.properties) for the Property member variables contained within
the class; m_xml_properties, m_html_properties, and m_text_properties.  I
believe placing the calls to the  loadPropertiesFile method within a try
catch block and if an exception is thrown, initialized the Property objects
manually.  Something like:

static public Properties getDefaultMethodProperties(String method)
  {

    Properties defaultProperties = null;

    try
    {
      if (null == m_xml_properties)  // fast check
      {
        synchronized (m_synch_object)
        {
          if (null == m_xml_properties)  // double check
          {
        try{
            m_xml_properties = loadPropertiesFile("output_xml.properties",
null);
        }
        catch(Exception e){
                //if the load propertiefile method fails then load the
default properties manually.
        m_xml_properties = new Properties();
        m_xml_properties.setProperty("encoding", "UTF-8");
        m_xml_properties.setProperty("indent", "no");
m_xml_properties.setProperty("media-type", text/xml");
m_xml_properties.setProperty("method", "xml");
....
....
....

}
          }
        }
      }

This along with the other fixes for the security issues (mentioned below and
elsewhere in this list) has enabled me to bring the up and run an applet in
Internet Explorer that uses xalan to transform xml without having to turn
off the security.

Please let me know if you all think that this is a good idea...

-Cary A. Bran


-----Original Message-----
From: Edwin Goei [mailto:Edwin.Goei@eng.sun.com]
Sent: Wednesday, March 07, 2001 2:52 PM
To: xalan-dev@xml.apache.org
Subject: Re: Applet and Xalan

"Cary A. Bran" wrote:
>
> Hello,
>
> I am having problems using Xalan from within an applet.  The problem
[snip]
> I
> have traced the code and it looks like the error is occurring in the
> OutputProperties.java loadPropertiesFile method.  There appears to be a
> problem getting the resource name when calling
> OutputProperties.class.getResourceAsStream(resourceName). The resultant

I also ran into probably the same problem.  See the following posting
for a patch that fixes it.  Hopefully, someone will review it and commit
it to the repository.

http://marc.theaimsgroup.com/?l=xalan-dev&m=98393112025313&w=2

I ran into another problem afterwards that I haven't gotten a chance to
debug yet, also described in the posting.

-Edwin


Re: Applet and Xalan

Posted by Edwin Goei <Ed...@eng.sun.com>.
"Cary A. Bran" wrote:
> 
> Hello,
> 
> I am having problems using Xalan from within an applet.  The problem
[snip]
> I
> have traced the code and it looks like the error is occurring in the
> OutputProperties.java loadPropertiesFile method.  There appears to be a
> problem getting the resource name when calling
> OutputProperties.class.getResourceAsStream(resourceName). The resultant

I also ran into probably the same problem.  See the following posting
for a patch that fixes it.  Hopefully, someone will review it and commit
it to the repository.

http://marc.theaimsgroup.com/?l=xalan-dev&m=98393112025313&w=2

I ran into another problem afterwards that I haven't gotten a chance to
debug yet, also described in the posting.

-Edwin