>From your output, it looks like your EntityResolver is being called and all of that is fine. The publicID would be supplied by the parser if your !DOCTYPE declaration used the PUBLIC form of the externalID. However, your document uses the SYSTEM form and that is exactly what is being passed.
So, I think your DTDResolver is basically fine. You have some cleanup to do. Your "if" statement checks this.dtdLocation but your message reports on publicID. But it is basically fine. This brings us to your transformation itself. I don't understand what you're doing with the source.setSystemId() call. It sounds like you're saying that the source and DTD both have the same name. Try changing the name on the setSystemId() call and see if the error message still refers to SonyDAMAssetMetadata.dtd. If so, it means that the parser just can't find your DTD. Also try changing the URL you're passing into setDTDLocation and see how this affects your error messages. Have you tried the transformation from the command line to make sure it works at all? Gary > -----Original Message----- > From: Pramodh Peddi [mailto:[EMAIL PROTECTED] > Sent: Wednesday, December 17, 2003 12:28 PM > To: Gary L Peskin; [EMAIL PROTECTED] > Subject: Re: resolving DTDs while transforming > > > Thanx for the response Gary. > > Sorry for the confusion on publicId thing. Though, I think it > is right, it is very confusing. I fixed that. > > Reg'g the set and get methods in the DTDResolver class: I > have to pass the dtd's URL (to be used as dtd) to the > DTDResolver class, so that it can return the InputSource of > that url. Thats the reason it has a get and a set method for > dtdLocation. I cleaned the class and used this code3, which > doesn't work either. It still generates an empty string after > transforming the source (as I said, its not exactly empty, it > has just xml header in it...that too not with the intended > encoding). This is my DTDesolver I am using right now. It is > invoking the resolveEntity method of the DTDResovler class. > > ***********************DTDResolver******************* > class DTDResolver implements EntityResolver { > String dtdLocation = null; > > public void setDtdLocation(String string){ > this.dtdLocation = string; > System.out.println("Setting dtdURL: " + this.dtdLocation); > } > > public String getDtdLocation(){ > System.out.println("Getting publicId"); > return this.dtdLocation; > } > > public InputSource resolveEntity (String publicId, String systemId){ > InputStream inputStream = null; > InputSource source = null; > try{ > System.out.println("systemId: " + systemId); > System.out.println("publicId: " + publicId); > System.out.println("dtdLocation is: " + this.dtdLocation); > if(StringUtils.isNotEmpty(this.dtdLocation)){ > > URL url = new URL(this.dtdLocation); > > inputStream = url.openStream(); > System.out.println("got the inputstream"); > source = new InputSource(inputStream); > }else{ > System.out.println("publicId is not specified!!!"); > } > }catch(Exception e){ > e.printStackTrace(); > } > > return source; > > } > }//end DTDResolver > ***************************************** > > And this is the output I am getting: > > --------------------------------output------------------------------- > 15:02:55,328 INFO [STDOUT] Setting dtdLocation: > http://localhost:8080/data/SonyDAMAs > setMetadata.dtd > 15:02:55,328 INFO [STDOUT] systemId: > file:///C:/jboss-3.0.6/bin/SonyDAMAssetMet > adata.dtd > 15:02:55,328 INFO [STDOUT] publicId: null > 15:02:55,328 INFO [STDOUT] dtdLocation is: > http://localhost:8080/data/SonyDAMAs > setMetadata.dtd > 15:02:55,343 INFO [STDOUT] got the inputstream > -----------------------------output--------------------------- > ------------- > > FYI: The application is running on JBoss appserver. > > As I said, in my previous reponse to Richard, the server is > running in jboss/bin directory and so the systemId is being > set to file:///C:/jboss-3.0.6/bin/SonyDAMAssetMetadata.dtd. > And I am not sure how will the publicId be set! Will it ever > be set and/or used? This is what makes me so uncomfortable > with EntityResolver. > > FYI: This is the transformation code: > > ####################################Transformation > code########################### > TransformerFactory tFactory = TransformerFactory.newInstance(); > > Transformer transformer = tFactory.newTransformer(new > StreamSource(new URL(stylesheet).openStream())); > > InputStream inputStream = > req.getContentObject().getMetadataInputStream(); > OutputStream outputStream = > req.getContentObject().getMetadataOutputStream(); > > SAXParserFactory pfactory= SAXParserFactory.newInstance(); > pfactory.setValidating(true); > // Get an XMLReader. > XMLReader reader = pfactory.newSAXParser().getXMLReader(); > > //create a resolver to resolve the DTD in the source xml > reader.setEntityResolver(new DTDResolver()); > DTDResolver resolver = (DTDResolver)reader.getEntityResolver(); > resolver.setDtdLocation(this.dtdURL); > > SAXSource source = new SAXSource(reader, > new InputSource(new InputStreamReader(inputStream))); > //not sure if this is right! //if i don't have this, it > throws an exception saying it cannot find "SonyDAMAssetMetadata.dtd" > source.setSystemId("SonyDAMAssetMetadata.dtd"); > > transformer.transform(source, new StreamResult(new > OutputStreamWriter(outputStream, "iso-8859-1"))); > ############################################################## > ############## > ################# > > Hope you found more info about my problem to help me better:-)! > > Thanks, > > Pramodh. >