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

📄 propertyfileresolver.java

📁 iiitAccessServer是一个用Java编写的基于规则的企业鉴别系统。它作为一个服务器工作
💻 JAVA
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * version $Id: PropertyFileResolver.java,v 1.10 2003/04/13 21:09:56 joerg Exp $ ******************************************************************************/package de.iiit.access.server.plugins.parser;import de.iiit.access.common.api.*;import de.iiit.access.server.*;import de.iiit.access.server.api.*;import de.iiit.xmlconfig.*;import java.util.*;import java.util.regex.*;import java.io.*;import org.apache.log4j.Logger;/** This is an example implementation of a resolver. This one reads its data from a * property file. * @version $Revision: 1.10 $ $Date: 2003/04/13 21:09:56 $ */public class PropertyFileResolver implements ResolverPluginIf{    /** CVS Version Tag */    private static final String vcid = "$Id: PropertyFileResolver.java,v 1.10 2003/04/13 21:09:56 joerg Exp $";        private static final String FILENAME = "FileName";    private static Properties expressions = new Properties();    private Logger logger = Logger.getLogger(this.getClass());    private Pattern pOperator = Pattern.compile("[&+\\-]");         // + or - or &        private boolean ignoreCase = false;        /** Creates a new instance of PropertyFileResolver */    public PropertyFileResolver()    {    }        /** Creates a new instance of PropertyFileResolver     * @param filename The name of the property file to read.     * @throws FileNotFoundException if the file could not be found.     * @throws IOException if an error occurred when reading from the input file.     */        public PropertyFileResolver(String filename) throws FileNotFoundException, IOException    {        expressions.load(new FileInputStream(filename));    }        /** Initializes the server     * @param config the configuration of the resolver. Currently the only parameter is     * <CODE>FileName</CODE> which defines the name of the property file to read.     */        public void initialize(Configuration config)    {        try        {            AccessServer.setVerifyUser(false);            ignoreCase = AccessServer.getIgnoreCase();                        String filename = config.getAttribute(FILENAME);            expressions.load(new FileInputStream(filename));                        if (ignoreCase)            {                Properties e = new Properties();                                Enumeration enum = expressions.keys();                                while (enum.hasMoreElements())                {                    String key = (String) enum.nextElement();                                        e.put(key.toLowerCase(), ((String) expressions.get(key)).toLowerCase());                }                                expressions = e;            }        }        catch(Exception e)        {            logger.fatal("Fatal error", e);            System.exit(1);        }    }        /** This method is called by the AccessServer when the background threads should     * stop because of a shutdown of the AccessServer itself.     *     */    public void shutdown()    {        // Do nothing    }        /** This method is called by the AccessServer when the background thread should     * start. It is called after the method initialize() is called for all plug-ins.     *     */    public void start()    {        // Do nothing    }            /** Resolves the expression on top of the stack. If the result is also an expression     * the parser is called to evaluate it.     * @param argStack This stack includes all expressions and subexpressions of the current tree     * inside the orginal expression.     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return The set of users described by the expression.     */        public Set resolve(ParserStackIf argStack) throws ParserException    {        String expression = (String) argStack.peek();        Set result = null;        String r = expressions.getProperty(expression);                if (r != null)         {            logger.info("Property = <" + r + ">");            Matcher mOperator  = pOperator.matcher(r);                        if (mOperator.find())            {                argStack.pushArgument(r);                Parser p = new Parser(this);                result = p.evaluate(argStack);                argStack.pop();            }            else            {                result = new HashSet();                String parts[] = r.split("\\s*,\\s*");                                int iMax = parts.length;                for (int i = 0; i < iMax; i++)                    result.add(parts[i]);            }        }                return result;    }        /** The evaluation is optimized in such way that     * it only retrieves information regarding the given user name.     * @param argStack This stack includes all expressions and subexpressions of the current tree     * inside the orginal expression.     * @param name The name of the user for whom the expression should be resolved.     * @throws ParserException if there is something wrong with the expression. The most common cases are syntax     * errors or circular references within the expression.     * @return An optimized set of users. It is guaranteed that it is correct for the given user     * but it is not guaranteed that it includes all users described by the expression.     */        public Set resolve(ParserStackIf argStack, String name) throws ParserException    {        return resolve(argStack);    }        /** Verifies whether a user exists in the user database.     * @param uid the user ID.     * @return true if the user exists or if there is no user database, false if the user     * doesn't exist.     */        public boolean verifyUser(String uid)    {        return true;    }    }/** * $Log: PropertyFileResolver.java,v $ * Revision 1.10  2003/04/13 21:09:56  joerg * Package structure modified * * Revision 1.9  2003/04/13 20:28:01  joerg * Package structure modified * * Revision 1.8  2003/04/13 20:16:42  joerg * Package structure modified * * Revision 1.7  2003/04/07 20:08:49  joerg * Improved JavaDoc. * * Revision 1.6  2003/01/17 19:56:27  joerg * Neue Methode verifyUser() * * Revision 1.5  2003/01/07 10:57:55  joerg * IgnoreCase eingebaut * * Revision 1.4  2003/01/01 21:04:18  joerg * Copyright-Statement aktualisiert * * Revision 1.3  2002/12/24 21:04:33  joerg * Umbau der Paketstruktur * iiitLdapPlugin integriert * JavaDoc-Kommentare weiter vervollstaendigt. * * Revision 1.2  2002/12/23 11:26:02  joerg * shutdown()-Methode hinzugefuegt. * * Revision 1.1  2002/12/19 15:24:23  joerg * Reparatur des CVS-Repositories * * Revision 1.4  2002/12/09 19:29:17  joerg * Versionsdaten in allen JavaDoc-Klassenbeschreibungen ergaenzt * * Revision 1.3  2002/12/09 16:32:26  joerg * JavaDoc Kommentare ergaenzt * * Revision 1.2  2002/11/27 16:39:40  joerg * Parameteruebergabe geaendert, um circulaere Recursion * zu erkennen * * Revision 1.1  2002/11/26 10:55:36  joerg * Package exprparser durch parser erstzt. * */

⌨️ 快捷键说明

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