You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by ne...@apache.org on 2001/11/02 20:36:18 UTC

cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n DefaultBundleMatcher.java BundleMatcher.java

neeme       01/11/02 11:36:18

  Modified:    src/scratchpad/org/apache/avalon/excalibur/i18n
                        BundleMatcher.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/i18n
                        DefaultBundleMatcher.java
  Log:
  converted bundlematcher into an interface and provided a default implementation instead
  
  Revision  Changes    Path
  1.2       +3 -45     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleMatcher.java
  
  Index: BundleMatcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/BundleMatcher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BundleMatcher.java	2001/10/30 21:38:56	1.1
  +++ BundleMatcher.java	2001/11/02 19:36:17	1.2
  @@ -7,64 +7,22 @@
    */
   package org.apache.avalon.excalibur.i18n;
   
  -import java.util.List;
  -import java.util.LinkedList;
  -
   import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
   
   /**
    * Used to map bundle information to string representation (e.g. URI),
    * to find the relevant bundle.
    *
    * @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/10/30 21:38:56 $ $Author: neeme $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/11/02 19:36:17 $ $Author: neeme $
    */
  -public abstract class BundleMatcher implements Configurable {
  -
  -    private List matchers = new LinkedList();
  -    private String type;
  +public interface BundleMatcher extends Configurable {
   
       /**
        * Get the string form of the bundle, based on bundle info.
        *
        * @return      the string form
  -     */
  -    public abstract boolean match(BundleInfo bundleInfo);
  -
  -    public String getType(BundleInfo bundleInfo) {
  -        if (match(bundleInfo)) {
  -            for (int i = 0; i < matchers.size(); i++) {
  -                String type = ((BundleMatcher) matchers.get(i)).getType(bundleInfo);
  -                if (type != null) return type;
  -            }
  -            return this.type;
  -        }
  -        return null;
  -    }
  -
  -    /**
  -     * Configure the component.
  -     *
  -     * @param configuration the configuration
        */
  -    public void configure(Configuration configuration) throws ConfigurationException {
  -        this.type = configuration.getAttribute("type");
  -        Configuration[] matcherConfs = configuration.getChildren("matcher");
  -        for (int i = 0; i < matcherConfs.length; i++) {
  -            BundleMatcher matcher = getBundleMatcherInstance(configuration.getAttribute("class"));
  -            matcher.configure(matcherConfs[i]);
  -            this.matchers.add(matcher);
  -        }
  -    }
  +    public String getType(BundleInfo bundleInfo);
   
  -    private BundleMatcher getBundleMatcherInstance(String className) throws ConfigurationException {
  -        try {
  -            return (BundleMatcher) Class.forName(className).newInstance();
  -        }
  -        catch (Exception e) {
  -            throw new ConfigurationException("unable to load bundleMatcher", e);
  -        }
  -    }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/i18n/DefaultBundleMatcher.java
  
  Index: DefaultBundleMatcher.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.excalibur.i18n;
  
  import java.util.List;
  import java.util.LinkedList;
  import java.util.Locale;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * Used to map bundle information to string representation (e.g. URI),
   * to find the relevant bundle.
   *
   * @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/02 19:36:17 $ $Author: neeme $
   */
  public class DefaultBundleMatcher implements BundleMatcher {
  
      private List bundleInfos = new LinkedList();
      private String type;
  
      /**
       * Get the string form of the bundle, based on bundle info.
       *
       * @return      the string form
       */
      public String getType(BundleInfo bundleInfo) {
          for (int i = 0; i < bundleInfos.size(); i++) {
              if (((BundleInfo) bundleInfos.get(i)).matches(bundleInfo))
                  return this.type;
          }
          return null;
      }
  
      /**
       * Configure the component.
       *
       * @param configuration the configuration
       */
      public void configure(Configuration configuration) throws ConfigurationException {
          this.type = configuration.getAttribute("type");
          Configuration[] bundleInfos = configuration.getChildren("bundle-info");
          for (int i = 0; i < bundleInfos.length; i++) {
  
              Locale locale = null;
              try {
                  Configuration localeConf = bundleInfos[i].getChild("locale");
                  locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"));
                  locale = new Locale(localeConf.getAttribute("language"), localeConf.getAttribute("country"),
                                      localeConf.getAttribute("variant"));
              }
              catch (ConfigurationException e) {
                  // ignore
              }
  
              String bundleName = null;
              try {
                  bundleName = bundleInfos[i].getAttribute("name");
              }
              catch (ConfigurationException e) {
                  // ignore
              }
  
              String ext = null;
              try {
                  ext = bundleInfos[i].getAttribute("ext");
              }
              catch (ConfigurationException e) {
                  // ignore
              }
              BundleInfo bundleInfo = new BundleInfo(bundleName, locale, ext);
              this.bundleInfos.add(bundleInfo);
          }
      }
  
  }
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>