View Javadoc

    1   /*
    2    * Copyright 2002,2004 The Apache Software Foundation.
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  package org.apache.commons.jelly.impl;
    17
    18  import java.util.List;
    19
    20  import org.apache.commons.jelly.Script;
    21
    22
    23  /***
    24   * <p><code>CompositeTextScriptBlock</code> represents a text body of a
    25   * a tag which contains expressions, so that whitespace trimming
    26   * can be handled differently.</p>
    27   *
    28   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    29   * @version $Revision: 155420 $
    30   */
    31  public class CompositeTextScriptBlock extends ScriptBlock {
    32
    33      /***
    34       * Create an instance.
    35       */
    36      public CompositeTextScriptBlock() {
    37      }
    38
    39
    40      /***
    41       * Trim the body of the script.
    42       * In this case, trim the whitespace from the start of the first element
    43       * and from the end of the last element.
    44       */
    45      public void trimWhitespace() {
    46          List list = getScriptList();
    47          int size = list.size();
    48          if ( size > 0 ) {
    49              Script script = (Script) list.get(0);
    50              if ( script instanceof TextScript ) {
    51                  TextScript textScript = (TextScript) script;
    52                  textScript.trimStartWhitespace();
    53              }
    54              if ( size > 1 ) {
    55                  script = (Script) list.get(size - 1);
    56                  if ( script instanceof TextScript ) {
    57                      TextScript textScript = (TextScript) script;
    58                      textScript.trimEndWhitespace();
    59                  }
    60              }
    61          }
    62      }
    63
    64
    65  }