haul        2002/08/11 13:12:00

  Modified:    src/java/org/apache/cocoon/sitemap Tag: cocoon_2_0_3_branch
                        AbstractSitemap.java
  Log:
    <action dev="CH" type="add">
     Backport usage of InputModules to compiled sitemap.
    </action>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.3  +53 -12    
xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java
  
  Index: AbstractSitemap.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/Attic/AbstractSitemap.java,v
  retrieving revision 1.10.2.2
  retrieving revision 1.10.2.3
  diff -u -r1.10.2.2 -r1.10.2.3
  --- AbstractSitemap.java      27 Jun 2002 18:52:01 -0000      1.10.2.2
  +++ AbstractSitemap.java      11 Aug 2002 20:12:00 -0000      1.10.2.3
  @@ -77,6 +77,9 @@
   import org.apache.cocoon.transformation.Transformer;
   import org.apache.cocoon.util.ClassUtils;
   
  +import org.apache.avalon.framework.component.ComponentSelector;
  +import org.apache.cocoon.components.modules.input.InputModule;
  +
   import java.io.IOException;
   import java.io.InputStream;
   import java.lang.reflect.InvocationTargetException;
  @@ -99,6 +102,9 @@
       private static LogKitManager logKitManager;
       private static Configuration defaultConfig;
   
  +    /** Selector for InputModules.*/
  +    private ComponentSelector inputModuleSelector = null;
  +
       /** The component manager instance */
       protected CocoonComponentManager manager;
   
  @@ -193,6 +199,10 @@
               this.manager.addComponentInstance(Action.ROLE + "Selector", 
this.actions);
               this.manager.addComponentInstance(Matcher.ROLE + "Selector", 
this.matchers);
               this.manager.addComponentInstance(Selector.ROLE + "Selector", 
this.selectors);
  +
  +            // obtain selector for InputModules
  +            this.inputModuleSelector = (ComponentSelector) 
this.manager.lookup(InputModule.ROLE +"Selector");
  +
           } catch (Exception e) {
               getLogger().error("cannot obtain the Component", e);
               throw new ComponentException("cannot obtain the URLFactory", e);
  @@ -315,7 +325,9 @@
         * Replaces occurences of xpath like expressions in an argument String
         * with content from a List of Maps
         */
  -    protected String substitute(List list, String expr) throws PatternException, 
NumberFormatException {
  +    protected String substitute(List list, String expr, Environment environment) 
  +        throws PatternException, NumberFormatException {
  +
           if (expr == null) {
               return null;
           }
  @@ -327,6 +339,7 @@
           int m = 0;
           int ii = 0;
           int i = -1;
  +        int n = -1;
           try {
               while (ii <= expr.length() && (i = expr.indexOf('{', ii)) != -1) {
                   result.append(expr.substring(ii, i));
  @@ -335,18 +348,41 @@
                       throw new PatternException("invalid expression in \"" + expr + 
"\"");
                   }
                   ii = j + 1;
  -                k = list.size() - 1;
                   s = expr.substring(i + 1, j);
  -                l = -3;
  -                m = -1;
  -                while ((l = s.indexOf("../", l + 3)) != -1) {
  -                    k--;
  -                    m = l;
  -                }
  -                if (m != -1) {
  -                    s = s.substring(m + 3);
  +                n = s.indexOf(':');
  +                Object value = null;
  +                if (n == -1) { // normal expression
  +                    k = list.size() - 1;
  +                    l = -3;
  +                    m = -1;
  +                    while ((l = s.indexOf("../", l + 3)) != -1) {
  +                        k--;
  +                        m = l;
  +                    }
  +                    if (m != -1) {
  +                        s = s.substring(m + 3);
  +                    }
  +                    value = ((Map)list.get(k)).get(s);
  +                } else { // InputModule expression
  +                    String inputName = s.substring(0,n);
  +                    String inputAttribute = s.substring(n + 1);
  +                    InputModule input = null;
  +                    if (getLogger().isDebugEnabled())
  +                        getLogger().debug("Using "+inputName+" to obtain 
"+inputAttribute);
  +                    try {
  +                        input = (InputModule) 
this.inputModuleSelector.select(inputName);
  +                        if (getLogger().isDebugEnabled())
  +                            getLogger().debug((input!=null?"Got ":"No ")+inputName);
  +                        value = input.getAttribute(inputAttribute, null, 
environment.getObjectModel());
  +                    } catch (Exception e) {
  +                        if (getLogger().isWarnEnabled())
  +                            getLogger().warn("Problem obtaining attribute " + 
inputAttribute 
  +                                             + " from " + inputName + " : " + 
e.getMessage());
  +                    } finally {
  +                        if (input != null) 
  +                            this.inputModuleSelector.release(input);
  +                    }
                   }
  -                Object value = ((Map)list.get(k)).get(s);
                   if (value != null){
                       result.append(value.toString());
                       if (getLogger().isDebugEnabled()) {
  @@ -449,6 +485,11 @@
        * dispose
        */
       public void dispose() {
  +        if (this.inputModuleSelector != null) {
  +            this.manager.release(inputModuleSelector);
  +        }
  +        this.inputModuleSelector = null;
  +
           manager.release(this.urlFactory);
           this.urlFactory = null;
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to