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: */package org.apache.openejb.util;
017:
018: public class HtmlUtilities {
019:
020: public static final String ANCHOR_NAME_TYPE = "name";
021:
022: public static final String ANCHOR_HREF_TYPE = "href";
023:
024: //we don't want anyone creating new instances of this class
025: private HtmlUtilities() {
026: }
027:
028: public static String createAnchor(String value, String display,
029: String type) {
030: //our type must be one of these two
031: if (!(ANCHOR_HREF_TYPE.equals(type) || ANCHOR_NAME_TYPE
032: .equals(type))) {
033: throw new IllegalArgumentException(
034: "The type argument must be either \"name\" or \"href\"");
035: }
036:
037: return new StringBuffer(100).append("<a ").append(type).append(
038: "=\"").append(value).append("\">").append(display)
039: .append("</a>").toString();
040: }
041:
042: public static String createSelectFormField(String name,
043: String onChange) {
044: StringBuffer temp = new StringBuffer(60).append(
045: "<select name=\"").append(name);
046:
047: if (onChange != null) {
048: temp.append("\" onChange=\"").append(onChange);
049: }
050:
051: return temp.append("\">").toString();
052: }
053:
054: public static String createSelectOption(String value,
055: String display, boolean selected) {
056: StringBuffer temp = new StringBuffer(65).append(
057: "<option value=\"").append(value).append("\"");
058:
059: if (selected) {
060: temp.append(" selected");
061: }
062:
063: return temp.append(">").append(display).append("</option>")
064: .toString();
065: }
066:
067: public static String createTextFormField(String name, String value,
068: int size, int maxLength) {
069: return createInputFormField("text", name, value, size,
070: maxLength, null, null, null, null, false, false, false);
071: }
072:
073: public static String createFileFormField(String name, String value,
074: int size) {
075: return createInputFormField("file", name, value, size, 0, null,
076: null, null, null, false, false, false);
077: }
078:
079: public static String createHiddenFormField(String name, String value) {
080: return createInputFormField("hidden", name, value, 0, 0, null,
081: null, null, null, false, false, false);
082: }
083:
084: public static String createSubmitFormButton(String name,
085: String value) {
086: return createInputFormField("submit", name, value, 0, 0, null,
087: null, null, null, false, false, false);
088: }
089:
090: public static String createInputFormField(String type, String name,
091: String value, int size, int maxLength, String onFocus,
092: String onBlur, String onChange, String onClick,
093: boolean checked, boolean disabled, boolean readOnly) {
094:
095: StringBuffer temp = new StringBuffer(150).append(
096: "<input type=\"").append(type).append("\" name=\"")
097: .append(name).append("\" value=\"").append(value)
098: .append("\"");
099:
100: if (size > 0) {
101: temp.append(" size=\"").append(size).append("\"");
102: }
103: if (maxLength > 0) {
104: temp.append(" maxlength=\"").append(maxLength).append("\"");
105: }
106: if (onFocus != null) {
107: temp.append(" onfocus=\"").append(onFocus).append("\"");
108: }
109: if (onBlur != null) {
110: temp.append(" onblur=\"").append(onBlur).append("\"");
111: }
112: if (onChange != null) {
113: temp.append(" onchange=\"").append(onChange).append("\"");
114: }
115: if (onClick != null) {
116: temp.append(" onclick=\"").append(onClick).append("\"");
117: }
118: if (checked) {
119: temp.append(" checked");
120: }
121: if (disabled) {
122: temp.append(" disabled");
123: }
124: if (readOnly) {
125: temp.append(" readonly");
126: }
127:
128: return temp.append(">").toString();
129: }
130:
131: public static String createTextArea(String name, String content,
132: int rows, int columns, String onFocus, String onBlur,
133: String onChange) {
134: StringBuffer temp = new StringBuffer(50);
135: temp.append("<textarea name=\"").append(name).append(
136: "\" rows=\"").append(rows).append("\" cols=\"").append(
137: columns).append("\"");
138:
139: if (onFocus != null) {
140: temp.append(" onfocus=\"").append(onFocus).append("\"");
141: }
142: if (onBlur != null) {
143: temp.append(" onblur=\"").append(onBlur).append("\"");
144: }
145: if (onChange != null) {
146: temp.append(" onchange=\"").append(onChange).append("\"");
147: }
148:
149: return temp.append(">").append(content).append("</textarea>")
150: .toString();
151: }
152: }
|