tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/src/documentation/content/xdocs site.xml
Date Sun, 06 Feb 2005 20:36:13 GMT
hlship      2005/02/06 12:36:13

  Modified:    .        status.xml
               src/documentation/content/xdocs/UsersGuide common.ent
                        configuration.xml template.xml
               framework/src/java/org/apache/tapestry/services/impl
                        ComponentMessagesSourceImpl.java
               framework/src/test/org/apache/tapestry/junit
                        MockPage1.properties MockPage1_fr.properties
                        TestComponentMessages.java
               src/documentation/content/xdocs site.xml
  Added:       src/documentation/content/xdocs/UsersGuide localization.xml
               framework/src/java/org/apache/tapestry/services/impl
                        ResourceLocalization.java
               framework/src/test/org/apache/tapestry/junit
                        Library_fr.properties Library.properties
               framework/src/java/org/apache/tapestry/engine
                        DefaultNamespacePropertySource.java
  Log:
  TAPESTRY-242: Allow namespaces to provide default messages for pages and components.
  
  Revision  Changes    Path
  1.64      +1 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- status.xml	6 Feb 2005 15:08:52 -0000	1.63
  +++ status.xml	6 Feb 2005 20:36:13 -0000	1.64
  @@ -139,6 +139,7 @@
         <action type="update" dev="HLS"> Add hivemind: binding prefix. </action>
         <action type="update" dev="HLS" fixes-bug="TAPESTRY-262"> Support more boolean
values. </action>
         <action type="update" dev="HLS"> Inject Messages into components; this means
that all Tapestry page and component classes are abstract. </action>
  +      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-242"> Allow namespaces to
define localized messages, providing defaults for pages and components within the namespace.
</action>
       </release>
       <release version="3.0" date="Apr 18 2004">
         <action type="fix" dev="HLS" fixes-bug="28345"> Workbench/Upload exception
when no file specified </action>
  
  
  
  1.15      +0 -2      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent
  
  Index: common.ent
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/common.ent,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- common.ent	30 Jan 2005 15:07:51 -0000	1.14
  +++ common.ent	6 Feb 2005 20:36:13 -0000	1.15
  @@ -50,8 +50,6 @@
   <!ENTITY hivemind-descriptor		'<link href="site:hivemind">HiveMind module deployment
descriptor</link>'>
   
   <!ENTITY configuration-property		'<link href="configuration.html#configuration.search-path">configuration
property</link>'>
  -<!ENTITY configuration.character-sets
  -									'<link href="configuration.html#configuration.character-sets">Character
Sets</link>'>
   <!ENTITY aso						'<link href="state.html#state.aso">application state object</link>'>
   									
   <!ENTITY init-parameter				'&lt;init-parameter&gt;'>
  \ No newline at end of file
  
  
  
  1.7       +18 -87    jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/configuration.xml
  
  Index: configuration.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/configuration.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- configuration.xml	27 Jan 2005 22:54:34 -0000	1.6
  +++ configuration.xml	6 Feb 2005 20:36:13 -0000	1.7
  @@ -479,6 +479,22 @@
   </tr>
   
   <tr>
  +	<td>org.apache.tapestry.messages-encoding</td>
  +	
  +  <td>
  +	Defines the character set used when reading the properties files comprising a
  +  page  or component <link href="localization.html#localization.component-catalog">message
catalog</link>.
  +	The default value is ISO-8859-1. 
  +
  +	
  +	<p>
  +	Please see the <link href="localization.html#localization.XXX">template localization
discussion</link> 
  +  for more information.
  +	</p>
  +  </td>
  +</tr>
  +
  +<tr>
   	<td>org.apache.tapestry.template-encoding</td>
   	
     <td>
  @@ -487,7 +503,8 @@
   
   	
   	<p>
  -	Please see the &configuration.character-sets; section for more information.
  +	Please see the <link href="localization.html#localization.XXX">template localization
discussion</link> 
  +  for more information.
   	</p>
     </td>
   </tr>
  @@ -640,91 +657,5 @@
   
   
   
  -<section id="configuration.character-sets">
  -	<title>Character Sets</title>
  -
  -<p>
  -Tapestry is designed to make the web application localization easy and 
  -offers the ability to define different localized templates for the same component.
  -For example, Home.html would be the default template of the Home page, however
  -Home_fr.html would be used in all French locales, while Home_zh_CN.html would be used in
  -China and Home_zh_TW.html would be used in Taiwan.
  -</p>
  -
  -<p>
  -Web developers and designers in different countries tend to use different character sets

  -for the templates they produce. English, German, French templates are typically produced
in
  -ISO-8859-1, Russian templates often use KOI8-R, and Chinese texts are normally written
in Big5.
  -Tapestry allows the application to configure the character set used in its templates 
  -and makes it possible to use different character sets for templates associated with 
  -different components and different locales.
  -</p>
  -
  -<p>
  -The character set of a template is defined using the 
  -org.apache.tapestry.template-encoding
  -&configuration-property;. The search path of this property is slightly different then
the
  -standard one and allows specific components to use other character sets:
  -</p>
  -	
  -<ul>
  -	<li>
  -		As a &spec.meta; of the &spec.page-specification; or the &spec.component-specification;

  -		(in the page or component specification). 
  -		<p>
  -		This configuration will apply only to the page or component where it is defined.
  -		</p>
  -	</li>
  -	<li>
  -		As a &spec.meta; of the &spec.library-specification; 
  -		(in the library specification, if the components are included in a library). 
  -		<p>
  -		This configuration will apply to all pages and components in the library.
  -		</p>
  -	</li>
  -	<li>
  -		As a &spec.meta; of the &spec.application; (in the application specification,
  -		if the application uses one).
  -	</li>
  -	<li>
  -		As an &init-parameter;
  -		for the servlet, in the web application deployment descriptor.
  -	</li>
  -	<li>
  -		As an &init-parameter;
  -		for the servlet context, also in the web application deployment descriptor.
  -	</li>
  -	<li>
  -		As a JVM system property.
  -	</li>
  -	<li>
  -		The hard-coded default "ISO-8859-1".
  -	</li>
  -</ul>
  -	
  -<p>
  -Tapestry also makes it possible to define the character set used by the templates specific

  -to a particular locale by appending the locale to the property name above. 
  -As an example, the 
  -org.apache.tapestry.template-encoding_ru configuration property would define
  -the character set used by the Russian templates, such as Home_ru.html. 
  -This allows templates for different locales to use different character sets, 
  -even though they are in the same application. 
  -For example, it is possible for all Russian templates in the application to use the KOI8-R

  -character set and all Chinese templates to use Big5 at the same time.
  -</p>
  -
  -<p>
  -The character sets used by the templates do not reflect in any way on the character set

  -Tapestry uses to encode its response to the browser. The character sets are used when reading
  -the template to translate it appropriately into Unicode.
  -The output character set is defined by the 
  -org.apache.tapestry.output-encoding &configuration-property;.
  -</p>
  -
  -	
  -</section>	<!-- configuration.character-sets -->
  -
  -
   </body>
   </document>
  \ No newline at end of file
  
  
  
  1.13      +4 -24     jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/template.xml
  
  Index: template.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/template.xml,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- template.xml	31 Jan 2005 15:39:56 -0000	1.12
  +++ template.xml	6 Feb 2005 20:36:13 -0000	1.13
  @@ -504,29 +504,8 @@
   	 <title>Localization</title>
   	 
   <p>
  -Tapestry includes a number of <link href="configuration.html#configuration.character-sets">localization
features</link>
  -localization features. An important part of which
  -is to allow each page or component to have its own catalog of localized messages (modeled
after the Java 
  -ResourceBundle class).
  -</p>	 
  -
  -<p>
  -The page (or component) message catalog 	is a collection of .properties files
  -that are stored with the page or component specification. They follow the same naming conventions

  -as for ResourceBundles, so component MyComponent (whose specification file
  -is MyComponent.jwc) might have a default
  -message file of MyComponent.properties, and a French translation as
  -MyComponent_fr.properties.
  -</p>
  -
  -<note>
  -	On oft-requested feature for Tapestry is to have a global message catalog, and a way to
  -	access that catalog from the individual pages and components. This would allow common
messages
  -	to be written (and translated) just once. This is a feature that may be added to Tapestry
3.1.	
  -</note>
  -
  -<p>
  -As we've seen, it is possible to access the messages for a page or component using the
  +Tapestry includes a number of <link href="localization.html">localization features</link>
  +localization features.  As we've seen, it is possible to access the messages for a page
or component using the
   <code>message:</code>	 prefix on a component parameter.
   </p>
   
  @@ -592,7 +571,8 @@
   filtered, so that any reserved
   HTML characters in a message string are expanded to HTML entities.  For example,
   a &lt;	 will be expanded to &amp;lt; If this is not desired,
  -add  the attribute value raw="yes" to the &span;. This defeats the filtering, and text
in the message
  +add  the attribute value <code>raw="yes"</code> to the &span;. 
  +This defeats the filtering, and text in the message
   is passed through as-is.
   </p>
   
  
  
  
  1.1                  jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/localization.xml
  
  Index: localization.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2005 The Apache Software Foundation
  
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
  -->
  
  <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "./dtd/document-v12.dtd"
[
    <!ENTITY projectroot '../'>
    <!ENTITY % links.ent SYSTEM "../links.ent">
    <!ENTITY % common.ent SYSTEM "common.ent">
    %links.ent;
    %common.ent;
    ]>
  <document>
    <header>
      <title>Localization</title>
    </header>
    <body>
      <p> Proper localization is a pervasive aspects of web application development.
Supporting users from different countries, with different languages, can be a tricky proposition
... it is more than just text that must be localized, but more subtle aspects of the application
such as date and currency formats. It is also more than text ... in some cases, a localized
application will want to change images or even color schemes. </p>
      <p> Localization support in Tapestry is likewise pervasive. </p>
      <section id="localization.component-catalog">
        <title>Component Message Catalogs</title>
        <p> The most fundamental aspect of localization in Tapestry are component message
catalogs (remember that pages are components too). A message catalog is a mapping from a logical
key (that may appear in Java code or in OGNL expressions) to a literal string. Tapestry message
catalogs are similar to Java's ResourceBundle class, except there is more flexibility in the
character set of the files, and the location of the files. </p>
        <p> Each component <em>may</em> have a message catalog, consisting
of a set of localized message properties files. </p>
        <p> These files are stored with the page or component specification file. They
are named the same as the specification file, but with a different extension (".properties"
instead of ".jwc" or ".page"). </p>
        <p> In addition, this is a <em>set</em> of files; a locale string
may be inserted just before the extension. For example, <code>WEB-INF/Home_fr.properties</code>
to contain the French language localization of the keys. </p>
        <p> We'll describe how to use the message catalog shortly, but first some notes
on how the message catalogs are read. </p>
        <section id="localization.component-catalog.encoding">
          <title>Properties file encoding</title>
          <p> For Java's ResourceBundle, the properties files must be in UTF-8 character
set. This can be problematic, as in non-western languages it is necessary to use Java's native2ascii
tool to convert from non-native files into an ASCII encoding of UTF-8. </p>
          <p> Tapestry can ready properties files in alternate character sets, but must
be told what character set the file is encoded in (internally, the contents must be converted
into standard multi-byte Unicode). </p>
          <p> This is accomplished by providing some metadata inside the component (or
page) specification. Metadata is specified using the &spec.meta; element. </p>
          <p> The resolution of the character set is somewhat complicated; it is  possible
that each properties file will use a different 
            character set. At the same time, repetition is bad ... therefore it is possible
to specify some of this information
            in the namespace meta data (in the containing application or library specification)
so that it can apply to all pages
            and components within the namespace.</p>
            
          <p>
            The basic key searched for is <code>org.apache.tapestry.messages-encoding</code>.
 The value for this key
            is the name of the charset for the properties file.
          </p>
          
          <p>
            However, the base key is modified to reflect the locale for the file being read;
the locale string is appended
            to the key; this <code>org.apache.tapestry.messages-encoding_fr</code>
will define the character set for
            the file <code>WEB-INF/Home_fr.properties</code>
          </p>
          
          <p>
            For each localization of the base key, a search of the following locations takes
place.
          </p>
          <ul>
            <li>The page or component specification.</li>
            <li>The namespace specification for the namespace containing the page or
component.</li>
            <li>The <link href="configuration.html#configuration.search-path">application
property search path</link></li>
          </ul>
          
          <p>
            Because localization of templates is similar to
            localization of message properties files,
            a second search occurs if the search for (variations of)
            <code>org.apache.tapestry.messages-encoding</code> fails; this time
for
            <code>org.apache.tapestry.template-encoding</code> occurs (again,
with variations
            for each locale).
          </p>
          
          <p>
            The ultimate default for encoding character set is
            ISO-8859-1; in other words, the same behavior as reading an ordinary
            Java ResourceBundle.
          </p>
            
        </section>
      </section>
      <!-- localization.component-catalog -->
      <section id="localization.template-text">
        <title>Template text localization</title>
        <p>As described in <link href="template.html#template.directives.l10n">the
discussion of Tapestry templates</link>, static text in an HTML template can be enclosed
in a specialized &span; tag. </p>
        
      </section>
      
      <section id="localization.localized-templates">
        <title>Localized templates</title>
      </section>
      
      <section id="localization.message-binding">
        <title>Using the message: binding prefix</title>
      </section>
      
      <section id="localization.messages-property">
        <title>Formatting messages</title>
      </section>
      
      <section id="localization.engine-locale">
        <title>Engine locale vs. page locale</title>
      </section>
    </body>
  </document>
  
  
  1.8       +148 -35   jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java
  
  Index: ComponentMessagesSourceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ComponentMessagesSourceImpl.java	6 Feb 2005 15:08:52 -0000	1.7
  +++ ComponentMessagesSourceImpl.java	6 Feb 2005 20:36:13 -0000	1.8
  @@ -19,7 +19,9 @@
   import java.io.InputStream;
   import java.net.URL;
   import java.util.ArrayList;
  +import java.util.Collections;
   import java.util.HashMap;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.Locale;
   import java.util.Map;
  @@ -31,7 +33,9 @@
   import org.apache.hivemind.util.Defense;
   import org.apache.hivemind.util.LocalizedNameGenerator;
   import org.apache.tapestry.IComponent;
  +import org.apache.tapestry.INamespace;
   import org.apache.tapestry.engine.DefaultComponentPropertySource;
  +import org.apache.tapestry.engine.DefaultNamespacePropertySource;
   import org.apache.tapestry.engine.IPropertySource;
   import org.apache.tapestry.event.ResetEventListener;
   import org.apache.tapestry.services.ComponentMessagesSource;
  @@ -83,62 +87,114 @@
           Resource specificationLocation = component.getSpecification().getSpecificationLocation();
           Locale locale = component.getPage().getLocale();
   
  -        Map propertiesMap = (Map) _componentCache.get(specificationLocation);
  -        if (propertiesMap == null)
  +        Map propertiesMap = findPropertiesMapForResource(specificationLocation);
  +
  +        Properties result = (Properties) propertiesMap.get(locale);
  +
  +        if (result == null)
           {
  -            propertiesMap = new HashMap();
  -            _componentCache.put(specificationLocation, propertiesMap);
  +
  +            // Not found, create it now.
  +
  +            result = assembleComponentProperties(
  +                    component,
  +                    specificationLocation,
  +                    propertiesMap,
  +                    locale);
  +
  +            propertiesMap.put(locale, result);
           }
   
  -        Properties result = (Properties) propertiesMap.get(locale);
  +        return result;
  +    }
  +
  +    private Map findPropertiesMapForResource(Resource resource)
  +    {
  +        Map result = (Map) _componentCache.get(resource);
   
  -        if (result != null)
  -            return result;
  +        if (result == null)
  +        {
  +            result = new HashMap();
  +            _componentCache.put(resource, result);
  +        }
  +
  +        return result;
  +    }
   
  -        // Not found, create it now.
  +    private Properties getNamespaceProperties(IComponent component, Locale locale)
  +    {
  +        INamespace namespace = component.getNamespace();
   
  -        result = assembleProperties(component, specificationLocation, propertiesMap, locale);
  +        Resource namespaceLocation = namespace.getSpecificationLocation();
  +
  +        Map propertiesMap = findPropertiesMapForResource(namespaceLocation);
  +
  +        Properties result = (Properties) propertiesMap.get(locale);
  +
  +        if (result == null)
  +        {
  +            result = assembleNamespaceProperties(namespace, propertiesMap, locale);
   
  -        propertiesMap.put(locale, result);
  +            propertiesMap.put(locale, result);
  +        }
   
           return result;
       }
   
  -    private Properties assembleProperties(IComponent component, Resource baseResourceLocation,
  -            Map propertiesMap, Locale locale)
  +    private Properties assembleComponentProperties(IComponent component,
  +            Resource baseResourceLocation, Map propertiesMap, Locale locale)
       {
  -        List locales = new ArrayList();
  -        List resources = new ArrayList();
  +        List localizations = findLocalizationsForResource(baseResourceLocation, locale);
   
  -        String fileName = baseResourceLocation.getName();
  -        int dotx = fileName.lastIndexOf('.');
  -        String baseName = fileName.substring(0, dotx);
  +        Properties parent = getNamespaceProperties(component, locale);
   
  -        LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, SUFFIX);
  +        Iterator i = localizations.iterator();
   
  -        while (g.more())
  +        while (i.hasNext())
           {
  -            String localizedName = g.next();
  -            Locale l = g.getCurrentLocale();
  +            ResourceLocalization rl = (ResourceLocalization) i.next();
  +
  +            Locale l = rl.getLocale();
  +
  +            Properties properties = (Properties) propertiesMap.get(l);
  +
  +            if (properties == null)
  +            {
  +                properties = readComponentProperties(component, l, rl.getResource(), parent);
  +
  +                propertiesMap.put(l, properties);
  +            }
   
  -            locales.add(l);
  -            resources.add(baseResourceLocation.getRelativeResource(localizedName));
  +            parent = properties;
           }
   
  +        return parent;
  +    }
  +
  +    private Properties assembleNamespaceProperties(INamespace namespace, Map propertiesMap,
  +            Locale locale)
  +    {
  +        List localizations = findLocalizationsForResource(
  +                namespace.getSpecificationLocation(),
  +                locale);
  +
           // Build them back up in reverse order.
   
           Properties parent = _emptyProperties;
  -        int count = locales.size();
  -        for (int i = count - 1; i >= 0; i--)
  +
  +        Iterator i = localizations.iterator();
  +
  +        while (i.hasNext())
           {
  -            Locale l = (Locale) locales.get(i);
  -            Properties properties = (Properties) propertiesMap.get(locale);
  +            ResourceLocalization rl = (ResourceLocalization) i.next();
  +
  +            Locale l = rl.getLocale();
  +
  +            Properties properties = (Properties) propertiesMap.get(l);
   
               if (properties == null)
               {
  -                Resource propertiesResource = (Resource) resources.get(i);
  -
  -                properties = readProperties(component, l, propertiesResource, parent);
  +                properties = readNamespaceProperties(namespace, l, rl.getResource(), parent);
   
                   propertiesMap.put(l, properties);
               }
  @@ -147,18 +203,67 @@
           }
   
           return parent;
  +
  +    }
  +
  +    /**
  +     * Finds the localizations of the provided resource. Returns a List of
  +     * {@link ResourceLocalization}(each pairing a locale with a localized resource). The
list is
  +     * ordered from most general (i.e., "foo.properties") to most specific (i.e.,
  +     * "foo_en_US_yokel.properties").
  +     */
  +
  +    private List findLocalizationsForResource(Resource resource, Locale locale)
  +    {
  +        List result = new ArrayList();
  +
  +        String baseName = extractBaseName(resource);
  +
  +        LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, SUFFIX);
  +
  +        while (g.more())
  +        {
  +            String localizedName = g.next();
  +            Locale l = g.getCurrentLocale();
  +            Resource localizedResource = resource.getRelativeResource(localizedName);
  +
  +            result.add(new ResourceLocalization(l, localizedResource));
  +        }
  +
  +        Collections.reverse(result);
  +
  +        return result;
  +    }
  +
  +    private String extractBaseName(Resource baseResourceLocation)
  +    {
  +        String fileName = baseResourceLocation.getName();
  +        int dotx = fileName.lastIndexOf('.');
  +
  +        return fileName.substring(0, dotx);
  +    }
  +
  +    private Properties readComponentProperties(IComponent component, Locale locale,
  +            Resource propertiesResource, Properties parent)
  +    {
  +        String encoding = getComponentMessagesEncoding(component, locale);
  +
  +        return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent);
       }
   
  -    private Properties readProperties(IComponent component, Locale locale,
  +    private Properties readNamespaceProperties(INamespace namespace, Locale locale,
               Resource propertiesResource, Properties parent)
       {
  -        URL resourceURL = propertiesResource.getResourceURL();
  +        String encoding = getNamespaceMessagesEncoding(namespace, locale);
  +
  +        return readPropertiesResource(propertiesResource.getResourceURL(), encoding, parent);
  +    }
   
  +    private Properties readPropertiesResource(URL resourceURL, String encoding, Properties
parent)
  +    {
           if (resourceURL == null)
               return parent;
   
  -        String encoding = getMessagesEncoding(component, locale);
  -
           Properties result = new Properties(parent);
   
           LocalizedProperties wrapper = new LocalizedProperties(result);
  @@ -218,7 +323,7 @@
                   getLocalizedProperties(component));
       }
   
  -    private String getMessagesEncoding(IComponent component, Locale locale)
  +    private String getComponentMessagesEncoding(IComponent component, Locale locale)
       {
           IPropertySource source = new DefaultComponentPropertySource(component,
                   _applicationPropertySource, locale);
  @@ -231,4 +336,12 @@
           return encoding;
       }
   
  +    private String getNamespaceMessagesEncoding(INamespace namespace, Locale locale)
  +    {
  +        IPropertySource source = new DefaultNamespacePropertySource(namespace,
  +                _applicationPropertySource, locale);
  +
  +        return source.getPropertyValue(MESSAGES_ENCODING_PROPERTY_NAME);
  +    }
  +
   }
  \ No newline at end of file
  
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ResourceLocalization.java
  
  Index: ResourceLocalization.java
  ===================================================================
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.services.impl;
  
  import java.util.Locale;
  
  import org.apache.hivemind.Resource;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class ResourceLocalization
  {
      private Locale _locale;
  
      private Resource _resource;
  
      public ResourceLocalization(Locale locale, Resource resource)
      {
          _locale = locale;
          _resource = resource;
      }
  
      public Locale getLocale()
      {
          return _locale;
      }
  
      /**
       * The localized version of the resource; this may or may not exist.
       */
  
      public Resource getResource()
      {
          return _resource;
      }
  }
  
  
  1.3       +2 -0      jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/MockPage1.properties
  
  Index: MockPage1.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/MockPage1.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockPage1.properties	5 Jan 2005 23:17:25 -0000	1.2
  +++ MockPage1.properties	6 Feb 2005 20:36:13 -0000	1.3
  @@ -18,3 +18,5 @@
   overwritten-in-variant=BASE4
   
   using-date-format=A formatted date: {0,date,short}
  +
  +component-overrides-namespace=MOCKPAGE1_BASE.component-overrides-namespace
  
  
  
  1.3       +1 -0      jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/MockPage1_fr.properties
  
  Index: MockPage1_fr.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/MockPage1_fr.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MockPage1_fr.properties	5 Jan 2005 23:17:25 -0000	1.2
  +++ MockPage1_fr.properties	6 Feb 2005 20:36:13 -0000	1.3
  @@ -13,3 +13,4 @@
   # limitations under the License.
   
   overwritten-in-language=LANGUAGE1_fr
  +localized-component-overrides-namespace=MOCKPAGE1_FR.localized-component-overrides-namespace
  \ No newline at end of file
  
  
  
  1.7       +51 -1     jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java
  
  Index: TestComponentMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestComponentMessages.java	6 Feb 2005 15:08:52 -0000	1.6
  +++ TestComponentMessages.java	6 Feb 2005 20:36:13 -0000	1.7
  @@ -35,6 +35,7 @@
   import org.apache.tapestry.services.impl.ComponentMessagesSourceImpl;
   import org.apache.tapestry.spec.ComponentSpecification;
   import org.apache.tapestry.spec.IComponentSpecification;
  +import org.apache.tapestry.spec.ILibrarySpecification;
   import org.apache.tapestry.spec.LibrarySpecification;
   
   /**
  @@ -69,6 +70,17 @@
           return spec;
       }
   
  +    private ILibrarySpecification newLibrarySpec()
  +    {
  +        Resource resource = new ClasspathResource(new DefaultClassResolver(),
  +                "/org/apache/tapestry/junit/Library.library");
  +
  +        ILibrarySpecification spec = new LibrarySpecification();
  +        spec.setSpecificationLocation(resource);
  +
  +        return spec;
  +    }
  +
       /**
        * Mocking up the page is too hard ... the relationship between the component messagess
source
        * and the page is too varied and complex. Instead, we use the tools to create the
page itself,
  @@ -102,7 +114,7 @@
   
           IPage page = newPage(spec, locale);
   
  -        INamespace namespace = new Namespace(null, null, new LibrarySpecification(), null,
null);
  +        INamespace namespace = new Namespace(null, null, newLibrarySpec(), null, null);
   
           page.setNamespace(namespace);
   
  @@ -116,6 +128,44 @@
           check(messages, "only-in-base", "BASE1");
       }
   
  +    /** @since 3.1 */
  +    public void testOnlyInNamespace()
  +    {
  +        Messages messages = createMessages(MOCK1, new Locale("en", "US"));
  +
  +        check(messages, "only-in-namespace", "LIBRARY_BASE.only-in-namespace");
  +    }
  +
  +    /** @since 3.1 */
  +    public void testLocalizedInNamespace()
  +    {
  +        Messages messages = createMessages(MOCK1, new Locale("fr"));
  +
  +        check(messages, "localized-in-namespace", "LIBRARY_FR.localized-in-namespace");
  +    }
  +
  +    /** @since 3.1 */
  +    public void testComponentOverridesNamespace()
  +    {
  +        Messages messages = createMessages(MOCK1, new Locale("en", "US"));
  +
  +        check(
  +                messages,
  +                "component-overrides-namespace",
  +                "MOCKPAGE1_BASE.component-overrides-namespace");
  +    }
  +
  +    /** @since 3.1 */
  +    public void testLocalizedComponentOverridesLocalizedNamespace()
  +    {
  +        Messages messages = createMessages(MOCK1, new Locale("fr"));
  +
  +        check(
  +                messages,
  +                "localized-component-overrides-namespace",
  +                "MOCKPAGE1_FR.localized-component-overrides-namespace");
  +    }
  +
       public void testMissingKey()
       {
           Messages messages = createMessages(MOCK1, new Locale("en", "GB"));
  
  
  
  1.1                  jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/Library_fr.properties
  
  Index: Library_fr.properties
  ===================================================================
  # Copyright 2005 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  localized-in-namespace=LIBRARY_FR.localized-in-namespace
  localized-component-overrides-namespace=LIBRARY_FR.localized-component-overrides-namespace
  
  
  1.1                  jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/Library.properties
  
  Index: Library.properties
  ===================================================================
  # Copyright 2005 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  only-in-namespace=LIBRARY_BASE.only-in-namespace
  
  component-overrides-namespace=LIBRARY_BASE.component-overrides-namespace
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/engine/DefaultNamespacePropertySource.java
  
  Index: DefaultNamespacePropertySource.java
  ===================================================================
  // Copyright 2005 The Apache Software Foundation
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package org.apache.tapestry.engine;
  
  import java.util.Locale;
  
  import org.apache.tapestry.INamespace;
  import org.apache.tapestry.util.DelegatingPropertySource;
  import org.apache.tapestry.util.LocalizedPropertySource;
  import org.apache.tapestry.util.PropertyHolderPropertySource;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class DefaultNamespacePropertySource implements IPropertySource
  {
      private IPropertySource _delegatingPropertySource;
  
      /**
       * Creates a new default component property source that is associated with the given
locale. The
       * property source will search property path specified in the class documentation for
the
       * localized versions of the property first.
       * 
       * @param namespace
       *            the namespace for which the properties will be looked up
       * @param applicationPropertySource
       *            the property source for the application
       * @param locale
       *            the locale to be used for localizing the properties
       */
      public DefaultNamespacePropertySource(INamespace namespace,
              IPropertySource applicationPropertySource, Locale locale)
      {
          DelegatingPropertySource source = new DelegatingPropertySource();
  
          // Search for the encoding property in the following order:
          // First search the component specification
          source.addSource(new PropertyHolderPropertySource(namespace.getSpecification()));
  
          // Then search the rest of the standard path
          source.addSource(applicationPropertySource);
  
          if (locale != null)
              source = new LocalizedPropertySource(locale, source);
  
          _delegatingPropertySource = source;
      }
  
      public String getPropertyValue(String propertyName)
      {
          return _delegatingPropertySource.getPropertyValue(propertyName);
      }
  
  }
  
  
  1.17      +1 -0      jakarta-tapestry/src/documentation/content/xdocs/site.xml
  
  Index: site.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/site.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- site.xml	27 Jan 2005 22:02:23 -0000	1.16
  +++ site.xml	6 Feb 2005 20:36:13 -0000	1.17
  @@ -40,6 +40,7 @@
         <intro label="Introduction" href="index.html"/>
         <templates label="Page and component templates" href="template.html"/>
         <components label="Creating Tapestry components" href="components.html"/>
  +      <localization label="Localization" href="localization.html"/>
         <state label="Managing server-side state" href="state.html"/>
         <hivemind label="HiveMind Integration" href="hivemind.html"/>
         <friend-urls label="Friendly URLs" href="friendly-urls.html"/>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org


Mime
View raw message