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