📄 permissionxmlparser.java
字号:
/*
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jdon.framework.test.service;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import com.jdon.controller.config.DTDEntityResolver;
import com.jdon.util.Debug;
import com.jdon.util.FileLocator;
/**
* @author <a href="mailto:banqJdon <AT>jdon.com">banq </a>
*
*/
public class PermissionXmlParser {
private final static String module = PermissionXmlParser.class.getName();
private FileLocator fileLocator = new FileLocator();
private Document doc;
private String configFileName;
/**
* @param permissionConfigureName
*/
public PermissionXmlParser(String configFileName) {
this.configFileName = configFileName;
}
public void parse(PermissionInterceptor permissionInterceptor) {
try {
if (configFileName == null)
return ;
if (doc == null){
buildDocument(configFileName);
}
if (doc == null)
return;
Element root = doc.getRootElement();
parse(root, permissionInterceptor);
Debug.logVerbose("<!-- config load finished -->", module);
} catch (Exception ex) {
Debug.logError("configure FileName: " + configFileName + " parsed error: " + ex, module);
}
}
private void buildDocument(String configFileName) {
Debug.logVerbose(" locate configure file :" + configFileName, module);
try {
InputStream xmlStream = fileLocator.getConfPathXmlStream(configFileName);
if (xmlStream == null){
Debug.logVerbose("can't locate file:" + configFileName, module);
return;
}else{
Debug.logVerbose(" configure file found :" + xmlStream, module);
}
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new DTDEntityResolver());
this.doc = builder.build(xmlStream);
Debug.logVerbose(" got mapping file ", module);
} catch (JDOMException e) {
Debug.logError(" JDOMException error: " + e, module);
}
}
public void parse(Element root, PermissionInterceptor permissionInterceptor) throws Exception {
List services = root.getChildren("service");
Iterator iter = services.iterator();
while (iter.hasNext()) {
Element service = (Element) iter.next();
String refName = service.getAttributeValue("ref");
if (service.getChildren("method") != null) {
Iterator i = service.getChildren("method").iterator();
while (i.hasNext()) {
Element method = (Element) i.next();
String methodName = method.getAttributeValue("name");
Debug.logVerbose(" method name=" + methodName, module);
List roles = method.getChildren("role");
Iterator ii = roles.iterator();
while (ii.hasNext()) {
Element role = (Element)ii.next();
String roleName = role.getText();
Debug.logVerbose(" role name=" + roleName, module);
permissionInterceptor.putRule(refName, methodName, roleName);
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -