[
https://issues.apache.org/jira/browse/DIGESTER-128?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12625260#action_12625260
]
jzwang commented on DIGESTER-128:
---------------------------------
Firstly I think usage for parse method is right.
digester.parse("c:/tmp/中文/datasource.xml");
Here we only need a location for a xml file.
Secondly the URL class in jdk can parse the URL correctly.
I can use this code to test.
URL url = new URL("file:/C:/tmp/中文/djc-setenv.sh"); // susscessfully
So this issue is not a jdk issue.
FYI, here is my call stack.
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:574)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at
com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:968)
at
com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:184)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at org.apache.commons.digester.Digester.parse(Digester.java:1704)
at SampleDigester.run(SampleDigester.java:39)
at SampleDigester.main(SampleDigester.java:16)
> When using Digester parsed a file with a directory that contained chinese
> charset it will throw java.net.MalformedURLException.
> -------------------------------------------------------------------------------------------------------------------------------
>
> Key: DIGESTER-128
> URL: https://issues.apache.org/jira/browse/DIGESTER-128
> Project: Commons Digester
> Issue Type: Bug
> Affects Versions: 1.7
> Environment: Windows XP
> Eclipse 3.2
> Reporter: jzwang
> Priority: Critical
>
> When I try to use Digester to parser a file I found if the file is in a
> directory with Chinese(such as c:/tmp/中文/datasource.xml) char set it will
> throw java.net.malformedURLException.
> My code is here.
> -------------------- SampleDigester.java -------------------
> import java.io.IOException;
> import java.util.Hashtable;
> import org.apache.commons.digester.Digester;
> import org.xml.sax.SAXException;
> public class SampleDigester
> {
> private Hashtable dataSources = new Hashtable();
> public static void main(String[] args)
> {
> SampleDigester sample = new SampleDigester();
> try
> {
> sample.run();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> }
> public void run() throws IOException, SAXException
> {
> Digester digester = new Digester();
> digester.push(this);
> digester.addCallMethod("datasources/datasource", "addDataSource", 5 );
> digester.addCallParam("datasources/datasource/name", 0);
> digester.addCallParam("datasources/datasource/driver", 1);
> digester.addCallParam("datasources/datasource/url", 2);
> digester.addCallParam("datasources/datasource/username", 3);
> digester.addCallParam("datasources/datasource/password", 4);
> // digester.parse("datasource.xml"); // ok
> digester.parse("c:/tmp/中文/datasource.xml"); // failed
> // digester.parse("c:/tmp/a b/datasource.xml"); // ok
> }
> public void addDataSource(String name,
> String driver,
> String url,
> String userName,
> String password)
> {
> DataSource dataSource = new DataSource(name, driver,url, userName,
> password);
> dataSources.put(name, dataSource);
> System.out.println("DataSource added: " + name);
> }
> }
> --------------------------- DataSource.java ---------------------
> public class DataSource
> {
> private String name;
> private String driver;
> private String url;
> private String password;
> private String userName;
> public DataSource(String name, String driver, String url, String userName,
> String password)
> {
> this.name = name;
> this.driver = driver;
> this.url = url;
> this.userName = userName;
> this.password = password;
> }
> public String getName()
> {
> return name;
> }
> public String getDriver()
> {
> return driver;
> }
> public String getURL()
> {
> return url;
> }
> public String getPassword()
> {
> return password;
> }
> public String getUserName()
> {
> return userName;
> }
> }
> --------------------------- DataSource.xml -------------
> <?xml version="1.0"?>
> <datasources>
> <datasource>
> <name>HsqlDataSource</name>
> <driver>org.hsqldb.jdbcDriver</driver>
> <url>jdbc:hsqldb:hsql://localhost</url>
> <username>sa</username>
> <password></password>
> </datasource>
> <datasource>
> <name>OracleDataSource</name>
> <driver>oracle.jdbc.driver.OracleDriver</driver>
> <url>jdbc:oracle:thin:@localhost:1521:orcl</url>
> <username>scott</username>
> <password>tiger</password>
> </datasource>
> </datasources>
> ----------------------------------------------
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.