List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMObligationExpression.java
public static boolean repair(Node nodeObligationExpression) throws DOMStructureException { Element elementObligationExpression = DOMUtil.getElement(nodeObligationExpression); boolean result = false; NodeList children = elementObligationExpression.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEASSIGNMENTEXPRESSION.equals(child.getLocalName())) { result = DOMAttributeAssignmentExpression.repair(child) || result; } else { logger.warn("Unexpected element " + child.getNodeName()); elementObligationExpression.removeChild(child); result = true;/*from w w w . ja v a2s.co m*/ } } } } result = DOMUtil.repairIdentifierAttribute(elementObligationExpression, XACML3.ATTRIBUTE_OBLIGATIONID, logger) || result; result = DOMUtil.repairStringAttribute(elementObligationExpression, XACML3.ATTRIBUTE_FULFILLON, RuleEffect.DENY.getName(), logger) || result; String string = DOMUtil.getStringAttribute(elementObligationExpression, XACML3.ATTRIBUTE_FULFILLON); RuleEffect ruleEffectType = RuleEffect.getRuleEffect(string); if (ruleEffectType == null) { logger.warn("Setting invalid RuleEffect " + string + " to " + RuleEffect.DENY.getName()); elementObligationExpression.setAttribute(XACML3.ATTRIBUTE_FULFILLON, RuleEffect.DENY.getName()); result = true; } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMObligationExpression.java
public static boolean repairList(Node nodeObligationExpressions) throws DOMStructureException { Element elementObligationExpressions = DOMUtil.getElement(nodeObligationExpressions); boolean result = false; boolean sawObligationExpression = false; NodeList children = elementObligationExpressions.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_OBLIGATIONEXPRESSION.equals(child.getLocalName())) { result = DOMObligationExpression.repair(child) || result; sawObligationExpression = true; } else { logger.warn("Unexpected element " + child.getNodeName()); elementObligationExpressions.removeChild(child); result = true;/* w w w.ja va 2 s. co m*/ } } } } if (!sawObligationExpression) { throw DOMUtil.newMissingElementException(elementObligationExpressions, XACML3.XMLNS, XACML3.ELEMENT_OBLIGATIONEXPRESSION); } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicy.java
public static boolean repair(Node nodePolicy) throws DOMStructureException { Element elementPolicy = DOMUtil.getElement(nodePolicy); boolean result = false; NodeList children = elementPolicy.getChildNodes(); int numChildren; boolean sawDescription = false; boolean sawIssuer = false; boolean sawTarget = false; boolean sawPolicyDefaults = false; boolean sawObligationExprs = false; boolean sawAdviceExprs = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child) && DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_DESCRIPTION.equals(childName)) { if (sawDescription) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true;/*from w ww. j a v a2 s . c o m*/ } else { sawDescription = true; } } else if (XACML3.ELEMENT_POLICYISSUER.equals(childName)) { if (sawIssuer) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } else { sawDescription = true; result = DOMPolicyIssuer.repair(child) || result; } } else if (XACML3.ELEMENT_POLICYDEFAULTS.equals(childName)) { if (sawPolicyDefaults) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } else { sawPolicyDefaults = true; result = DOMPolicyDefaults.repair(child) || result; } } else if (XACML3.ELEMENT_TARGET.equals(childName)) { if (sawTarget) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } else { sawTarget = true; result = DOMTarget.repair(child) || result; } } else if (XACML3.ELEMENT_COMBINERPARAMETERS.equals(childName)) { result = DOMCombinerParameter.repair(child) || result; } else if (XACML3.ELEMENT_RULECOMBINERPARAMETERS.equals(childName)) { result = DOMRuleCombinerParameters.repair(child) || result; } else if (XACML3.ELEMENT_VARIABLEDEFINITION.equals(childName)) { result = DOMVariableDefinition.repair(child) || result; } else if (XACML3.ELEMENT_RULE.equals(childName)) { result = DOMRule.repair(child) || result; } else if (XACML3.ELEMENT_OBLIGATIONEXPRESSIONS.equals(childName)) { if (sawObligationExprs) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } else { sawObligationExprs = true; result = DOMObligationExpression.repairList(child) || result; } } else if (XACML3.ELEMENT_ADVICEEXPRESSIONS.equals(childName)) { if (sawAdviceExprs) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } else { sawAdviceExprs = true; result = DOMAdviceExpression.repairList(child) || result; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicy.removeChild(child); result = true; } } } } result = DOMUtil.repairIdentifierAttribute(elementPolicy, XACML3.ATTRIBUTE_POLICYID, logger) || result; result = DOMUtil.repairVersionAttribute(elementPolicy, XACML3.ATTRIBUTE_VERSION, logger) || result; result = DOMUtil.repairIdentifierAttribute(elementPolicy, XACML3.ATTRIBUTE_RULECOMBININGALGID, XACML3.ID_RULE_DENY_OVERRIDES, logger) || result; Identifier identifier = DOMUtil.getIdentifierAttribute(elementPolicy, XACML3.ATTRIBUTE_RULECOMBININGALGID); CombiningAlgorithm<Rule> combiningAlgorithmRule = null; try { combiningAlgorithmRule = CombiningAlgorithmFactory.newInstance().getRuleCombiningAlgorithm(identifier); } catch (FactoryException ex) { combiningAlgorithmRule = null; } if (combiningAlgorithmRule == null) { logger.warn("Setting invalid " + XACML3.ATTRIBUTE_RULECOMBININGALGID + " attribute " + identifier.stringValue() + " to " + XACML3.ID_RULE_DENY_OVERRIDES.stringValue()); elementPolicy.setAttribute(XACML3.ATTRIBUTE_RULECOMBININGALGID, XACML3.ID_RULE_DENY_OVERRIDES.stringValue()); result = true; } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicyCombinerParameter.java
public static boolean repair(Node nodePolicyCombinerParameter) throws DOMStructureException { Element elementPolicyCombinerParameter = DOMUtil.getElement(nodePolicyCombinerParameter); boolean result = false; NodeList children = elementPolicyCombinerParameter.getChildNodes(); int numChildren; boolean sawAttributeValue = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) { if (sawAttributeValue) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicyCombinerParameter.removeChild(child); result = true;// w w w . ja v a2 s. com } else { sawAttributeValue = true; result = DOMAttributeValue.repair(child) || result; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicyCombinerParameter.removeChild(child); result = true; } } } } if (!sawAttributeValue) { throw DOMUtil.newMissingElementException(nodePolicyCombinerParameter, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE); } result = DOMUtil.repairStringAttribute(elementPolicyCombinerParameter, XACML3.ATTRIBUTE_PARAMETERNAME, "parameter", logger) || result; result = DOMUtil.repairIdentifierAttribute(elementPolicyCombinerParameter, XACML3.ATTRIBUTE_POLICYIDREF, logger) || result; return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicyDefaults.java
public static boolean repair(Node nodePolicyDefaults) throws DOMStructureException { Element elementPolicyDefaults = DOMUtil.getElement(nodePolicyDefaults); boolean result = false; NodeList children = elementPolicyDefaults.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_XPATHVERSION.equals(child.getLocalName())) { try { DOMUtil.getURIContent(child); } catch (DOMStructureException ex) { logger.warn("Setting invalid " + XACML3.ELEMENT_XPATHVERSION + " attribute " + child.getTextContent() + " to " + XACML.XPATHVERSION_2_0); child.setTextContent(XACML.XPATHVERSION_2_0); result = true;//w ww. ja v a2s .co m } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicyDefaults.removeChild(child); result = true; } } } } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicyIssuer.java
public static boolean repair(Node nodePolicyIssuer) throws DOMStructureException { Element elementPolicyIssuer = DOMUtil.getElement(nodePolicyIssuer); boolean result = false; boolean sawContent = false; NodeList children = elementPolicyIssuer.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child) && DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_CONTENT.equals(childName)) { if (sawContent) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicyIssuer.removeChild(child); result = true;/*from www . j a v a 2s. c o m*/ } else { sawContent = true; } } else if (XACML3.ELEMENT_ATTRIBUTE.equals(childName)) { result = DOMAttribute.repair(child) || result; } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicyIssuer.removeChild(child); result = true; } } } } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicySet.java
public static boolean repair(Node nodePolicySet) throws DOMStructureException { Element elementPolicySet = DOMUtil.getElement(nodePolicySet); boolean result = false; NodeList children = elementPolicySet.getChildNodes(); int numChildren; boolean sawDescription = false; boolean sawPolicyIssuer = false; boolean sawPolicyDefaults = false; boolean sawTarget = false; boolean sawObligationExprs = false; boolean sawAdviceExprs = false; if (children != null && (numChildren = children.getLength()) > 0) { /*/*from w ww. j a va2 s . c o m*/ * Now process the other elements so we can pull up the parent policy defaults */ for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_DESCRIPTION.equals(childName)) { if (sawDescription) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawDescription = true; } } else if (XACML3.ELEMENT_POLICYISSUER.equals(childName)) { if (sawPolicyIssuer) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawPolicyIssuer = true; result = DOMPolicyIssuer.repair(child) || result; } } else if (XACML3.ELEMENT_POLICYSETDEFAULTS.equals(childName)) { if (sawPolicyDefaults) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawPolicyDefaults = true; result = DOMPolicyDefaults.repair(child) || result; } } else if (XACML3.ELEMENT_TARGET.equals(childName)) { if (sawTarget) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawTarget = true; result = DOMTarget.repair(child) || result; } } else if (XACML3.ELEMENT_POLICYSET.equals(childName)) { result = DOMPolicySet.repair(child) || result; } else if (XACML3.ELEMENT_POLICY.equals(childName)) { result = DOMPolicy.repair(child) || result; } else if (XACML3.ELEMENT_POLICYIDREFERENCE.equals(childName)) { result = DOMPolicyIdReference.repair(child) || result; } else if (XACML3.ELEMENT_POLICYSETIDREFERENCE.equals(childName)) { result = DOMPolicySetIdReference.repair(child) || result; } else if (XACML3.ELEMENT_COMBINERPARAMETERS.equals(childName)) { result = DOMCombinerParameter.repair(child) || result; } else if (XACML3.ELEMENT_POLICYCOMBINERPARAMETERS.equals(childName)) { result = DOMPolicyCombinerParameter.repair(child) || result; } else if (XACML3.ELEMENT_POLICYSETCOMBINERPARAMETERS.equals(childName)) { result = DOMPolicySetCombinerParameter.repair(child) || result; } else if (XACML3.ELEMENT_OBLIGATIONEXPRESSIONS.equals(childName)) { if (sawObligationExprs) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawObligationExprs = true; result = DOMObligationExpression.repairList(child) || result; } } else if (XACML3.ELEMENT_ADVICEEXPRESSIONS.equals(childName)) { if (sawAdviceExprs) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } else { sawAdviceExprs = true; result = DOMAdviceExpression.repairList(child) || result; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySet.removeChild(child); result = true; } } } } if (!sawTarget) { throw DOMUtil.newMissingElementException(nodePolicySet, XACML3.XMLNS, XACML3.ELEMENT_TARGET); } /* * Get the attributes */ result = DOMUtil.repairIdentifierAttribute(elementPolicySet, XACML3.ATTRIBUTE_POLICYSETID, logger) || result; result = DOMUtil.repairVersionAttribute(elementPolicySet, XACML3.ATTRIBUTE_VERSION, logger) || result; result = DOMUtil.repairIdentifierAttribute(elementPolicySet, XACML3.ATTRIBUTE_POLICYCOMBININGALGID, XACML3.ID_POLICY_DENY_OVERRIDES, logger) || result; Identifier identifier = DOMUtil.getIdentifierAttribute(elementPolicySet, XACML3.ATTRIBUTE_POLICYCOMBININGALGID); CombiningAlgorithm<PolicySetChild> combiningAlgorithm = null; try { combiningAlgorithm = CombiningAlgorithmFactory.newInstance().getPolicyCombiningAlgorithm(identifier); } catch (FactoryException ex) { combiningAlgorithm = null; } if (combiningAlgorithm == null) { logger.warn("Setting invalid " + XACML3.ATTRIBUTE_POLICYCOMBININGALGID + " attribute " + identifier.stringValue() + " to " + XACML3.ID_POLICY_DENY_OVERRIDES.stringValue()); elementPolicySet.setAttribute(XACML3.ATTRIBUTE_POLICYCOMBININGALGID, XACML3.ID_POLICY_DENY_OVERRIDES.stringValue()); result = true; } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMPolicySetCombinerParameter.java
public static boolean repair(Node nodeCombinerParameter) throws DOMStructureException { Element elementPolicySetCombinerParameter = DOMUtil.getElement(nodeCombinerParameter); boolean result = false; NodeList children = elementPolicySetCombinerParameter.getChildNodes(); int numChildren; boolean sawAttributeValue = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) { if (sawAttributeValue) { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySetCombinerParameter.removeChild(child); result = true;// w w w . jav a2s .co m } else { sawAttributeValue = true; result = DOMAttributeValue.repair(child) || result; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementPolicySetCombinerParameter.removeChild(child); result = true; } } } } if (!sawAttributeValue) { throw DOMUtil.newMissingElementException(elementPolicySetCombinerParameter, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE); } result = DOMUtil.repairStringAttribute(elementPolicySetCombinerParameter, XACML3.ATTRIBUTE_PARAMETERNAME, "parameter", logger) || result; result = DOMUtil.repairIdentifierAttribute(elementPolicySetCombinerParameter, XACML3.ATTRIBUTE_POLICYSETIDREF, logger) || result; return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMRule.java
public static boolean repair(Node nodeRule) throws DOMStructureException { Element elementRule = DOMUtil.getElement(nodeRule); boolean result = false; NodeList children = elementRule.getChildNodes(); int numChildren; boolean sawDescription = false; boolean sawTarget = false; boolean sawCondition = false; boolean sawObligationExpressions = false; boolean sawAdviceExpressions = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_DESCRIPTION.equals(childName)) { if (sawDescription) { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } else { sawDescription = true; }/* w w w . j a v a 2 s .c o m*/ } else if (XACML3.ELEMENT_TARGET.equals(childName)) { if (sawTarget) { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } else { sawTarget = true; result = DOMTarget.repair(child) || result; } } else if (XACML3.ELEMENT_CONDITION.equals(childName)) { if (sawCondition) { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } else { sawCondition = true; Node nodeExpression = DOMUtil.getFirstChildElement(child); if (nodeExpression == null) { throw DOMUtil.newMissingElementException(child, XACML3.XMLNS, XACML3.ELEMENT_EXPRESSION); } result = DOMExpression.repair(nodeExpression) || result; } } else if (XACML3.ELEMENT_OBLIGATIONEXPRESSIONS.equals(childName)) { if (sawObligationExpressions) { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } else { sawObligationExpressions = true; result = DOMObligationExpression.repairList(child) || result; } } else if (XACML3.ELEMENT_ADVICEEXPRESSIONS.equals(childName)) { if (sawAdviceExpressions) { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } else { sawAdviceExpressions = true; result = DOMAdviceExpression.repairList(child) || result; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementRule.removeChild(child); result = true; } } } } result = DOMUtil.repairStringAttribute(elementRule, XACML3.ATTRIBUTE_RULEID, IdentifierImpl.gensym().stringValue(), logger) || result; result = DOMUtil.repairStringAttribute(elementRule, XACML3.ATTRIBUTE_EFFECT, RuleEffect.DENY.getName(), logger) || result; String string = DOMUtil.getStringAttribute(elementRule, XACML3.ATTRIBUTE_EFFECT); RuleEffect ruleEffect = RuleEffect.getRuleEffect(string); if (ruleEffect == null) { logger.warn("Setting invalid " + XACML3.ATTRIBUTE_EFFECT + " attribute " + string + " to " + RuleEffect.DENY.getName()); elementRule.setAttribute(XACML3.ATTRIBUTE_EFFECT, RuleEffect.DENY.getName()); result = true; } return result; }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMRuleCombinerParameters.java
public static boolean repair(Node nodeRuleCombinerParameters) throws DOMStructureException { Element elementRuleCombinerParameters = DOMUtil.getElement(nodeRuleCombinerParameters); boolean result = false; NodeList children = elementRuleCombinerParameters.getChildNodes(); int numChildren; boolean sawAttributeValue = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_ATTRIBUTEVALUE.equals(child.getLocalName())) { if (sawAttributeValue) { logger.warn("Unexpected element " + child.getNodeName()); elementRuleCombinerParameters.removeChild(child); result = true;/*from www .j a v a 2 s . c o m*/ } else { sawAttributeValue = true; result = result || DOMAttributeValue.repair(child); } } else { logger.warn("Unexpected element " + child.getNodeName()); elementRuleCombinerParameters.removeChild(child); result = true; } } } } if (!sawAttributeValue) { throw DOMUtil.newMissingElementException(nodeRuleCombinerParameters, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE); } result = result || DOMUtil.repairStringAttribute(elementRuleCombinerParameters, XACML3.ATTRIBUTE_PARAMETERNAME, "parameter", logger); result = result || DOMUtil.repairIdentifierAttribute(elementRuleCombinerParameters, XACML3.ATTRIBUTE_RULEIDREF, logger); return result; }