You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2002/07/31 00:10:19 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dv DatatypeException.java

sandygao    2002/07/30 15:10:19

  Modified:    java/src/org/apache/xerces/impl/dv DatatypeException.java
  Log:
  Overrides getMessage() method in DatatypeException to return
  the formatted&localized error message.
  
  REVISIT: the system locale is used to load the property file.
  do we want to allow the appilcation to specify a different locale?
  
  Revision  Changes    Path
  1.4       +36 -1     xml-xerces/java/src/org/apache/xerces/impl/dv/DatatypeException.java
  
  Index: DatatypeException.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dv/DatatypeException.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DatatypeException.java	29 Jan 2002 01:15:11 -0000	1.3
  +++ DatatypeException.java	30 Jul 2002 22:10:18 -0000	1.4
  @@ -57,6 +57,10 @@
   
   package org.apache.xerces.impl.dv;
   
  +import java.util.ResourceBundle;
  +import java.util.PropertyResourceBundle;
  +import java.util.MissingResourceException;
  +
   /**
    * Base class for datatype exceptions. For DTD types, the exception can be
    * created from an error message. For Schema types, it needs an error code
  @@ -102,5 +106,36 @@
        */
       public Object[] getArgs() {
           return args;
  +    }
  +    
  +    /**
  +     * Overrides this method to get the formatted&localized error message.
  +     * 
  +     * REVISIT: the system locale is used to load the property file.
  +     *          do we want to allow the appilcation to specify a
  +     *          different locale?
  +     */
  +    public String getMessage() {
  +        ResourceBundle resourceBundle = null;
  +        resourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSchemaMessages");
  +        if (resourceBundle == null)
  +            throw new MissingResourceException("Property file not found!", "org.apache.xerces.impl.msg.XMLSchemaMessages", key);
  +
  +        String msg = resourceBundle.getString(key);
  +        if (msg == null) {
  +            msg = resourceBundle.getString("BadMessageKey");
  +            throw new MissingResourceException(msg, "org.apache.xerces.impl.msg.XMLSchemaMessages", key);
  +        }
  +
  +        if (args != null) {
  +            try {
  +                msg = java.text.MessageFormat.format(msg, args);
  +            } catch (Exception e) {
  +                msg = resourceBundle.getString("FormatFailed");
  +                msg += " " + resourceBundle.getString(key);
  +            }
  +        } 
  +
  +        return msg;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org