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.taglib.decl.HasIdBindingAndRendered;
021    import org.apache.myfaces.tobago.taglib.decl.HasLabel;
022    import org.apache.myfaces.tobago.taglib.component.SeparatorTag;
023    import org.apache.myfaces.tobago.taglib.component.LabelTag;
024    import org.apache.myfaces.tobago.apt.annotation.Tag;
025    import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
026    
027    import javax.servlet.jsp.tagext.BodyTagSupport;
028    import javax.servlet.jsp.JspException;
029    import javax.faces.webapp.FacetTag;
030    
031    /**
032     * Renders a separator.
033     * <br />
034     * Short syntax of:
035     * <p/>
036     * <pre>
037     * &lt;tc:separator>
038     *   &lt;f:facet name="label">
039     *     &lt;tc:label value="label"/>
040     *   &lt;/f:facet>
041     * &lt;/tc:separator>
042     * </pre>
043     */
044    
045    @Tag(name = "separator")
046    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.SeparatorTag")
047    public class SeparatorExtensionTag extends BodyTagSupport implements HasIdBindingAndRendered, HasLabel {
048      private String binding;
049      private String rendered;
050      private String label;
051    
052      private SeparatorTag separatorTag;
053      private FacetTag facetTag;
054      private LabelTag labelTag;
055    
056      @Override
057      public int doStartTag() throws JspException {
058        separatorTag = new SeparatorTag();
059        separatorTag.setPageContext(pageContext);
060        separatorTag.setParent(getParent());
061        if (binding != null) {
062          separatorTag.setBinding(binding);
063        }
064        if (rendered != null) {
065          separatorTag.setRendered(rendered);
066        }
067        facetTag = new FacetTag();
068        facetTag.setPageContext(pageContext);
069        facetTag.setParent(separatorTag);
070        facetTag.setName(org.apache.myfaces.tobago.TobagoConstants.FACET_LABEL);
071    
072        facetTag.doStartTag();
073        labelTag = new LabelTag();
074        labelTag.setPageContext(pageContext);
075        labelTag.setParent(facetTag);
076        if (label != null) {
077          labelTag.setValue(label);
078        }
079        labelTag.doStartTag();
080        return super.doStartTag();
081      }
082    
083      @Override
084      public int doEndTag() throws JspException {
085        labelTag.doEndTag();
086        facetTag.doEndTag();
087        separatorTag.doEndTag();
088        return super.doEndTag();
089      }
090    
091      @Override
092      public void release() {
093        super.release();
094        binding = null;
095        rendered = null;
096        label = null;
097        separatorTag = null;
098        facetTag = null;
099        labelTag = null;
100      }
101    
102      public void setBinding(String binding) throws JspException {
103        this.binding = binding;
104      }
105    
106      public void setRendered(String rendered) {
107        this.rendered = rendered;
108      }
109    
110      public void setLabel(String label) {
111        this.label = label;
112      }
113    }