jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/XMLUtils.java
author mullan
Mon, 26 Sep 2011 17:20:45 -0700
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 18240 cda839ac048f
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.utils;
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.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.io.OutputStream;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    27
import java.security.AccessController;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    28
import java.security.PrivilegedAction;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    29
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    32
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.NamedNodeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import org.w3c.dom.Text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * DOM and XML accessibility and comfort functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class XMLUtils {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    55
   private static boolean ignoreLineBreaks =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    56
      AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    57
         public Boolean run() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    58
            return Boolean.getBoolean
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    59
               ("com.sun.org.apache.xml.internal.security.ignoreLineBreaks");
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    60
         }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    61
      });
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    * Constructor XMLUtils
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   private XMLUtils() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      // we don't allow instantiation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    71
   public static Element getNextElement(Node el) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    72
           while ((el!=null) && (el.getNodeType()!=Node.ELEMENT_NODE)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    73
                   el=el.getNextSibling();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    74
           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    75
           return (Element)el;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    77
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    * @param rootNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    * @param result
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    * @param exclude
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    * @param com wheather comments or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    85
   public static void getSet(Node rootNode,Set<Node> result,Node exclude ,boolean com) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
          if ((exclude!=null) && isDescendantOrSelf(exclude,rootNode)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      getSetRec(rootNode,result,exclude,com);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
   }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    91
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    92
   @SuppressWarnings("fallthrough")
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    93
   static final void getSetRec(final Node rootNode,final Set<Node> result,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        final Node exclude ,final boolean com) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
           //Set result = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
       if (rootNode==exclude) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
          return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
           switch (rootNode.getNodeType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                case Node.ELEMENT_NODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                result.add(rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                        Element el=(Element)rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                if (el.hasAttributes()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                NamedNodeMap nl = ((Element)rootNode).getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                for (int i=0;i<nl.getLength();i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                        result.add(nl.item(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   109
                //no return keep working - ignore fallthrough warning
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                case Node.DOCUMENT_NODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                for (Node r=rootNode.getFirstChild();r!=null;r=r.getNextSibling()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                        if (r.getNodeType()==Node.TEXT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                                result.add(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                                while ((r!=null) && (r.getNodeType()==Node.TEXT_NODE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                                        r=r.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                if (r==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                        getSetRec(r,result,exclude,com);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        case Node.COMMENT_NODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                if (com) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                        result.add(rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        case Node.DOCUMENT_TYPE_NODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                result.add(rootNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
           return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    * Outputs a DOM tree to an {@link OutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    * @param contextNode root node of the DOM tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    * @param os the {@link OutputStream}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   public static void outputDOM(Node contextNode, OutputStream os) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      XMLUtils.outputDOM(contextNode, os, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    * Outputs a DOM tree to an {@link OutputStream}. <I>If an Exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    * thrown during execution, it's StackTrace is output to System.out, but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    * Exception is not re-thrown.</I>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    * @param contextNode root node of the DOM tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    * @param os the {@link OutputStream}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    * @param addPreamble
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
   public static void outputDOM(Node contextNode, OutputStream os,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                boolean addPreamble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         if (addPreamble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            os.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         os.write(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            Canonicalizer.getInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
               Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS).canonicalizeSubtree(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
               contextNode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      } catch (IOException ex) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      catch (InvalidCanonicalizerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      } catch (CanonicalizationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    * Serializes the <CODE>contextNode</CODE> into the OutputStream, <I>but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    * supresses all Exceptions</I>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    * <BR />
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    * NOTE: <I>This should only be used for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    * NOT in a production environment; this method ignores all exceptions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    * so you won't notice if something goes wrong. If you're asking what is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    * be used in a production environment, simply use the code inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    * <code>try{}</code> statement, but handle the Exceptions appropriately.</I>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    * @param contextNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    * @param os
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
   public static void outputDOMc14nWithComments(Node contextNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
           OutputStream os) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         os.write(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            Canonicalizer.getInstance(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
               Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS).canonicalizeSubtree(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
               contextNode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         // throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      } catch (InvalidCanonicalizerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         // throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      } catch (CanonicalizationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         // throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    * Method getFullTextChildrenFromElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    * @return the string of chi;ds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
   public static String getFullTextChildrenFromElement(Element element) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      NodeList children = element.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      int iMax = children.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      for (int i = 0; i < iMax; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         Node curr = children.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         if (curr.getNodeType() == Node.TEXT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            sb.append(((Text) curr).getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   234
   static  String dsPrefix=null;
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   235
   static Map<String, String> namePrefixes=new HashMap<String, String>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    * Creates an Element in the XML Signature specification namespace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    * @param doc the factory Document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    * @param elementName the local name of the Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    * @return the Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
   public static Element createElementInSignatureSpace(Document doc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
           String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      if (doc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         throw new RuntimeException("Document is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   250
      if ((dsPrefix == null) || (dsPrefix.length() == 0)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   251
         return doc.createElementNS(Constants.SignatureSpecNS, elementName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   253
      String namePrefix= namePrefixes.get(elementName);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   254
      if (namePrefix==null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   255
          StringBuffer tag=new StringBuffer(dsPrefix);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   256
          tag.append(':');
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   257
          tag.append(elementName);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   258
          namePrefix=tag.toString();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   259
          namePrefixes.put(elementName,namePrefix);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   260
      }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
      return doc.createElementNS(Constants.SignatureSpecNS, namePrefix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    * Returns true if the element is in XML Signature namespace and the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    * name equals the supplied one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    * @param localName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    * @return true if the element is in XML Signature namespace and the local name equals the supplied one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
   public static boolean elementIsInSignatureSpace(Element element,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
           String localName) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   274
      return ElementProxy.checker.isNamespaceElement(element, localName, Constants.SignatureSpecNS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    * Returns true if the element is in XML Encryption namespace and the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    * name equals the supplied one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    * @param element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    * @param localName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    * @return true if the element is in XML Encryption namespace and the local name equals the supplied one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
   public static boolean elementIsInEncryptionSpace(Element element,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
           String localName) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   287
           return ElementProxy.checker.isNamespaceElement(element, localName, EncryptionConstants.EncryptionSpecNS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    * This method returns the owner document of a particular node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    * This method is necessary because it <I>always</I> returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    * {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    * if the {@link Node} is a {@link Document}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    * @param node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    * @return the owner document of the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
   public static Document getOwnerDocument(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      if (node.getNodeType() == Node.DOCUMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         return (Document) node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return node.getOwnerDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         } catch (NullPointerException npe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                           + " Original message was \""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                           + npe.getMessage() + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * This method returns the first non-null owner document of the Node's in this Set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * This method is necessary because it <I>always</I> returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * {@link Document}. {@link Node#getOwnerDocument} returns <CODE>null</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * if the {@link Node} is a {@link Document}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param xpathNodeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @return the owner document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   323
    public static Document getOwnerDocument(Set<Node> xpathNodeSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
       NullPointerException npe = null;
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   325
       for (Node node : xpathNodeSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
           int nodeType =node.getNodeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
           if (nodeType == Node.DOCUMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
              return (Document) node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
              try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                 if (nodeType==Node.ATTRIBUTE_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    return ((Attr)node).getOwnerElement().getOwnerDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                 return node.getOwnerDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
              } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                  npe = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
       throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                       + " Original message was \""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                                       + (npe == null ? "" : npe.getMessage()) + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   345
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   346
     * Method createDSctx
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   347
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   348
     * @param doc
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   349
     * @param prefix
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   350
     * @param namespace
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   351
     * @return the element.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   352
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   353
    public static Element createDSctx(Document doc, String prefix,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   354
                                      String namespace) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   356
       if ((prefix == null) || (prefix.trim().length() == 0)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   357
          throw new IllegalArgumentException("You must supply a prefix");
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   358
       }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   360
       Element ctx = doc.createElementNS(null, "namespaceContext");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   362
       ctx.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix.trim(),
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   363
                          namespace);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   365
       return ctx;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   366
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    * Method addReturnToElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    * @param e
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
   public static void addReturnToElement(Element e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   375
      if (!ignoreLineBreaks) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   376
         Document doc = e.getOwnerDocument();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   377
         e.appendChild(doc.createTextNode("\n"));
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   378
      }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   379
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   381
   public static void addReturnToElement(Document doc, HelperNodeList nl) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   382
      if (!ignoreLineBreaks) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   383
         nl.appendChild(doc.createTextNode("\n"));
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   384
      }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   385
   }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   386
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   387
   public static void addReturnBeforeChild(Element e, Node child) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   388
      if (!ignoreLineBreaks) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   389
         Document doc = e.getOwnerDocument();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   390
         e.insertBefore(doc.createTextNode("\n"), child);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   391
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    * Method convertNodelistToSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    * @param xpathNodeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    * @return the set with the nodelist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   400
   public static Set<Node> convertNodelistToSet(NodeList xpathNodeSet) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
      if (xpathNodeSet == null) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   403
         return new HashSet<Node>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      int length = xpathNodeSet.getLength();
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   407
      Set<Node> set = new HashSet<Node>(length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         set.add(xpathNodeSet.item(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      return set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    * This method spreads all namespace attributes in a DOM document to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    * children. This is needed because the XML Signature XPath transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    * must evaluate the XPath against all nodes in the input, even against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    * XPath namespace nodes. Through a bug in XalanJ2, the namespace nodes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    * not fully visible in the Xalan XPath model, so we have to do this by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    * hand in DOM spaces so that the nodes become visible in XPath space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    * @param doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">Namespace axis resolution is not XPath compliant </A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
   public static void circumventBug2650(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      Element documentElement = doc.getDocumentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      // if the document element has no xmlns definition, we add xmlns=""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      Attr xmlnsAttr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         documentElement.getAttributeNodeNS(Constants.NamespaceSpecNS, "xmlns");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      if (xmlnsAttr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         documentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      XMLUtils.circumventBug2650internal(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    * This is the work horse for {@link #circumventBug2650}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    * @param node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    * @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">Namespace axis resolution is not XPath compliant </A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   449
   @SuppressWarnings("fallthrough")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
   private static void circumventBug2650internal(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
           Node parent=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
           Node sibling=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
           final String namespaceNs=Constants.NamespaceSpecNS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
           do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         switch (node.getNodeType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         case Node.ELEMENT_NODE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                 Element element = (Element) node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
             if (!element.hasChildNodes())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                 break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
             if (element.hasAttributes()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
             NamedNodeMap attributes = element.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
             int attributesLength = attributes.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
             for (Node child = element.getFirstChild(); child!=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                child=child.getNextSibling()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if (child.getNodeType() != Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                Element childElement = (Element) child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                for (int i = 0; i < attributesLength; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        Attr currentAttr = (Attr) attributes.item(i);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   474
                        if (namespaceNs!=currentAttr.getNamespaceURI())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        if (childElement.hasAttributeNS(namespaceNs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                        currentAttr.getLocalName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                        childElement.setAttributeNS(namespaceNs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                                currentAttr.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                                currentAttr.getNodeValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         case Node.ENTITY_REFERENCE_NODE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         case Node.DOCUMENT_NODE :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                 parent=node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                 sibling=node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         while ((sibling==null) && (parent!=null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                         sibling=parent.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                         parent=parent.getParentNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
       if (sibling==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                         return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
         node=sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         sibling=node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
           } while (true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    * @param number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
   public static Element selectDsNode(Node sibling, String nodeName, int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        while (sibling!=null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   515
                if (ElementProxy.checker.isNamespaceElement(sibling, nodeName, Constants.SignatureSpecNS )) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        if (number==0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                return (Element)sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                        number--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                sibling=sibling.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    * @param number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
   public static Element selectXencNode(Node sibling, String nodeName, int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        while (sibling!=null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   535
                if (ElementProxy.checker.isNamespaceElement(sibling, nodeName, EncryptionConstants.EncryptionSpecNS )) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        if (number==0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                return (Element)sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        number--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                sibling=sibling.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    * @param number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
   public static Text selectDsNodeText(Node sibling, String nodeName, int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            Node n=selectDsNode(sibling,nodeName,number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (n==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        n=n.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        while (n!=null && n.getNodeType()!=Node.TEXT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                n=n.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return (Text)n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    * @param number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
   public static Text selectNodeText(Node sibling, String uri, String nodeName, int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        Node n=selectNode(sibling,uri,nodeName,number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    if (n==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    n=n.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    while (n!=null && n.getNodeType()!=Node.TEXT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        n=n.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    return (Text)n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    * @param number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
   public static Element selectNode(Node sibling, String uri,String nodeName, int number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        while (sibling!=null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   593
                if (ElementProxy.checker.isNamespaceElement(sibling, nodeName, uri)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                        if (number==0){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                return (Element)sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        number--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                sibling=sibling.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
   public static Element[] selectDsNodes(Node sibling,String nodeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     return selectNodes(sibling,Constants.SignatureSpecNS,nodeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    * @param sibling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    * @param nodeName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public static Element[] selectNodes(Node sibling,String uri,String nodeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        int size=20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        Element[] a= new Element[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        int curr=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        //List list=new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        while (sibling!=null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   624
                if (ElementProxy.checker.isNamespaceElement(sibling, nodeName, uri)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        a[curr++]=(Element)sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                        if (size<=curr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                                int cursize= size<<2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                Element []cp=new Element[cursize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                                System.arraycopy(a,0,cp,0,size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                                a=cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                size=cursize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                sibling=sibling.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        Element []af=new Element[curr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        System.arraycopy(a,0,af,0,curr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return af;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    * @param signatureElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    * @param inputSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    * @return nodes with the constrain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   646
    public static Set<Node> excludeNodeFromSet(Node signatureElement, Set<Node> inputSet) {
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   647
          Set<Node> resultSet = new HashSet<Node>();
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   648
          Iterator<Node> iterator = inputSet.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
          while (iterator.hasNext()) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   651
            Node inputNode = iterator.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            if (!XMLUtils
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    .isDescendantOrSelf(signatureElement, inputNode)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
               resultSet.add(inputNode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         return resultSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    * Returns true if the descendantOrSelf is on the descendant-or-self axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    * of the context node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    * @param ctx
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    * @param descendantOrSelf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    * @return true if the node is descendant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
   static public boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
      if (ctx == descendantOrSelf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
      Node parent = descendantOrSelf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         if (parent == ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         if (parent.getNodeType() == Node.ATTRIBUTE_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            parent = ((Attr) parent).getOwnerElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            parent = parent.getParentNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   693
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   694
    public static boolean ignoreLineBreaks() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   695
        return ignoreLineBreaks;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   696
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
}