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

📄 filters.jsp

📁 jive3论坛开源 最新 有版主功能 jive3论坛开源 最新 有版主功能 jive3论坛开源 最新 有版主功能
💻 JSP
📖 第 1 页 / 共 3 页
字号:
<%--  - $RCSfile: filters.jsp,v $  - $Revision: 1.14.4.2 $  - $Date: 2003/06/05 20:29:58 $  -  - Copyright (C) 1999-2003 Jive Software. All rights reserved.  -  - This software is the proprietary information of Jive Software.  Use is subject to license terms.--%><%@ page import="java.beans.*,                 java.util.*,                 com.jivesoftware.util.*,                 com.jivesoftware.forum.*,                 com.jivesoftware.forum.database.*,                 com.jivesoftware.forum.util.*,                 java.lang.reflect.Method,                com.jivesoftware.base.Filter"    errorPage="error.jsp"%><%@ include file="global.jsp" %><%! // Global variables/methods for this page    private boolean isInstalledFilter(FilterManager filterManager,            Filter filter)    {        try {            int filterCount = filterManager.getFilterCount();            if (filter == null) {                return false;            }            if (filterCount < 1) {                return false;            }            String filterClassname = filter.getClass().getName();            for (int i=0; i<filterCount; i++) {                Filter installedFilter = filterManager.getFilter(i);                if (filterClassname.equals(installedFilter.getClass().getName())) {                    return true;                }            }        } catch (Exception e) {}        return false;    }    private String getHTML(Filter filter, PropertyDescriptor descriptor)    {        // HTML of the customizer for this property        StringBuffer html = new StringBuffer(50);        // Get the name of the property (this becomes the name of the form element)        String propName = descriptor.getName();        // Get the current value of the property        Object propValue = null;        try {            propValue = descriptor.getReadMethod().invoke(filter,null);        }        catch (Exception e) {e.printStackTrace();}        // Get the classname of this property        String className = descriptor.getPropertyType().getName();        // HTML form elements for number values (rendered as small textfields)        if ("int".equals(className)            || "double".equals(className)            || "long".equals(className))        {            html.append("<input type=\"text\" name=\"").append(propName).append("\" size=\"6\" maxlength=\"10\"");            if (propValue != null) {                html.append(" value=\"").append(propValue.toString()).append("\"");            }            html.append(">");        }        // HTML form elements for boolean values (rendered as Yes/No radio buttons)        else if ("boolean".equals(className)) {            boolean value = false;            if ("true".equals(propValue.toString())) {                value = true;            }            html.append("<input type=\"radio\" name=\"").append(propName).append("\" id=\"rb").append(propName).append("1\" ");            html.append("value=\"true\"");            html.append((value)?" checked":"");            html.append("> <label for=\"rb").append(propName).append("1\">Yes</label> ");            html.append("<input type=\"radio\" name=\"").append(propName).append("\" id=\"rb").append(propName).append("2\" ");            html.append("value=\"false\"");            html.append((!value)?" checked":"");            html.append("> <label for=\"rb").append(propName).append("2\">No</label> ");        }        else if ("java.lang.String".equals(className)) {            // Indicates we should print a textarea if the large text field is specified to be used            boolean useLarge = ("true".equals(descriptor.getValue("useLargeTextField")));            // HTML elements for a String or String[] (rendered as a single-line textarea)            if (descriptor.getPropertyType().isArray()) {                // Print out a customizer for a String array:                String[] valArray = (String[])propValue;                for (int i=0; i<valArray.length; i++) {                    html.append(printStringHTML(propName+i, valArray[i], useLarge));                    html.append("<input type=\"submit\" name=\"deletePropEntry")                        .append(i).append("\" value=\"Delete\">")                        .append("<br>");                }                html.append("<br>");                html.append(printStringHTML(propName, null, useLarge));                html.append("<input type=\"hidden\" name=\"addNewPropName");                html.append("\" value=\"").append(propName).append("\">");                html.append("<input type=\"submit\" name=\"addNewProp\" ");                html.append("value=\"Add\">");                html.append("<input type=\"hidden\" name=\"deletePropertyName");                html.append("\" value=\"").append(propName).append("\">");            }            // Else, it's just a POS (plain old String) :)            else {                if (propName.toLowerCase().equals("password")) {                    html.append("<input type=\"password\"").append(" name=\"").append(propName);                    html.append("\" size=\"30\" maxlength=\"150\"");                    if (propValue != null) {                        html.append(" value=\"").append(escapeHTML(propValue.toString())).append("\"");                    }                    html.append(">");                }                else {                    String value = null;                    if (propValue != null) {                        value = propValue.toString();                    }                    html.append(printStringHTML(propName, value, useLarge));                }            }        }        if (html.length() == 0) {            html.append("&nbsp;");        }        return html.toString();    }    // Handles printing a string text field either as a textfield or a textarea.    private String printStringHTML(String name, String value, boolean useLarge) {        StringBuffer buf = new StringBuffer(50);        if (useLarge) {            buf.append("<textarea name=\"").append(name).append("\" cols=\"40\" rows=\"3\">");            if (value != null) {                buf.append(escapeHTML(value));            }            buf.append("</textarea>");        }        else {            buf.append("<input type=\"text\" name=\"").append(name).append("\" size=\"40\" maxlength=\"255\" ");            if (value != null) {                buf.append("value=\"").append(escapeHTML(value)).append("\"");            }            buf.append(">");        }        return buf.toString();    }    private Map getFilterPropertyValues(HttpServletRequest request, Filter filter) {        // Map of filter property name/value pairs        Map map = new HashMap();        try {            // Property descriptors            PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(filter.getClass());            // Loop through the properties, get the value of the property as a            // parameter from the HttpRequest object            for (int i=0; i<descriptors.length; i++) {                // Don't set any array properties:                if (!descriptors[i].getPropertyType().isArray()) {                    String propName = descriptors[i].getName();                    String propValue = ParamUtils.getParameter(request,propName);                    map.put(propName, propValue);                }            }        }        catch (Exception e) {}        return map;    }    private String escapeHTML(String html) {        html = StringUtils.replace(html, "\"", "&quot;");        return StringUtils.escapeHTMLTags(html);    }%><%	// Get parameters    long forumID = ParamUtils.getLongParameter(request,"forum",-1);    String classname = ParamUtils.getParameter(request,"filters");    boolean install = ParamUtils.getBooleanParameter(request,"install");    boolean remove = ParamUtils.getBooleanParameter(request,"remove");    int position = ParamUtils.getIntParameter(request,"pos",-1);    boolean edit = ParamUtils.getBooleanParameter(request,"edit");    boolean addFilter = ParamUtils.getBooleanParameter(request,"addFilter");    String newClassname = ParamUtils.getParameter(request,"newClassname");    boolean saveProperties = ParamUtils.getBooleanParameter(request,"saveProperties");    int filterIndex = ParamUtils.getIntParameter(request,"filterIndex",-1);    boolean changePosition = ParamUtils.getBooleanParameter(request,"changePos");    boolean up = ParamUtils.getBooleanParameter(request,"up");    boolean down = ParamUtils.getBooleanParameter(request,"down");    String deletePropertyName = ParamUtils.getParameter(request,"deletePropertyName");    boolean addNewProp = request.getParameter("addNewProp") != null;    int applyToSubj = ParamUtils.getIntParameter(request, "applyToSubj", -1);    int applyToBody = ParamUtils.getIntParameter(request, "applyToBody", -1);    int applyToProp = ParamUtils.getIntParameter(request, "applyToProp", -1);    // Determine if we need to delete a String[] property entry    boolean deletePropEntry = false;    int deleteIndex = -1;    for (Enumeration enum=request.getParameterNames(); enum.hasMoreElements(); ) {        String name = (String)enum.nextElement();        if (name.startsWith("deletePropEntry")) {            try {                int pos = "deletePropEntry".length();                deleteIndex = Integer.parseInt(                        name.substring(pos, name.length())                );            }            catch (Exception ignored) {}            if (deleteIndex > -1) {                deletePropEntry = true;                break;            }        }    }    // Indicate if we're doing global filters    boolean isGlobal = (forumID == -1L);    // Security check    if (isGlobal) {        if (!isSystemAdmin) {            throw new UnauthorizedException("You don't have admin privileges to perform this operation.");        }    }    else {        if (!isSystemAdmin && !isForumAdmin) {            throw new UnauthorizedException("You don't have admin privileges to perform this operation.");        }    }    // Load the forum    Forum forum = null;    if (forumID > 0L) {        forum = forumFactory.getForum(forumID);    }    // Get the filter manager    FilterManager filterManager = null;    if (forum != null) {        filterManager = forum.getFilterManager();    }    else {        filterManager = forumFactory.getFilterManager();    }    // Add a new property for a String[] property type:    if (addNewProp) {        // Get the name of the filter for the new property:        String newPropName = ParamUtils.getParameter(request,"addNewPropName");        if (newPropName != null) {            // Get the value of the new property:            String newPropValue = ParamUtils.getParameter(request,"addNewProp" + newPropName);            if (newPropValue != null) {                // The filter we're working with:                Filter filter = filterManager.getFilter(filterIndex);                PropertyDescriptor[] descriptors = (Introspector.getBeanInfo(filter.getClass())).getPropertyDescriptors();                PropertyDescriptor propDescriptor = null;                // Look for the property specified                for (int i=0; i<descriptors.length; i++) {                    if (descriptors[i].getName().equals(newPropName)) {                        propDescriptor = descriptors[i];                        break;                    }                }                if (propDescriptor != null) {                    // Get both the read and write methods:                    Method readMethod = propDescriptor.getReadMethod();                    Method writeMethod = propDescriptor.getWriteMethod();                    // Get the String[] via the read method:                    String[] entries = (String[])readMethod.invoke(filter, null);                    // Make a new entry array of entries.length+1 because we're                    // adding one more entry to the property                    String[] newEntries = new String[entries.length+1];                    for (int i=0; i<entries.length; i++) {                        newEntries[i] = entries[i];                    }                    // The new prop value goes in the last spot of newEntries:                    newEntries[newEntries.length-1] = newPropValue;                    // Use the write method to save the new entries:                    writeMethod.invoke(filter, new Object[]{newEntries});                    // Save filters                    filterManager.saveFilters();                    // Done, so redirect                    StringBuffer url = new StringBuffer();                    url.append("filters.jsp?forum=").append(forumID);

⌨️ 快捷键说明

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