Esempio n. 1
0
 static void valTest(Map s, Object[] key) {
   int size = s.size();
   int sum = 0;
   timer.start("Traverse key or value  ", size);
   if (s.containsValue(MISSING)) ++sum;
   timer.finish();
   reallyAssert(sum == 0);
   checkSum += sum;
 }
Esempio n. 2
0
  /**
   * Evaluates a URI and adds it to the namespace map as a namespace.
   *
   * @param uri URI
   */
  protected void addNamespaceURI(URI uri) {

    if (uri == null) {
      throw new IllegalArgumentException("URI argument is null.");
    }

    // extract URI without fragment
    String uriString = uri.toString();
    String newURI = null;

    if (uriString != null) {

      // determine what comes last a '#' or '/'
      int hashindex = uriString.lastIndexOf('#');
      int slashindex = uriString.lastIndexOf('/');

      // validate (URI must contain a forward slash)
      if (slashindex == -1) {
        // namespace may have been evaluated already
        return;
      }

      // is there a '/' after the '#'?
      if (slashindex > hashindex) {

        // remove everything after the last '/'
        int index = uriString.lastIndexOf('/');
        newURI = uriString.substring(0, index) + "/";
      } else {

        // '#' comes after last '/' (remove entire fragment)
        newURI = uriString.replaceAll(uri.getFragment(), "");
      }

      // only add namespace if it is new
      if ((newURI != null) && (!namespaces.containsValue(newURI))) {
        // add to namespaces
        namespaces.put("ns" + namespaces.size(), newURI);
      }
    }
  }
  public static String getHumanReadableMediaTypeFromMimeType(String mediaType) {

    try {
      if (humanReadableMediaTypeMap == null) {
        populateMediaTypeMappings();
      }

      if (humanReadableMediaTypeMap.containsValue(mediaType)) {
        for (Map.Entry<String, String> entry : humanReadableMediaTypeMap.entrySet()) {
          if (entry.getValue().equals(mediaType)) {
            return entry.getKey();
          }
        }
      }
      return mediaType;

    } catch (RegistryException e) {
      String msg = FAILED_TO_READ_THE_THE_HUMAN_READABLE_MEDIA_TYPE_MIME_TYPE_MAPPINGS_FILE_MSG;
      log.error(msg);
    }

    return null;
  }