1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /** 6 * Licensed to the Apache Software Foundation (ASF) under one 7 * or more contributor license agreements. See the NOTICE file 8 * distributed with this work for additional information 9 * regarding copyright ownership. The ASF licenses this file 10 * to you under the Apache License, Version 2.0 (the 11 * "License"); you may not use this file except in compliance 12 * with the License. You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, 17 * software distributed under the License is distributed on an 18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19 * KIND, either express or implied. See the License for the 20 * specific language governing permissions and limitations 21 * under the License. 22 */ 23 package com.sun.org.apache.xml.internal.security.utils; 24 25 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 26 import org.w3c.dom.Element; 27 import org.w3c.dom.Node; 28 29 /**@deprecated*/ 30 @Deprecated 31 public abstract class ElementCheckerImpl implements ElementChecker { 32 33 public boolean isNamespaceElement(Node el, String type, String ns) { 34 if ((el == null) || 35 ns != el.getNamespaceURI() || !el.getLocalName().equals(type)){ 36 return false; 37 } 38 39 return true; 40 } 41 42 /** A checker for DOM that interns NS */ 43 public static class InternedNsChecker extends ElementCheckerImpl { 44 public void guaranteeThatElementInCorrectSpace( 45 ElementProxy expected, Element actual 46 ) throws XMLSecurityException { 47 48 String expectedLocalname = expected.getBaseLocalName(); 49 String expectedNamespace = expected.getBaseNamespace(); 50 51 String localnameIS = actual.getLocalName(); 52 String namespaceIS = actual.getNamespaceURI(); 53 if ((expectedNamespace != namespaceIS) || 54 !expectedLocalname.equals(localnameIS)) { 55 Object exArgs[] = { namespaceIS + ":" + localnameIS, 56 expectedNamespace + ":" + expectedLocalname}; 57 throw new XMLSecurityException("xml.WrongElement", exArgs); 58 } 59 } 60 } 61 62 /** A checker for DOM that interns NS */ 63 public static class FullChecker extends ElementCheckerImpl { 64 65 public void guaranteeThatElementInCorrectSpace( 66 ElementProxy expected, Element actual 67 ) throws XMLSecurityException { 68 String expectedLocalname = expected.getBaseLocalName(); 69 String expectedNamespace = expected.getBaseNamespace(); 70 71 String localnameIS = actual.getLocalName(); 72 String namespaceIS = actual.getNamespaceURI(); 73 if ((!expectedNamespace.equals(namespaceIS)) || 74 !expectedLocalname.equals(localnameIS) ) { 75 Object exArgs[] = { namespaceIS + ":" + localnameIS, 76 expectedNamespace + ":" + expectedLocalname}; 77 throw new XMLSecurityException("xml.WrongElement", exArgs); 78 } 79 } 80 } 81 82 /** An empty checker if schema checking is used */ 83 public static class EmptyChecker extends ElementCheckerImpl { 84 public void guaranteeThatElementInCorrectSpace( 85 ElementProxy expected, Element actual 86 ) throws XMLSecurityException { 87 // empty 88 } 89 } 90 }