"Andrew Friebel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I apologise for my lack of information. What you have given me has helped, > however a new issue has arisen from it. > > I did turn off validation as per the other suggestion from my post. This > allowed me to parse the web.xml file, however, I still need to save the > document declaration. When you turn off validation, I was unable to > rebuild > DTD reference. Just a note for others who are watching this post. > > I am running Java 1.6.0, and I am writing a standalone application. I > have > inserted the code snippet as suggested into my SAX parser (using xerces): > > public InputSource resolveEntity(String pubid, String sysid) throws > IOException{ > > if("-//Sun Microsystems, Inc.//DTD Web Application > 2.3//EN".equals(pubid)) { > InputStream is = > this.getClass().getClassLoader().getResourceAsStream("/javax/servlet/resourc > es/web-app_2_3.dtd"); > return new InputSource(is);
Looking at Tomcat's EntityResolver for parsing web.xml, it looks like this should probably be: URL resource = this.getClass().getClassLoader().getResource("/javax/servlet/resources/web-app_2_3.dtd"); return new InputSource(resource.toExternalForm()); > } > return null; > } > > I had to add 'this.getClass().' in front of 'getClassLoader()' from your > snippet. If I didn't I would get a compilation error - 'Method > getClassLoader() is undefined' > > > > My parser sets the entity resolver (note: the class WebXmlParser extends > 'DefaultHandler'): > > public WebXmlParser(StringBuffer tmpIS) > { > > System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser > "); > > try { > > // Create SAX 2 parser... > XMLReader xr = XMLReaderFactory.createXMLReader(); > > xr.setEntityResolver(this); > // Set the ContentHandler... > xr.setContentHandler( this ); > > try{ > xr.parse(new InputSource(new > StringReader(tmpIS.toString()))); > }catch(Exception e){ > e.printStackTrace(); > strError = e.getMessage(); > } > > }catch ( Exception e ) > { > e.printStackTrace(); > strError = e.getMessage(); > } > > } > > I now get the following stack trace: > > > java.net.MalformedURLException > at java.net.URL.<init>(Unknown Source) > at java.net.URL.<init>(Unknown Source) > at java.net.URL.<init>(Unknown Source) > at > org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) > at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown > Source) > at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown > Source) > at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown > Source) > at > org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown > Source) > at > org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown > Source) > at org.apache.xerces.parsers.XML11Configuration.parse(Unknown > Source) > at org.apache.xerces.parsers.XML11Configuration.parse(Unknown > Source) > at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) > at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) > at WebXmlParser.<init>(WebXmlParser.java:49) > at UpdateOneSite.changeWebXml(UpdateOneSite.java:332) > at UpdateOneSite.access$0(UpdateOneSite.java:309) > at > UpdateOneSite$ButtonListener.actionPerformed(UpdateOneSite.java:141) > at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) > at javax.swing.AbstractButton$Handler.actionPerformed(Unknown > Source) > at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown > Source) > at javax.swing.DefaultButtonModel.setPressed(Unknown Source) > at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown > Source) > at java.awt.Component.processMouseEvent(Unknown Source) > at javax.swing.JComponent.processMouseEvent(Unknown Source) > at java.awt.Component.processEvent(Unknown Source) > at java.awt.Container.processEvent(Unknown Source) > at java.awt.Component.dispatchEventImpl(Unknown Source) > at java.awt.Container.dispatchEventImpl(Unknown Source) > at java.awt.Component.dispatchEvent(Unknown Source) > at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) > at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) > at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) > at java.awt.Container.dispatchEventImpl(Unknown Source) > at java.awt.Window.dispatchEventImpl(Unknown Source) > at java.awt.Component.dispatchEvent(Unknown Source) > at java.awt.EventQueue.dispatchEvent(Unknown Source) > at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown > Source) > at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) > at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown > Source) > at java.awt.EventDispatchThread.pumpEvents(Unknown Source) > at java.awt.EventDispatchThread.pumpEvents(Unknown Source) > at java.awt.EventDispatchThread.run(Unknown Source) > Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException > at UpdateOneSite.changeWebXml(UpdateOneSite.java:334) > at UpdateOneSite.access$0(UpdateOneSite.java:309) > at > UpdateOneSite$ButtonListener.actionPerformed(UpdateOneSite.java:141) > at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) > at javax.swing.AbstractButton$Handler.actionPerformed(Unknown > Source) > at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown > Source) > at javax.swing.DefaultButtonModel.setPressed(Unknown Source) > at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown > Source) > at java.awt.Component.processMouseEvent(Unknown Source) > at javax.swing.JComponent.processMouseEvent(Unknown Source) > at java.awt.Component.processEvent(Unknown Source) > at java.awt.Container.processEvent(Unknown Source) > at java.awt.Component.dispatchEventImpl(Unknown Source) > at java.awt.Container.dispatchEventImpl(Unknown Source) > at java.awt.Component.dispatchEvent(Unknown Source) > at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) > at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) > at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) > at java.awt.Container.dispatchEventImpl(Unknown Source) > at java.awt.Window.dispatchEventImpl(Unknown Source) > at java.awt.Component.dispatchEvent(Unknown Source) > at java.awt.EventQueue.dispatchEvent(Unknown Source) > at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown > Source) > at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) > at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown > Source) > at java.awt.EventDispatchThread.pumpEvents(Unknown Source) > at java.awt.EventDispatchThread.pumpEvents(Unknown Source) > at java.awt.EventDispatchThread.run(Unknown Source) > > > > I tried using the 'sysid' from the method to get the 'InputStream', but > this > didn't work either. I am presuming it is the 'InputStream' assignment > that > is throwing the error, but I am not 100% sure. > > Has anyone got any ideas on how to get around this? > > Regards, > Andrew > > -----Original Message----- > From: Bill Barker [mailto:[EMAIL PROTECTED] > Sent: Monday, 2 July 2007 12:28 PM > To: users@tomcat.apache.org > Subject: Re: WEB.XML file parsing > > > "Andrew Friebel" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >>I am having trouble parsing a web.xml file using SAX. The war file will >> deploy with no hassles, however, I am writing a local program that will >> allow me to change the web.xml file locally before distribution. >> >> >> >> My problem is the DTD definition in the web.xml file. I require the DTD >> file definition, yet when I try and parse the file with the DTD >> definition, >> I keep getting a connection timeout error. When I remove the DTD >> definition, the file is parsed with no issues. >> >> > > You are a bit sparse on details for how you are doing this and versions, > but > > assuming that you are using SAX, you need to set and EntityResolver that > does something like (for 5.5): > > public ImputSource resolveEntity(String pubid, String sysid) throws > IOException{ > if("-//Sun Microsystems, Inc.//DTD Web Application > 2.3//EN".equals(pubid)) { > InputStream is = > getClassloader().getResourceAsStream("/javax/servlet/resources/web-app_2_3.d > td"); > return new InputSource(is); > } > return null; > } > > > >> >> How do I get around the timeout issue when parsing the web.xml file with >> the >> DTD definition? >> >> >> >> The DTD definition is: >> >> >> >> <!DOCTYPE web-app >> >> PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" >> >> "http://java.sun.com/dtd/web-app_2_3.dtd"> >> >> >> >> Regards, >> >> Andrew >> >> > > > > > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]