1/* 2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25/* 26 * $Id: XPathFilterParameterSpec.java,v 1.4 2005/05/10 16:40:17 mullan Exp $ 27 */ 28package javax.xml.crypto.dsig.spec; 29 30import javax.xml.crypto.dsig.Transform; 31import java.util.Collections; 32import java.util.HashMap; 33import java.util.Iterator; 34import java.util.Map; 35 36/** 37 * Parameters for the <a href="http://www.w3.org/TR/xmldsig-core/#sec-XPath"> 38 * XPath Filtering Transform Algorithm</a>. 39 * The parameters include the XPath expression and an optional <code>Map</code> 40 * of additional namespace prefix mappings. The XML Schema Definition of 41 * the XPath Filtering transform parameters is defined as: 42 * <pre><code> 43 * <element name="XPath" type="string"/> 44 * </code></pre> 45 * 46 * @author Sean Mullan 47 * @author JSR 105 Expert Group 48 * @since 1.6 49 * @see Transform 50 */ 51public final class XPathFilterParameterSpec implements TransformParameterSpec { 52 53 private final String xPath; 54 private final Map<String,String> nsMap; 55 56 /** 57 * Creates an <code>XPathFilterParameterSpec</code> with the specified 58 * XPath expression. 59 * 60 * @param xPath the XPath expression to be evaluated 61 * @throws NullPointerException if <code>xPath</code> is <code>null</code> 62 */ 63 public XPathFilterParameterSpec(String xPath) { 64 if (xPath == null) { 65 throw new NullPointerException(); 66 } 67 this.xPath = xPath; 68 this.nsMap = Collections.emptyMap(); 69 } 70 71 /** 72 * Creates an <code>XPathFilterParameterSpec</code> with the specified 73 * XPath expression and namespace map. The map is copied to protect against 74 * subsequent modification. 75 * 76 * @param xPath the XPath expression to be evaluated 77 * @param namespaceMap the map of namespace prefixes. Each key is a 78 * namespace prefix <code>String</code> that maps to a corresponding 79 * namespace URI <code>String</code>. 80 * @throws NullPointerException if <code>xPath</code> or 81 * <code>namespaceMap</code> are <code>null</code> 82 * @throws ClassCastException if any of the map's keys or entries are not 83 * of type <code>String</code> 84 */ 85 public XPathFilterParameterSpec(String xPath, Map<String,String> namespaceMap) { 86 if (xPath == null || namespaceMap == null) { 87 throw new NullPointerException(); 88 } 89 this.xPath = xPath; 90 Map<String,String> tempMap = Collections.checkedMap(new HashMap<>(), 91 String.class, 92 String.class); 93 tempMap.putAll(namespaceMap); 94 this.nsMap = Collections.unmodifiableMap(tempMap); 95 } 96 97 /** 98 * Returns the XPath expression to be evaluated. 99 * 100 * @return the XPath expression to be evaluated 101 */ 102 public String getXPath() { 103 return xPath; 104 } 105 106 /** 107 * Returns a map of namespace prefixes. Each key is a namespace prefix 108 * <code>String</code> that maps to a corresponding namespace URI 109 * <code>String</code>. 110 * <p> 111 * This implementation returns an {@link Collections#unmodifiableMap 112 * unmodifiable map}. 113 * 114 * @return a <code>Map</code> of namespace prefixes to namespace URIs (may 115 * be empty, but never <code>null</code>) 116 */ 117 public Map<String,String> getNamespaceMap() { 118 return nsMap; 119 } 120} 121