📄 domrulesetunmarshaller.java
字号:
/*
* jRevProxy, an opensource Java reverse proxy server
*
* 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, USA.
*
* $Id: DOMRulesetUnmarshaller.java,v 2.5 2003/03/27 15:53:57 fnoe Exp $
*/
package cx.noe.jrevproxy;
import cx.noe.jrevproxy.Ruleset;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* DOMRulesetUnmarshaller
*
* @author <a href="mailto:frederik@noe.cx">Frederik Noe</a>
* @version <tt>$Revision: 2.5 $</tt>
*/
public class DOMRulesetUnmarshaller {
public Ruleset unmarshallRuleset(Node rootNode) throws Exception{
Ruleset rset = new Ruleset();
Node n;
NodeList nodes = rootNode.getChildNodes();
for(int i=0 ; i<nodes.getLength(); i++) {
n = nodes.item( i );
if(n.getNodeType() == Node.ELEMENT_NODE) {
if( n.getNodeName().equals("rule"))
rset.addRule(unmarshallRule(n));
else {
// unexpected element in Ruleset
}
}
else {
// unexpected node-type in Ruleset
}
}
return rset;
}
private Rule unmarshallRule(Node node) throws Exception{
Rule rule = new Rule();
Node n;
NodeList nodes = node.getChildNodes();
for( int i=0 ; i<nodes.getLength(); i++ ) {
n = nodes.item( i );
if( n.getNodeType() == Node.ELEMENT_NODE ) {
if( n.getNodeName().equals("name")) {
rule.setName( unmarshallText(n));
}
else if(n.getNodeName().equals("virtualdir")) {
rule.setVirtualDir(unmarshallText(n));
}
else if (n.getNodeName().equals("junction")){
rule.setJunction((unmarshallText(n)));
}
else if (n.getNodeName().equals("users")) {
rule = unmarshallUsers(n,rule);
}
}else {
// unexpected node-type in Rule
}
}
return rule;
}
private Rule unmarshallUsers(Node node, Rule rule) {
Node n;
NodeList nodes = node.getChildNodes();
for( int i=0 ; i<nodes.getLength(); i++ ) {
n = nodes.item( i );
if( n.getNodeType() == Node.ELEMENT_NODE ) {
if( n.getNodeName().equals("subjectdn")) {
rule.addUser(unmarshallText(n));
}
else {
// unexpected node-type in Users
}
}
else {
// unexpected node-type in Users
}
}
return rule;
}
private String unmarshallText( Node textNode ) {
StringBuffer buf = new StringBuffer();
Node n;
NodeList nodes = textNode.getChildNodes();
for( int i=0; i<nodes.getLength(); i++ ){
n = nodes.item( i );
if( n.getNodeType() == Node.TEXT_NODE ) {
buf.append( n.getNodeValue() );
}else{
// expected a text-only node!
}
}
return buf.toString().trim();
}
private String unmarshallAttribute( Node node, String name, String defaultValue ) {
Node n = node.getAttributes().getNamedItem( name );
return (n!=null)?(n.getNodeValue()):(defaultValue);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -