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

📄 useragentgroup.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
package org.jahia.services.htmlcache;/** * Title:        Jahia * Description: * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * @author Serge Huber * @version 1.0 */import java.util.*;import org.apache.regexp.*;import org.jahia.utils.*;/** * The purpose of this class is to store all the information relative to a group * of user agents, as well as the regular expressions that are use to evaluate * if a new user agent should fit into this group. * @author Serge Huber */public class UserAgentGroup {    private String name;    private Vector regexpList = new Vector();    private Vector regexpStrings = new Vector();    private Set userAgentSet = new TreeSet();    /**     * This constructor is used notably when de-serializing objects from     * persistant storage, in the case of this implementation most probably     * from XML files.     * @param name the name of the group     * @param regexpStrings a vector of Strings that contain the regular expressions     * to be evaluated using the matchesInsertCriterias method. This allows for     * quick evaluation of wether a newly encountered user agent should be     * insert into this group. This is a list because the order of the entries     * is crucial to correct evaluation of the criterias     * @param userAgentSet a list of Strings containing user agent string to     * initialize the group with.     */    public UserAgentGroup(String name, Vector regexpStrings, Set userAgentSet) {        this.name = name;        Enumeration regexpEnum = regexpStrings.elements();        while (regexpEnum.hasMoreElements()) {            Object curRegExpObj = regexpEnum.nextElement();            if (curRegExpObj instanceof String) {                String curRegExpStr = (String) curRegExpObj;                try {                    RE curRE = new RE(curRegExpStr);                    this.regexpList.add(curRE);                    this.regexpStrings.add(curRegExpStr);                } catch (RESyntaxException res) {                    JahiaConsole.println("UserAgentGroup.constructor",                                         "Invalid regular expression syntax : " +                                         curRegExpStr + ", ignoring it...");                }            }        }        Iterator userAgentIter = userAgentSet.iterator();        while (userAgentIter.hasNext()) {            Object userAgentObj = userAgentIter.next();            if (userAgentObj instanceof String) {                String userAgentStr = (String) userAgentObj;                this.userAgentSet.add(userAgentStr);            }        }    }    /**     * Tests the specified user agent against all the regular expressions     * declared for this group.     * @param newUserAgent a String containing the user agent to test.     * @return true as soon as a regexp matched the specified user agent string.     * The evaluation is immediately stopped as soon as the first regexp matches     * the user agent string     */    public boolean matchesInsertCriterias(String newUserAgent) {        Enumeration regexpEnum = regexpList.elements();        while (regexpEnum.hasMoreElements()) {            RE curRE = (RE) regexpEnum.nextElement();            if (curRE.match(newUserAgent)) {                return true;            }        }        return false;    }    /**     * Returns the name of this user agent group     * @return a String object containing the name of this user agent group.     */    public final String getName() {        return name;    }    /**     * Returns an enumation to be able to view all the elements of the regular     * expression list.     * @return an enumeration of String objects that contain the regular     * expression. The order should normally be the same as at the time of     * creation of the UserAgentGroup instance.     * @todo FIXME : test the ordering...     */    public final Enumeration getRegExpStrings() {        return regexpStrings.elements();    }    /**     * Returns an iterator on a set of user agent strings that are contained in     * this group.     * @return an Iterator object on a Set of String objects that contain the     * user agent string inserted when creating this instance of the object.     */    public final Iterator getUserAgentSetIterator() {        return userAgentSet.iterator();    }    /**     * Adds the specified user agent into the set of this group. Warning : there     * is no verification that this user agent complies to the regular expressions     * Use matchInsertCriterias first to know if you should insert this agent     * in this group.     * @param newUserAgent the new user agent String to insert in this group.     * @return true if insertion was successful, false otherwise (which means     * the user agent already exists in the set).     */    public boolean setUserAgent(String newUserAgent) {        return userAgentSet.add(newUserAgent);    }}

⌨️ 快捷键说明

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