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

📄 xmlpermissionsparser.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * XMLPermissionsParser.java * * Created on June 13, 2003, 9:46 AM */package gov.nist.security.permissions.parser;import java.io.IOException;import java.util.Hashtable;import java.util.List;import java.util.Vector;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import org.xml.sax.XMLReader;import org.xml.sax.helpers.DefaultHandler;import org.apache.log4j.Logger;/** * Class parsing a xml permissions file * @author  DERUELLE Jean */public class XMLPermissionsParser extends DefaultHandler {    /**log4j logging*/    private static Logger logger= Logger.getLogger(XMLPermissionsParser.class);    //Fields to fill in through the xml permissions file    /**list of permissions in a xml permissions file*/    private Hashtable permissionsTagList;        /**a permission tag*/    private PermissionTag permissionTag;        /**class name of a permission*/    private String permissionClass;     /**actions of a permission*/    private String action;        /**a method tag*/    private MethodTag methodTag;    /**list of methods to check for a permission*/    private Vector methods;        /**list of arguments of a method*/    private Vector arguments;    /**an inheritance tag*/    private InheritanceTag inheritanceTag;       /**list of super classes to check for a permission*/    private List superClasses;    /**a bytecode tag*/    private ByteCodeTag byteCodeTag;    /**list of a bytecode method argument*/    private Vector byteCodeArguments;    /**a bytecode argument tag*/    private ByteCodeArgumentTag byteCodeArgumentTag;    //utility fields    /**the parser*/    private XMLReader saxParser;            /**the file to parse*/    private String file;         /**      * start the parsing     * @param fileLocation - file to parse     */    public XMLPermissionsParser(String fileLocation) {		try{			SAXParserFactory saxParserFactory=SAXParserFactory.newInstance();			SAXParser saxParser = saxParserFactory.newSAXParser();			XMLReader xmlReader = saxParser.getXMLReader();			xmlReader.setContentHandler(this);			xmlReader.setFeature			("http://xml.org/sax/features/validation",false);			// parse the xml specification for the event tags.			xmlReader.parse(fileLocation);			} catch (SAXParseException spe) {			spe.printStackTrace();		} catch (SAXException sxe) {			sxe.printStackTrace();		} catch (IOException ioe) {			// I/O error			ioe.printStackTrace();		} catch (Exception pce) {			// Parser with specified options can't be built			pce.printStackTrace();		}                   file=fileLocation;                       }    /**Retrieve the list of permissions in a xml permissions file     * @return list of permissions in a xml permissions file     */    public Hashtable getPermissionsTagList() {        return permissionsTagList;    }        //===========================================================    // SAX DocumentHandler methods    //===========================================================    public void startDocument() throws SAXException {        try {             System.out.println("ProxyDebug, XMLPermissionsParser, startDocument(): "+             " Parsing XML permissions file");        }         catch (Exception e) {            throw new SAXException("XMLPermissionsParser error", e);        }    }    public void endDocument() throws SAXException {        try {           System.out.println("ProxyDebug, XMLPermissionsParser , endDocument(): "+           " XML permissions file parsed successfully!!!");        }         catch (Exception e) {            throw new SAXException("ProxyDebug XMLPermissionsParser error", e);        }    }    public void startElement(String namespaceURI,                             String lName, // local name                             String qName, // qualified name                             Attributes attrs)                             throws SAXException    {                String element=qName;        if (element.compareToIgnoreCase("permissions") ==0 )             permissionsTagList=new Hashtable();                if (element.compareToIgnoreCase("permission") ==0 ) {            permissionTag=new PermissionTag();                        permissionClass= attrs.getValue("class");            if (permissionClass!=null)                 permissionClass=permissionClass.trim();                            action= attrs.getValue("action");            if (action!=null)                 action=action.trim();                        logger.debug("PERMISSION: "+permissionClass+" "+action);        }             if (element.compareToIgnoreCase("inheritance") ==0 ) {            inheritanceTag=new InheritanceTag();        }        if(element.compareToIgnoreCase("superclasses")==0){            superClasses=new Vector();        }        if(element.compareToIgnoreCase("superclass") ==0 ) {                String superClassName= attrs.getValue("name");                if (superClassName!=null)                 superClassName=superClassName.trim();                superClasses.add(superClassName);            superClassName=null;        }        if (element.compareToIgnoreCase("methods") ==0 ) {            methods=new Vector();        }        if(element.compareToIgnoreCase("method") ==0 ) {                         String methodName= attrs.getValue("name");                if (methodName!=null)                 methodName=methodName.trim();                                                   String methodClass= attrs.getValue("class");                        if (methodClass!=null)                 methodClass=methodClass.trim();                                        String methodReturnType= attrs.getValue("return");                        if (methodReturnType!=null)                 methodReturnType=methodReturnType.trim();                            methodTag=new MethodTag(permissionClass,action,methodClass,methodName,methodReturnType,new Vector());            String checkValue= attrs.getValue("bytecode_check");                                    if (checkValue!=null) {                checkValue=checkValue.trim();                                                if(checkValue.equals("at runtime"))                    methodTag.setCheckValue(true);                else                    methodTag.setCheckValue(false);            }                         logger.debug("METHOD: "+methodName+" "+methodClass+" "+methodReturnType+" "+permissionClass+" "+action+" "+checkValue);        }                        if (element.compareToIgnoreCase("arguments") ==0 )             arguments=new Vector();                if (element.compareToIgnoreCase("argument") ==0 ) {            String className= attrs.getValue("classname");                        if (className!=null) {                className=className.trim();                                                arguments.add(className);            }                                      logger.debug("METHOD ARGUMENT: "+className);        }                if(element.compareToIgnoreCase("bytecode") ==0 ) {                        String classToInvoke= attrs.getValue("class");                        if (classToInvoke!=null)                 classToInvoke=classToInvoke.trim();                                                                        String method= attrs.getValue("method");                        if (method!=null)                 method=method.trim();                                                        byteCodeTag=new ByteCodeTag(classToInvoke,method);            logger.debug("BYTECODE METHOD: "+classToInvoke+" "+method);        }        if (element.compareToIgnoreCase("BC_args") ==0 )             byteCodeArguments=new Vector();                if (element.compareToIgnoreCase("BC_arg") ==0 ) {            byteCodeArgumentTag=new ByteCodeArgumentTag();            String className= attrs.getValue("classname");                        if (className!=null) {                className=className.trim();                                                byteCodeArgumentTag.setClassName(className);            }            /*String checkValue= attrs.getValue("permission_name");                        if (checkValue!=null) {                checkValue=checkValue.trim();                                                if(checkValue.equals("yes"))                    byteCodeArgumentTag.setIsPermissionName(true);            }*/            String argumentNumber= attrs.getValue("argument_number");                        if (argumentNumber!=null) {                argumentNumber=argumentNumber.trim();                                                int num=Integer.parseInt(argumentNumber);                byteCodeArgumentTag.setArgumentNumber(num);            }            logger.debug("BYTECODE METHOD ARGUMENT: "+className+" "+argumentNumber);        }    }        public void endElement(String namespaceURI,    String sName, // simple name    String qName  // qualified name    )    throws SAXException    {                String element=qName;                if (element.compareToIgnoreCase("permission") ==0 ) {            permissionTag.setClassName(permissionClass);            permissionTag.setActions(action);            permissionTag.setMethodsToCheck(methods);            permissionsTagList.put(permissionClass+","+action,permissionTag);             methods=null;            permissionTag=null;        }                if (element.compareToIgnoreCase("inheritance") ==0 ) {            permissionTag.setInheritanceTag(inheritanceTag);            inheritanceTag=null;        }        if (element.compareToIgnoreCase("superclasses") ==0 ) {            inheritanceTag.setSuperClassesToCheck(superClasses);            superClasses=null;        }          if (element.compareToIgnoreCase("method") ==0 ) {            if(methodTag!=null)                methods.addElement(methodTag);                        methodTag=null;                    }                        if (element.compareToIgnoreCase("arguments") ==0 ) {            if(arguments!=null && arguments.size()!=0)                methodTag.setArguments(arguments);                        arguments=null;        }        if(element.compareToIgnoreCase("bytecode") ==0 ) {                          if(byteCodeTag!=null){                if(methodTag!=null)                    methodTag.setByteCodeTag(byteCodeTag);                                        if(inheritanceTag!=null)                    inheritanceTag.setByteCodeTag(byteCodeTag);                                    }            byteCodeTag=null;        }        if (element.compareToIgnoreCase("BC_args") ==0 ) {            if(byteCodeArguments!=null && byteCodeArguments.size()!=0)                byteCodeTag.setArguments(byteCodeArguments);            byteCodeArguments=null;        }        if (element.compareToIgnoreCase("BC_arg") ==0 ) {            if(byteCodeArgumentTag!=null)                byteCodeArguments.add(byteCodeArgumentTag);            byteCodeArgumentTag=null;        }    }          }

⌨️ 快捷键说明

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