jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/params/InclusiveNamespaces.java
author mullan
Mon, 26 Sep 2011 17:20:45 -0700
changeset 10694 cf59e2badd14
parent 2 90ce3da70b43
child 18780 f47b920867e7
permissions -rw-r--r--
7088502: Security libraries don't build with javac -Werror Summary: Changes to files in src/share/classes/com/sun/org/apache/xml/internal/security and its subpackages to remove warnings Reviewed-by: mullan Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.transforms.params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.SortedSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.TreeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.transforms.TransformParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This Object serves as Content for the ds:Transforms for exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Canonicalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <BR />
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * It implements the {@link Element} interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * and can be used directly in a DOM tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class InclusiveNamespaces extends ElementProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        implements TransformParam {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
   /** Field _TAG_EC_INCLUSIVENAMESPACES */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   public static final String _TAG_EC_INCLUSIVENAMESPACES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      "InclusiveNamespaces";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   /** Field _ATT_EC_PREFIXLIST */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
   public static final String _ATT_EC_PREFIXLIST = "PrefixList";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
   /** Field ExclusiveCanonicalizationNamespace */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   public static final String ExclusiveCanonicalizationNamespace =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
      "http://www.w3.org/2001/10/xml-exc-c14n#";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * Constructor XPathContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    * @param doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    * @param prefixList
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   public InclusiveNamespaces(Document doc, String prefixList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      this(doc, InclusiveNamespaces.prefixStr2Set(prefixList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    * Constructor InclusiveNamespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * @param doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    * @param prefixes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 2
diff changeset
    77
   public InclusiveNamespaces(Document doc, Set<String> prefixes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      super(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      StringBuffer sb = new StringBuffer();
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 2
diff changeset
    82
      SortedSet<String> prefixList = new TreeSet<String>(prefixes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 2
diff changeset
    86
      for (String prefix : prefixList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         if (prefix.equals("xmlns")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            sb.append("#default ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            sb.append(prefix + " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      this._constructionElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         .setAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                       sb.toString().trim());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    * Method getInclusiveNamespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    * @return The Inclusive Namespace string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   public String getInclusiveNamespaces() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      return this._constructionElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         .getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    * Constructor InclusiveNamespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   public InclusiveNamespaces(Element element, String BaseURI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
           throws XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      super(element, BaseURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    * Decodes the <code>inclusiveNamespaces</code> String and returns all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    * selected namespace prefixes as a Set. The <code>#default</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    * namespace token is represented as an empty namespace prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    * (<code>"xmlns"</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    * <BR/>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    * The String <code>inclusiveNamespaces=" xenc    ds #default"</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    * is returned as a Set containing the following Strings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    * <LI><code>xmlns</code></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    * <LI><code>xenc</code></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    * <LI><code>ds</code></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    * @param inclusiveNamespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    * @return A set to string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 2
diff changeset
   138
   public static SortedSet<String> prefixStr2Set(String inclusiveNamespaces) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 2
diff changeset
   140
      SortedSet<String> prefixes = new TreeSet<String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      if ((inclusiveNamespaces == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
              || (inclusiveNamespaces.length() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         return prefixes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      StringTokenizer st = new StringTokenizer(inclusiveNamespaces, " \t\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         String prefix = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         if (prefix.equals("#default")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            prefixes.add("xmlns" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            prefixes.add( prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      return prefixes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    * Method getBaseNamespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
   public String getBaseNamespace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      return InclusiveNamespaces.ExclusiveCanonicalizationNamespace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    * Method getBaseLocalName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
   public String getBaseLocalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}