forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: xml-forrest/src/java/org/apache/cocoon/components/modules/input LocationMapModule.java
Date Wed, 25 Feb 2004 15:59:00 GMT
unico       2004/02/25 07:59:00

  Modified:    src/java/org/apache/cocoon/components/modules/input/lm
                        AbstractNode.java SelectNode.java LocationMap.java
                        LocatorNode.java MatchNode.java LocationNode.java
               src/java/org/apache/cocoon/components/modules/input
                        LocationMapModule.java
  Log:
  some minor improvements to robustness, documentation enhancements and better logging
  
  Revision  Changes    Path
  1.3       +1 -1      xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/AbstractNode.java
  
  Index: AbstractNode.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/AbstractNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractNode.java	22 Oct 2003 16:56:05 -0000	1.2
  +++ AbstractNode.java	25 Feb 2004 15:58:59 -0000	1.3
  @@ -94,7 +94,7 @@
        * <code>null</code> if the configuration contained no parameters.
        * @throws ConfigurationException
        */
  -    protected final Map getParameters(final Configuration configuration) 
  +    private final Map getParameters(final Configuration configuration) 
           throws ConfigurationException {
           
           final Configuration[] children = configuration.getChildren("parameter");
  
  
  
  1.2       +1 -2      xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/SelectNode.java
  
  Index: SelectNode.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/SelectNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SelectNode.java	21 Oct 2003 08:33:36 -0000	1.1
  +++ SelectNode.java	25 Feb 2004 15:59:00 -0000	1.2
  @@ -65,7 +65,7 @@
   
   
   /**
  - * LocationMap node representing a Selector.
  + * Locationmap select statement.
    * 
    * @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
    */
  @@ -131,7 +131,6 @@
           }
           m_nodes = (AbstractNode[]) nodes.toArray(new AbstractNode[nodes.size()]);
       }
  -    
       
       public String locate(Map om, InvokeContext context) throws Exception {
           
  
  
  
  1.4       +71 -36    xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocationMap.java
  
  Index: LocationMap.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocationMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocationMap.java	22 Oct 2003 17:41:12 -0000	1.3
  +++ LocationMap.java	25 Feb 2004 15:59:00 -0000	1.4
  @@ -94,9 +94,9 @@
       
       /** 
        * The locationmap namespace: 
  -     * <code>http://apache.org/cocoon/locationmap/1.0</code>
  +     * <code>http://apache.org/forrest/locationmap/1.0</code>
        */
  -    public static final String URI = "http://apache.org/cocoon/locationmap/1.0";
  +    public static final String URI = "http://apache.org/forrest/locationmap/1.0";
       
       /**
        * Name of the special anchor map passed into the VariableContext.
  @@ -106,7 +106,7 @@
        * inside the locationmap definition.
        * </p>
        * <p>
  -     * Special locationmap parameters are available thru this anchor map.
  +     * Special locationmap parameters are available through this anchor map.
        * For instance the hint parameter defined below can be accessed in 
        * the locationmap definition as follows: <code>{#lm:hint}</code>
        * </p>
  @@ -130,7 +130,8 @@
        */
       public static final String HINT_PARAM = "#" + ANCHOR_NAME + ":" + HINT_KEY;
       
  -    
  +    // Component manager containing the locationmap components
  +    // as declared in the components section.
       private LocationMapComponentManager m_manager;
       
       // default matcher as configured in the components section
  @@ -142,49 +143,58 @@
       // the list of LocatorNodes
       private LocatorNode[] m_locatorNodes;
       
  +    
       public LocationMap(ComponentManager manager) {
           m_manager = new LocationMapComponentManager(manager);
       }
       
  +    /**
  +     * Build the LocationMap by creating the components and recursively building
  +     * the LocatorNodes.
  +     */
       public void build(final Configuration configuration) throws ConfigurationException
{
           
           // components
           final Configuration components = configuration.getChild("components");
           
           // matchers
  -        final DefaultComponentSelector matcherSelector = new DefaultComponentSelector();
  -        Configuration child = components.getChild("matchers",true);
  -        m_defaultMatcher = child.getAttribute("default");
  -        final Configuration[] matchers = child.getChildren("matcher");
  -        for (int i = 0; i < matchers.length; i++) {
  -            String name = matchers[i].getAttribute("name");
  -            String src  = matchers[i].getAttribute("src");
  -            Matcher matcher = (Matcher) createComponent(src,matchers[i]);
  -            matcherSelector.put(name,matcher);
  -        }
  -        matcherSelector.makeReadOnly();
  -        if (!matcherSelector.hasComponent(m_defaultMatcher)) {
  -            throw new ConfigurationException("Default matcher is not defined.");
  +        Configuration child = components.getChild("matchers",false);
  +        if (child != null) {
  +            final DefaultComponentSelector matcherSelector = new DefaultComponentSelector();
  +            m_defaultMatcher = child.getAttribute("default");
  +            final Configuration[] matchers = child.getChildren("matcher");
  +            for (int i = 0; i < matchers.length; i++) {
  +                String name = matchers[i].getAttribute("name");
  +                String src  = matchers[i].getAttribute("src");
  +                Matcher matcher = (Matcher) createComponent(src,matchers[i]);
  +                matcherSelector.put(name,matcher);
  +            }
  +            matcherSelector.makeReadOnly();
  +            if (!matcherSelector.hasComponent(m_defaultMatcher)) {
  +                throw new ConfigurationException("Default matcher is not defined.");
  +            }
  +            m_manager.put(Matcher.ROLE+"Selector",matcherSelector);
           }
  -        m_manager.put(Matcher.ROLE+"Selector",matcherSelector);
           
           // selectors
  -        final DefaultComponentSelector selectorSelector = new DefaultComponentSelector();
  -        child = components.getChild("selectors");
  -        m_defaultSelector = child.getAttribute("default");
  -        final Configuration[] selectors = child.getChildren("selector");
  -        for (int i = 0; i < selectors.length; i++) {
  -            String name = selectors[i].getAttribute("name");
  -            String src  = selectors[i].getAttribute("src");
  -            Selector selector = (Selector) createComponent(src,selectors[i]);
  -            selectorSelector.put(name,selector);
  -        }
  -        selectorSelector.makeReadOnly();
  -        if (!selectorSelector.hasComponent(m_defaultSelector)) {
  -            throw new ConfigurationException("Default selector is not defined.");
  +        child = components.getChild("selectors",false);
  +        if (child != null) {
  +            final DefaultComponentSelector selectorSelector = new DefaultComponentSelector();
  +            m_defaultSelector = child.getAttribute("default");
  +            final Configuration[] selectors = child.getChildren("selector");
  +            for (int i = 0; i < selectors.length; i++) {
  +                String name = selectors[i].getAttribute("name");
  +                String src  = selectors[i].getAttribute("src");
  +                Selector selector = (Selector) createComponent(src,selectors[i]);
  +                selectorSelector.put(name,selector);
  +            }
  +            selectorSelector.makeReadOnly();
  +            if (!selectorSelector.hasComponent(m_defaultSelector)) {
  +                throw new ConfigurationException("Default selector is not defined.");
  +            }
  +            m_manager.put(Selector.ROLE+"Selector",selectorSelector);
  +            m_manager.makeReadOnly();
           }
  -        m_manager.put(Selector.ROLE+"Selector",selectorSelector);
  -        m_manager.makeReadOnly();
           
           // locators
           final Configuration[] children = configuration.getChildren("locator");
  @@ -196,6 +206,15 @@
           }
       }
       
  +    /**
  +     * Creates a LocationMap component.
  +     * <p>
  +     *  supported component creation lifecycles that are:
  +     *  - LogEnabled
  +     *  - Configurable
  +     *  - Initializable
  +     * </p>
  +     */
       private Object createComponent(String src, Configuration config) throws ConfigurationException
{
           Object component = null;
           try {
  @@ -221,6 +240,11 @@
           m_locatorNodes = null;
       }
       
  +    /**
  +     * Loop through the list of locator nodes invoking
  +     * the <code>locate()</code> method on each and return
  +     * the first non-null result.
  +     */
       public String locate(String hint, Map om) throws Exception {
           
           String location = null;
  @@ -241,21 +265,33 @@
               }
           }
           
  -        //context.popMap();
  -        //context.reset();
           context.dispose();
           
  +        if (getLogger().isDebugEnabled() && location == null) {
  +            getLogger().debug("No location matched request with hint " + hint);
  +        }
  +        
           return location;
       }
       
  +    /**
  +     * Expose the default Matcher to LocatorNodes
  +     */
       String getDefaultMatcher() {
           return m_defaultMatcher;
       }
       
  +    /**
  +     * Expose the default Selector to LocatorNodes
  +     */
       String getDefaultSelector() {
           return m_defaultSelector;
       }
       
  +    /**
  +     * Overide DefaultComponentManager to access the list of all
  +     * components.
  +     */
       private static class LocationMapComponentManager extends DefaultComponentManager {
           
           LocationMapComponentManager(ComponentManager parent) {
  @@ -265,6 +301,5 @@
           Iterator getComponents() {
               return super.getComponentMap().values().iterator();
           }
  -        
       }
   }
  
  
  
  1.4       +17 -2     xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocatorNode.java
  
  Index: LocatorNode.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocatorNode.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocatorNode.java	11 Dec 2003 05:14:51 -0000	1.3
  +++ LocatorNode.java	25 Feb 2004 15:59:00 -0000	1.4
  @@ -65,7 +65,17 @@
   
   
   /**
  - * LocationMap node for containing a set <code>MatchNode</code>s.
  + * Top level locate statement containing 
  + * <code>MatchNode</code>s and <code>SelectNode</code>s.
  + * 
  + * <p>
  + * A locator defines a common location context for its
  + * contained location statements. Location strings resolved within
  + * the context of a given locator will be prefixed with the
  + * locator's base location. This base location is specified
  + * using the <code>base</code> attribute on the <code>&lt;locator&gt;</code>
  + * element and defaults to <code>.</code>.
  + * </p>
    * 
    * @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
    */
  @@ -77,7 +87,7 @@
       // location base resolver
       private VariableResolver m_baseLocation;
       
  -    // the contained MatchNodes
  +    // the contained Match- and SelectNodes
       private AbstractNode[] m_nodes;
       
       public LocatorNode(final LocationMap lm, final ComponentManager manager) {
  @@ -115,6 +125,11 @@
           m_nodes = (AbstractNode[]) nodes.toArray(new AbstractNode[nodes.size()]);
       }
       
  +    /**
  +     * Loop over the list of match and select nodes and call their
  +     * respective <code>locate()</code> methods returning the first
  +     * non-null result.
  +     */
       public String locate(Map om, InvokeContext context) throws Exception {
           
           // resolve the base location and put it in the anchor map
  
  
  
  1.2       +17 -2     xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/MatchNode.java
  
  Index: MatchNode.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/MatchNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MatchNode.java	21 Oct 2003 08:33:36 -0000	1.1
  +++ MatchNode.java	25 Feb 2004 15:59:00 -0000	1.2
  @@ -64,7 +64,22 @@
   import org.apache.cocoon.matching.Matcher;
   
   /**
  - * LocationMap node representing a Matcher.
  + * Locationmap match statement.
  + * 
  + * <p>
  + * The &lt;match&gt; element has one required <code>pattern</code>
attribute
  + * which identifies the pattern the associated Matcher should match
  + * against and one optional <code>type</code> attribute that identifies
  + * the Matcher that is to do the matching.
  + * </p>
  + * 
  + * Match statements can contain <code>&lt;match&gt;</code>,
  + * <code>&lt;select&gt;</code> and <code>&lt;location&gt;</code>
  + * child statements.
  + * 
  + * <p>
  + * Match nodes can be parametrized using <code>&lt;parameter&gt;</code>
child elements.
  + * </p>
    * 
    * @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
    */
  @@ -143,7 +158,7 @@
           Map substitutions = m_matcher.match(m_pattern,om,parameters);
           if (substitutions != null) {
               if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("matched " + m_pattern);
  +                getLogger().debug("matched: " + m_pattern);
               }
               context.pushMap(null,substitutions);
               for (int i = 0; i < m_nodes.length; i++) {
  
  
  
  1.4       +10 -2     xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocationNode.java
  
  Index: LocationNode.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/lm/LocationNode.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LocationNode.java	11 Dec 2003 05:14:51 -0000	1.3
  +++ LocationNode.java	25 Feb 2004 15:59:00 -0000	1.4
  @@ -62,7 +62,13 @@
   import org.apache.excalibur.source.SourceUtil;
   
   /**
  - * LocationMap node representing a location.
  + * locationmap leaf statement identifying a location.
  + * 
  + * <p>
  + *  The <code>&lt;location&gt;</code> element has one
  + *  required attribute <code>src</code> that contains the
  + *  location string.
  + * </p>
    * 
    * @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
    */
  @@ -89,6 +95,9 @@
   
       }
       
  +    /**
  +     * Resolve the location string against the InvokeContext.
  +     */
       public String locate(Map om, InvokeContext context) throws Exception {
           
           String src = m_src.resolve(context,om);
  @@ -104,7 +113,6 @@
           }
           
           return src;
  -        
       }
   
   }
  
  
  
  1.3       +12 -1     xml-forrest/src/java/org/apache/cocoon/components/modules/input/LocationMapModule.java
  
  Index: LocationMapModule.java
  ===================================================================
  RCS file: /home/cvs/xml-forrest/src/java/org/apache/cocoon/components/modules/input/LocationMapModule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LocationMapModule.java	22 Oct 2003 16:52:34 -0000	1.2
  +++ LocationMapModule.java	25 Feb 2004 15:59:00 -0000	1.3
  @@ -90,6 +90,11 @@
       private SourceValidity m_srcVal;
       private LocationMap m_lm;
       
  +    // ---------------------------------------------------- lifecycle
  +    
  +    public LocationMapModule() {
  +    }
  +    
       public void compose(ComponentManager manager) throws ComponentException {
           m_manager = manager;
           m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
  @@ -173,6 +178,12 @@
           return configuration;
       }
       
  +    // ---------------------------------------------------- Module implementation
  +    
  +    /**
  +     * Execute the current request against the locationmap returning the
  +     * resulting string.
  +     */
       public Object getAttribute(
           final String name,
           final Configuration modeConf,
  @@ -193,7 +204,7 @@
       
       /**
        * The possibilities are endless. No way to enumerate them all.
  -     * Therefore returns an empty Iterator.
  +     * Therefore returns null.
        */
       public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
           throws ConfigurationException {
  
  
  

Mime
View raw message