Uploaded image for project: 'Commons Digester'
  1. Commons Digester
  2. DIGESTER-128

When using Digester parsed a file with a directory that contained chinese charset it will throw java.net.MalformedURLException.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Invalid
    • 1.7
    • None
    • None
    • Windows XP
      Eclipse 3.2

    Description

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            jzwang jzwang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: