commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Kitching (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DIGESTER-128) When using Digester parsed a file with a directory that contained chinese charset it will throw java.net.MalformedURLException.
Date Mon, 25 Aug 2008 07:05:44 GMT

    [ https://issues.apache.org/jira/browse/DIGESTER-128?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12625259#action_12625259
] 

Simon Kitching commented on DIGESTER-128:
-----------------------------------------

The string "c:/tmp/中文/datasource.xml" is not a URL.

A URL for a file will look like "file://.....". And I'm not sure that non-ascii characters
are actually allowed in a URL at all. So I think that this exception is technically correct.
Anyway, it is being thrown by the Java libraries, not Digester, so there is not much that
Digester code can do about it.

I do vaguely remember hearing something about the official specification for URLs having been
updated to allow unicode, but even if that is true it will have only been recently. So you
will probably need to look up the official rules for URLs and then build an appropriately-encoded
string.

Anyway, Digester already has method
  Digester.parse(File f)
which is probably the right thing for you to use here, ie create a File object to wrap your
filename-string rather than trying to interpret it as a URL.

> 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.


Mime
View raw message