001    package org.apache.myfaces.tobago.taglib.component;
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 static org.apache.myfaces.tobago.TobagoConstants.ATTR_APPLICATION_ICON;
021    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DOCTYPE;
022    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_FOCUS_ID;
023    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_HEIGHT;
024    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
025    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_METHOD;
026    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_STATE;
027    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH;
028    import org.apache.myfaces.tobago.component.ComponentUtil;
029    import org.apache.myfaces.tobago.component.UIPage;
030    import org.apache.myfaces.tobago.component.UIPopup;
031    
032    import javax.faces.component.UIComponent;
033    import javax.servlet.jsp.JspException;
034    import javax.servlet.jsp.tagext.BodyTag;
035    import java.util.List;
036    
037    // Some Weblogic versions need explicit 'implements' for BodyTag
038    public class PageTag extends TobagoBodyTag
039        implements BodyTag, PageTagDeclaration {
040    
041      private String doctype = "loose";
042    
043      // TODO move to renderkit
044      private String method = "POST";
045    
046      private String state;
047    
048      private String focusId;
049    
050      private String label;
051    
052      private String width;
053    
054      private String height;
055    
056      private String applicationIcon;
057    
058      public int doEndTag() throws JspException {
059        UIPage page = (UIPage) getComponentInstance();
060        List<UIPopup> popups = page.getPopups();
061        int result = super.doEndTag();
062    
063        // clear popups;
064        popups.clear();
065    
066        // reseting doctype and charset
067        doctype = "loose";
068        //charset = null;
069        return result;
070      }
071    
072      public String getComponentType() {
073        return UIPage.COMPONENT_TYPE;
074      }
075    
076      public void release() {
077        super.release();
078        doctype = "loose";
079        method = "POST";
080        state = null;
081        focusId = null;
082        label = null;
083        width = null;
084        height = null;
085        applicationIcon = null;
086      }
087    
088      protected void setProperties(UIComponent component) {
089        super.setProperties(component);
090        ComponentUtil.setStringProperty(component, ATTR_METHOD, method);
091        ComponentUtil.setStringProperty(component, ATTR_DOCTYPE, doctype);
092        ComponentUtil.setStringProperty(component, ATTR_FOCUS_ID, focusId);
093        ComponentUtil.setStringProperty(component, ATTR_LABEL, label);
094        ComponentUtil.setValueBinding(component, ATTR_STATE, state);
095        ComponentUtil.setIntegerSizeProperty(component, ATTR_WIDTH, width);
096        ComponentUtil.setIntegerSizeProperty(component, ATTR_HEIGHT, height);
097        ComponentUtil.setStringProperty(component, ATTR_APPLICATION_ICON, applicationIcon);
098      }
099    
100      public void setDoctype(String doctype) {
101        this.doctype = doctype;
102      }
103    
104      public void setMethod(String method) {
105        this.method = method;
106      }
107    
108      public void setState(String state) {
109        this.state = state;
110      }
111    
112      public String getFocusId() {
113        return focusId;
114      }
115    
116      public void setFocusId(String focusId) {
117        this.focusId = focusId;
118      }
119    
120      public String getLabel() {
121        return label;
122      }
123    
124      public void setLabel(String label) {
125        this.label = label;
126      }
127    
128      public String getWidth() {
129        return width;
130      }
131    
132      public void setWidth(String width) {
133        this.width = width;
134      }
135    
136      public String getHeight() {
137        return height;
138      }
139    
140      public void setHeight(String height) {
141        this.height = height;
142      }
143    
144      public void setApplicationIcon(String icon) {
145        applicationIcon = icon;
146      }
147    
148      public String getApplicationIcon() {
149        return applicationIcon;
150      }
151    }
152