001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.html.form;
018
019import org.apache.wicket.markup.ComponentTag;
020import org.apache.wicket.markup.MarkupStream;
021import org.apache.wicket.model.IModel;
022
023/**
024 * Multi-row text editing component.
025 * 
026 * @author Jonathan Locke
027 * 
028 * @param <T>
029 *            The model object type
030 */
031public class TextArea<T> extends AbstractTextComponent<T>
032{
033        private static final long serialVersionUID = 1L;
034
035        /**
036         * @see org.apache.wicket.Component#Component(String)
037         */
038        public TextArea(final String id)
039        {
040                super(id);
041        }
042
043        /**
044         * @param id
045         * @param model
046         * @see org.apache.wicket.Component#Component(String, IModel)
047         */
048        public TextArea(final String id, final IModel<T> model)
049        {
050                super(id, model);
051        }
052
053        /**
054         * Handle the container's body.
055         * 
056         * @param markupStream
057         *            The markup stream
058         * @param openTag
059         *            The open tag for the body
060         * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
061         */
062        @Override
063        public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
064        {
065                checkComponentTag(openTag, "textarea");
066
067                String value = getValue();
068                if (value != null)
069                {
070                        if (value.startsWith("\n"))
071                        {
072                                value = "\n" + value;
073                        }
074                        else if (value.startsWith("\r\n"))
075                        {
076                                value = "\r\n" + value;
077                        }
078                        else if (value.startsWith("\r"))
079                        {
080                                value = "\r" + value;
081                        }
082                }
083                replaceComponentTagBody(markupStream, openTag, value);
084        }
085}