You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2004/01/29 22:03:06 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom DOMMessageFormatter.java

elena       2004/01/29 13:03:06

  Modified:    java/src/org/apache/xerces/dom DOMMessageFormatter.java
  Log:
  Let DOMMessageFormatter also support reporting XML messages (needed for well-formness check).
  
  Revision  Changes    Path
  1.3       +43 -16    xml-xerces/java/src/org/apache/xerces/dom/DOMMessageFormatter.java
  
  Index: DOMMessageFormatter.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMMessageFormatter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DOMMessageFormatter.java	17 Jul 2002 18:36:58 -0000	1.2
  +++ DOMMessageFormatter.java	29 Jan 2004 21:03:06 -0000	1.3
  @@ -69,8 +69,11 @@
    */
   public class DOMMessageFormatter {
   
  +    public static final String XML_DOMAIN = "http://www.w3.org/TR/1998/REC-xml-19980210";
       public static final String DOM_DOMAIN = "http://www.w3.org/dom/DOMTR";
       public static final String SERIALIZER_DOMAIN = "http://apache.org/xml/serializer";
  +    
  +    
   
       /**
        * Formats a message with the specified arguments using the given
  @@ -90,33 +93,57 @@
        public static String formatMessage(String domain, 
               String key, Object[] arguments)
               throws MissingResourceException {
  -        
  +
  +        // TODO: need to support locale information
           ResourceBundle resourceBundle = null;
           if(domain.equals(DOM_DOMAIN)) {
               resourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.DOMMessages");
           } else if (domain.equals(SERIALIZER_DOMAIN)) {
               resourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSerializerMessages");
  -        } else {
  +        } else if (domain.equals(XML_DOMAIN)){
  +            resourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLMessages");
  +            
  +        }else {
               throw new MissingResourceException("Unknown domain" + domain, null, key);
           }
  -        if (resourceBundle == null)
  -            throw new MissingResourceException("Property file not found!", "org.apache.xerces.impl.msg.DOMMessages", key);
   
  -        String msg = key + ": " + resourceBundle.getString(key);
  +        // format message
  +        String msg;
  +        try {
  +            msg = key + ": " + resourceBundle.getString(key);
  +            if (arguments != null) {
  +                try {
  +                    msg = java.text.MessageFormat.format(msg, arguments);
  +                } 
  +                catch (Exception e) {
  +                    msg = resourceBundle.getString("FormatFailed");
  +                    msg += " " + resourceBundle.getString(key);
  +                }
  +            } 
  +        }
  +        
   
  -        if (arguments != null) {
  -            try {
  -                msg = java.text.MessageFormat.format(msg, arguments);
  -            } catch (Exception e) {
  -                msg = resourceBundle.getString("FormatFailed");
  -                msg += " " + resourceBundle.getString(key);
  -            }
  -        } 
  +        // error
  +        catch (MissingResourceException e) {
  +            msg = resourceBundle.getString("BadMessageKey");
  +            throw new MissingResourceException(key, msg, key);
  +        }
   
  +        // no message
           if (msg == null) {
  -            msg = resourceBundle.getString("BadMessageKey");
  -            throw new MissingResourceException(msg, "org.apache.xerces.impl.msg.DOMMessages", key);
  +            msg = key;
  +            if (arguments.length > 0) {
  +                StringBuffer str = new StringBuffer(msg);
  +                str.append('?');
  +                for (int i = 0; i < arguments.length; i++) {
  +                    if (i > 0) {
  +                        str.append('&');
  +                    }
  +                    str.append(String.valueOf(arguments[i]));
  +                }
  +            }
           }
  +
   
           return msg;
       }
  
  
  

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