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

📄 servletincluderequestwrapper.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (user != null) {                if (appRequest == null) {                    JahiaConsole.println("RequestWrapper", "Null application request object, exiting isUserInRole...");                    return false;                }                if (appRequest.getApplicationBean() == null) {                    JahiaConsole.println("RequestWrapper", "Null application bean object, exiting isUserInRole...");                    return false;                }                // Hollis all apps groups roles are a group with siteID=0                JahiaGroup roleGroup = ServicesRegistry.getInstance().getJahiaGroupManagerService().lookupGroup(0,appRequest.getApplicationBean().getID() + "_" + contextIdentifier + "_" + role);                if (roleGroup != null) {                    if (roleGroup.isMember(user) == true) {                        JahiaConsole.println("RequestWrapper", "User [" + user.getUsername() + "] is a member of role [" + roleGroup.getName() + "]");                        return true; // user is indeed member of role (aka group)                    } else {                        JahiaConsole.println("RequestWrapper", "User [" + user.getUsername() + "] is NOT a member of role [" + roleGroup.getName() + "]");                        return false; // user is not member of role (=group)                    }                } else {                    JahiaConsole.println("RequestWrapper", "Role [" +                                 appRequest.getApplicationBean().getID() +                                 "_" + contextIdentifier + "_" + role +                                 "] not found in Jahia's groups!");                    return false; // the role (aka group) does not exist                }            } else {                JahiaConsole.println("RequestWrapper", "No user logged, ignoring call !");                return false;            }        } else {            // default servlet behavior            JahiaConsole.println("RequestWrapper", "Using servlet API standard call...");            return super.isUserInRole(role);        }    }    public void setContextPath(String newPath) {        JahiaConsole.println("RequestWrapper", "setContextPath(" + newPath + ")");    }    public String getContextPath() {        String contextPath = super.getContextPath();        if (emulatedURL != null) {            if ( hasRequestURIChanged() ){                return contextPath;            }        }        JahiaConsole.println("RequestWrapper", "super.getContextPath=[" + contextPath + "]");        JahiaConsole.println("RequestWrapper", "emulatedContextPath = [" + emulatedContextPath + "]");        return emulatedContextPath;    }    /**     * Perform a shallow copy of the specified Map, and return the result.     *     * @param orig Origin Map to be copied     * @return the copy of the original Map     */    Map copyMap(Map orig) {        if (orig == null)            return (new Hashtable());        Hashtable dest = new Hashtable();        synchronized (orig) {            Iterator keys = orig.keySet().iterator();            while (keys.hasNext()) {            String key = (String) keys.next();            dest.put(key, orig.get(key));            }        }        return (dest);    }    /**     * Removes all the attributes specified in the data string for the     * map passed in parameter.     * <p>     * <strong>IMPLEMENTATION NOTE</strong>:  URL decoding is performed     * individually on the parsed name and value elements, rather than on     * the entire query string ahead of time, to properly deal with the case     * where the name or value includes an encoded "=" or "&" character     * that would otherwise be interpreted as a delimiter.     *     * @param map Map that accumulates the resulting parameters     * @param data Input string containing request parameters     * @param urlParameters true if we're parsing parameters on the URL     *     * @exception IllegalArgumentException if the data is malformed     */    public static void removeStringParameters(Map map, String data,                                          boolean urlParameters) {        if ((data == null) || (data.length() < 1))        return;        //JahiaConsole.println("RequestWrapper", "Parsing string [" + data + "]");        // Initialize the variables we will require        StringParser parser = new StringParser(data);        boolean first = true;        int nameStart = 0;        int nameEnd = 0;        int valueStart = 0;        int valueEnd = 0;        String name = null;        String value = null;        String oldValues[] = null;        String newValues[] = null;        // Loop through the "name=value" entries in the input data        while (true) {            // Extract the name and value components            if (first)                first = false;            else                parser.advance();            nameStart = parser.getIndex();            nameEnd = parser.findChar('=');            parser.advance();            valueStart = parser.getIndex();            valueEnd = parser.findChar('&');            name = parser.extract(nameStart, nameEnd);            value = parser.extract(valueStart, valueEnd);            // A zero-length name means we are done            if (name.length() < 1)                break;                // Decode the name and value if required                if ((name.indexOf('%') >= 0) || (name.indexOf('+') >= 0)) {                    try {                        if (urlParameters) {                            name = URLDecode(name);                        } else {                            name = java.net.URLDecoder.decode(name);                        }                    } catch (Throwable t) {                        ;                    }                }                if ((value.indexOf('%') >= 0) || (value.indexOf('+') >= 0)) {                    try {                        if (urlParameters) {                            value = URLDecode(value);                        } else {                            value = java.net.URLDecoder.decode(value);                        }                    } catch (Throwable t) {                        ;                    }                }            //JahiaConsole.println("RequestWrapper", "removeParameters. Removing key [" + name + "]");            map.remove(name);        }    }    /**     * Append request parameters from the specified String to the specified     * Map.  It is presumed that the specified Map is not accessed from any     * other thread, so no synchronization is performed.     * <p>     * <strong>IMPLEMENTATION NOTE</strong>:  URL decoding is performed     * individually on the parsed name and value elements, rather than on     * the entire query string ahead of time, to properly deal with the case     * where the name or value includes an encoded "=" or "&" character     * that would otherwise be interpreted as a delimiter.     *     * @param map Map that accumulates the resulting parameters     * @param data Input string containing request parameters     * @param urlParameters true if we're parsing parameters on the URL     *     * @exception IllegalArgumentException if the data is malformed     */    public static void parseStringParameters(Map map, String data,                                          boolean urlParameters) {        if ((data == null) || (data.length() < 1))        return;        // JahiaConsole.println("RequestWrapper", "Parsing string [" + data + "]");        // Initialize the variables we will require        StringParser parser = new StringParser(data);        boolean first = true;        int nameStart = 0;        int nameEnd = 0;        int valueStart = 0;        int valueEnd = 0;        String name = null;        String value = null;        String oldValues[] = null;        String newValues[] = null;        // Loop through the "name=value" entries in the input data        while (true) {            // Extract the name and value components            if (first)                first = false;            else                parser.advance();            nameStart = parser.getIndex();            nameEnd = parser.findChar('=');            parser.advance();            valueStart = parser.getIndex();            valueEnd = parser.findChar('&');            name = parser.extract(nameStart, nameEnd);            value = parser.extract(valueStart, valueEnd);            // A zero-length name means we are done            if (name.length() < 1)                break;                // Decode the name and value if required                if ((name.indexOf('%') >= 0) || (name.indexOf('+') >= 0)) {                    try {                        if (urlParameters) {                            name = URLDecode(name);                        } else {                            name = java.net.URLDecoder.decode(name);                        }                    } catch (Throwable t) {                        ;                    }                }                if ((value.indexOf('%') >= 0) || (value.indexOf('+') >= 0)) {                    try {                        if (urlParameters) {                            value = URLDecode(value);                        } else {                            value = java.net.URLDecoder.decode(value);                        }                    } catch (Throwable t) {                        ;                    }                }            // Create or update the array of values for this name            // JahiaConsole.println("RequestWrapper", "parseParameters. Storing key [" + name + "]");            map.put(name, value);        }    }    /**     * Parse the parameters of this request, if it has not already occurred.     * If parameters are present in both the query string and the request     * content, they are merged.     * @param originalRequest the non emulated original request     */    protected void parseParameters(HttpServletRequest originalRequest) {        //JahiaConsole.println("RequestWrapper", "Parsing parameters...");        if (parsed)            return;        Map results = parameters;        if (results == null)            results = new Hashtable();        // we can't do the following because getParameterMap is not implemented in all        // servlet containers yet. :((((        // results = copyMap(originalRequest.getParameterMap());        // so in the meantime we do the following junk...        Enumeration paramNames = originalRequest.getParameterNames();        while (paramNames.hasMoreElements()) {            String paramName = (String)paramNames.nextElement();            results.put(paramName, originalRequest.getParameterValues(paramName));        }        // JahiaConsole.println("RequestWrapper", "Parsing query string [" + originalRequest.getQueryString() + "] and removing it's parameters");        removeStringParameters(results, originalRequest.getQueryString(), true);        // Parse any parameters specified in the query string        String queryString = emulatedURL.getQuery();        // JahiaConsole.println("RequestWrapper", "Parsing query string [" + queryString + "]");        if ((queryString != null) && (queryString.length() > 0)) {            try {                parseStringParameters(results, queryString, true);            } catch (Throwable t) {                JahiaConsole.printe("Error parsing URL parameters !", t);            }        }        // JahiaConsole.println("RequestWrapper", "Printing out full set of parameter keys...");        Hashtable results2 = (Hashtable) results;        Enumeration resultKeys = results2.keys();        while (resultKeys.hasMoreElements()) {            String nextKey = (String)resultKeys.nextElement();            // JahiaConsole.println("RequestWrapper", "Parameter keys [" + nextKey + "] defined");        }        // JahiaConsole.println("RequestWrapper", "...done printing parameter keys !");        parsed = true;        parameters = results;    }    /**     * Decode and return the specified URL-encoded String.     *     * @param str The url-encoded string     * @return the string containing the decoded URL     *     * @exception IllegalArgumentException if a '%' character is not followed     * by a valid 2-digit hexadecimal number     */    public static String URLDecode(String str)    throws IllegalArgumentException {        if (str == null)            return (null);        StringBuffer dec = new StringBuffer();        int pos = 0;        int len = str.length();        dec.ensureCapacity(str.length());        while (pos < len) {            int lookahead;	// Look-ahead position            // Look ahead to the next URLencoded metacharacter, if any            for (lookahead = pos; lookahead < len; lookahead++) {            char ch = str.charAt(lookahead);            if ((ch == '+') || (ch == '%'))                break;            }            // If there were non-metacharacters, copy them as a block            if (lookahead > pos) {            dec.append(str.substring(pos, lookahead));            pos = lookahead;            }            // Shortcut out if we are at the end of the string            if (pos >= len)            break;            // Process the next metacharacter            char meta = str.charAt(pos);

⌨️ 快捷键说明

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