hlship      2003/08/01 07:41:30

  Modified:    hivemind/xdocs localization.xml
               hivemind/src/test/hivemind/test/config
                        TestExtensionPoint.java
               hivemind/src/java/org/apache/commons/hivemind/schema/rules
                        BaseRule.java ReadContentRule.java
                        ReadAttributeRule.java
               hivemind maven.xml
  Added:       hivemind/src/test/hivemind/test/config Localized.xml
  Log:
  Add support for references to localized messages in contributed elements and 
attributes.
  
  Revision  Changes    Path
  1.4       +26 -2     jakarta-commons-sandbox/hivemind/xdocs/localization.xml
  
  Index: localization.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/xdocs/localization.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- localization.xml  31 Jul 2003 21:06:24 -0000      1.3
  +++ localization.xml  1 Aug 2003 14:41:29 -0000       1.4
  @@ -27,7 +27,31 @@
   </p> 
   
   <p>
  -<b>TODO: Implement '%' to access localized messages.</b>     
  +In a module descriptor, within the &extension; and &invoke-factory; elements, you 
can reference
  +     a localized message in an attribute or element content simply by prefixing the 
message key
  +     with '%'.  Examples:
  +     
  +<source><![CDATA[
  +  <extension point-id=". . .">
  +  
  +    <some-item message="%message.key">
  +      %other.message.key
  +    </some-item>
  +    
  +  </extension>
  + ]]></source>
  +</p>
  +
  +<p>
  +The two keys (<code>message.key</code>        and <code>other.message.key</code>) 
are searched
  +for in the <em>contributing</em> module's messages.
  +</p>
  +
  +<p>
  +HiveMind gracefully recovers from undefined messages.  If a message is not in the 
properties file, the 
  +HiveMind provides a substitute value by converting the key to upper-case and adding 
brackets, i.e. 
  +<code>[MESSAGE.KEY]</code>.  This allows your application to continue running, but 
clearly identifies missing
  +messages.
   </p>
   
        
  
  
  
  1.3       +13 -0     
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestExtensionPoint.java
  
  Index: TestExtensionPoint.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/TestExtensionPoint.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestExtensionPoint.java   30 Jul 2003 22:34:53 -0000      1.2
  +++ TestExtensionPoint.java   1 Aug 2003 14:41:29 -0000       1.3
  @@ -280,4 +280,17 @@
           assertEquals("key2", e.getAttributeValue("key"));
           assertEquals("${value2}", e.getAttributeValue("value"));
       }
  +
  +    public void testLocalized() throws Exception
  +    {
  +        Registry r = buildRegistry("Localized.xml");
  +
  +        List l = r.getExtensionPointElements("hivemind.test.config.Localized");
  +        assertEquals(1, l.size());
  +
  +        Datum d = (Datum) l.get(0);
  +
  +        assertEquals("message", d.getKey());
  +        assertEquals("Some Damn Thing", d.getValue());
  +    }
   }
  
  
  
  1.1                  
jakarta-commons-sandbox/hivemind/src/test/hivemind/test/config/Localized.xml
  
  Index: Localized.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!-- $Id: Localized.xml,v 1.1 2003/08/01 14:41:29 hlship Exp $ -->
  <module id="hivemind.test.config" version="1.0.0">
        <extension-point id="Localized">
                <schema>
                        <element name="datum">
                          <attribute name="key" required="true"/>
                          <attribute name="value" required="true"/>
                                <rules>
                                        <create-object 
class="hivemind.test.config.impl.Datum"/>
                                        <read-attribute property="key" 
attribute="key"/>
                                        <read-attribute property="value" 
attribute="value"/>
                                        <invoke-parent method="addElement"/>
                                </rules>
                        </element>
                </schema>
        </extension-point>
        <extension point-id="Localized">
                <datum key="message" value="%inner-message"/>
        </extension>
  
  </module>
  
  
  
  1.2       +22 -4     
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/BaseRule.java
  
  Index: BaseRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/BaseRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseRule.java     29 Jul 2003 22:20:48 -0000      1.1
  +++ BaseRule.java     1 Aug 2003 14:41:30 -0000       1.2
  @@ -78,14 +78,32 @@
       private static final Log LOG = LogFactory.getLog(BaseRule.class);
   
       /**
  -     * Expands symbols in the input value.
  +     * Invoked to process text from an attribute or from an element's content.  
Performs
  +     * two jobs:
  +     * <ul>
  +     * <li>Convert localized message references to localized strings
  +     * <li>Expand symbols using [EMAIL PROTECTED] Registry#expandSymbols(String, 
ILocation)}
  +     * </ul>
        * 
  -     * @see Registry#expandSymbols(String, ILocation)
  +     * <p>
  +     * Note: if the input is a localized message then no symbol expansion takes 
place.
  +     * Localized message references are simply strings that begin with '%'.  The 
remainder
  +     * of the string is the message key.
  +     * 
  +     * <p>
  +     * A null input value passes through unchanged.
        */
  -    protected String expandSymbols(SchemaProcessor processor, Element element, 
String inputValue)
  +    protected String processText(SchemaProcessor processor, Element element, String 
inputValue)
       {
           if (inputValue == null)
               return null;
  +
  +        if (inputValue.startsWith("%"))
  +        {
  +            String key = inputValue.substring(1);
  +
  +            return processor.getContributingModule().getMessages().getMessage(key);
  +        }
   
           Registry registry = processor.getContributingModule().getRegistry();
   
  
  
  
  1.2       +2 -2      
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ReadContentRule.java
  
  Index: ReadContentRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ReadContentRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReadContentRule.java      29 Jul 2003 22:20:48 -0000      1.1
  +++ ReadContentRule.java      1 Aug 2003 14:41:30 -0000       1.2
  @@ -81,7 +81,7 @@
   
       public void begin(SchemaProcessor processor, Element element)
       {
  -        String value = expandSymbols(processor, element, element.getContent());
  +        String value = processText(processor, element, element.getContent());
   
           Object finalValue =
               _translator == null ? value : _translator.translate(processor, element, 
value);
  
  
  
  1.2       +2 -2      
jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ReadAttributeRule.java
  
  Index: ReadAttributeRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/hivemind/src/java/org/apache/commons/hivemind/schema/rules/ReadAttributeRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReadAttributeRule.java    29 Jul 2003 22:20:48 -0000      1.1
  +++ ReadAttributeRule.java    1 Aug 2003 14:41:30 -0000       1.2
  @@ -84,7 +84,7 @@
           if (rawValue == null && _skipIfNull)
               return;
   
  -        String value = expandSymbols(processor, element, rawValue);
  +        String value = processText(processor, element, rawValue);
   
           Object finalValue =
               _translator == null ? value : _translator.translate(processor, element, 
value);
  
  
  
  1.6       +2 -2      jakarta-commons-sandbox/hivemind/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/hivemind/maven.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- maven.xml 1 Aug 2003 14:21:38 -0000       1.5
  +++ maven.xml 1 Aug 2003 14:41:30 -0000       1.6
  @@ -12,7 +12,7 @@
                <manifestClassPath property="hivemind.manifest.class.path">
                        <classpath>
                                
  -                             <!-- This, unforutnately, includes a few dependencies 
we don't want, but
  +                             <!-- This, unfortunately, includes a few dependencies 
we don't want, but
                                           that's largely OK. -->
                                           
                                <path refid="maven.dependency.classpath"/>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to