Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
EntityResolver in a document() function to solve OASIS Catalog

EntityResolver in a document() function to solve OASIS Catalog

2006-10-17       - By Marc
Reply:     1     2  

I send the answer to my question, the probleme is that the CatalogResolver
class don't set the EntityResolver of the XMLReader of the returned source.
Then I create my own URIResolver to solve this problem :
class MyURIResolver implements URIResolver
{
   CatalogResolver catalogResolver;
  MyURIResolver()
  {
      catalogResolver = new CatalogResolver();
  }
 
  public Source resolve(String href,String base) throws javax.xml.transform
.TransformerException{
      Source source = catalogResolver.resolve(href,base);
      if (source == null) return(null);
      try {
           XMLReader XMLr;
           //get a SAXParserFactory instance
           SAXParserFactory SAXpf=SAXParserFactory.newInstance();
           
           //enabling the namespaces processing
           if(SAXpf.isNamespaceAware()==false)
               SAXpf.setNamespaceAware(true);
           
           //get a SAXParser object
           SAXParser SAXparser=SAXpf.newSAXParser();
           
           //get the XMLReader
           XMLr=SAXparser.getXMLReader();
           XMLr.setEntityResolver(catalogResolver);
           
           //creating the SAXSource
           SAXSource sXML=new SAXSource(XMLr,new InputSource(source
.getSystemId()));
           sXML.setXMLReader(XMLr);
      return(sXML);
      }
      catch (javax.xml.parsers.ParserConfigurationException e) {
          return(null);
      }
      catch (org.xml.sax.SAXException e) {
          return(null);
      }
}
}

-----------------------------------------
Le dimanche 15 octobre 2006 à 19:36:09, vous écriviez :

M> Hello,

M> I try to use the OASIS Catalog to solve the PUBLIC DTD.
M> All is OK but I have a problem with the XML file charged by the document().
M> I use the CatalogResolver with the setURIResolver for the Factory, and the
setEntityResolver for the XMLReader, but I don't find how the set the
Entityresolver for the XMLReader used by the
M> transformer.
M> Here is my code :
M>             SAXTransformerFactory tFactory = (SAXTransformerFactory)
TransformerFactory.newInstance();
           
M>             // on met en place la gestion du catalog
M>             CatalogResolver ct = new CatalogResolver();
M>             tFactory.setURIResolver(ct);
M>             javax.xml.transform.sax.TemplatesHandler templatesHandler =
M>                     tFactory.newTemplatesHandler();
           
M>             // Create an XMLReader and set its ContentHandler.
M>             org.xml.sax.XMLReader reader =
M>                     org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
M>             reader.setContentHandler(templatesHandler);
M>             reader.setEntityResolver(new CatalogResolver());
M>             // Parse the stylesheet.
M>             reader.parse(fichierXSLT);
M>             // Get the Templates object (generated during the parsing of the
stylesheet)
M>             // from the TemplatesHandler.
M>             javax.xml.transform.Templates templates =
M>                     templatesHandler.getTemplates();
M>             // Create a Transformer ContentHandler to handle parsing of
M>             // the XML Source.
M>             javax.xml.transform.sax.TransformerHandler transformerHandler
M>                     = tFactory.newTransformerHandler(templates);
M>             // Reset the XMLReader's ContentHandler to the
TransformerHandler.
M>             reader.setContentHandler(transformerHandler);
M>             // Set the ContentHandler to also function as a LexicalHandler,
which
M>             // can process "lexical" events (such as comments and CDATA).
M>             reader.setProperty("http://xml.org/sax/properties/lexical
-handler",
M>                     transformerHandler);
           
M>             // Set up a Serializer to serialize the Result to a file.
M>             org.apache.xml.serializer.Serializer serializer =
M>                     org.apache.xml.serializer.SerializerFactory.getSerializer
M>                     (org.apache.xml.serializer.OutputPropertiesFactory
.getDefaultMethodProperties
M>                     ("xml"));
M>             serializer.setOutputStream(new java.io.FileOutputStream
(fichierSortie));
M>             // The Serializer functions as a SAX ContentHandler.
M>             javax.xml.transform.Result result =
M>                     new javax.xml.transform.sax.SAXResult(serializer
.asContentHandler());
M>             transformerHandler.setResult(result);
           
M>             // Parse the XML input document.
M>             reader.parse(fichierEntree);
M> I try something more simple with a transformer without contentHandler but it
's the same:
M>             SAXTransformerFactory tFactory = (SAXTransformerFactory)
TransformerFactory.newInstance();
           
M>             // on met en place la gestion du catalog
M>             CatalogResolver ct = new CatalogResolver();
M>             tFactory.setURIResolver(ct);
           
M>             // Use the TransformerFactory to instantiate a Transformer that
will work with
M>             // the stylesheet you specify. This method call also processes
the stylesheet
M>             // into a compiled Templates object.
M>             InputSource inputXSLT = new InputSource(new FileReader(new File
(VerifFichierServeurXSL(fichierXSLT))));
M>             Source sourceXSLT = new StreamSource(inputXSLT
.getCharacterStream(), inputXSLT.getSystemId());
M>             Transformer transformer = tFactory.newTransformer(sourceXSLT);
M>             //   Transformer transformer = tFactory.newTransformer(new
StreamSource(fichierXSLT));
M>             XMLReader XMLr;
M>             //get a SAXParserFactory instance
M>             SAXParserFactory SAXpf=SAXParserFactory.newInstance();
           
M>             //enabling the namespaces processing
M>             if(SAXpf.isNamespaceAware()==false)
M>                 SAXpf.setNamespaceAware(true);
           
M>             //get a SAXParser object
M>             SAXParser SAXparser=SAXpf.newSAXParser();
           
M>             //get the XMLReader
M>             XMLr=SAXparser.getXMLReader();
M>             XMLr.setEntityResolver(new CatalogResolver());
           
M>             //creating the SAXSource
M>             SAXSource sXML=new SAXSource(XMLr, new InputSource
M>                     (fichierEntree));
M>             sXML.setXMLReader(XMLr);
M>             transformer.transform(sXML, fichierSortie);

M> If someone as an idea?

M> Thank's

M> Marc