maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject cvs commit: jakarta-turbine-maven/src/java/org/apache/maven MavenUtils.java
Date Tue, 03 Dec 2002 02:48:36 GMT
jvanzyl     2002/12/02 18:48:36

  Modified:    src/java/org/apache/maven MavenUtils.java
  Log:
  o adding really simple localized messaging and just
  defaulting to english right now.
  
  Revision  Changes    Path
  1.73      +48 -1     jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- MavenUtils.java	2 Dec 2002 15:21:44 -0000	1.72
  +++ MavenUtils.java	3 Dec 2002 02:48:36 -0000	1.73
  @@ -818,4 +818,51 @@
               baseObject.addProperty( name + ":" + value );
           }
       }
  +
  +    private static Properties messages;
  +
  +    private static void loadMessages()
  +    {
  +        messages = loadProperties(
  +            MavenUtils.class.getClassLoader().getResourceAsStream(
  +                "org/apache/maven/messages/messages.en" ) );
  +    }
  +
  +    /**
  +     * Retrieve a user message.
  +     *
  +     * @param messageId Id of message type to use.
  +     * @return Message for the user's locale.
  +     */
  +    public static String getMessage( String messageId )
  +    {
  +        return getMessage( messageId, null );
  +    }
  +
  +   /**
  +     * Retrieve a user message.
  +     *
  +     * @param messageId Id of message type to use.
  +     * @param variable Value to substitute for ${1} in the given message.
  +     * @return Message for the user's locale.
  +     */
  +    public static String getMessage( String messageId, Object variable )
  +    {
  +        if ( messages == null )
  +        {
  +            loadMessages();
  +        }
  +
  +        if ( variable == null )
  +        {
  +            return messages.getProperty( messageId );
  +        }
  +        else
  +        {
  +            return StringUtils.replace( messages.getProperty( messageId ),
  +                                        "${1}",
  +                                        variable.toString() );
  +        }
  +
  +    }
   }
  
  
  

Mime
View raw message