cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/i18n AbstractBundleFactory.java XMLResourceBundleFactory.java BundleFactory.java AbstractBunldeFactory.java
Date Wed, 15 Jan 2003 11:30:42 GMT
cziegeler    2003/01/15 03:30:42

  Modified:    src/java/org/apache/cocoon/i18n
                        XMLResourceBundleFactory.java BundleFactory.java
  Added:       src/java/org/apache/cocoon/i18n AbstractBundleFactory.java
  Removed:     src/java/org/apache/cocoon/i18n AbstractBunldeFactory.java
  Log:
  Adding copyright, formattign source...
  
  Revision  Changes    Path
  1.10      +61 -103   xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java
  
  Index: XMLResourceBundleFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/XMLResourceBundleFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLResourceBundleFactory.java	13 Nov 2002 22:09:35 -0000	1.9
  +++ XMLResourceBundleFactory.java	15 Jan 2003 11:30:41 -0000	1.10
  @@ -61,10 +61,14 @@
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.component.DefaultComponentSelector;
  +import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   
   import org.xml.sax.SAXParseException;
   
  @@ -79,8 +83,9 @@
    * @version $Id$
    */
   
  -public class XMLResourceBundleFactory extends DefaultComponentSelector
  -    implements BundleFactory {
  +public class XMLResourceBundleFactory 
  +    extends DefaultComponentSelector
  +    implements BundleFactory, Composable, Configurable, Disposable, ThreadSafe, LogEnabled
{
   
       /** Should we load bundles to cache on startup or not? */
       protected boolean cacheAtStartup = false;
  @@ -100,8 +105,7 @@
       /**
        * Default constructor.
        */
  -    public XMLResourceBundleFactory()
  -    {
  +    public XMLResourceBundleFactory() {
       }
   
       public void compose(ComponentManager manager) {
  @@ -121,35 +125,21 @@
       }
   
       /**
  -     * Set the logger.
  -     *
  -     * @param logger the logger
  -     */
  -    public void enableLogging(final Logger logger) {
  -        this.logger = logger;
  -    }
  -
  -    /**
        * Configure the component.
        *
        * @param configuration the configuration
        */
  -    public void configure( Configuration configuration ) throws ConfigurationException
  -    {
  +    public void configure( Configuration configuration ) throws ConfigurationException
{
           this.cacheAtStartup = configuration.getChild(ConfigurationKeys.CACHE_AT_STARTUP).getValueAsBoolean(false);
   
  -        try
  -        {
  +        try {
               this.directory = configuration.getChild(ConfigurationKeys.ROOT_DIRECTORY, true).getValue();
  -        }
  -        catch (ConfigurationException e)
  -        {
  +        } catch (ConfigurationException e) {
               if (logger.isWarnEnabled()) logger.warn("Root directory not provided in configuration,
using default (root).");
               this.directory = "";
           }
   
  -        if (logger.isDebugEnabled())
  -        {
  +        if (logger.isDebugEnabled()) { 
               logger.debug(
                   "XMLResourceBundleFactory configured with: cacheAtStartup = " +
                   cacheAtStartup + ", directory = '" + directory + "'"
  @@ -166,8 +156,7 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component select(String name, Locale locale)
  -        throws ComponentException
  -    {
  +        throws ComponentException {
           return select(name, locale, cacheAtStartup);
       }
   
  @@ -181,8 +170,7 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component select(String name, Locale loc, boolean cacheAtStartup)
  -        throws ComponentException
  -    {
  +        throws ComponentException {
           Component bundle = _select(name, loc, cacheAtStartup);
           if (bundle == null)
               throw new ComponentException("Unable to locate resource: " + name);
  @@ -196,8 +184,7 @@
        * @param locale            locale
        * @return                  the bundle
        */
  -    private Component _select(String name, Locale loc)
  -    {
  +    private Component _select(String name, Locale loc) {
           return _select(name, loc, cacheAtStartup);
       }
   
  @@ -209,8 +196,7 @@
        * @param locale            locale
        * @return                  the bundle
        */
  -    protected Component selectParent(String name, Locale loc)
  -    {
  +    protected Component selectParent(String name, Locale loc) {
           return selectParent(name, loc, cacheAtStartup);
       }
   
  @@ -223,8 +209,7 @@
        * @param cacheAtStartup    cache all the keys when constructing?
        * @return                  the bundle
        */
  -    protected Component selectParent(String name, Locale loc, boolean cacheAtStartup)
  -    {
  +    protected Component selectParent(String name, Locale loc, boolean cacheAtStartup) {
           return _select(name, getParentLocale(loc), cacheAtStartup);
       }
   
  @@ -237,8 +222,7 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component select(String name, String localeName)
  -        throws ComponentException
  -    {
  +        throws ComponentException {
           return select(name, new Locale(localeName, localeName) );
       }
   
  @@ -250,8 +234,7 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component selectFromFilename(String fileName)
  -        throws ComponentException
  -    {
  +        throws ComponentException {
           return selectFromFilename(fileName, cacheAtStartup);
       }
   
  @@ -264,8 +247,7 @@
        * @exception ComponentException if a bundle is not found
        */
       public Component selectFromFilename(String fileName, boolean cacheAtStartup)
  -        throws ComponentException
  -    {
  +        throws ComponentException {
           Component bundle = _select(fileName, null, cacheAtStartup);
           if (bundle == null)
               throw new ComponentException("Unable to locate resource: " + fileName);
  @@ -281,25 +263,20 @@
        * @return                  the bundle
        * @exception ComponentException if a bundle is not found
        */
  -    private Component _select(String name, Locale loc, boolean cacheAtStartup)
  -    {
  +    private Component _select(String name, Locale loc, boolean cacheAtStartup) {
           if (logger.isDebugEnabled()) logger.debug("_getBundle: " + name + ", locale " +
loc);
           String fileName = getFileName(name, loc);
           XMLResourceBundle bundle = (XMLResourceBundle) selectCached(fileName);
  -        if (bundle == null && !isNotFoundBundle(fileName))
  -        {
  +        if (bundle == null && !isNotFoundBundle(fileName)) {
               if (logger.isDebugEnabled()) logger.debug("not found in cache, loading: " +
fileName);
  -            synchronized(this)
  -            {
  +            synchronized(this) {
                   bundle = (XMLResourceBundle) selectCached(fileName);
  -                if (bundle == null && !isNotFoundBundle(fileName))
  -                {
  +                if (bundle == null && !isNotFoundBundle(fileName)) {
                       if (logger.isDebugEnabled()) logger.debug("synchronized: not found
in cache, loading: " + fileName);
                       bundle = _loadBundle(name, fileName, loc, cacheAtStartup);
                       Locale parentLoc = loc;
                       String parentBundleName;
  -                    while (bundle == null && parentLoc != null && !parentLoc.getLanguage().equals(""))
  -                    {
  +                    while (bundle == null && parentLoc != null && !parentLoc.getLanguage().equals(""))
{
                           if (logger.isDebugEnabled()) logger.debug("synchronized: still
not found, trying parent: " + fileName);
                           parentLoc = getParentLocale(parentLoc);
                           parentBundleName = getFileName(name, parentLoc);
  @@ -322,13 +299,12 @@
        * @param cacheAtStartup    cache all the keys when constructing?
        * @return                  the bundle, null if loading failed
        */
  -    private XMLResourceBundle _loadBundle(String name, String fileName, Locale loc, boolean
cacheAtStartup)
  -    {
  -        if (logger.isDebugEnabled()) logger.debug("Trying to load bundle: " + name + ",
locale " + loc + ", filename " + fileName);
  +    private XMLResourceBundle _loadBundle(String name, String fileName, Locale loc, boolean
cacheAtStartup) {
  +        if (logger.isDebugEnabled()) 
  +            logger.debug("Trying to load bundle: " + name + ", locale " + loc + ", filename
" + fileName);
           XMLResourceBundle bundle = null;
           XMLResourceBundle parentBundle = null;
  -        try
  -        {
  +        try {
               if (loc != null && !loc.getLanguage().equals(""))
                   parentBundle = (XMLResourceBundle) selectParent(name, loc);
               bundle = new XMLResourceBundle();
  @@ -336,24 +312,18 @@
               bundle.compose(this.manager);
               bundle.init(name, fileName, loc, parentBundle, cacheAtStartup);
               return bundle;
  -        }
  -        catch (FileNotFoundException fe)
  -        {
  +        } catch (FileNotFoundException fe) {
               logger.info("Resource not found: " + name + ", locale " + loc
                   + ", bundleName " + fileName + ". Exception: " + fe.getMessage());
  -        }
  -        catch (SAXParseException se)
  -        {
  +        } catch (SAXParseException se) {
               logger.error("Incorrect resource format", se);
  -        }
  -        catch (Exception e) {
  +        } catch (Exception e) {
               logger.error("Resource loading failed", e);
           }
           return null;
       }
   
  -    public void release(Component component)
  -    {
  +    public void release(Component component) {
           // Do nothing
       }
   
  @@ -365,17 +335,14 @@
        * @param locale            the locale
        * @return                  the parent locale
        */
  -    protected Locale getParentLocale(Locale loc)
  -    {
  +    protected Locale getParentLocale(Locale loc) {
           Locale newloc;
  -        if (loc.getVariant().equals(""))
  -        {
  +        if (loc.getVariant().equals("")) {
               if (loc.getCountry().equals(""))
                   newloc = new Locale("","","");
               else
                   newloc = new Locale(loc.getLanguage(), "", "");
  -        }
  -        else
  +        } else
               newloc = new Locale(loc.getLanguage(), loc.getCountry(), "");
   
           return newloc;
  @@ -388,24 +355,19 @@
        * @param locale            the locale
        * @return                  the parent locale
        */
  -    protected String getFileName(String name, Locale loc)
  -    {
  +    protected String getFileName(String name, Locale loc) {
           StringBuffer sb = new StringBuffer(getDirectory());
           sb.append('/').append(name);
  -        if (loc != null)
  -        {
  -            if (! loc.getLanguage().equals(""))
  -            {
  +        if (loc != null) {
  +            if (! loc.getLanguage().equals("")) {
                   sb.append("_");
                   sb.append(loc.getLanguage());
               }
  -            if (! loc.getCountry().equals(""))
  -            {
  +            if (! loc.getCountry().equals("")) {
                   sb.append("_");
                   sb.append(loc.getCountry());
               }
  -            if (! loc.getVariant().equals(""))
  -            {
  +            if (! loc.getVariant().equals("")) {
                   sb.append("_");
                   sb.append(loc.getVariant());
               }
  @@ -423,16 +385,12 @@
        * @param fileName          file name of the bundle
        * @return                  the cached bundle; null, if not found
        */
  -    protected Component selectCached(String fileName)
  -    {
  +    protected Component selectCached(String fileName) {
           Component bundle = null;
  -        try
  -        {
  +        try {
               bundle = super.select(fileName);
               if (logger.isDebugEnabled()) logger.debug("Returning from cache: " + fileName);
  -        }
  -        catch (ComponentException e)
  -        {
  +        } catch (ComponentException e) {
               if (logger.isDebugEnabled()) logger.debug("Not found in cache: " + fileName);
           }
           return bundle;
  @@ -445,15 +403,12 @@
        * @return                  true, if the bundle wasn't found already before;
        *                          otherwise, false.
        */
  -    protected boolean isNotFoundBundle(String fileName)
  -    {
  +    protected boolean isNotFoundBundle(String fileName) {
           String result = (String)(cacheNotFound.get(fileName));
  -        if (result != null)
  -        {
  +        if (result != null) {
               if (logger.isDebugEnabled()) logger.debug("Returning from not_found_cache:
" + fileName);
           }
  -        else
  -        {
  +        else {
               if (logger.isDebugEnabled()) logger.debug("Not found in not_found_cache: "
+ fileName);
           }
           return result != null;
  @@ -466,15 +421,12 @@
        * @return                  true, if the bundle wasn't found already before;
        *                          otherwise, false.
        */
  -    protected void updateCache(String fileName, XMLResourceBundle bundle)
  -    {
  -        if (bundle == null)
  -        {
  +    protected void updateCache(String fileName, XMLResourceBundle bundle) {
  +        if (bundle == null) {
               if (logger.isDebugEnabled()) logger.debug("Updating not_found_cache: " + fileName);
               cacheNotFound.put(fileName, fileName);
           }
  -        else
  -        {
  +        else {
               if (logger.isDebugEnabled()) logger.debug("Updating cache: " + fileName);
               super.put((Object) fileName, (Component) bundle);
           }
  @@ -485,8 +437,7 @@
        *
        * @return the directory path
        */
  -    public String getDirectory()
  -    {
  +    public String getDirectory() {
           return directory;
       }
   
  @@ -495,8 +446,15 @@
        *
        * @return true if pre-loading all resources; false otherwise
        */
  -    public boolean cacheAtStartup()
  -    {
  +    public boolean cacheAtStartup() {
           return cacheAtStartup;
       }
  +    
  +	/**
  +	 * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
  +	 */
  +	public void enableLogging(Logger logger) {
  +        this.logger = logger;
  +	}
  +
   }
  
  
  
  1.2       +52 -8     xml-cocoon2/src/java/org/apache/cocoon/i18n/BundleFactory.java
  
  Index: BundleFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/BundleFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BundleFactory.java	13 Nov 2002 22:09:35 -0000	1.1
  +++ BundleFactory.java	15 Jan 2003 11:30:41 -0000	1.2
  @@ -1,15 +1,60 @@
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
  + Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
   package org.apache.cocoon.i18n;
   
   import java.util.Locale;
   
  -import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentSelector;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.thread.ThreadSafe;
   
   /**
    * Bundle Factory realizations are responsible for loading and providing
  @@ -18,8 +63,7 @@
    * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
    * @version $Id$
    */
  -public interface BundleFactory extends ComponentSelector, Composable,
  -    Configurable, Disposable, LogEnabled, ThreadSafe {
  +public interface BundleFactory extends ComponentSelector {
   
       String ROLE = "org.apache.cocoon.i18n.BundleFactory";
   
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/i18n/AbstractBundleFactory.java
  
  Index: AbstractBundleFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.i18n;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * Bundle factory implementation base class.
   *
   * @author <a href="mailto:kpiroumian@apache.org">Konstantin Piroumian</a>
   * @version $Id: AbstractBundleFactory.java,v 1.1 2003/01/15 11:30:41 cziegeler Exp $
   */
  public abstract class AbstractBundleFactory 
    extends AbstractLogEnabled
    implements BundleFactory, Composable, Configurable, Disposable, LogEnabled, ThreadSafe
{
  
      /** Should we load bundles to cache on startup or not. */
      protected boolean cacheAtStartup = false;
  
      /** Root directory to all bundle names */
      protected String directory;
  
      protected ComponentManager manager = null;
  
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      /**
       * Configure this component.
       *
       * @param configuration the configuration.
       */
      public void configure(Configuration configuration)
          throws ConfigurationException {
  
          this.cacheAtStartup =
              configuration.getChild(
                  ConfigurationKeys.CACHE_AT_STARTUP).getValueAsBoolean(false);
  
          try {
              this.directory = configuration.getChild(
                  ConfigurationKeys.ROOT_DIRECTORY, true).getValue();
          } catch (ConfigurationException e) {
              if (getLogger().isWarnEnabled()) {
                  getLogger().warn(
                      "Root directory not provided in configuration, "
                      + "using default (root)"
                  );
              }
              this.directory = "";
          }
  
          if (getLogger().isDebugEnabled()) {
              getLogger().debug(
                  "Bundle Factory implementation configured with: cacheAtStartup = "
                  + cacheAtStartup + ", directory = '" + directory + "'"
              );
          }
      }
  
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message