📄 acldaoxml.java
字号:
/* * XP Forum * * Copyright (c) 2002-2003 RedSoft Group. All rights reserved. * */package org.redsoft.forum.dao.xml;import java.io.File;import java.util.Hashtable;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.redsoft.forum.dao.AclDAO;import org.redsoft.forum.security.ProtectedResource;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/** * AclDAO's implmentation for xml * * @@author <a href="mailto:chjxm@msn.com">cinc</a> * * @@version $Id: AclDAOxml.java,v 1.2 2004/04/10 19:56:59 cinc Exp $ */public class AclDAOxml implements AclDAO{ /** * A hashtable that contains protected resources */ protected Hashtable protectedResourceTable = new Hashtable(); /** * Constructor, read protected Resource infomation from acl-config.xml, * and save them to a hashtable * * @param filename full filename of acl-config.xml */ public AclDAOxml(String filename){ int i; File xmlFile = new File( filename ); Document doc = null; try{ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // validate xml file by parser // that is: use a dtd file to validate the xml file dbf.setValidating(true); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse( xmlFile ); Element root = doc.getDocumentElement(); NodeList nodes = root.getChildNodes(); for (i=0; i<nodes.getLength() ; i++){ Node node = nodes.item(i); if (node.getNodeName().equals( ProtectedResource.PROPERTY_PROTECTED_RESOURCE )){ ProtectedResource pr = parseNode(node); //System.out.println (pr.getUri()+":"+pr.getDesc()); protectedResourceTable.put( pr.getUri(), pr ); } } }catch(Exception e){ System.out.println ("Error reading acl-config.xml: " + e); } } /** * Read uri and desc from a protected-resource node * * @param protectedResourceNode node of protected resource in xml file */ protected ProtectedResource parseNode(Node protectedResourceNode){ String property, value; NodeList nodes = protectedResourceNode.getChildNodes(); String uri = null; String desc = null; for (int i=0; i<nodes.getLength() ; i++){ Node node = nodes.item(i); if (node.getNodeName().equals( "#text" )){ continue; } property = node.getNodeName(); value = node.getFirstChild().getNodeValue(); if ( property.equals( ProtectedResource.PROPERTY_URI ) ){ uri = value; }else if ( property.equals( ProtectedResource.PROPERTY_DESC ) ){ desc = value; } } return new ProtectedResource(uri, desc); } /** * Check if a uri is a protected Resource * * @return boolean - if this uri is a protected Resource */ public boolean isProtectedResource(String uri){ return protectedResourceTable.containsKey(uri); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -