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

📄 usersviewhelper.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////              . . . i n   j a h i a   w e   t r u s t . . .////package org.jahia.viewhelper;import java.util.*;import javax.servlet.http.HttpServletRequest;import org.jahia.registries.ServicesRegistry;import org.jahia.services.sites.JahiaSite;import org.jahia.services.usermanager.*;import org.jahia.utils.JahiaConsole;import org.jahia.utils.JahiaString;import org.jahia.utils.JahiaTools;/** * desc: The role of this class is to prepare and format user datas for *  display according to the JSP files needs in administration and engine. * * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * * @author Philippe Martin * * @version 1.0 */public class UsersViewHelper {    /**     * Constructor : initialize the jahia site and the user manager service.     * @param js a JahiaSite object     */    public UsersViewHelper(JahiaSite js) {        jahiaSite = js;        jahiaUserManagerService = ServicesRegistry.getInstance().getJahiaUserManagerService();    }    /**     * Get the user search result from the parameter form given by the request.     * If the form is not in the request then all the Jahia users will be search.     *     * @param request the request that should contain the HTML formular with the     * following fields :     * - searchString     * - searchIn     * - properties     * - storedOn     * - providers     * @return a Properties object that contain the search criterium     */    public Set getSearchResult(HttpServletRequest request) {        String searchString = request.getParameter("searchString");        String searchIn = request.getParameter("searchIn");        String[] searchInProps = request.getParameterValues("properties");        String storedOn = request.getParameter("storedOn");        String[] providers = request.getParameterValues("providers");        Properties searchParameters = new Properties();        Set searchResults = new HashSet();        if (searchIn == null) { // Necessary condition to say there is no formular.            JahiaConsole.println(CLASS_NAME + ".getSearchParameters",                                 "No formular transmited. Finding all Jahia DB users.");            searchParameters.setProperty("*", "*");            searchResults.addAll(jahiaUserManagerService.                searchUsers("jahia_db", jahiaSite.getID(), searchParameters));        } else {            //if (searchString == null || "".equals(searchString)) {            if ("".equals(searchString)) {                searchString = "*";            }            if ("allProps".equals(searchIn) || searchInProps == null) {                searchParameters.setProperty("*", searchString);            } else {                for (int i = 0; i < searchInProps.length; i++) {                    searchParameters.setProperty(searchInProps[i], searchString);                }            }            if ("everywhere".equals(storedOn) || providers == null) {                searchResults.addAll(jahiaUserManagerService.                    searchUsers(jahiaSite.getID(), searchParameters));            } else {                for (int i = 0; i < providers.length; i++) {                    String curServer = providers[i];                    Set curSearchResults = jahiaUserManagerService.                        searchUsers(curServer, jahiaSite.getID(), searchParameters);                    if (curSearchResults != null) {                        searchResults.addAll(curSearchResults);                    }                }            }        }        return searchResults;    }    /**     * Return an ArrayList object containing the user in a specific format for     * the HTML select box.     *     * @param searchResults a set of jahia user given by the method "getSearchResult".     * @return the result list containing the formatted string user that will be     * display in the JSP select box. (see the user_display.jsp file).     */    public ArrayList getUserListForDisplay(Set searchResults) { //String format = null) {        ArrayList resultList = new ArrayList();        Iterator resultListEnum = searchResults.iterator();        while (resultListEnum.hasNext()) {            JahiaUser user = (JahiaUser) resultListEnum.next();            // is user declared in site or just a member of it ?            if (jahiaUserManagerService.lookupUser(jahiaSite.getID(), user.getUsername()) == null) {                // user is just a member, not created in this site,                // let's ignore him for the moment            } else {                String provider = JahiaString.adjustStringSize(user.getProviderName(), 6) + " ";                String usrname = JahiaString.adjustStringSize(user.getUsername(), 15);                // Find a displayable user property                String properties = "";                String firstname = user.getProperty("firstname");                String lastname = user.getProperty("lastname");                if (firstname != null) {                    properties += firstname;                    if (firstname.length() < 20) properties += " ";                }                if (lastname != null) properties += lastname;                if ("".equals(properties)) {                    String email = user.getProperty("email");                    if (email != null) properties += email;                }                properties = JahiaString.adjustStringSize(properties, 20);                String resultValue = "u " + provider + " " + user.getUsername();                String result = "u " + provider + usrname + " " + properties;                resultList.add(JahiaTools.replacePattern(resultValue, " ", "&nbsp;"));                resultList.add(JahiaTools.replacePattern(result, " ", "&nbsp;"));            }        }        return resultList;    }    private static final String CLASS_NAME = UsersViewHelper.class.getName();    private JahiaUserManagerService jahiaUserManagerService;    private JahiaSite jahiaSite;}

⌨️ 快捷键说明

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