jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/resolver/ResourceResolverSpi.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.resolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    24
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * During reference validation, we have to retrieve resources from somewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    34
 * @author $Author: mullan $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public abstract class ResourceResolverSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
   /** {@link java.util.logging} logging facility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        java.util.logging.Logger.getLogger(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                    ResourceResolverSpi.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   /** Field _properties */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    44
   protected java.util.Map<String,String> _properties = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    * This is the workhorse method used to resolve resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    * @return the resource wrapped arround a XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    * @throws ResourceResolverException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
   public abstract XMLSignatureInput engineResolve(Attr uri, String BaseURI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
      throws ResourceResolverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    * Method engineSetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * @param value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   public void engineSetProperty(String key, String value) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    65
          if (_properties==null) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    66
                  _properties=new HashMap<String,String>();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    67
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      this._properties.put(key, value);
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
    * Method engineGetProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * @param key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    * @return the value of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   public String engineGetProperty(String key) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    78
          if (_properties==null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
                        return null;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
          }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    81
      return this._properties.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    * @param properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    88
   public void engineAddProperies(Map<String,String> properties) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    89
          if (properties!=null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
                  if (_properties==null) {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    91
                          _properties=new HashMap<String,String>();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    92
                  }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
                  this._properties.putAll(properties);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    94
          }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    96
   /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
    * Tells if the implementation does can be reused by several threads safely.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
    * It normally means that the implemantation does not have any member, or there is
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    99
    * member change betwen engineCanResolve & engineResolve invocations. Or it mantians all
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   100
    * member info in ThreadLocal methods.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
    */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
   public boolean engineIsThreadSafe() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
           return false;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    * This method helps the {@link ResourceResolver} to decide whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    * {@link ResourceResolverSpi} is able to perform the requested action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    * @param uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    * @param BaseURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    * @return true if the engine can resolve the uri
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   public abstract boolean engineCanResolve(Attr uri, String BaseURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    * Method engineGetPropertyKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    * @return the property keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
   public String[] engineGetPropertyKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      return new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    * Method understandsProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    * @param propertyToTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    * @return true if understands the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   public boolean understandsProperty(String propertyToTest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      String[] understood = this.engineGetPropertyKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      if (understood != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         for (int i = 0; i < understood.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            if (understood[i].equals(propertyToTest)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
               return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    * Fixes a platform dependent filename to standard URI form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    * @param str The string to fix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    * @return Returns the fixed URI string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   public static String fixURI(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      // handle platform dependent strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
      str = str.replace(java.io.File.separatorChar, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      if (str.length() >= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         // str =~ /^\W:\/([^/])/ # to speak perl ;-))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         char ch0 = Character.toUpperCase(str.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         char ch1 = str.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         char ch2 = str.charAt(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         char ch3 = str.charAt(3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         boolean isDosFilename = ((('A' <= ch0) && (ch0 <= 'Z'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                  && (ch1 == ':') && (ch2 == '/')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                  && (ch3 != '/'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         if (isDosFilename) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   170
            if (log.isLoggable(java.util.logging.Level.FINE))
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   171
                log.log(java.util.logging.Level.FINE, "Found DOS filename: " + str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      // Windows fix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      if (str.length() >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         char ch1 = str.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         if (ch1 == ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            char ch0 = Character.toUpperCase(str.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (('A' <= ch0) && (ch0 <= 'Z')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
               str = "/" + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}