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

📄 jspviewhandlerimpl.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {        if (path.length() > 0 && path.charAt(0) == '/')        {            return facesContext.getExternalContext().getRequestContextPath() + path;        }        else        {            return path;        }    }    public void renderView(FacesContext facesContext, UIViewRoot viewToRender)            throws IOException, FacesException    {        if (viewToRender == null)        {            log.fatal("viewToRender must not be null");            throw new NullPointerException("viewToRender must not be null");        }        ExternalContext externalContext = facesContext.getExternalContext();        String viewId = facesContext.getViewRoot().getViewId();        if (PortletUtil.isPortletRequest(facesContext)) {            externalContext.dispatch(viewId);            return;        }                ServletMapping servletMapping = getServletMapping(externalContext);        if (servletMapping.isExtensionMapping())        {            String defaultSuffix = externalContext.getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);            String suffix = defaultSuffix != null ? defaultSuffix : ViewHandler.DEFAULT_SUFFIX;            DebugUtils.assertError(suffix.charAt(0) == '.',                                   log, "Default suffix must start with a dot!");            if (!viewId.endsWith(suffix))            {                int dot = viewId.lastIndexOf('.');                if (dot == -1)                {                    if (log.isTraceEnabled()) log.trace("Current viewId has no extension, appending default suffix " + suffix);                    viewId = viewId + suffix;                }                else                {                    if (log.isTraceEnabled()) log.trace("Replacing extension of current viewId by suffix " + suffix);                    viewId = viewId.substring(0, dot) + suffix;                }                facesContext.getViewRoot().setViewId(viewId);            }        }        if (log.isTraceEnabled()) log.trace("Dispatching to " + viewId);        // handle character encoding as of section 2.5.2.2 of JSF 1.1        if (externalContext.getResponse() instanceof ServletResponse) {            ServletResponse response = (ServletResponse) externalContext.getResponse();            response.setLocale(viewToRender.getLocale());        }                // TODO: 2.5.2.2 for Portlet?  What do I do?        externalContext.dispatch(viewId);        // handle character encoding as of section 2.5.2.2 of JSF 1.1        if (externalContext.getRequest() instanceof HttpServletRequest) {            HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();            HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();            HttpSession session = request.getSession(false);            if (session != null) {                session.setAttribute(ViewHandler.CHARACTER_ENCODING_KEY, response.getCharacterEncoding());            }        }    }    public UIViewRoot restoreView(FacesContext facesContext, String viewId)    {        Application application = facesContext.getApplication();        ViewHandler applicationViewHandler = application.getViewHandler();        String renderKitId = applicationViewHandler.calculateRenderKitId(facesContext);        UIViewRoot viewRoot = application.getStateManager().restoreView(facesContext,                                                                        viewId,                                                                        renderKitId);        return viewRoot;    }    /**     * Writes a state marker that is replaced later by one or more hidden form     * inputs.     * @param facesContext     * @throws IOException     */    public void writeState(FacesContext facesContext) throws IOException    {        if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))        {            facesContext.getResponseWriter().write(FORM_STATE_MARKER);        }    }    protected String getViewIdPath(FacesContext facescontext, String viewId)    {        if (viewId == null)        {            log.error("ViewId must not be null");            throw new NullPointerException("ViewId must not be null");        }        if (!viewId.startsWith("/"))        {            log.error("ViewId must start with '/' (viewId = " + viewId + ")");            throw new IllegalArgumentException("ViewId must start with '/' (viewId = " + viewId + ")");        }        if (PortletUtil.isPortletRequest(facescontext))         {            return viewId;        }                ServletMapping servletMapping = getServletMapping(facescontext.getExternalContext());        if (servletMapping.isExtensionMapping())        {            // extension mapping            String urlpattern = servletMapping.getUrlPattern();            if (urlpattern.startsWith("*"))            {                urlpattern = urlpattern.substring(1, urlpattern.length());            }            if (viewId.endsWith(urlpattern))            {                return viewId;            }            else            {                int idx = viewId.lastIndexOf(".");                if (idx >= 0)                {                    return viewId.substring(0, idx) + urlpattern;                }                else                {                    return viewId + urlpattern;                }            }        }        else        {            // prefix mapping            String urlpattern = servletMapping.getUrlPattern();            if (urlpattern.endsWith("/*"))            {                urlpattern = urlpattern.substring(0, urlpattern.length() - 2);            }            return urlpattern + viewId;        }    }    private static ServletMapping getServletMapping(ExternalContext externalContext)    {        String servletPath = externalContext.getRequestServletPath();        String requestPathInfo = externalContext.getRequestPathInfo();        WebXml webxml = WebXml.getWebXml(externalContext);        List mappings = webxml.getFacesServletMappings();        boolean isExtensionMapping = (requestPathInfo == null);        for (int i = 0, size = mappings.size(); i < size; i++)        {            ServletMapping servletMapping = (ServletMapping) mappings.get(i);            if (servletMapping.isExtensionMapping() == isExtensionMapping)            {                String urlpattern = servletMapping.getUrlPattern();                if (isExtensionMapping)                {                    String extension = urlpattern.substring(1, urlpattern.length());                    if (servletPath.endsWith(extension))                    {                        return servletMapping;                    }                }                else                {                    urlpattern = urlpattern.substring(0, urlpattern.length() - 2);                    // servletPath starts with "/" except in the case where the                    // request is matched with the "/*" pattern, in which case                    // it is the empty string (see Servlet Sepc 2.3 SRV4.4)                    if (servletPath.equals(urlpattern))                    {                        return servletMapping;                    }                }            }        }        // handle cases as best possible where servletPath is not a faces servlet,         // such as when coming through struts-faces        if (mappings.size() > 0) {            return (ServletMapping) mappings.get(0);        }        else {            log.error("no faces servlet mappings found");            throw new IllegalArgumentException("could not find pathMapping for servletPath = " + servletPath +                      " requestPathInfo = " + requestPathInfo);        }    }}

⌨️ 快捷键说明

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