⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmllayoutrenderer.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.custom.layout;import org.apache.myfaces.renderkit.RendererUtils;import org.apache.myfaces.renderkit.html.HTML;import org.apache.myfaces.renderkit.html.HtmlRenderer;import org.apache.myfaces.renderkit.html.HtmlRendererUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import javax.faces.component.UIComponent;import javax.faces.context.FacesContext;import javax.faces.context.ResponseWriter;import java.io.IOException;/** * @author Manfred Geiler (latest modification by $Author: matze $) * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:57 $ */public class HtmlLayoutRenderer        extends HtmlRenderer{    private static final Log log = LogFactory.getLog(HtmlLayoutRenderer.class);    public static final String CLASSIC_LAYOUT = "classic";    public static final String NAV_RIGHT_LAYOUT = "navigationRight";    public static final String UPSIDE_DOWN_LAYOUT = "upsideDown";    public boolean getRendersChildren()    {        return true;    }    public void encodeBegin(FacesContext context, UIComponent component) throws IOException    {    }    public void encodeChildren(FacesContext context, UIComponent component) throws IOException    {    }    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException    {        RendererUtils.checkParamValidity(facesContext, component, HtmlPanelLayout.class);        HtmlPanelLayout panelLayout = (HtmlPanelLayout)component;        String layout = panelLayout.getLayout();        if (layout == null || layout.equals(CLASSIC_LAYOUT))        {            renderClassic(facesContext, panelLayout);        }        else if (layout.equals(NAV_RIGHT_LAYOUT))        {            renderNavRight(facesContext, panelLayout);        }        else if (layout.equals(UPSIDE_DOWN_LAYOUT))        {            renderUpsideDown(facesContext, panelLayout);        }        else        {            log.error("Unknown panel layout '" + layout + "'!");        }        if (panelLayout.getChildCount() > 0)        {            log.error("PanelLayout must not have children, only facets allowed!");        }    }    protected void renderClassic(FacesContext facesContext, HtmlPanelLayout panelLayout)            throws IOException    {        ResponseWriter writer = facesContext.getResponseWriter();        UIComponent header = panelLayout.getHeader();        UIComponent navigation = panelLayout.getNavigation();        UIComponent body = panelLayout.getBody();        UIComponent footer = panelLayout.getFooter();        writer.startElement(HTML.TABLE_ELEM, null);        HtmlRendererUtils.renderHTMLAttributes(writer, panelLayout, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);        if (header != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, header,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getHeaderClass(),                            panelLayout.getHeaderStyle());            writer.endElement(HTML.TR_ELEM);        }        if (navigation != null || body != null)        {            writer.startElement(HTML.TR_ELEM, null);            if (navigation != null)            {                renderTableCell(facesContext, writer, navigation, 0,                                panelLayout.getNavigationClass(),                                panelLayout.getNavigationStyle());            }            if (body != null)            {                renderTableCell(facesContext, writer, body, 0,                                panelLayout.getBodyClass(),                                panelLayout.getBodyStyle());            }            writer.endElement(HTML.TR_ELEM);        }        if (footer != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, footer,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getFooterClass(),                            panelLayout.getFooterStyle());            writer.endElement(HTML.TR_ELEM);        }        writer.endElement(HTML.TABLE_ELEM);    }    protected void renderNavRight(FacesContext facesContext, HtmlPanelLayout panelLayout)            throws IOException    {        ResponseWriter writer = facesContext.getResponseWriter();        UIComponent header = panelLayout.getHeader();        UIComponent navigation = panelLayout.getNavigation();        UIComponent body = panelLayout.getBody();        UIComponent footer = panelLayout.getFooter();        writer.startElement(HTML.TABLE_ELEM, null);        HtmlRendererUtils.renderHTMLAttributes(writer, panelLayout, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);        if (header != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, header,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getHeaderClass(),                            panelLayout.getHeaderStyle());            writer.endElement(HTML.TR_ELEM);        }        if (navigation != null || body != null)        {            writer.startElement(HTML.TR_ELEM, null);            if (body != null)            {                renderTableCell(facesContext, writer, body, 0,                                panelLayout.getBodyClass(),                                panelLayout.getBodyStyle());            }            if (navigation != null)            {                renderTableCell(facesContext, writer, navigation, 0,                                panelLayout.getNavigationClass(),                                panelLayout.getNavigationStyle());            }            writer.endElement(HTML.TR_ELEM);        }        if (footer != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, footer,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getFooterClass(),                            panelLayout.getFooterStyle());            writer.endElement(HTML.TR_ELEM);        }        writer.endElement(HTML.TABLE_ELEM);    }    protected void renderUpsideDown(FacesContext facesContext, HtmlPanelLayout panelLayout)            throws IOException    {        ResponseWriter writer = facesContext.getResponseWriter();        UIComponent header = panelLayout.getHeader();        UIComponent navigation = panelLayout.getNavigation();        UIComponent body = panelLayout.getBody();        UIComponent footer = panelLayout.getFooter();        writer.startElement(HTML.TABLE_ELEM, null);        HtmlRendererUtils.renderHTMLAttributes(writer, panelLayout, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);        if (footer != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, footer,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getFooterClass(),                            panelLayout.getFooterStyle());            writer.endElement(HTML.TR_ELEM);        }        if (navigation != null || body != null)        {            writer.startElement(HTML.TR_ELEM, null);            if (navigation != null)            {                renderTableCell(facesContext, writer, navigation, 0,                                panelLayout.getNavigationClass(),                                panelLayout.getNavigationStyle());            }            if (body != null)            {                renderTableCell(facesContext, writer, body, 0,                                panelLayout.getBodyClass(),                                panelLayout.getBodyStyle());            }            writer.endElement(HTML.TR_ELEM);        }        if (header != null)        {            writer.startElement(HTML.TR_ELEM, null);            renderTableCell(facesContext, writer, header,                            (navigation != null && body != null) ? 2 : 1,                            panelLayout.getHeaderClass(),                            panelLayout.getHeaderStyle());            writer.endElement(HTML.TR_ELEM);        }        writer.endElement(HTML.TABLE_ELEM);    }    protected void renderTableCell(FacesContext facesContext,                                   ResponseWriter writer,                                   UIComponent component,                                   int colspan,                                   String styleClass,                                   String style)            throws IOException    {        writer.startElement(HTML.TD_ELEM, null);        if (colspan > 0)        {            writer.writeAttribute(HTML.COLSPAN_ATTR, Integer.toString(colspan), null);        }        if (styleClass != null)        {            writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);        }        if (style != null)        {            writer.writeAttribute(HTML.STYLE_ATTR, style, null);        }        RendererUtils.renderChild(facesContext, component);        writer.endElement(HTML.TD_ELEM);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -