  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | MalformedURLException | MalformedURLException 2007-01-05 - By Huma
Back I have a model.xml file which I have placed in a directory /home/huma/ab???. But when I parse this file I get a MalformedURLException. Strangely, if the same file is moved to the location /home/huma, I don't get any exception. To summarize, if the xml file is in some directory that contains non-english characters, I am getting a MalformedURL exception. Is there some work-around? Can someone help me with this?
Here is the code snippet:
final String DEF_ENC = "UTF-8 (See http://UTF-8.ora-code.com)"; String str = new String("ab\u00e4\u00df\u00f6"); String newStr = null; try { newStr = new String(str.getBytes(DEF_ENC), DEF_ENC); str = "/home/huma/" + newStr + "/model.xml"; String fileName = null; fileName = new String(str.getBytes(DEF_ENC), DEF_ENC); File file = new File(fileName); File parent = file.getParentFile(); InputStream iStream = null;
iStream = new FileInputStream(file); InputSource is = new InputSource(iStream); if(parent != null) { is.setSystemId(parent.toURL().toString()); } SAXBuilder saxbuilder = new SAXBuilder(true); Document doc = saxbuilder.build(is); Element root = doc.getRootElement(); String version = root.getAttributeValue("schemaVersion"); System.out.println("version: " + version); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JDOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
This is the exception I am getting:
java.net.MalformedURLException: no protocol: model.dtd at java.net.URL.<init>(URL.java:537) at java.net.URL.<init>(URL.java:434) at java.net.URL.<init>(URL.java:383) 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 org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453) at ModelTest.main(ModelTest.java:47)
I have a model.xml file which I have placed in a directory /home/huma/ab???. But when I parse this file I get a MalformedURLException. Strangely, if the same file is moved to the location /home/huma, I don't get any exception. To summarize, if the xml file is in some directory that contains non-english characters, I am getting a MalformedURL exception. Is there some work-around? Can someone help me with this? <br><br>Here is the code snippet:<br><br> final String DEF_ENC = "UTF-8 (See http://UTF-8.ora-code.com)"; <br> String str = new String("ab\u00e4 \u00df\u00f6");<br> String newStr = null;<br> try {<br> newStr = new String( str.getBytes(DEF_ENC), DEF_ENC);<br> str = "/home/huma/" + newStr + "/model.xml"; <br> String fileName = null;<br> fileName = new String(str.getBytes(DEF_ENC), DEF_ENC);<br> File file = new File(fileName); <br> File parent = file.getParentFile(); <br> InputStream iStream = null;<br> <br> <br> iStream = new FileInputStream(file);<br> InputSource is = new InputSource(iStream);<br> if(parent != null)<br> { <br> is.setSystemId (parent.toURL().toString());<br> }<br> SAXBuilder saxbuilder = new SAXBuilder(true);<br>   ; Document doc = saxbuilder.build (is);<br> Element root = doc.getRootElement();<br> String version = root.getAttributeValue("schemaVersion");<br> System.out.println( "version: " + version);<br> } <br> catch (FileNotFoundException e1) {<br > // TODO Auto-generated catch block<br> e1 .printStackTrace();<br> }<br> <br> catch (UnsupportedEncodingException e) {<br> // TODO Auto-generated catch block <br> e.printStackTrace( );<br> } catch (MalformedURLException e) { <br> // TODO Auto -generated catch block<br> e.printStackTrace();<br> } catch (JDOMException e) {<br> // TODO Auto-generated catch block <br> e.printStackTrace( );<br> } catch (IOException e) {<br> // TODO Auto-generated catch block<br> e .printStackTrace();<br> }<br> }<br><br><br>This is the exception I am getting: <br><br>java.net.MalformedURLException: no protocol: model.dtd<br> at java.net.URL.<init>(URL.java:537)<br> at java .net.URL.<init>(URL.java:434)<br> at java.net.URL.< ;init>(URL.java:383)<br> at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)<br> at org.apache.xerces.impl.XMLEntityManager.startEntity (Unknown Source)<br> at org.apache.xerces.impl .XMLEntityManager.startDTDEntity(Unknown Source) <br> at org.apache.xerces.impl.XMLDTDScannerImpl .setInputSource(Unknown Source)<br> at org.apache.xerces.impl .XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)<br> at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown Source)<br> at org.apache.xerces.parsers .XML11Configuration.parse(Unknown Source)<br> at org.apache .xerces.parsers.XML11Configuration.parse(Unknown Source)<br> at org.apache.xerces.parsers.XMLParser.parse (Unknown Source)<br> at org.apache.xerces.parsers .AbstractSAXParser.parse(Unknown Source)<br> at org.apache .xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)<br> at org.jdom.input.SAXBuilder.build(SAXBuilder.java :453)<br> at ModelTest.main(ModelTest.java:47)<br><br><br>
__ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
|
|
 |