1 17 package com.sun.org.apache.xml.internal.security.transforms.params; 18 19 20 21 import java.util.Iterator ; 22 import java.util.Set ; 23 import java.util.SortedSet ; 24 import java.util.StringTokenizer ; 25 import java.util.TreeSet ; 26 27 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 28 import com.sun.org.apache.xml.internal.security.transforms.TransformParam; 29 import com.sun.org.apache.xml.internal.security.utils.ElementProxy; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 33 34 43 public class InclusiveNamespaces extends ElementProxy 44 implements TransformParam { 45 46 47 public static final String _TAG_EC_INCLUSIVENAMESPACES = 48 "InclusiveNamespaces"; 49 50 51 public static final String _ATT_EC_PREFIXLIST = "PrefixList"; 52 53 54 public static final String ExclusiveCanonicalizationNamespace = 55 "http://www.w3.org/2001/10/xml-exc-c14n#"; 56 57 63 public InclusiveNamespaces(Document doc, String prefixList) { 64 this(doc, InclusiveNamespaces.prefixStr2Set(prefixList)); 65 } 66 67 73 public InclusiveNamespaces(Document doc, Set prefixes) { 74 75 super(doc); 76 77 StringBuffer sb = new StringBuffer (); 78 SortedSet prefixList = new TreeSet (prefixes); 79 80 81 Iterator it = prefixList.iterator(); 82 83 while (it.hasNext()) { 84 String prefix = (String ) it.next(); 85 86 if (prefix.equals("xmlns")) { 87 sb.append("#default "); 88 } else { 89 sb.append(prefix + " "); 90 } 91 } 92 93 this._constructionElement 94 .setAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST, 95 sb.toString().trim()); 96 } 97 98 103 public String getInclusiveNamespaces() { 104 return this._constructionElement 105 .getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST); 106 } 107 108 115 public InclusiveNamespaces(Element element, String BaseURI) 116 throws XMLSecurityException { 117 super(element, BaseURI); 118 } 119 120 137 public static SortedSet prefixStr2Set(String inclusiveNamespaces) { 138 139 SortedSet prefixes = new TreeSet (); 140 141 if ((inclusiveNamespaces == null) 142 || (inclusiveNamespaces.length() == 0)) { 143 return prefixes; 144 } 145 146 StringTokenizer st = new StringTokenizer (inclusiveNamespaces, " \t\r\n"); 147 148 while (st.hasMoreTokens()) { 149 String prefix = st.nextToken(); 150 151 if (prefix.equals("#default")) { 152 prefixes.add("xmlns" ); 153 } else { 154 prefixes.add( prefix); 155 } 156 } 157 158 return prefixes; 159 } 160 161 166 public String getBaseNamespace() { 167 return InclusiveNamespaces.ExclusiveCanonicalizationNamespace; 168 } 169 170 175 public String getBaseLocalName() { 176 return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES; 177 } 178 } 179 | Popular Tags |