001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.tag;
016:
017: import java.io.Writer;
018: import java.util.HashMap;
019: import java.util.Map;
020: import javax.servlet.jsp.JspException;
021: import javax.servlet.jsp.PageContext;
022: import org.araneaframework.jsp.tag.basic.AttributedTagInterface;
023:
024: /**
025: * Attributed base tag.
026: *
027: * @author Oleg Mürk
028: */
029: public class PresentationTag extends BaseTag implements
030: AttributedTagInterface {
031: protected String style = null;
032: protected String styleClass = null;
033: protected String baseStyleClass = null;
034:
035: protected Map attributes = new HashMap();
036:
037: protected int doStartTag(Writer out) throws Exception {
038: super .doStartTag(out);
039: addContextEntry(PresentationTag.ATTRIBUTED_TAG_KEY, this );
040: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
041: return EVAL_BODY_INCLUDE;
042: }
043:
044: public void setPageContext(PageContext pageContext) {
045: super .setPageContext(pageContext);
046: }
047:
048: /**
049: * Callback: add attribute.
050: */
051: public void addAttribute(String name, String value)
052: throws JspException {
053: if (value == null)
054: attributes.remove(name);
055: else
056: attributes
057: .put(name, evaluate("value", value, Object.class));
058: }
059:
060: // Styles
061: /**
062: * @jsp.attribute
063: * type = "java.lang.String"
064: * required = "false"
065: * description = "Inline style for HTML tag."
066: */
067: public void setStyle(String style) throws JspException {
068: this .style = (String) evaluate("style", style, String.class);
069: }
070:
071: public String getStyle() throws JspException {
072: return this .style;
073: }
074:
075: /**
076: * @jsp.attribute
077: * type = "java.lang.String"
078: * required = "false"
079: * description = "CSS class for tag"
080: */
081: public void setStyleClass(String styleClass) throws JspException {
082: if (styleClass != null)
083: this .styleClass = (String) evaluate("styleClass",
084: styleClass, String.class);
085: }
086:
087: /**
088: * Callback: get default css class for tag or <code>null</code>.
089: */
090: protected String getStyleClass() throws JspException {
091: return calculateStyleClass(baseStyleClass, styleClass);
092: }
093:
094: /** @since 1.1 */
095: public static final String calculateStyleClass(
096: String baseStyleClass, String styleClass) {
097: StringBuffer result = new StringBuffer();
098: if (baseStyleClass != null) {
099: result.append(baseStyleClass);
100: if (styleClass != null)
101: result.append(" ");
102: }
103: if (styleClass != null) {
104: result.append(styleClass);
105: }
106:
107: return result.length() == 0 ? null : result.toString();
108: }
109: }
|