Not sure if the following looks good to you.  I get an exception: “java.io.FileNotFoundException: C:\messagepoint\reports\operationsReports\1\2 (Access is denied)”.

I checked the folder name. It is right.

 

It looks same with the previous one which works well.

 

 

package com.messagepoint.model.util;

 

import java.io.File;

import java.io.FileInputStream;

import java.io.InputStream;

 

import javax.xml.transform.Result;

import javax.xml.transform.Source;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerException;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.URIResolver;

import javax.xml.transform.stream.StreamResult;

import javax.xml.transform.stream.StreamSource;

 

import net.sf.saxon.trans.XPathException;

 

//This class is used to transform XML and XSLT to HTML file.

//If we need to chunk HTML file, SAXON is called.

public class XMLTransformer {

      

       public static void TransToHTML(String xslFilePath, String xmlFilePath, String htmlOutputFilePath, Boolean chunkHTML) throws Exception {

             

             

              InputStream xsltStream = null;

              xsltStream = MessageContentUtil.class.getClassLoader().getResourceAsStream(xslFilePath);

 

              Source xsltSource = new StreamSource(xsltStream);

             

              File xmlFile = new File( "\\messagepoint\\reports\\operationsReports\\operationsReport.xml" );

              InputStream xmlStream = new FileInputStream(xmlFile);

              Source xmlSource = new StreamSource(xmlStream);

             

              TransformerFactory transFact = getTransformerFactory(chunkHTML);

             

              URIResolver resolver = new URIResolver() {

                     public Source resolve(String href, String base)

                                  throws TransformerException {

                           InputStream includeXSLTStream = MessageContentUtil.class

                                         .getClassLoader().getResourceAsStream(

                                                       "com/prinova/messagepoint/model/util/" + href);

                           Source includeXSLTSource = new StreamSource(includeXSLTStream);

                           return includeXSLTSource;

                     }

              };

              transFact.setURIResolver(resolver);

              Transformer trans = transFact.newTransformer(xsltSource);

              ((net.sf.saxon.Controller)trans).setOutputURIResolver(new MyOutputResolver());

             

              File output = getOutputFile(chunkHTML, htmlOutputFilePath );

              StreamResult sr = new StreamResult(output.toURI().toASCIIString());

             

              if (!output.exists()) {

                     output.mkdir();

        }

             

              trans.transform(xmlSource, sr);

       }

      

       private static TransformerFactory getTransformerFactory(Boolean chunkHTML){      

              if( chunkHTML)            

                     return new net.sf.saxon.TransformerFactoryImpl();

              else

                     return TransformerFactory.newInstance();

       }

      

       private static File getOutputFile(Boolean chunkHTML, String htmlOutputFilePath ){       

              if(chunkHTML)       

                     return  new File(htmlOutputFilePath);

              else

                     return new File(htmlOutputFilePath + ".xml");

             

       }

}

 

class MyOutputResolver extends net.sf.saxon.lib.StandardOutputResolver {

 

         public Result resolve(String href, String base) throws XPathException {

           System.out.println(href + "; " + base);

           return super.resolve(href, base);

         }

}

 

 

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: September-09-11 1:42 PM
To: Kate Tang
Cc: Saxon Help List
Subject: Re: [saxon] Help about saxon9he.jar

 


I don't have enough information to debug this for you - I can only make suggestions.

For diagnostics you could try setting an OutputURIResolver. Something like this:

class MyOutputResolver extends net.sf.saxon.lib.StandardOutputURIResolver {

  public Result resolve(String href, String base) throws XPathException {
    System.out.println(href + "; " + base);
    return super.resolve(href, base);
  }}

and then

((net.sf.saxon.Controller)transformer).setOutputURIResolver(new MyOutputResolver());

Michael Kay
Saxonica

On 09/09/2011 18:18, Kate Tang wrote:

The file name are set by the node name.
It works if I only use java saxon9he.jar ... to produce the code.


From: Michael Kay
To: Kate Tang
Cc: saxon-help@lists.sourceforge.net
Sent: Fri Sep 09 13:08:13 2011
Subject: Re: [saxon] Help about saxon9he.jar
It looks to me as if you are now setting the base URI successfully, but the value of the href attribute produced by xsl:result-document is an empty string.

Michael Kay
Saxonica

On 09/09/2011 17:42, Kate Tang wrote:

This is the folder I want to write to.
The first output file output correctly. However, the others didn't. I am think if I should do more setting for the URI.


From: Michael Kay
To: Kate Tang
Cc: saxon-help@lists.sourceforge.net
Sent: Fri Sep 09 12:22:52 2011
Subject: Re: [saxon] Help about saxon9he.jar
On 09/09/2011 16:14, Kate Tang wrote:

The following is what I got.

 

 

11:10:47,456 ERROR [STDERR] Error at xsl:value-of on line 33

  java.io.FileNotFoundException:

  C:\messagepoint\reports\operationsReports\1\2\operationsReport_1_111031\output (Access is denied)

11:10:47,456 ERROR [STDERR]   at xsl:for-each (#29)

11:10:47,456 ERROR [STDERR]      processing /Report/Jobs[1]/Job[6]

11:10:47,458 INFO  [STDOUT] A1FC7D4E66DE26153DD37E623A47DF89 superuser@prinova.com:127.0.0.1 2011-09-09 11:10:47,456 ERROR com.prinova.messagepoint.platform.services.export.ExportOperationsReportToXMLService,Thread-36:71 -  unexpected exception when invoking ExportOperationsReportToXMLService execute method

; SystemID: ; Line#: 33; Column#: -1

net.sf.saxon.trans.XPathException: java.io.FileNotFoundException: C:\messagepoint\reports\operationsReports\1\2\operationsReport_1_111031\output (Access is denied)

 

Is C:\messagepoint\reports\operationsReports\1\2\operationsReport_1_111031\output

the file you were
intending to write to?

Do you have any idea why access to this file is denied?

It looks suspiciously to me as if this is the name of a directory rather than a "real" file, which would probably account for the error.

Michael Kay
Saxonica