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

📄 servletincluderesponsewrapper.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        JahiaConsole.println("ResponseWrapper", "Error getting dispatch context [" +                                     appBean.getContext() + "]");                        return super.encodeURL(URL);                    }                    try {                        String path = URL;                        if ( URL.startsWith(appBean.getContext()) ){                            // remove the context                            path = URL.substring(URL.indexOf(appBean.getContext()))                                 .substring(appBean.getContext().length());                        }                        path = dispatchedContext.getRealPath(path);                        File f = new File(path);                        if ( f.isFile() ){                            return super.encodeURL(URL);                        }                    } catch ( Throwable t ){                    }                } catch ( Throwable t){                    JahiaConsole.printe("Exception retrieving Applicatiton Context appid["+appUniqueIDStr+"]\n",t);                    return super.encodeURL(URL);                }            }            boolean fullScreenEngineOn = false;            if (jahiaParams.getEngine().equals(FullScreenDispatcherEngine.ENGINE_NAME)) {                fullScreenEngineOn = true;            }            String realURL = new String(URL);            // first let's check if there are special codes that are            // actually Jahia mode settings.            if (realURL != null) {                if (realURL.startsWith("###JAHIA###")) {                    // we have detected a special URL...                    realURL = realURL.substring(11); // remove the ###JAHIA###                    while (realURL.indexOf("###") >= 0) {                        int seperatorPos = realURL.indexOf("###");                        String jahiaModifier = realURL.substring(0, seperatorPos);                        if (jahiaModifier != null) {                            if ("fullscreen".equals(jahiaModifier.toLowerCase())) {                                fullScreenEngineOn = true;                            }                            if ("restore".equals(jahiaModifier.toLowerCase())) {                                fullScreenEngineOn = false;                            }                        }                        realURL = realURL.substring(seperatorPos + 3);                    }                }            }            String URLPort;            java.net.URL resolvedURL;            if (jahiaParams.getRequest().getServerPort() == 80) {                URLPort = "";            } else {                Integer conv = new Integer(jahiaParams.getRequest().getServerPort());                URLPort = ":" + conv.toString();            }            try {                java.net.URL contextURL = null;                if (URL.startsWith("/")) { // if it starts with a "/" it is relative to the                                          // the context URL                    contextURL = new java.net.URL(jahiaParams.getRequest().getScheme() + "://" +                                                  jahiaParams.getRequest().getServerName() +                                                  URLPort + "/");                } else {                    // no starting "/", relative URL...                    java.net.URL emulURL = new java.net.URL(emulatedURL);                    if ((emulURL.getPort() != 80) && (emulURL.getPort() != -1)) {                        contextURL = new java.net.URL(emulURL.getProtocol() + "://" +                                                      emulURL.getHost() + ":" +                                                      emulURL.getPort() +                                                      emulURL.getPath());                    } else {                        contextURL = new java.net.URL(emulURL.getProtocol() + "://" +                                                      emulURL.getHost() +                                                      emulURL.getPath());                    }                }                JahiaConsole.println("ResponseWrapper", "encodeURL.contextURL=[" + contextURL.toString() + "]");                resolvedURL = new java.net.URL(contextURL, realURL);            } catch (java.net.MalformedURLException mue) {                return null;            }            //logger.debug( "encodeURL.resolvedURL=[" +            //                     resolvedURL.toString() + "]");            ServletIncludeURL = super.encodeURL(resolvedURL.toString()); // let's add Java servlet            // logger.debug( "encodeURL.ServletIncludeURL=[" +            //                     ServletIncludeURL + "]");            ServletIncludeURL = java.net.URLEncoder.encode(ServletIncludeURL);            try {                // Hollis : append app anchor                String anchorID = ServletIncludeResponseWrapper.getFieldIDPart(appUniqueIDStr);                if ( anchorID != null ){                    jahiaParams.setAnchor("field_" + anchorID);                    // logger.debug( "set anchor to " + jahiaParams.getAnchor() );                }                // let's deactivate the cache in these requests since we must                // never cache application requests.                String savedCacheStatus = jahiaParams.getCacheStatus();                jahiaParams.setCacheStatus(ParamBean.CACHE_BYPASS);                String fullScreenStr = "";                String fullScreenIDStr = jahiaParams.getRequest().getParameter("fullscreen");                if (fullScreenIDStr == null) {                    fullScreenIDStr = jahiaParams.getRequest().getParameter("maximize");                }                if (fullScreenIDStr != null) {                       fullScreenStr = "&fullscreen=" + fullScreenIDStr;                }                if (fullScreenEngineOn) {                    // we are using the full screen engine instead of the                    // regular core engine.                    Properties extraParams = new Properties();                    extraParams.setProperty(ParamBean.PAGE_ID_PARAMETER,                            Integer.toString(jahiaParams.getPageID()));                    ServletIncludeURL =                            jahiaParams.composeEngineUrl(                                FullScreenDispatcherEngine.ENGINE_NAME,                                extraParams,                                "?appid=" +                                appUniqueIDStr +                                "&appparams=" +                                ServletIncludeURL +                                "&resetAppSession=true"                            );                } else {                    ServletIncludeURL = jahiaParams.composeUrl(	"?appid=" +                            appUniqueIDStr +                            fullScreenStr +                            "&appparams=" +                            ServletIncludeURL +                            "&resetAppSession=true"                            );                }                jahiaParams.setCacheStatus(savedCacheStatus);            } catch (JahiaException je) {                ServletIncludeURL = null;            }        } else {            if (URL.indexOf(";jsessionid=") != -1) {                JahiaConsole.println("ResponseWrapper", "jsessionid already in URL, ignoring call and returning unmodified URL... ");                ServletIncludeURL = URL;            } else {                ServletIncludeURL = super.encodeURL(URL); // let's add Java servlet            }        }        return ServletIncludeURL;    }    public String encodeUrl(String URL) {        return encodeURL(URL);    }    public void sendRedirect(String location) throws IOException {        JahiaConsole.println("ResponseWrapper", "location=" + location + "");        if (redirectLocation != null) {            JahiaConsole.println("ResponseWrapper", "Multiple calls to sendRedirect, keeping only the first one.");        } else {            if ( location.endsWith("/") ){                redirectLocation = location.substring(0,location.length()-1);            } else {                redirectLocation = location;            }        }        if (isPassThrough) {            JahiaConsole.println("ResponseWrapper", "Pass-through active, sending redirect to wrapped response directly...");            super.sendRedirect(location);        } else {            JahiaConsole.println("ResponseWrapper", "redirectLocation=" + redirectLocation + "");        }    }    public void setContentType(java.lang.String type) {        JahiaConsole.println("ResponseWrapper", "Content-type set to [" + type + "]");        if (forceEncoding != null) {            JahiaConsole.println("ResponseWrapper", "Enforcing charset=[" + forceEncoding + "]");            int separatorPos = type.indexOf(";");            if (separatorPos > 0) {                type = type.substring(0, separatorPos);            }            type += ";charset=" + forceEncoding;        }        this.contentType = type;        int charsetPos = type.toLowerCase().indexOf("charset=");        if (charsetPos > 0) {            encoding = type.toUpperCase().substring(charsetPos + "charset=".length()).trim();        }        super.setContentType(this.contentType);    }    /**     * Returns the stored content type.     * @return a string containing the set contained type, or null if none     * was ever set.     */    public String getContentType() {        return this.contentType;    }    //--------------------------------------------------------------------------    /**     * Return the second id Part ( = the field id ) in the Application ID Str     *     * @param 	appUniqueIDStr Application ID Str     * @return  String The Second ID part or null if not matching     */    public static String getFieldIDPart(String appUniqueIDStr){        if ( appUniqueIDStr == null ){            return null;        }        mRExpFieldID.match(appUniqueIDStr);        return mRExpFieldID.getParen(1);    }    public void addCookie(Cookie cookie) {        JahiaConsole.println("ResponseWrapper", "Adding cookie name=" + cookie.getName() );        super.addCookie(cookie);    }    private void checkStreams() {        if ((strOutputStream == null) && (strPrintWriter == null)) {            try {                // strPrintWriter = new StringPrintWriter(new StringWriter(), outputStringBuffer);                if (isPassThrough) {                    JahiaConsole.println("ResponseWrapper", "Creating output streams for response wrapper using pass-through servlet output stream...");                    strOutputStream = new StringServletOutputStream(super.getResponse().getOutputStream(), encoding);                } else {                    JahiaConsole.println("ResponseWrapper", "Creating output streams for response wrapper using only stringbuffers and no pass-through...");                    strOutputStream = new StringServletOutputStream(encoding);                }                OutputStreamWriter streamWriter;                if (encoding != null) {                    JahiaConsole.println("ResponseWrapper", "Using PrintWriter with encoding : " + encoding);                    streamWriter = new OutputStreamWriter(strOutputStream, encoding);                } else {                    streamWriter = new OutputStreamWriter(strOutputStream);                }                strPrintWriter = new PrintWriter(streamWriter, true);            } catch (Exception e) {                JahiaConsole.printe("Error creating StringPrintWriter object !", e);            }        }    }}

⌨️ 快捷键说明

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