You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2008/01/07 19:53:26 UTC

svn commit: r609738 - in /xml/security/trunk/src/org/apache/xml/security/utils: ElementChecker.java ElementCheckerImpl.java

Author: raul
Date: Mon Jan  7 10:53:24 2008
New Revision: 609738

URL: http://svn.apache.org/viewvc?rev=609738&view=rev
Log:
Small refactor for ElementProxy to get rid of the state, it was an old 
vestige that where taking space and obfuscating the code.
Fixed bug 40897: String comparisons using '==' causes validation errors 
with some parsers. Thanks Vishal Mahajan

Added:
    xml/security/trunk/src/org/apache/xml/security/utils/ElementChecker.java
    xml/security/trunk/src/org/apache/xml/security/utils/ElementCheckerImpl.java

Added: xml/security/trunk/src/org/apache/xml/security/utils/ElementChecker.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/utils/ElementChecker.java?rev=609738&view=auto
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/utils/ElementChecker.java (added)
+++ xml/security/trunk/src/org/apache/xml/security/utils/ElementChecker.java Mon Jan  7 10:53:24 2008
@@ -0,0 +1,14 @@
+package org.apache.xml.security.utils;
+
+import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.w3c.dom.Element;
+
+public interface ElementChecker {
+	 /**
+	  * Check that the elemnt is the one expect
+	  *
+	  * @throws XMLSecurityException
+	  */
+	   void guaranteeThatElementInCorrectSpace(ElementProxy expected, Element actual)
+	           throws XMLSecurityException;
+}

Added: xml/security/trunk/src/org/apache/xml/security/utils/ElementCheckerImpl.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/utils/ElementCheckerImpl.java?rev=609738&view=auto
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/utils/ElementCheckerImpl.java (added)
+++ xml/security/trunk/src/org/apache/xml/security/utils/ElementCheckerImpl.java Mon Jan  7 10:53:24 2008
@@ -0,0 +1,51 @@
+package org.apache.xml.security.utils;
+
+import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.w3c.dom.Element;
+
+public class ElementCheckerImpl {
+	/** A checker for DOM that interns NS */
+	public static class InternedNsChecker implements ElementChecker {
+		public void guaranteeThatElementInCorrectSpace(ElementProxy expected,
+				Element actual) throws XMLSecurityException {
+
+		      String localnameSHOULDBE = expected.getBaseLocalName();
+		      String namespaceSHOULDBE = expected.getBaseNamespace();
+		      
+		      String localnameIS = actual.getLocalName();
+		      String namespaceIS = actual.getNamespaceURI();
+		      if ((namespaceSHOULDBE!=namespaceIS) ||
+		       !localnameSHOULDBE.equals(localnameIS) ) {      
+		         Object exArgs[] = { namespaceIS +":"+ localnameIS, 
+		           namespaceSHOULDBE +":"+ localnameSHOULDBE};
+		         throw new XMLSecurityException("xml.WrongElement", exArgs);
+		      }			
+		}		
+	}
+	
+	/** A checker for DOM that interns NS */
+	public static class FullChecker implements ElementChecker {
+		public void guaranteeThatElementInCorrectSpace(ElementProxy expected,
+				Element actual) throws XMLSecurityException {
+
+		      String localnameSHOULDBE = expected.getBaseLocalName();
+		      String namespaceSHOULDBE = expected.getBaseNamespace();
+		      
+		      String localnameIS = actual.getLocalName();
+		      String namespaceIS = actual.getNamespaceURI();
+		      if ((!namespaceSHOULDBE.equals(namespaceIS)) ||
+		       !localnameSHOULDBE.equals(localnameIS) ) {      
+		         Object exArgs[] = { namespaceIS +":"+ localnameIS, 
+		           namespaceSHOULDBE +":"+ localnameSHOULDBE};
+		         throw new XMLSecurityException("xml.WrongElement", exArgs);
+		      }			
+		}		
+	}
+	
+	/** An empty checker if schema checking is used */
+	public static class EmptyChecker implements ElementChecker {
+		public void guaranteeThatElementInCorrectSpace(ElementProxy expected,
+				Element actual) throws XMLSecurityException {
+		}		
+	}
+}