Home » tapestry-src-5.0.19 » org.apache.tapestry5.corelib.components » [javadoc | source]

    1   // Copyright 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.corelib.components;
   16   
   17   import org.apache.tapestry5.MarkupWriter;
   18   import org.apache.tapestry5.annotations.Mixin;
   19   import org.apache.tapestry5.annotations.Parameter;
   20   import org.apache.tapestry5.corelib.mixins.DiscardBody;
   21   
   22   import java.util.regex.Pattern;
   23   
   24   /**
   25    * Outputs paragraph oriented text, typically collected via a {@link org.apache.tapestry5.corelib.components.TextArea}
   26    * component.  The TextArea is split into lines, and each line it output inside its own <p> element.
   27    */
   28   public class TextOutput
   29   {
   30       @Parameter(required = true)
   31       private String value;
   32   
   33       @Mixin
   34       private DiscardBody discardBody;
   35   
   36       private static final Pattern SPLIT_PATTERN = Pattern.compile("((\\r\\n)|\\r|\\n)", Pattern.MULTILINE);
   37   
   38       void beginRender(MarkupWriter writer)
   39       {
   40           if (value == null) return;
   41   
   42           String[] lines = SPLIT_PATTERN.split(value);
   43   
   44           for (String line : lines)
   45           {
   46               writer.element("p");
   47   
   48               writer.write(line.trim());
   49   
   50               writer.end();
   51           }
   52       }
   53   
   54       void injectValue(String value)
   55       {
   56           this.value = value;
   57       }
   58   }

Home » tapestry-src-5.0.19 » org.apache.tapestry5.corelib.components » [javadoc | source]