joerg       2003/06/19 16:19:58

  Modified:    
src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation
                        SessionPostTransformer.java
  Log:
  replaced deprecated StringBufferInputStream with ByteArrayInputStream,
  removed "== true" in boolean tests,
  code formatting
  
  Revision  Changes    Path
  1.4       +98 -120   
cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPostTransformer.java
  
  Index: SessionPostTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/session-fw/java/org/apache/cocoon/webapps/session/transformation/SessionPostTransformer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionPostTransformer.java       16 May 2003 07:19:43 -0000      1.3
  +++ SessionPostTransformer.java       19 Jun 2003 23:19:58 -0000      1.4
  @@ -50,8 +50,8 @@
   */
   package org.apache.cocoon.webapps.session.transformation;
   
  +import java.io.ByteArrayInputStream;
   import java.io.IOException;
  -import java.io.StringBufferInputStream;
   import java.util.Map;
   
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -78,14 +78,13 @@
    * destroying. Thus it should be the last transformer (before the xsl) in
    * the pipeline.
    * For performance and simplicity reasons this transformer inherits from
  - * the SessionPreTransformer, although this is not needed (But then the
  - * implementation of the SessionTransformer would be very unperformant.
  + * the SessionPreTransformer, although this is not needed (but then the
  + * implementation of the SessionTransformer would be very unperformant).
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Id$
  -*/
  -public class SessionPostTransformer
  -extends SessionPreTransformer {
  + */
  +public class SessionPostTransformer extends SessionPreTransformer {
   
       public static final String DELETECONTEXT_ELEMENT = "deletecontext";
       public static final String DELETECONTEXT_NAME_ATTRIBUTE = "name";
  @@ -132,9 +131,9 @@
       public static final String FORM_VALIDATESET_ELEMENT = "validate-set";
   
       /** State: no element parsed */
  -    private static final int STATE_OUTSIDE   = 0;
  +    private static final int STATE_OUTSIDE = 0;
       /** State: form element */
  -    private static final int STATE_FORM      = 1;
  +    private static final int STATE_FORM = 1;
   
       /** The current state */
       private int state;
  @@ -145,8 +144,7 @@
       /** The validation results */
       private Map validationResultMap;
   
  -    public void setupTransforming()
  -    throws ProcessingException, SAXException, IOException {
  +    public void setupTransforming() throws ProcessingException, SAXException, 
IOException {
           super.setupTransforming();
           this.state = STATE_OUTSIDE;
           this.formName = null;
  @@ -158,42 +156,39 @@
        * The event is checked for a valid element and the corresponding command
        * is executed.
        */
  -    public void startTransformingElement(String uri,
  -                                         String name,
  -                                         String raw,
  -                                         Attributes attr)
  -    throws ProcessingException, IOException, SAXException {
  -        if (this.getLogger().isDebugEnabled() == true) {
  -            this.getLogger().debug("BEGIN startTransformingElement uri=" + uri +
  -                                   ", name=" + name + ", raw=" + raw + ", attr=" + 
attr);
  +    public void startTransformingElement(String uri, String name, String raw, 
Attributes attr)
  +            throws ProcessingException, IOException, SAXException {
  +        if (this.getLogger().isDebugEnabled()) {
  +            this.getLogger().debug("BEGIN startTransformingElement uri=" + uri + ", 
name=" + name
  +                                                              + ", raw=" + raw + ", 
attr=" + attr);
           }
  -        if (name.equals(DELETECONTEXT_ELEMENT) == true) {
  +        if (name.equals(DELETECONTEXT_ELEMENT)) {
               
this.getContextManager().deleteContext(attr.getValue(DELETECONTEXT_NAME_ATTRIBUTE));
   
  -        } else if (name.equals(SETXML_ELEMENT) == true) {
  +        } else if (name.equals(SETXML_ELEMENT)) {
               this.startRecording();
               stack.push(attr.getValue(SETXML_CONTEXT_ATTRIBUTE));
               stack.push(attr.getValue(SETXML_PATH_ATTRIBUTE));
   
  -        // Element: mergexml
  -        } else if (name.equals(MERGEXML_ELEMENT) == true) {
  +            // Element: mergexml
  +        } else if (name.equals(MERGEXML_ELEMENT)) {
               this.startRecording();
               stack.push(attr.getValue(MERGEXML_CONTEXT_ATTRIBUTE));
               stack.push(attr.getValue(MERGEXML_PATH_ATTRIBUTE));
   
  -        // Element: appendxml
  -        } else if (name.equals(APPENDXML_ELEMENT) == true) {
  +            // Element: appendxml
  +        } else if (name.equals(APPENDXML_ELEMENT)) {
               this.startRecording();
               stack.push(attr.getValue(APPENDXML_CONTEXT_ATTRIBUTE));
               stack.push(attr.getValue(APPENDXML_PATH_ATTRIBUTE));
   
  -        // Element: removexml
  -        } else if (name.equals(REMOVEXML_ELEMENT) == true) {
  +            // Element: removexml
  +        } else if (name.equals(REMOVEXML_ELEMENT)) {
               this.startTextRecording();
               stack.push(attr.getValue(REMOVEXML_CONTEXT_ATTRIBUTE));
               stack.push(attr.getValue(REMOVEXML_PATH_ATTRIBUTE));
   
  -        } else if (name.equals(SAVECONTEXT_ELEMENT) == true) {
  +        } else if (name.equals(SAVECONTEXT_ELEMENT)) {
               this.startParametersRecording();
               stack.push(attr.getValue(SAVECONTEXT_CONTEXT_ATTRIBUTE));
               if (attr.getValue(SAVECONTEXT_PATH_ATTRIBUTE) != null) {
  @@ -202,8 +197,8 @@
                   stack.push("/");
               }
   
  -        // Element: inputxml
  -        } else if (name.equals(INPUTXML_ELEMENT) == true) {
  +            // Element: inputxml
  +        } else if (name.equals(INPUTXML_ELEMENT)) {
               stack.push(attr.getValue(INPUTXML_CONTEXT_ATTRIBUTE));
               String fieldname = attr.getValue(INPUTXML_NAME_ATTRIBUTE);
               stack.push(fieldname);
  @@ -212,27 +207,22 @@
               AttributesImpl newattr = new AttributesImpl();
               newattr.addAttribute("", INPUTXML_NAME_ATTRIBUTE, 
INPUTXML_NAME_ATTRIBUTE, "CDATA", fieldname);
               if (attr.getValue(INPUTXML_TYPE_ATTRIBUTE) != null) {
  -                newattr.addAttribute("",
  -                                     INPUTXML_TYPE_ATTRIBUTE,
  -                                     INPUTXML_TYPE_ATTRIBUTE,
  -                                     "CDATA", 
attr.getValue(INPUTXML_TYPE_ATTRIBUTE));
  +                newattr.addAttribute("", INPUTXML_TYPE_ATTRIBUTE, 
INPUTXML_TYPE_ATTRIBUTE, "CDATA",
  +                                     attr.getValue(INPUTXML_TYPE_ATTRIBUTE));
               }
   
               ValidatorActionResult validationResult = null;
               if (validationResultMap != null && validationResultMap.get(fieldname) 
!= null) {
                   validationResult = 
(ValidatorActionResult)validationResultMap.get(fieldname);
  -                newattr.addAttribute("",
  -                                     INPUTXML_VALIDATIONRESULT_ATTRIBUTE,
  -                                     INPUTXML_VALIDATIONRESULT_ATTRIBUTE,
  -                                     "CDATA", validationResult.toString());
  +                newattr.addAttribute("", INPUTXML_VALIDATIONRESULT_ATTRIBUTE,
  +                                     INPUTXML_VALIDATIONRESULT_ATTRIBUTE,"CDATA", 
validationResult.toString());
               }
   
               super.startTransformingElement("", name, name, newattr); // remove 
namespace
               this.startRecording();
   
  -        // Element form
  -        } else if (name.equals(FORM_ELEMENT) == true
  -                   && this.state == STATE_OUTSIDE) {
  +            // Element form
  +        } else if (name.equals(FORM_ELEMENT) && this.state == STATE_OUTSIDE) {
               String formName = attr.getValue("name");
               if (formName == null) {
                   throw new ProcessingException("The name attribute of the form 
element is required.");
  @@ -241,21 +231,18 @@
               this.state = STATE_FORM;
               this.stack.push(new AttributesImpl(attr));
   
  -        // Element form action
  -        } else if (name.equals(FORM_ACTION_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form action
  +        } else if (name.equals(FORM_ACTION_ELEMENT) && this.state == STATE_FORM) {
               this.startTextRecording();
   
  -        // Element form content
  -        } else if (name.equals(FORM_CONTENT_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form content
  +        } else if (name.equals(FORM_CONTENT_ELEMENT) && this.state == STATE_FORM) {
               // get validation results to be used for inputxml elements
  -            validationResultMap = (Map)this.getSessionManager().getSession(true).
  -                            getAttribute(this.formName + "validation-result");
  +            validationResultMap = (Map)this.getSessionManager().getSession(true)
  +                                                 .getAttribute(this.formName + 
"validation-result");
   
  -        // Element form validation rules
  -        } else if (name.equals(FORM_VALIDATION_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form validation rules
  +        } else if (name.equals(FORM_VALIDATION_ELEMENT) && this.state == 
STATE_FORM) {
               this.startRecording();
               if (attr.getValue(FORM_VALIDATION_SOURCE_ATTRIBUTE) != null) {
                   stack.push(attr.getValue(FORM_VALIDATION_SOURCE_ATTRIBUTE));
  @@ -266,63 +253,58 @@
           } else {
               super.startTransformingElement(uri, name, raw, attr);
           }
  -        if (this.getLogger().isDebugEnabled() == true) {
  +        if (this.getLogger().isDebugEnabled()) {
               this.getLogger().debug("END startTransformingElement");
           }
       }
   
  -    public void endTransformingElement(String uri,
  -                                       String name,
  -                                       String raw)
  -    throws ProcessingException ,IOException, SAXException {
  -        if (this.getLogger().isDebugEnabled() == true) {
  +    public void endTransformingElement(String uri, String name, String raw)
  +            throws ProcessingException, IOException, SAXException {
  +        if (this.getLogger().isDebugEnabled()) {
               this.getLogger().debug("BEGIN endTransformingElement uri=" + uri + ", 
name=" + name + ", raw=" + raw);
           }
  -        if (name.equals(DELETECONTEXT_ELEMENT) == true) {
  +        if (name.equals(DELETECONTEXT_ELEMENT)) {
               // do nothing, the context was destroyed on the startElement event
   
               // Element: setxml
  -        } else if (name.equals(SETXML_ELEMENT) == true) {
  -            String path        = (String)stack.pop();
  +        } else if (name.equals(SETXML_ELEMENT)) {
  +            String path = (String)stack.pop();
               String contextName = (String)stack.pop();
               this.getSessionManager().setContextFragment(contextName, path, 
this.endRecording());
   
  -        // Element: mergexml
  -        } else if (name.equals(MERGEXML_ELEMENT) == true) {
  -            String path        = (String)stack.pop();
  +            // Element: mergexml
  +        } else if (name.equals(MERGEXML_ELEMENT)) {
  +            String path = (String)stack.pop();
               String contextName = (String)stack.pop();
               this.getSessionManager().mergeContextFragment(contextName, path, 
this.endRecording());
   
  -        // Element: appendxml
  -        } else if (name.equals(APPENDXML_ELEMENT) == true) {
  -            String path        = (String)stack.pop();
  +            // Element: appendxml
  +        } else if (name.equals(APPENDXML_ELEMENT)) {
  +            String path = (String)stack.pop();
               String contextName = (String)stack.pop();
               this.getSessionManager().appendContextFragment(contextName, path, 
this.endRecording());
   
  -        // Element: removexml
  -        } else if (name.equals(REMOVEXML_ELEMENT) == true) {
  -            String path        = (String)stack.pop();
  +            // Element: removexml
  +        } else if (name.equals(REMOVEXML_ELEMENT)) {
  +            String path = (String)stack.pop();
               String contextName = (String)stack.pop();
               // result is ignored
               endTextRecording();
               this.getSessionManager().removeContextFragment(contextName, path);
   
  -        // Element: savexml
  -        } else if (name.equals(SAVECONTEXT_ELEMENT) == true) {
  -            String path        = (String)stack.pop();
  +            // Element: savexml
  +        } else if (name.equals(SAVECONTEXT_ELEMENT)) {
  +            String path = (String)stack.pop();
               String contextName = (String)stack.pop();
               SourceParameters pars = 
this.endParametersRecording((SourceParameters)null);
               pars.setSingleParameterValue("contextname", contextName);
               pars.setSingleParameterValue("path", path);
   
  -            this.getContextManager().getContext(contextName).saveXML(path,
  -                                                                     pars,
  -                                                                     
this.objectModel,
  -                                                                     this.resolver,
  -                                                                     this.manager);
  +            this.getContextManager().getContext(contextName).saveXML(path, pars, 
this.objectModel,
  +                                                                     this.resolver, 
this.manager);
   
  -        // Element: inputxml
  -        } else if (name.equals(INPUTXML_ELEMENT) == true) {
  +            // Element: inputxml
  +        } else if (name.equals(INPUTXML_ELEMENT)) {
               String path = (String)this.stack.pop();
               String fieldname = (String)this.stack.pop();
               String contextname = (String)this.stack.pop();
  @@ -331,40 +313,40 @@
               if (this.formName == null) {
                   throw new ProcessingException("The inputxml must be contained 
inside a form.");
               }
  -            DocumentFragment value = 
this.getFormManager().registerInputField(contextname, path, fieldname, formName);
  -            if (value == null) value = defaultFragment;
  +            DocumentFragment value = 
this.getFormManager().registerInputField(contextname, path,
  +                                                                              
fieldname, formName);
  +            if (value == null) {
  +                value = defaultFragment;
  +            }
               this.sendEvents(value);
               super.endTransformingElement("", name, name);
   
  -        // Element form
  -        } else if (name.equals(FORM_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form
  +        } else if (name.equals(FORM_ELEMENT) && this.state == STATE_FORM) {
               this.state = ((Integer)this.stack.pop()).intValue();
               this.sendEndElementEvent("form");
               this.formName = null;
   
  -        // Element form action
  -        } else if (name.equals(FORM_ACTION_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form action
  +        } else if (name.equals(FORM_ACTION_ELEMENT) && this.state == STATE_FORM) {
               String action = this.endTextRecording();
               AttributesImpl a = (AttributesImpl)this.stack.pop();
               this.formName = a.getValue("name");
               boolean hasPars = (action.indexOf("?") != -1);
  -            action = this.response.encodeURL(action + (hasPars ? '&' : '?') + 
SessionConstants.SESSION_FORM_PARAMETER+'='+this.formName);
  +            action = this.response.encodeURL(action + (hasPars ? '&' : '?')
  +                                             + 
SessionConstants.SESSION_FORM_PARAMETER + '=' + this.formName);
               a.addAttribute("", "action", "action", "CDATA", action);
               if (a.getValue("method") == null) {
                   a.addAttribute("", "method", "method", "CDATA", "POST");
               }
               this.sendStartElementEvent("form", a);
   
  -        // Element form content
  -        } else if (name.equals(FORM_CONTENT_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form content
  +        } else if (name.equals(FORM_CONTENT_ELEMENT) && this.state == STATE_FORM) {
               // ignore this
   
  -        // Element form validation rules
  -        } else if (name.equals(FORM_VALIDATION_ELEMENT) == true
  -                   && this.state == STATE_FORM) {
  +            // Element form validation rules
  +        } else if (name.equals(FORM_VALIDATION_ELEMENT) && this.state == 
STATE_FORM) {
               if (this.formName == null) {
                   throw new ProcessingException("The validate element must be 
contained inside a form.");
               }
  @@ -373,38 +355,36 @@
               if (!source.equals("EMPTY")) {
                   // get configuration from external file
                   // referenced by "src" attribute of "validate" element
  -
  -                Configuration conf = null;
  -                Session session = null;
                   try {
                       Source resource = this.resolver.resolveURI(source);
                       SAXConfigurationHandler saxBuilder = new 
SAXConfigurationHandler();
                       SourceUtil.parse(this.manager, resource, saxBuilder);
   
  -                    conf = saxBuilder.getConfiguration();
  -                    session = this.getSessionManager().getSession(true);
  +                    Configuration conf = saxBuilder.getConfiguration();
  +                    Session session = this.getSessionManager().getSession(true);
                       session.setAttribute(this.formName, conf);
  -                    
  +
                       if (validationDoc != null) {
                           //validationDoc contains "validate-set" element
                           validationDoc.normalize();
                           Node validationNode = validationDoc.getFirstChild();
                           while (validationNode.getNodeType() != Node.ELEMENT_NODE) {
                               validationNode = validationNode.getNextSibling();
  -                            if (validationNode == null) break;
  +                            if (validationNode == null) {
  +                                break;
  +                            }
                           }
  -                        if (validationNode != null &&
  -                            validationNode.getNodeType() == Node.ELEMENT_NODE &&
  -                            
validationNode.getNodeName().equals(FORM_VALIDATESET_ELEMENT)) {
  +                        if (validationNode != null && validationNode.getNodeType() 
== Node.ELEMENT_NODE
  +                                && 
validationNode.getNodeName().equals(FORM_VALIDATESET_ELEMENT)) {
                               String validationXML = 
XMLUtils.serializeNodeToXML(validationNode);
                               DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
  -                            conf = builder.build(new 
StringBufferInputStream(validationXML));
  -                            session.setAttribute(this.formName+"validate-set", 
conf);
  +                            conf = builder.build(new 
ByteArrayInputStream(validationXML.getBytes()));
  +                            session.setAttribute(this.formName + "validate-set", 
conf);
                           }
                       }
  -                    
  +
                   } catch (SourceException se) {
  -                    throw new ProcessingException("Cannot resolve"+source, se);
  +                    throw new ProcessingException("Cannot resolve" + source, se);
                   } catch (ConfigurationException ce) {
                       throw new ProcessingException("Error building Configuration out 
of validate-set element", ce);
                   }
  @@ -416,21 +396,19 @@
                       Node validationNode = validationDoc.getFirstChild();
                       while (validationNode.getNodeType() != Node.ELEMENT_NODE) {
                           validationNode = validationNode.getNextSibling();
  -                        if (validationNode == null) break;
  +                        if (validationNode == null) {
  +                            break;
  +                        }
                       }
  -                    if (validationNode != null &&
  -                        validationNode.getNodeType() == Node.ELEMENT_NODE &&
  -                        validationNode.getNodeName().equals("root")) {
  -
  +                    if (validationNode != null && validationNode.getNodeType() == 
Node.ELEMENT_NODE
  +                            && validationNode.getNodeName().equals("root")) {
                           String validationXML = 
XMLUtils.serializeNodeToXML(validationNode);
                           DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
  -                        Configuration conf = null;
  -                        Session session = null;
  -                        conf = builder.build(new 
StringBufferInputStream(validationXML));
  -                        session = this.getSessionManager().getSession(true);
  +                        Configuration conf = builder.build(new 
ByteArrayInputStream(validationXML.getBytes()));
  +                        Session session = this.getSessionManager().getSession(true);
                           session.setAttribute(this.formName, conf);
                           //the constraint-set to validate is the first and single one
  -                        session.setAttribute(this.formName+"validate-set", 
conf.getChildren ("constraint-set")[0]);
  +                        session.setAttribute(this.formName + "validate-set", 
conf.getChildren("constraint-set")[0]);
   
                       }
                   } catch (ConfigurationException ce) {
  @@ -441,7 +419,7 @@
           } else {
               super.endTransformingElement(uri, name, raw);
           }
  -        if (this.getLogger().isDebugEnabled() == true) {
  +        if (this.getLogger().isDebugEnabled()) {
               this.getLogger().debug("END endTransformingElement");
           }
       }
  
  
  

Reply via email to