|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcs.advanced.variables;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.*;
/**
* This class provides input/output of conditions from/to xml file.
*
* @author Martin Entlicher
*/
public class ConditionIO extends Object {
public static final String CONDITION_TAG = "condition"; // NOI18N
public static final String CONDITION_VAR_ATTR = "var"; // NOI18N
public static final String VAR_TAG = "var"; // NOI18N
public static final String VAR_NAME_ATTR = "name"; // NOI18N
public static final String VAR_VALUE_ATTR = "value"; // NOI18N
public static final String VAR_VALUE_IGNORE_CASE_ATTR = "valueIgnoreCase"; // NOI18N
public static final String VAR_VALUE_CONTAINS_ATTR = "valueContains"; // NOI18N
public static final String VAR_VALUE_CONTAINS_IGNORE_CASE_ATTR = "valueContainsIgnoreCase"; // NOI18N
public static final String AND_TAG = "and"; // NOI18N
public static final String OR_TAG = "or"; // NOI18N
public static final String NOT_TAG = "not"; // NOI18N
/** Creates a new instance of ConditionIO */
private ConditionIO() {
}
/**
* Read a list of conditions from the specified document.
*/
public static Condition[] readConditions(Document doc) throws DOMException {
List conditions = new ArrayList();
Element rootElem = doc.getDocumentElement();
if (!VariableIO.CONFIG_ROOT_ELEM.equals(rootElem.getNodeName())) return null;
NodeList conditionsList = rootElem.getElementsByTagName(CONDITION_TAG);
int n = conditionsList.getLength();
for (int i = 0; i < n; i++) {
Element conditionElement = (Element) conditionsList.item(i);
NamedNodeMap attrs = conditionElement.getAttributes();
if (attrs.getLength() == 0) continue;
Node varAttrNode = attrs.getNamedItem(CONDITION_VAR_ATTR);
if (varAttrNode == null) continue;
String varName = varAttrNode.getNodeValue();
Condition c = new Condition(varName);
readCondition(c, conditionElement);
conditions.add(c);
}
return (Condition[]) conditions.toArray(new Condition[conditions.size()]);
}
private static void readCondition(Condition c, Element conditionElement) throws DOMException {
String[] varValuePtr = new String[1];
int[] compareValuePtr = new int[1];
NodeList children = conditionElement.getChildNodes();
int n = children.getLength();
List elements = new ArrayList();
for (int i = 0; i < n; i++) {
Node node = children.item(i);
if (Node.ELEMENT_NODE != node.getNodeType()) {
continue;
}
elements.add(node);
}
n = elements.size();
for (int i = 0; i < n; i++) {
Element elem = (Element) elements.get(i);
String tagName = elem.getTagName();
if (VAR_TAG.equals(tagName)) {
String name = readVariable(elem, varValuePtr, compareValuePtr);
if (name == null) continue;
c.addVar(name, varValuePtr[0], compareValuePtr[0], true);
} else if (NOT_TAG.equals(tagName)) {
NodeList notChildren = elem.getChildNodes();
int nn = notChildren.getLength();
for (int ni = 0; ni < nn; ni++) {
Node nnode = notChildren.item(ni);
if (Node.ELEMENT_NODE != nnode.getNodeType()) continue;
Element nvar = (Element) nnode;
String name = readVariable(nvar, varValuePtr, compareValuePtr);
if (name == null) continue;
c.addVar(name, varValuePtr[0], compareValuePtr[0], false);
}
} else if (AND_TAG.equals(tagName)) {
if (n == 1) { // just
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.