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/framework/src/test/org/apache/tapestry/junit TestComponentMessages.java
Date Tue, 08 Feb 2005 15:18:09 GMT
hlship      2005/02/08 07:18:08

  Modified:    .        status.xml
               src/documentation/content/xdocs/UsersGuide spec.xml
                        common.ent configuration.xml components.xml
                        localization.xml
               framework/src/java/org/apache/tapestry/services
                        Infrastructure.java
               framework/src/java/org/apache/tapestry/services/impl
                        InfrastructureImpl.java
                        ComponentMessagesSourceImpl.java
                        ImplStrings.properties ImplMessages.java
               framework/src/descriptor/META-INF hivemodule.xml
                        tapestry.props.xml
               framework/src/test/org/apache/tapestry/junit
                        TestComponentMessages.java
  Added:       framework/src/java/org/apache/tapestry/services
                        ComponentPropertySource.java
               framework/src/java/org/apache/tapestry/services/impl
                        LocalizedPropertySource.java
                        ComponentPropertySourceImpl.java
               framework/src/test/org/apache/tapestry/services/impl
                        TestLocalizedPropertySource.java
  Log:
  Add new ComponentPropertySource service for accessing component meta-data properties.
  
  Revision  Changes    Path
  1.66      +2 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- status.xml	7 Feb 2005 19:41:19 -0000	1.65
  +++ status.xml	8 Feb 2005 15:18:07 -0000	1.66
  @@ -141,6 +141,8 @@
         <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>
         <action type="update" dev="HLS"> Change handling of initial values for properties
to be based on injected logic. </action>
  +      <action type="fix" dev="HLS" fixes-bug="TAPESTRY-265" due-to="Michael Frericks">
Fix bad link in UsersGuide/spec.xml. </action>
  +      <action type="update" dev="HLS"> Add new ComponentPropertySource service for
accessing component meta-data properties. </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.20      +1 -1      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml
  
  Index: spec.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/spec.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- spec.xml	4 Feb 2005 02:28:06 -0000	1.19
  +++ spec.xml	8 Feb 2005 15:18:08 -0000	1.20
  @@ -161,7 +161,7 @@
   <p>
   In all of these cases, Tapestry will create a <em>new property</em> at runtime.
That is, it will create the accessor method
   (or methods), the instance variables, and any necessary setup or cleanup code automatically.
 As with 
  -<link href="state#state.page-properties">persistent page properties</link>,
you should at most declare <em>abstract</em>
  +<link href="state.html#state.page-properties">persistent page properties</link>,
you should at most declare <em>abstract</em>
   accessor methods.
   </p>
     
  
  
  
  1.16      +3 -1      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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- common.ent	6 Feb 2005 20:36:13 -0000	1.15
  +++ common.ent	8 Feb 2005 15:18:08 -0000	1.16
  @@ -49,7 +49,9 @@
   <!ENTITY listener-method			'listener method'>
   <!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-property		'<link href="configuration.html#configuration.properties">configuration
property</link>'>
  +<!ENTITY app-property-source		'<link href="configuration.html#configuration.app-property-source">application
property source</link>'>
  +<!ENTITY global-property-source		'<link href="configuration.html#configuration.global-property-source">global
property source</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.8       +44 -10    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- configuration.xml	6 Feb 2005 20:36:13 -0000	1.7
  +++ configuration.xml	8 Feb 2005 15:18:08 -0000	1.8
  @@ -216,8 +216,8 @@
   	
   </section>  <!-- configuration.deployment-descriptor -->
   
  -<section id="configuration.search-path">
  -	<title>Configuration Search Path</title>
  +<section id="configuration.app-property-source">
  +	<title>Application Property Source</title>
   	
   <p>
   Tapestry occasionally must obtain a value for a configuration property.    These configuration
  @@ -255,17 +255,20 @@
   </ul>
   
   <p>
  -It is expected that some configurations are not defined at any level; those will
  +It is expected that some configuration properties are not defined at any level; those will
   return null.
   </p>
   
   
   <p>
  -Applications are free to leverage this lookup mechanism as well.  &IEngine; defines
  -a propertySource property (of type &IPropertySource;)
  -that can be used to perform such lookups.
  +Applications are free to leverage this lookup mechanism as well.
   </p>
   
  +<fixme author="HLS">
  +  Need to reference the  ApplicationPropertySource, GlobalPropertySource and
  +  ComponentPropertySource services here.
  +</fixme>
  +
   <p>
   Applications may also want to change or augment
   the default search path; this is accomplished by overriding
  @@ -278,6 +281,38 @@
     involve a HiveMind contribution, details to be provided.
   </fixme>
   		
  +
  +</section>  <!-- configuration.app-property-source -->
  +    
  +<section id="configuration.global-property-source">
  +  <title>Global Property Source</title>
  +  
  +  <p>
  +    In some cases, a slightly different property source is used, the global property source.

  +  </p>
  +  
  +<ul>
  +	<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>
  +		Hard-coded "factory" defaults (for some properties). These are accessed as 
  +    &HiveMind; symbols.
  +	</li>
  +</ul>  
  +</section> <!-- configuration.global-property-source -->
  +
  +<section id="configuration.properties">
  +  <title>Configuration Properties</title>
  +
   <p>
   The following are all the configuration values
   currently used in Tapestry:
  @@ -488,7 +523,7 @@
   
   	
   	<p>
  -	Please see the <link href="localization.html#localization.XXX">template localization
discussion</link> 
  +	Please see the <link href="localization.html#localization.component-catalog.encoding">message
catalog localization discussion</link> 
     for more information.
   	</p>
     </td>
  @@ -503,14 +538,13 @@
   
   	
   	<p>
  -	Please see the <link href="localization.html#localization.XXX">template localization
discussion</link> 
  +	Please see the <link href="localization.html#localization.template-encoding">template
localization discussion</link> 
     for more information.
   	</p>
     </td>
   </tr>
   </table>
  -
  -</section>  <!-- configuration.search-path -->
  +</section>  <!-- configuration.properties -->
   
   <section id="configuration.extensions">
   	<title>Application extensions</title>
  
  
  
  1.8       +1 -1      jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/components.xml
  
  Index: components.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/components.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- components.xml	5 Jan 2005 23:17:21 -0000	1.7
  +++ components.xml	8 Feb 2005 15:18:08 -0000	1.8
  @@ -564,7 +564,7 @@
   </p>
   
   <p>
  -This behavior is controlled by a pair of <link href="configuration.html#configuration.search-path">configuration
properties</link>:
  +This behavior is controlled by a pair of <link href="configuration.html#configuration.properties">configuration
properties</link>:
   org.apache.tapestry.asset.dir and org.apache.tapestry.asset.URL.
   
   </p>	
  
  
  
  1.3       +14 -6     jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/localization.xml
  
  Index: localization.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/src/documentation/content/xdocs/UsersGuide/localization.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- localization.xml	7 Feb 2005 16:28:33 -0000	1.2
  +++ localization.xml	8 Feb 2005 15:18:08 -0000	1.3
  @@ -56,23 +56,23 @@
             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
  +          The basic meta-data  property name searched for is <code>org.apache.tapestry.messages-encoding</code>.
 The value for this name
             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
  +          However, the base name is modified to reflect the locale for the file being read;
the locale string is appended
  +          to the key, thus <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.
  +          For each localization of the base property name, 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>
  +          <li>The namespace (library or application) specification for the namespace
containing the page or component.</li>
  +          <li>The &global-property-source;.</li>
           </ul>
           
           <p>
  @@ -195,6 +195,14 @@
         
       </section>
       
  +    <section id="localization.assets">
  +      <title>Localization of Assets</title>
  +      
  +      <p>
  +        Coming soon.
  +      </p>
  +    </section>  <!-- localization.assets -->
  +    
       <section id="localization.messages-property">
         <title>Formatting messages</title>
         
  
  
  
  1.16      +8 -0      jakarta-tapestry/framework/src/java/org/apache/tapestry/services/Infrastructure.java
  
  Index: Infrastructure.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/Infrastructure.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Infrastructure.java	29 Jan 2005 16:45:15 -0000	1.15
  +++ Infrastructure.java	8 Feb 2005 15:18:08 -0000	1.16
  @@ -47,6 +47,14 @@
        * See <code>tapestry.ApplicationPropertySource</code>.
        */
       public IPropertySource getApplicationPropertySource();
  +    
  +    /**
  +     * Returns an  {@link IPropertySource} configured to search
  +     * the servlet, servlet context, and factory defaults.
  +     * 
  +     */
  +    
  +    public IPropertySource getGlobalPropertySource();
   
       /**
        * Returns the coordinator to be notified of reset events (which will, in turn, notify
other
  
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/services/ComponentPropertySource.java
  
  Index: ComponentPropertySource.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;
  
  import java.util.Locale;
  
  import org.apache.tapestry.IComponent;
  
  /**
   * Enapsulates the logic for searching for component meta-data.
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public interface ComponentPropertySource
  {
      /**
       * Returns the property value for a particular named meta-data property of the component.
The
       * search order is:
       * <ul>
       * <li>The component's specification</li>
       * <li>The specification of the application (or the library containing the component).</li>
       * <li>The chain of global property sources.</li>
       * </ul>
       * 
       * @return the value of the given key, or null if not found.
       */
  
      public String getComponentProperty(IComponent component, String propertyName);
  
      /**
       * Like {@link #getComponentProperty(IComponent, String)}, but the property name will
be
       * localized to the component's current locale (determined from its page). Localizing
the
       * property name means that a suffix may be appended to it. If the fully localized name
is not
       * found, then the locale is generalized (i.e., from "en_UK" to "en" to nothing) until
a match
       * is found.
       * 
       * @return the value of the given property name, or null if not found.
       */
      public String getLocalizedComponentProperty(IComponent component, Locale locale,
              String propertyName);
  }
  
  
  1.16      +15 -3     jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
  
  Index: InfrastructureImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- InfrastructureImpl.java	29 Jan 2005 16:45:14 -0000	1.15
  +++ InfrastructureImpl.java	8 Feb 2005 15:18:08 -0000	1.16
  @@ -51,6 +51,8 @@
   
       private IPropertySource _applicationPropertySource;
   
  +    private IPropertySource _globalPropertySource;
  +
       private ResetEventCoordinator _resetEventCoordinator;
   
       private ComponentMessagesSource _componentMessagesSource;
  @@ -84,7 +86,7 @@
       private HttpServletRequest _request;
   
       private HttpServletResponse _response;
  -    
  +
       private ServletContext _context;
   
       private String _applicationId;
  @@ -294,14 +296,24 @@
       {
           _applicationId = applicationId;
       }
  -    
  +
       public void setContext(ServletContext context)
       {
           _context = context;
       }
  -    
  +
       public Resource getContextRoot()
       {
           return new ContextResource(_context, "/");
       }
  +
  +    public IPropertySource getGlobalPropertySource()
  +    {
  +        return _globalPropertySource;
  +    }
  +
  +    public void setGlobalPropertySource(IPropertySource globalPropertySource)
  +    {
  +        _globalPropertySource = globalPropertySource;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.9       +21 -12    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ComponentMessagesSourceImpl.java	6 Feb 2005 20:36:13 -0000	1.8
  +++ ComponentMessagesSourceImpl.java	8 Feb 2005 15:18:08 -0000	1.9
  @@ -34,11 +34,11 @@
   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;
  +import org.apache.tapestry.services.ComponentPropertySource;
   import org.apache.tapestry.util.text.LocalizedProperties;
   
   /**
  @@ -68,12 +68,9 @@
   
       private Map _componentCache = new HashMap();
   
  -    private IPropertySource _applicationPropertySource;
  +    private IPropertySource _globalPropertySource;
   
  -    public void setApplicationPropertySource(IPropertySource source)
  -    {
  -        _applicationPropertySource = source;
  -    }
  +    private ComponentPropertySource _componentPropertySource;
   
       /**
        * Returns an instance of {@link Properties}containing the properly localized messages
for the
  @@ -325,13 +322,16 @@
   
       private String getComponentMessagesEncoding(IComponent component, Locale locale)
       {
  -        IPropertySource source = new DefaultComponentPropertySource(component,
  -                _applicationPropertySource, locale);
  -
  -        String encoding = source.getPropertyValue(MESSAGES_ENCODING_PROPERTY_NAME);
  +        String encoding = _componentPropertySource.getLocalizedComponentProperty(
  +                component,
  +                locale,
  +                MESSAGES_ENCODING_PROPERTY_NAME);
   
           if (encoding == null)
  -            encoding = source.getPropertyValue(TemplateSourceImpl.TEMPLATE_ENCODING_PROPERTY_NAME);
  +            encoding = _componentPropertySource.getLocalizedComponentProperty(
  +                    component,
  +                    locale,
  +                    TemplateSourceImpl.TEMPLATE_ENCODING_PROPERTY_NAME);
   
           return encoding;
       }
  @@ -339,9 +339,18 @@
       private String getNamespaceMessagesEncoding(INamespace namespace, Locale locale)
       {
           IPropertySource source = new DefaultNamespacePropertySource(namespace,
  -                _applicationPropertySource, locale);
  +                _globalPropertySource, locale);
   
           return source.getPropertyValue(MESSAGES_ENCODING_PROPERTY_NAME);
       }
   
  +    public void setGlobalPropertySource(IPropertySource source)
  +    {
  +        _globalPropertySource = source;
  +    }
  +
  +    public void setComponentPropertySource(ComponentPropertySource componentPropertySource)
  +    {
  +        _componentPropertySource = componentPropertySource;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.8       +3 -1      jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplStrings.properties
  
  Index: ImplStrings.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplStrings.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ImplStrings.properties	6 Jan 2005 02:17:11 -0000	1.7
  +++ ImplStrings.properties	8 Feb 2005 15:18:08 -0000	1.8
  @@ -45,4 +45,6 @@
   unable-to-write-expression=Unable to update OGNL expression ''{0}'' of {1} to {2}: {3}
   is-constant-expression-error=Error evaluating OGNL expression ''{0}'': {1}
   template-parameter-name=template parameter {0}
  -template-tag-parameter-name=implicit template tag parameter
  \ No newline at end of file
  +template-tag-parameter-name=implicit template tag parameter
  +
  +component-property-source-description=<PropertySource for {0}>
  \ No newline at end of file
  
  
  
  1.9       +7 -0      jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplMessages.java
  
  Index: ImplMessages.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ImplMessages.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ImplMessages.java	5 Jan 2005 23:16:57 -0000	1.8
  +++ ImplMessages.java	8 Feb 2005 15:18:08 -0000	1.9
  @@ -28,6 +28,7 @@
   import org.apache.tapestry.IComponent;
   import org.apache.tapestry.engine.IEngineService;
   import org.apache.tapestry.services.Infrastructure;
  +import org.apache.tapestry.spec.IComponentSpecification;
   import org.apache.tapestry.spec.IContainedComponent;
   
   /**
  @@ -198,4 +199,10 @@
       {
           return _formatter.format("template-parameter-name", name);
       }
  +
  +    public static String componentPropertySourceDescription(IComponentSpecification spec)
  +    {
  +        return _formatter.format("component-property-source-description", spec
  +                .getSpecificationLocation());
  +    }
   }
  \ No newline at end of file
  
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/LocalizedPropertySource.java
  
  Index: LocalizedPropertySource.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.util.Defense;
  import org.apache.hivemind.util.LocalizedNameGenerator;
  import org.apache.tapestry.engine.IPropertySource;
  
  /**
   * Wraps around a {@link org.apache.tapestry.engine.IPropertySource}to query a series of
localized
   * keys.
   * <p>
   * This is much simpler than the old {@link org.apache.tapestry.util.LocalizedPropertySource},
and
   * allows the locale to be specified on a thread-safe, per-invocation basis.
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class LocalizedPropertySource
  {
      private IPropertySource _source;
  
      public LocalizedPropertySource(IPropertySource source)
      {
          Defense.notNull(source, "source");
  
          _source = source;
      }
  
      /**
       * Get the property from the source, trying different variations of propertyName (adding
       * suffixes).
       * 
       * @param propertyName
       *            the base property name to search with.
       * @param local
       *            the Locale used to generate suffixes (may be null).
       */
  
      public String getPropertyValue(String propertyName, Locale locale)
      {
          Defense.notNull(propertyName, "propertyName");
  
          LocalizedNameGenerator g = new LocalizedNameGenerator(propertyName, locale, "");
  
          while (g.more())
          {
              String localizedName = g.next();
  
              String result = _source.getPropertyValue(localizedName);
  
              if (result != null)
                  return result;
          }
  
          return null;
      }
  }
  
  
  1.1                  jakarta-tapestry/framework/src/java/org/apache/tapestry/services/impl/ComponentPropertySourceImpl.java
  
  Index: ComponentPropertySourceImpl.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.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  import org.apache.hivemind.Resource;
  import org.apache.hivemind.lib.chain.ChainBuilder;
  import org.apache.tapestry.IComponent;
  import org.apache.tapestry.engine.IPropertySource;
  import org.apache.tapestry.event.ResetEventListener;
  import org.apache.tapestry.services.ComponentPropertySource;
  import org.apache.tapestry.spec.IComponentSpecification;
  import org.apache.tapestry.util.PropertyHolderPropertySource;
  
  /**
   * TODO: Figure out a testing strategy for this beast!
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class ComponentPropertySourceImpl implements ComponentPropertySource, ResetEventListener
  {
      private IPropertySource _globalProperties;
  
      private ChainBuilder _chainBuilder;
  
      private Map _componentSources = new HashMap();
  
      private Map _localizedComponentSources = new HashMap();
  
      public synchronized void resetEventDidOccur()
      {
          _componentSources.clear();
          _localizedComponentSources.clear();
      }
  
      private synchronized IPropertySource getSourceForComponent(IComponent component)
      {
          Resource key = component.getSpecification().getSpecificationLocation();
  
          IPropertySource result = (IPropertySource) _componentSources.get(key);
  
          if (result == null)
          {
              result = createSourceForComponent(component);
              _componentSources.put(key, result);
          }
  
          return result;
      }
  
      private synchronized LocalizedPropertySource getLocalizedSourceForComponent(IComponent
component)
      {
          Resource key = component.getSpecification().getSpecificationLocation();
  
          LocalizedPropertySource result = (LocalizedPropertySource) _componentSources.get(key);
  
          if (result == null)
          {
              result = new LocalizedPropertySource(getSourceForComponent(component));
  
              _componentSources.put(key, result);
          }
  
          return result;
  
      }
  
      private IPropertySource createSourceForComponent(IComponent component)
      {
          IComponentSpecification specification = component.getSpecification();
  
          List sources = new ArrayList();
  
          sources.add(new PropertyHolderPropertySource(specification));
          sources.add(new PropertyHolderPropertySource(component.getNamespace().getSpecification()));
          sources.add(_globalProperties);
  
          return (IPropertySource) _chainBuilder.buildImplementation(
                  IPropertySource.class,
                  sources,
                  ImplMessages.componentPropertySourceDescription(specification));
      }
  
      public String getComponentProperty(IComponent component, String propertyName)
      {
          return getSourceForComponent(component).getPropertyValue(propertyName);
      }
  
      public String getLocalizedComponentProperty(IComponent component, Locale locale,
              String propertyName)
      {
          return getLocalizedSourceForComponent(component).getPropertyValue(propertyName,
locale);
      }
  
      public void setChainBuilder(ChainBuilder chainBuilder)
      {
          _chainBuilder = chainBuilder;
      }
  
      public void setGlobalProperties(IPropertySource globalProperties)
      {
          _globalProperties = globalProperties;
      }
  }
  
  
  1.21      +3 -1      jakarta-tapestry/framework/src/descriptor/META-INF/hivemodule.xml
  
  Index: hivemodule.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/hivemodule.xml,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- hivemodule.xml	29 Jan 2005 16:45:14 -0000	1.20
  +++ hivemodule.xml	8 Feb 2005 15:18:08 -0000	1.21
  @@ -59,6 +59,7 @@
         <construct class="org.apache.tapestry.services.impl.InfrastructureImpl">
           <set-object  property="applicationSpecification" value="service-property:tapestry.globals.ApplicationGlobals:specification"/>
           <set-service property="applicationPropertySource" service-id="tapestry.props.ApplicationPropertySource"/>
  +        <set-service property="globalPropertySource" service-id="tapestry.props.GlobalPropertySource"/>
           <set-service property="componentMessagesSource" service-id="ComponentMessagesSource"/>
           <set-service property="resetEventCoordinator" service-id="ResetEventCoordinator"/>
           <set-service property="templateSource" service-id="tapestry.parse.TemplateSource"/>
  @@ -140,7 +141,8 @@
       <invoke-factory>
         <construct class="org.apache.tapestry.services.impl.ComponentMessagesSourceImpl">
           <event-listener service-id="ResetEventCoordinator"/>
  -        <set-object property="applicationPropertySource" value="infrastructure:applicationPropertySource"/>
  +        <set-object property="globalPropertySource" value="infrastructure:globalPropertySource"/>
  +        <set-service property="componentPropertySource" service-id="tapestry.props.ComponentPropertySource"/>
         </construct>
       </invoke-factory>
       
  
  
  
  1.5       +17 -1     jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.props.xml
  
  Index: tapestry.props.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/descriptor/META-INF/tapestry.props.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- tapestry.props.xml	4 Feb 2005 02:08:09 -0000	1.4
  +++ tapestry.props.xml	8 Feb 2005 15:18:08 -0000	1.5
  @@ -86,6 +86,21 @@
     </contribution>
     
     
  +  <service-point id="ComponentPropertySource" interface="org.apache.tapestry.services.ComponentPropertySource">
  +    
  +    Provides access to component meta-data, with a search path that  includes the component's
namespace,
  +    and the GlobalPropertySource.
  +    
  +    <invoke-factory>
  +      <construct class="org.apache.tapestry.services.impl.ComponentPropertySourceImpl">
  +        <set-service property="chainBuilder" service-id="hivemind.lib.ChainBuilder"/>
  +        <set-service property="globalProperties" service-id="GlobalPropertySource"/>
  +        <event-listener service-id="tapestry.ResetEventCoordinator"/>
  +      </construct>
  +      
  +    </invoke-factory>
  +  </service-point>
  +  
     <configuration-point id="ApplicationPropertySources" schema-id="hivemind.lib.ChainContribution">
       
       Property sources used by the application, which includes a search of the
  @@ -180,5 +195,6 @@
     <contribution configuration-id="hivemind.SymbolSources">
       <source name="SystemProperties" before="hivemind.ApplicationDefaults" 
         class="org.apache.hivemind.impl.SystemPropertiesSymbolSource"/>
  -  </contribution>  
  +  </contribution> 
  +   
   </module>
  \ No newline at end of file
  
  
  
  1.1                  jakarta-tapestry/framework/src/test/org/apache/tapestry/services/impl/TestLocalizedPropertySource.java
  
  Index: TestLocalizedPropertySource.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.test.HiveMindTestCase;
  import org.apache.tapestry.engine.IPropertySource;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.tapestry.services.impl.LocalizedPropertySource}.
   * 
   * @author Howard M. Lewis Ship
   * @since 3.1
   */
  public class TestLocalizedPropertySource extends HiveMindTestCase
  {
      public void testFound()
      {
          MockControl control = newControl(IPropertySource.class);
          IPropertySource ps = (IPropertySource) control.getMock();
  
          ps.getPropertyValue("property-name_en");
          control.setReturnValue(null);
  
          ps.getPropertyValue("property-name");
          control.setReturnValue("fred");
  
          replayControls();
  
          LocalizedPropertySource lps = new LocalizedPropertySource(ps);
  
          String result = lps.getPropertyValue("property-name", Locale.ENGLISH);
  
          assertEquals("fred", result);
  
          verifyControls();
      }
  
      public void testNotFound()
      {
          MockControl control = newControl(IPropertySource.class);
          IPropertySource ps = (IPropertySource) control.getMock();
  
          ps.getPropertyValue("property-name_fr");
          control.setReturnValue(null);
  
          ps.getPropertyValue("property-name");
          control.setReturnValue(null);
  
          replayControls();
  
          LocalizedPropertySource lps = new LocalizedPropertySource(ps);
  
          assertNull(lps.getPropertyValue("property-name", Locale.FRENCH));
  
          verifyControls();
      }
  }
  
  
  1.8       +20 -2     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestComponentMessages.java	6 Feb 2005 20:36:13 -0000	1.7
  +++ TestComponentMessages.java	8 Feb 2005 15:18:08 -0000	1.8
  @@ -25,6 +25,7 @@
   import org.apache.hivemind.service.ClassFactory;
   import org.apache.hivemind.service.impl.ClassFactoryImpl;
   import org.apache.hivemind.util.ClasspathResource;
  +import org.apache.tapestry.IComponent;
   import org.apache.tapestry.INamespace;
   import org.apache.tapestry.IPage;
   import org.apache.tapestry.engine.Namespace;
  @@ -32,6 +33,7 @@
   import org.apache.tapestry.enhance.InjectMessagesWorker;
   import org.apache.tapestry.html.BasePage;
   import org.apache.tapestry.junit.mock.c21.NullPropertySource;
  +import org.apache.tapestry.services.ComponentPropertySource;
   import org.apache.tapestry.services.impl.ComponentMessagesSourceImpl;
   import org.apache.tapestry.spec.ComponentSpecification;
   import org.apache.tapestry.spec.IComponentSpecification;
  @@ -39,7 +41,7 @@
   import org.apache.tapestry.spec.LibrarySpecification;
   
   /**
  - * Tests the class {@link org.apache.tapestry.engine.DefaultStringsSource}.
  + * Tests the class {@link org.apache.tapestry.services.impl.ComponentMessagesSourceImpl}.
    * <p>
    * TODO: Add tests realted to messages encoding (which can be specified as meta-data on
the
    * component specification or, ultimately, in the namespace (library specification).
  @@ -50,6 +52,21 @@
   
   public class TestComponentMessages extends TapestryTestCase
   {
  +    private static class NullComponentPropertySource implements ComponentPropertySource
  +    {
  +
  +        public String getComponentProperty(IComponent component, String propertyName)
  +        {
  +            return null;
  +        }
  +
  +        public String getLocalizedComponentProperty(IComponent component, Locale locale,
  +                String propertyName)
  +        {
  +            return null;
  +        }
  +    }
  +
       private void check(Messages messages, String key, String expected)
       {
           String actual = messages.getMessage(key);
  @@ -108,7 +125,8 @@
       private Messages createMessages(String location, Locale locale)
       {
           ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl();
  -        source.setApplicationPropertySource(new NullPropertySource());
  +        source.setGlobalPropertySource(new NullPropertySource());
  +        source.setComponentPropertySource(new NullComponentPropertySource());
   
           IComponentSpecification spec = newSpec(location);
   
  
  
  

---------------------------------------------------------------------
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