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