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.component;
021    
022    import org.apache.commons.logging.Log;
023    import org.apache.commons.logging.LogFactory;
024    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_HEIGHT;
025    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_INNER_WIDTH;
026    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_HEIGHT;
027    import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LAYOUT_WIDTH;
028    import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_DEFAULT_LAYOUT;
029    
030    import javax.faces.component.UIComponent;
031    import javax.faces.context.FacesContext;
032    
033    public class UIDefaultLayout extends UILayout {
034      private static final Log LOG = LogFactory.getLog(UIDefaultLayout.class);
035    
036      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.DefaultLayout";
037      public static final String COMPONENT_FAMILY = "org.apache.myfaces.tobago.Layout";
038    
039    
040      private static UIDefaultLayout instance;
041    
042      public static synchronized UIDefaultLayout getInstance() {
043        if (instance == null) {
044          instance = (UIDefaultLayout)
045              ComponentUtil.createComponent(COMPONENT_TYPE, RENDERER_TYPE_DEFAULT_LAYOUT, "UIDefaultLayout");
046        }
047        return instance;
048      }
049    
050      public void layoutBegin(FacesContext facesContext, UIComponent component) {
051        super.layoutBegin(facesContext, component);
052        //TODO why is this needed? 
053        for (Object child : component.getChildren()) {
054          ((UIComponent) child).getAttributes().remove(ATTR_INNER_WIDTH);
055          ((UIComponent) child).getAttributes().remove(ATTR_INNER_HEIGHT);
056          ((UIComponent) child).getAttributes().remove(ATTR_LAYOUT_WIDTH);
057          ((UIComponent) child).getAttributes().remove(ATTR_LAYOUT_HEIGHT);
058        }
059      }
060    
061      public String getFamily() {
062        return COMPONENT_FAMILY;
063      }
064    
065    }