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