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.layout;
016:
017: import java.io.Writer;
018: import java.util.List;
019: import javax.servlet.jsp.JspException;
020: import org.apache.commons.collections.ResettableIterator;
021: import org.apache.commons.collections.iterators.LoopingIterator;
022: import org.araneaframework.jsp.tag.PresentationTag;
023: import org.araneaframework.jsp.tag.layout.support.CellClassProvider;
024: import org.araneaframework.jsp.tag.layout.support.NullIterator;
025: import org.araneaframework.jsp.tag.layout.support.RowClassProvider;
026: import org.araneaframework.jsp.util.JspUtil;
027:
028: /**
029: * Layout row base tag.
030: * @author Taimo Peelo (taimo@araneaframework.org)
031: */
032: public abstract class BaseLayoutRowTag extends PresentationTag
033: implements CellClassProvider {
034: protected boolean overrideLayout = true;
035:
036: /**
037: * HTML id of the row.
038: * @since 1.1 */
039: protected String id;
040:
041: protected List cellClasses;
042: private ResettableIterator cellIter;
043:
044: protected int doStartTag(Writer out) throws Exception {
045: super .doStartTag(out);
046:
047: cellIter = cellClasses != null ? (ResettableIterator) new LoopingIterator(
048: cellClasses)
049: : new NullIterator();
050: if (cellClasses != null)
051: addContextEntry(CellClassProvider.KEY, this );
052:
053: return EVAL_BODY_INCLUDE;
054: }
055:
056: public String getCellClass() throws JspException {
057: return cellIter.hasNext() ? (String) cellIter.next() : null;
058: }
059:
060: public String getStyleClass() throws JspException {
061: cellIter.reset();
062: RowClassProvider rowClassProvider = (RowClassProvider) getContextEntry(RowClassProvider.KEY);
063: String result = rowClassProvider != null ? rowClassProvider
064: .getRowClass() : null;
065: result = (result != null && result.length() == 0) ? null
066: : result;
067:
068: String super StyleClass = super .getStyleClass();
069: if (super StyleClass != null) {
070: StringBuffer sb = new StringBuffer(super StyleClass);
071: if (!overrideLayout && result != null)
072: sb.append(' ').append(result);
073:
074: result = sb.toString();
075: }
076:
077: return result;
078: }
079:
080: /* ***********************************************************************************
081: * Tag attributes
082: * ***********************************************************************************/
083:
084: /**
085: * @jsp.attribute
086: * type = "java.lang.String"
087: * required = "false"
088: * description = "Default styleclass of cells inside this row. This is multi-valued attribute and overwrites cell styleclasses defined by surrounding layout."
089: */
090: public void setCellClasses(String cellClasses) throws JspException {
091: this .cellClasses = JspUtil
092: .parseMultiValuedAttribute((String) evaluate(
093: "cellClasses", cellClasses, String.class));
094: }
095:
096: /**
097: * @jsp.attribute
098: * type = "java.lang.String"
099: * required = "false"
100: * description = "Whether row's styleClass completely overrides styleClass provided by surrounding layout (default behaviour), or is appended to layout's styleClass."
101: */
102: public void setOverrideLayout(String overrideLayout)
103: throws JspException {
104: this .overrideLayout = ((Boolean) evaluate("overrideLayout",
105: overrideLayout, Boolean.class)).booleanValue();
106: }
107:
108: /**
109: * @jsp.attribute
110: * type = "java.lang.String"
111: * required = "false"
112: * description = "HTML id of this row."
113: * @since 1.1
114: */
115: public void setId(String id) throws JspException {
116: this .id = (String) evaluate("id", id, String.class);
117: }
118: }
|