01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.jsp.tag.uilib.form.element.text;
16:
17: import java.io.Writer;
18: import java.util.StringTokenizer;
19: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementDisplayTag;
20: import org.araneaframework.jsp.util.JspUtil;
21: import org.araneaframework.uilib.form.control.StringArrayRequestControl;
22:
23: /**
24: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
25: *
26: * @jsp.tag
27: * name = "textareaDisplay"
28: * body-content = "JSP"
29: * description = "Form textarea display field, represents UiLib "TextareaControl"."
30: */
31: public class FormTextareaDisplayHtmlTag extends
32: BaseFormElementDisplayTag {
33: /** @since 1.0.6 */
34: protected boolean escapeSingleSpaces = true;
35:
36: {
37: baseStyleClass = "aranea-textarea-display";
38: }
39:
40: protected int doEndTag(Writer out) throws Exception {
41: StringArrayRequestControl.ViewModel viewModel = ((StringArrayRequestControl.ViewModel) controlViewModel);
42:
43: JspUtil.writeOpenStartTag(out, "span");
44: JspUtil.writeAttribute(out, "class", getStyleClass());
45: JspUtil.writeAttribute(out, "style", getStyle());
46: JspUtil.writeAttributes(out, attributes);
47: JspUtil.writeCloseStartTag(out);
48:
49: if (viewModel.getSimpleValue() != null)
50: for (StringTokenizer lines = new StringTokenizer(viewModel
51: .getSimpleValue(), "\n"); lines.hasMoreTokens();) {
52: String line = lines.nextToken();
53: for (int i = 0; i < line.length(); i++) {
54: if (line.charAt(i) == ' ') {
55: out.write(escapeSingleSpaces ? " " : " ");
56: int spaceCount = 1;
57: while (line.length() > i + spaceCount
58: && line.charAt(i + spaceCount) == ' ') {
59: if ((spaceCount % 2) == 1)
60: out.write(" ");
61: else
62: out.write(" ");
63: spaceCount++;
64: }
65: i = i + spaceCount - 1;
66: } else {
67: JspUtil.writeEscaped(out, line.substring(i,
68: i + 1));
69: }
70: }
71:
72: if (lines.hasMoreTokens())
73: JspUtil.writeStartEndTag(out, "br");
74: }
75:
76: JspUtil.writeEndTag(out, "span");
77:
78: return super .doEndTag(out);
79: }
80:
81: /**
82: * @since 1.0.6
83: *
84: * @jsp.attribute
85: * type = "java.lang.String"
86: * required = "false"
87: * description = "Whether even single spaces (blanks) should be replace with &nbsp; entities in output."
88: */
89: public void setEscapeSingleSpaces(String escapeSingleSpaces)
90: throws Exception {
91: this .escapeSingleSpaces = ((Boolean) evaluate(
92: "escapeSingleSpaces", escapeSingleSpaces, Boolean.class))
93: .booleanValue();
94: }
95: }
|