cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation WoodyPipelineConfig.java WidgetReplacingPipe.java EffectWidgetReplacingPipe.java
Date Mon, 29 Dec 2003 15:37:28 GMT
mpo         2003/12/29 07:37:28

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/transformation
                        WoodyPipelineConfig.java WidgetReplacingPipe.java
                        EffectWidgetReplacingPipe.java
  Log:
  Hiding the jxpathContext inside the pipeline-config.
  More reuse of the code accross Woody-pipeline-components.
  (similar work TBD on the Locale)
  PR:
  Obtained from:
  Submitted by:	
  Reviewed by:	
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +140 -21   cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WoodyPipelineConfig.java
  
  Index: WoodyPipelineConfig.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WoodyPipelineConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WoodyPipelineConfig.java	23 Dec 2003 08:46:17 -0000	1.1
  +++ WoodyPipelineConfig.java	29 Dec 2003 15:37:28 -0000	1.2
  @@ -50,6 +50,8 @@
   */
   package org.apache.cocoon.woody.transformation;
   
  +import java.io.IOException;
  +import java.io.StringReader;
   import java.util.Locale;
   import java.util.Map;
   
  @@ -61,9 +63,11 @@
   import org.apache.cocoon.environment.Session;
   import org.apache.cocoon.i18n.I18nUtils;
   import org.apache.cocoon.woody.formmodel.Form;
  +import org.apache.cocoon.xml.AttributesImpl;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.Variables;
  +import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   
   /**
  @@ -96,16 +100,39 @@
        * The locale currently used by the transformer. */
       private Locale locale;
   
  +    /**
  +     * Value for the action attribute of the form.
  +     */
  +    private String formAction;
  +
  +    /**
  +     * Value for the method attribute of the form.
  +     */
  +    private String formMethod;
  +
  +
   
       
  -    private WoodyPipelineConfig(String attName, Request req, JXPathContext jxpc, Locale
localeParam) {
  +    private WoodyPipelineConfig(JXPathContext jxpc, Request req, Locale localeParam, 
  +            String attName, String actionExpression, String method) {
           this.attributeName = attName;
           this.request = req;
           this.jxpathContext =jxpc;
           this.localeParameter = localeParam;
  +        this.formAction = translateText(actionExpression);
  +        this.formMethod = method;
       }
       
      
  +    /**
  +     * Creates and initializes a WoodyPipelineConfig object based on the passed
  +     * arguments of the setup() of the specific Pipeline-component.
  +     * 
  +     * @param objectModel the objectmodel as passed in the setup()
  +     * @param parameters the parameters as passed in the setup()
  +     * @return an instance of WoodyPipelineConfig initialized according to the 
  +     * settings in the sitemap.
  +     */
       public static WoodyPipelineConfig createConfig(Map objectModel, Parameters parameters)
{
           // create and set the jxpathContext...
           Object flowContext = FlowHelper.getContextObject(objectModel);
  @@ -119,15 +146,21 @@
           vars.declareVariable("session", session);
           vars.declareVariable("parameters", parameters);
           
  -        String attributeName = parameters.getParameter("attribute-name", null);
  -        
           Locale localeParameter = null;
           String localeStr = parameters.getParameter("locale", null);
           if (localeStr != null) {
               localeParameter = I18nUtils.parseLocale(localeStr);
           }
  +
  +        String attributeName = parameters.getParameter("attribute-name", null);
  +        String actionExpression = parameters.getParameter("form-action", null);
  +        String formMethod = parameters.getParameter("form-method", "POST");
  +        //TODO (20031223 mpo)think about adding form-encoding for the Generator.
  +        // Note generator will also need some text to go on the submit-button? 
  +        // Alternative to adding more here is to apply xinclude ?
           
  -        return new WoodyPipelineConfig(attributeName, request, jxpc, localeParameter);
  +        return new WoodyPipelineConfig(jxpc, request, localeParameter, 
  +                attributeName, actionExpression, formMethod);
       }
       
       
  @@ -193,26 +226,76 @@
           }
       }
   
  -    public JXPathContext getJXPathContext() {
  -        return jxpathContext;
  -    }
  -
  -    public String getAttributeName() {
  -        return attributeName;
  -    }
  -
  -    public Request getRequest() {
  -        return request;
  -    }
  -
  -    public JXPathContext getJxpathContext() {
  -        return jxpathContext;
  +    /**
  +     * Replaces JXPath expressions embedded inside #{ and } by their value.
  +     * This will parse the passed String looking for #{} occurances and then
  +     * uses the {@see #evaluateExpression(String)} to evaluate the found expression.
  +     * 
  +     * @return the original String with it's #{}-parts replaced by the evaulated results.
  +     */
  +    public String translateText(String original) {
  +        if (original==null) {
  +            return null;
  +        }
  +        
  +        StringBuffer expression;
  +        StringBuffer translated = new StringBuffer();
  +        StringReader in = new StringReader(original);
  +        int chr;
  +        try {
  +            while ((chr = in.read()) != -1) {
  +                char c = (char) chr;
  +                if (c == '#') {
  +                    chr = in.read();
  +                    if (chr != -1) {
  +                        c = (char) chr;
  +                        if (c == '{') {
  +                            expression = new StringBuffer();
  +                            boolean more = true;
  +                            while ( more ) {
  +                                more = false;
  +                                if ((chr = in.read()) != -1) {
  +                                    c = (char)chr;
  +                                    if (c != '}') {
  +                                        expression.append(c);
  +                                        more = true;
  +                                    } else {
  +                                        translated.append(evaluateExpression(expression.toString()).toString());
  +                                    }
  +                                } else {
  +                                    translated.append('#').append('{').append(expression);
  +                                }
  +                            }
  +                        }
  +                    } else {
  +                        translated.append((char) chr);
  +                    }
  +                } else {
  +                    translated.append(c);
  +                }
  +            }
  +        } catch (IOException ignored) {
  +            ignored.printStackTrace();
  +        }
  +        return translated.toString();
       }
   
  -//    public void setJxpathContext(JXPathContext jxpathContext) {
  -//        this.jxpathContext = jxpathContext;
  -//    }
  +    /**
  +     * Evaluates the passed xpath expression using the internal jxpath context 
  +     * holding the declared variables:
  +     * <ol><li>continuation: as made available by flowscript</li>
  +     * <li>request: as present in the cocoon processing environment</li>
  +     * <li>session: as present in the cocoon processing environment</li>
  +     * <li>parameters: as present in the cocoon sitemap node of the pipeline component</li></ol>
  +     * 
  +     * @param expression
  +     * @return the object-value resulting the expression evaluation.
  +     */
  +    public Object evaluateExpression(String expression) {
  +        return this.jxpathContext.getValue(expression);
  +    }    
   
  +    
       public Locale getLocale() {
           return locale;
       }
  @@ -225,6 +308,42 @@
           return localeParameter;
       }
   
  +    /**
  +     * The value for the wi:form-generated/@action. 
  +     * Note: wi:form-template copies this from its wt:form-template counterpart.
  +     *  
  +     * @return the {@see #translateText(String)} result of the 'form-action' sitemap 
  +     * parameter to the pipeline component, or null if that parameter was not set.
  +     */
  +    public String getFormAction() {
  +        return formAction;
  +    }
   
  +    /**
  +     * The value for the wi:form-generated/@method.
  +     * Note: wi:form-template copies this from its wt:form-template counterpart.
  +     * 
  +     * @return the value of the 'form-method' sitemap parameter to the pipeline 
  +     * component. Defaults to 'POST' if it was not set.
  +     */
  +    public String getFormMethod() {
  +        return formMethod;
  +    }
  +    
  +    /**
  +     * The grouped attributes to set on the wi:form-generated element.
  +     * Note: wi:form-template copies this from its wt:form-template counterpart.
  +     * 
  +     * @see #getFormAction()
  +     * @see #getFormMethod()
  +     */
  +    public Attributes getFormAttributes() {
  +        AttributesImpl formAtts = new AttributesImpl();
  +        if (getFormAction() != null) {
  +            formAtts.addCDATAAttribute("action", getFormAction());
  +        }
  +        formAtts.addCDATAAttribute("method", getFormMethod());
  +        return formAtts;
  +    }
   
   }
  
  
  
  1.22      +5 -56     cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java
  
  Index: WidgetReplacingPipe.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- WidgetReplacingPipe.java	29 Dec 2003 06:14:49 -0000	1.21
  +++ WidgetReplacingPipe.java	29 Dec 2003 15:37:28 -0000	1.22
  @@ -50,8 +50,6 @@
   */
   package org.apache.cocoon.woody.transformation;
   
  -import java.io.IOException;
  -import java.io.StringReader;
   import java.util.Locale;
   
   import org.apache.avalon.excalibur.pool.Recyclable;
  @@ -216,14 +214,14 @@
   
                   String localeAttr = attributes.getValue("locale");
                   if (localeAttr != null) { // first use value of locale attribute if any
  -                    localeAttr = translateText(localeAttr);
  +                    localeAttr = pipeContext.translateText(localeAttr);
                       pipeContext.setLocale(I18nUtils.parseLocale(localeAttr));
                   } else if (pipeContext.getLocaleParameter() != null) { // then use locale
specified as transformer parameter, if any
                       pipeContext.setLocale(pipeContext.getLocaleParameter());
                   } else { // use locale specified in bizdata supplied for form
                       Object locale = null;
                       try {
  -                        locale = pipeContext.getJXPathContext().getValue("/locale");
  +                        locale = pipeContext.evaluateExpression("/locale");
                       } catch (JXPathException e) {}
                       if (locale != null) {
                           pipeContext.setLocale((Locale)locale);
  @@ -241,7 +239,7 @@
               } else if (localName.equals(CONTINUATION_ID)){
                   // Insert the continuation id
                   // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel
here.
  -                Object idObj = pipeContext.getJXPathContext().getValue("$continuation/id");
  +                Object idObj = pipeContext.evaluateExpression("$continuation/id");
                   if (idObj == null) {
                       throw new SAXException("No continuation found");
                   }
  @@ -271,62 +269,13 @@
               for (int i = 0; i < names.length; i++) {
                   String name = names[i];
                   int position = newAtts.getIndex(name);
  -                String newValue = translateText(newAtts.getValue(position));
  +                String newValue = pipeContext.translateText(newAtts.getValue(position));
                   newAtts.setValue(position, newValue);                
               }
           }
           return newAtts;
       }
   
  -    /**
  -     * Replaces JXPath expressions embedded inside #{ and } by their value.
  -     */
  -    private String translateText(String original) {
  -        StringBuffer expression;
  -        StringBuffer translated = new StringBuffer();
  -        StringReader in = new StringReader(original);
  -        int chr;
  -        try {
  -            while ((chr = in.read()) != -1) {
  -                char c = (char) chr;
  -                if (c == '#') {
  -                    chr = in.read();
  -                    if (chr != -1) {
  -                        c = (char) chr;
  -                        if (c == '{') {
  -                            expression = new StringBuffer();
  -                            boolean more = true;
  -                            while ( more ) {
  -                                more = false;
  -                                if ((chr = in.read()) != -1) {
  -                                    c = (char)chr;
  -                                    if (c != '}') {
  -                                        expression.append(c);
  -                                        more = true;
  -                                    } else {
  -                                        translated.append(evaluateExpression(expression.toString()));
  -                                    }
  -                                } else {
  -                                    translated.append('#').append('{').append(expression);
  -                                }
  -                            }
  -                        }
  -                    } else {
  -                        translated.append((char) chr);
  -                    }
  -                } else {
  -                    translated.append(c);
  -                }
  -            }
  -        } catch (IOException ignored) {
  -            ignored.printStackTrace();
  -        }
  -        return translated.toString();
  -    }
  -
  -    private String evaluateExpression(String expression) {
  -        return pipeContext.getJXPathContext().getValue(expression).toString();
  -    }
   
       protected Widget getWidget(Attributes attributes) throws SAXException {
           String widgetId = attributes.getValue("id");
  
  
  
  1.2       +58 -57    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/EffectWidgetReplacingPipe.java
  
  Index: EffectWidgetReplacingPipe.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/EffectWidgetReplacingPipe.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EffectWidgetReplacingPipe.java	29 Dec 2003 06:14:49 -0000	1.1
  +++ EffectWidgetReplacingPipe.java	29 Dec 2003 15:37:28 -0000	1.2
  @@ -50,8 +50,6 @@
   */
   package org.apache.cocoon.woody.transformation;
   
  -import java.io.IOException;
  -import java.io.StringReader;
   import java.util.HashMap;
   import java.util.LinkedList;
   import java.util.Locale;
  @@ -64,6 +62,7 @@
   import org.apache.cocoon.woody.formmodel.Struct;
   import org.apache.cocoon.woody.formmodel.Union;
   import org.apache.cocoon.woody.formmodel.Widget;
  +import org.apache.cocoon.woody.transformation.EffectPipe.Handler;
   import org.apache.cocoon.xml.AbstractXMLPipe;
   import org.apache.cocoon.xml.SaxBuffer;
   import org.apache.commons.jxpath.JXPathException;
  @@ -281,14 +280,16 @@
                   //TODO pull this locale stuff also up in the Config object?
                   String localeAttr = input.attrs.getValue("locale");
                   if (localeAttr != null) { // first use value of locale attribute if any
  -                    localeAttr = translateText(localeAttr);
  +                    localeAttr = pipeContext.translateText(localeAttr);
                       pipeContext.setLocale(I18nUtils.parseLocale(localeAttr));
                   } else if (pipeContext.getLocaleParameter() != null) { // then use locale
specified as transformer parameter, if any
                       pipeContext.setLocale(pipeContext.getLocaleParameter());
  -                } else { // use locale specified in bizdata supplied for form
  +                } else { 
  +                    //TODO pull this locale stuff also up in the Config object?
  +                    // use locale specified in bizdata supplied for form
                       Object locale = null;
                       try {
  -                        locale = pipeContext.getJXPathContext().getValue("/locale");
  +                        locale = pipeContext.evaluateExpression("/locale");
                       } catch (JXPathException e) {}
                       if (locale != null) {
                           pipeContext.setLocale((Locale)locale);
  @@ -597,7 +598,7 @@
               case EVENT_START_ELEMENT:
                   // Insert the continuation id
                   // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel
here.
  -                Object idObj = pipeContext.getJXPathContext().getValue("$continuation/id");
  +                Object idObj = pipeContext.evaluateExpression("$continuation/id");
                   if (idObj == null) {
                       throwSAXException("No continuation found");
                   }
  @@ -625,62 +626,62 @@
               for (int i = 0; i < names.length; i++) {
                   String name = names[i];
                   int position = newAtts.getIndex(name);
  -                String newValue = translateText(newAtts.getValue(position));
  +                String newValue = pipeContext.translateText(newAtts.getValue(position));
                   newAtts.setValue(position, newValue);                
               }
           }
           return newAtts;
       }
   
  -    /**
  -     * Replaces JXPath expressions embedded inside #{ and } by their value.
  -     */
  -    private String translateText(String original) {
  -        StringBuffer expression;
  -        StringBuffer translated = new StringBuffer();
  -        StringReader in = new StringReader(original);
  -        int chr;
  -        try {
  -            while ((chr = in.read()) != -1) {
  -                char c = (char) chr;
  -                if (c == '#') {
  -                    chr = in.read();
  -                    if (chr != -1) {
  -                        c = (char) chr;
  -                        if (c == '{') {
  -                            expression = new StringBuffer();
  -                            boolean more = true;
  -                            while ( more ) {
  -                                more = false;
  -                                if ((chr = in.read()) != -1) {
  -                                    c = (char)chr;
  -                                    if (c != '}') {
  -                                        expression.append(c);
  -                                        more = true;
  -                                    } else {
  -                                        translated.append(evaluateExpression(expression.toString()));
  -                                    }
  -                                } else {
  -                                    translated.append('#').append('{').append(expression);
  -                                }
  -                            }
  -                        }
  -                    } else {
  -                        translated.append((char) chr);
  -                    }
  -                } else {
  -                    translated.append(c);
  -                }
  -            }
  -        } catch (IOException ignored) {
  -            ignored.printStackTrace();
  -        }
  -        return translated.toString();
  -    }
  -
  -    private String evaluateExpression(String expression) {
  -        return pipeContext.getJXPathContext().getValue(expression).toString();
  -    }
  +//    /**
  +//     * Replaces JXPath expressions embedded inside #{ and } by their value.
  +//     */
  +//    private String translateText(String original) {
  +//        StringBuffer expression;
  +//        StringBuffer translated = new StringBuffer();
  +//        StringReader in = new StringReader(original);
  +//        int chr;
  +//        try {
  +//            while ((chr = in.read()) != -1) {
  +//                char c = (char) chr;
  +//                if (c == '#') {
  +//                    chr = in.read();
  +//                    if (chr != -1) {
  +//                        c = (char) chr;
  +//                        if (c == '{') {
  +//                            expression = new StringBuffer();
  +//                            boolean more = true;
  +//                            while ( more ) {
  +//                                more = false;
  +//                                if ((chr = in.read()) != -1) {
  +//                                    c = (char)chr;
  +//                                    if (c != '}') {
  +//                                        expression.append(c);
  +//                                        more = true;
  +//                                    } else {
  +//                                        translated.append(evaluateExpression(expression.toString()));
  +//                                    }
  +//                                } else {
  +//                                    translated.append('#').append('{').append(expression);
  +//                                }
  +//                            }
  +//                        }
  +//                    } else {
  +//                        translated.append((char) chr);
  +//                    }
  +//                } else {
  +//                    translated.append(c);
  +//                }
  +//            }
  +//        } catch (IOException ignored) {
  +//            ignored.printStackTrace();
  +//        }
  +//        return translated.toString();
  +//    }
  +
  +//    private String evaluateExpression(String expression) {
  +//        return pipeContext.evaluateExpression(expression).toString();
  +//    }
   
       public void recycle() {
           super.recycle();
  
  
  

Mime
View raw message