001    package org.apache.myfaces.tobago.taglib.extension;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.apt.annotation.Tag;
021    import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
022    import org.apache.myfaces.tobago.taglib.component.GridLayoutTag;
023    import org.apache.myfaces.tobago.taglib.component.LabelTag;
024    import org.apache.myfaces.tobago.taglib.component.PanelTag;
025    import org.apache.myfaces.tobago.taglib.decl.HasTip;
026    import org.apache.myfaces.tobago.taglib.decl.HasValue;
027    import static org.apache.myfaces.tobago.TobagoConstants.FACET_LAYOUT;
028    
029    import javax.faces.webapp.FacetTag;
030    import javax.servlet.jsp.JspException;
031    import javax.servlet.jsp.tagext.BodyTagSupport;
032    
033    @Tag(name = "label")
034    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.LabelTag")
035    public class LabelExtensionTag extends BodyTagSupport
036        implements HasValue, HasTip {
037    
038      private String value;
039      private String tip;
040      private String rendered;
041      private String columns = "fixed;*";
042    
043      private PanelTag panelTag;
044    
045      @Override
046      public int doStartTag() throws JspException {
047    
048        panelTag = new PanelTag();
049        panelTag.setPageContext(pageContext);
050        panelTag.setParent(getParent());
051        if (rendered != null) {
052          panelTag.setRendered(rendered);
053        }
054        panelTag.doStartTag();
055    
056        FacetTag facetTag = new FacetTag();
057        facetTag.setPageContext(pageContext);
058        facetTag.setName(FACET_LAYOUT);
059        facetTag.setParent(panelTag);
060        facetTag.doStartTag();
061    
062        GridLayoutTag gridLayoutTag = new GridLayoutTag();
063        gridLayoutTag.setPageContext(pageContext);
064        gridLayoutTag.setColumns(columns);
065        gridLayoutTag.setParent(facetTag);
066        gridLayoutTag.doStartTag();
067        gridLayoutTag.doEndTag();
068    
069        facetTag.doEndTag();
070    
071        LabelTag labelTag = new LabelTag();
072        labelTag.setPageContext(pageContext);
073        if (value != null) {
074          labelTag.setValue(value);
075        }
076        if (tip != null) {
077          labelTag.setTip(tip);
078        }
079        labelTag.setFor("@auto");
080        labelTag.setParent(panelTag);
081        labelTag.doStartTag();
082        labelTag.doEndTag();
083    
084        return super.doStartTag();
085      }
086    
087      @Override
088      public int doEndTag() throws JspException {
089        panelTag.doEndTag();
090        return super.doEndTag();
091      }
092    
093      @Override
094      public void release() {
095        super.release();
096        value = null;
097        tip = null;
098        rendered = null;
099        columns = "fixed;*";
100        panelTag = null;
101      }
102    
103      public void setValue(String value) {
104        this.value = value;
105      }
106    
107      public void setTip(String tip) {
108        this.tip = tip;
109      }
110    
111      public void setRendered(String rendered) {
112        this.rendered = rendered;
113      }
114    
115      void setColumns(String columns) {
116        this.columns = columns;
117      }
118    }