You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Thomas, Mary" <MT...@DeepBridge.Com> on 2001/08/09 16:29:12 UTC

javax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser???

Hi 
I am able to run the fo from command line and get the printed output.
Now the next is to embed in servlet.
I tried running this servlet from jbuilder.
with the library pointing to fop.jar,xalan.jar xcerces.jar , batik.jar,
buildtools.jar
I run into following error.

javax.xml.transform.TransformerConfigurationException: Namespace not
supported by SAXParser


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.apache.fop.apps.*;
import org.xml.sax.*;
import javax.xml.transform.*;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;


public class fotest extends HttpServlet {
  
  /**Initialize global variables*/
  public void init() throws ServletException {
  }
  /**Process the HTTP Get request*/
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

try{
    XMLReader xmlreader =createParser();

    Writer writer = new StringWriter();

    // Get an xslt processor factory
    TransformerFactory tFactory = TransformerFactory.newInstance();

    File xmlfile = new File("d:\\temp\\Footnotes.xml");
    Source xmlSource  = new StreamSource(xmlfile);
    File xslfile = new File("d:\\temp\\Footnotes.xsl");
    Source xslSheet  = new StreamSource(xslfile);
    StreamResult xmlResult = new StreamResult(writer);

    Transformer transformer = tFactory.newTransformer(xslSheet);

    // Perform the transformation.
    transformer.transform(xmlSource, xmlResult);


    // send output from xsl transformation to a string reader
    // create a input source containing the xsl:fo file which can be fed to
    //Fop
    Reader reader = new StringReader(writer.toString());
    writer.flush();
    writer.close();

    //set Driver methods to start Fop processing
    Driver driver = new Driver();

    driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",".14");
    driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
    driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
    driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
    driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");

    // send pdf writer output to a byte array stream
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(baos);
    //driver.setWriter(printWriter);
    driver.setOutputStream(baos);
    driver.buildFOTree(xmlreader, new InputSource(reader));
    driver.format();
    driver.render();

    // send the bytes out to the servlet output stream
    response.setContentType("application/pdf");
    response.setContentLength(baos.size());

    long sixty = System.currentTimeMillis() + 60*1000;
    response.setDateHeader("Expires", sixty);
    baos.writeTo(response.getOutputStream());
    response.getOutputStream().flush();
    }
    catch (Exception e) {
	    System.out.println(e);
	}


  }

 /**
       * creates a SAX parser, using the value of org.xml.sax.parser
       * defaulting to org.apache.xerces.parsers.SAXParser
       *
       * @return the created SAX parser
       */
    static XMLReader createParser()
    {
     XMLReader  xmlreader = null;
        try {
         String parserClassName = System.getProperty("org.xml.sax.parser");
        if (parserClassName == null) {
            parserClassName = "org.apache.xerces.parsers.SAXParser";
        }
        xmlreader= (XMLReader) Class.forName(parserClassName).newInstance();

        } catch (Exception e) {
	    System.out.println(e);
	}
        return xmlreader;
    }

  /**Clean up resources*/
  public void destroy() {
  }
}
-------------
Do let me know what the problem is .
Thanks in advance.
Mary

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: javax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser???

Posted by Jeremias Maerki <je...@outline.ch>.
> I am able to run the fo from command line and get the printed output.
> Now the next is to embed in servlet.
> I tried running this servlet from jbuilder.
> with the library pointing to fop.jar,xalan.jar xcerces.jar , batik.jar,
> buildtools.jar
> I run into following error.
> 
> javax.xml.transform.TransformerConfigurationException: Namespace not
> supported by SAXParser

Try using "org.apache.fop.apps.TraxInputHandler". It lets you specify
the files for the input XML and XSLT and gives you back an XMLReader and
InputSource for use with buildFOTree(). That should allow you to skip
the buffering you do with StringWriter/StringReader (The SAX events will
get sent right through to FOP --> faster, less memory). I haven't tested
it, but that's the way it is done when you use Fop.java.


Jeremias Märki

mailto:jeremias.maerki@outline.ch

OUTLINE AG
Postfach 3954 - Rhynauerstr. 15 - CH-6002 Luzern
Fon +41 (41) 317 2020 - Fax +41 (41) 317 2029
Internet http://www.outline.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org


Re: javax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser???

Posted by Vallikun Kathiresan <va...@mars-systems.com>.
Hi Mary:
  You are Missing the code that sets the namespace feature.
After making a call to the create Parser, you need to set features. I have
included it below.

Vallikun
> try{
>     XMLReader xmlreader =createParser(); 

------------------------------------------------
    // set the parser features
    try
    {

parser.setFeature("http://xml.org/sax/features/namespace-prefixes",true);
    }
    catch (SAXException e)
    {
	// note: fix exceptions to print stack trace of original exception
        // see ServletUtils.getStackTraceAsString()
        //*****
      throw new Exception("Error in setting up parser feature " +
                           "namespace-prefixes.\n  You need a parser " +
                           "which support SAX version 2");
    }


--------------------------------------------------------------


On Thu, 9 Aug 2001, Thomas, Mary wrote:

> Hi 
> I am able to run the fo from command line and get the printed output.
> Now the next is to embed in servlet.
> I tried running this servlet from jbuilder.
> with the library pointing to fop.jar,xalan.jar xcerces.jar , batik.jar,
> buildtools.jar
> I run into following error.
> 
> javax.xml.transform.TransformerConfigurationException: Namespace not
> supported by SAXParser
> 
> 
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> import java.util.*;
> import org.apache.fop.apps.*;
> import org.xml.sax.*;
> import javax.xml.transform.*;
> import javax.xml.transform.Source;
> import javax.xml.transform.stream.StreamSource;
> import javax.xml.transform.stream.StreamResult;
> 
> 
> public class fotest extends HttpServlet {
>   
>   /**Initialize global variables*/
>   public void init() throws ServletException {
>   }
>   /**Process the HTTP Get request*/
>   public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> 
> try{
>     XMLReader xmlreader =createParser();
> 
>     Writer writer = new StringWriter();
> 
>     // Get an xslt processor factory
>     TransformerFactory tFactory = TransformerFactory.newInstance();
> 
>     File xmlfile = new File("d:\\temp\\Footnotes.xml");
>     Source xmlSource  = new StreamSource(xmlfile);
>     File xslfile = new File("d:\\temp\\Footnotes.xsl");
>     Source xslSheet  = new StreamSource(xslfile);
>     StreamResult xmlResult = new StreamResult(writer);
> 
>     Transformer transformer = tFactory.newTransformer(xslSheet);
> 
>     // Perform the transformation.
>     transformer.transform(xmlSource, xmlResult);
> 
> 
>     // send output from xsl transformation to a string reader
>     // create a input source containing the xsl:fo file which can be fed to
>     //Fop
>     Reader reader = new StringReader(writer.toString());
>     writer.flush();
>     writer.close();
> 
>     //set Driver methods to start Fop processing
>     Driver driver = new Driver();
> 
>     driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",".14");
>     driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
>     driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
>     driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
>     driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
> 
>     // send pdf writer output to a byte array stream
>     ByteArrayOutputStream baos = new ByteArrayOutputStream();
>     PrintWriter printWriter = new PrintWriter(baos);
>     //driver.setWriter(printWriter);
>     driver.setOutputStream(baos);
>     driver.buildFOTree(xmlreader, new InputSource(reader));
>     driver.format();
>     driver.render();
> 
>     // send the bytes out to the servlet output stream
>     response.setContentType("application/pdf");
>     response.setContentLength(baos.size());
> 
>     long sixty = System.currentTimeMillis() + 60*1000;
>     response.setDateHeader("Expires", sixty);
>     baos.writeTo(response.getOutputStream());
>     response.getOutputStream().flush();
>     }
>     catch (Exception e) {
> 	    System.out.println(e);
> 	}
> 
> 
>   }
> 
>  /**
>        * creates a SAX parser, using the value of org.xml.sax.parser
>        * defaulting to org.apache.xerces.parsers.SAXParser
>        *
>        * @return the created SAX parser
>        */
>     static XMLReader createParser()
>     {
>      XMLReader  xmlreader = null;
>         try {
>          String parserClassName = System.getProperty("org.xml.sax.parser");
>         if (parserClassName == null) {
>             parserClassName = "org.apache.xerces.parsers.SAXParser";
>         }
>         xmlreader= (XMLReader) Class.forName(parserClassName).newInstance();
> 
>         } catch (Exception e) {
> 	    System.out.println(e);
> 	}
>         return xmlreader;
>     }
> 
>   /**Clean up resources*/
>   public void destroy() {
>   }
> }
> -------------
> Do let me know what the problem is .
> Thanks in advance.
> Mary
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
> For additional commands, email: fop-dev-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-dev-unsubscribe@xml.apache.org
For additional commands, email: fop-dev-help@xml.apache.org