public MetaMetadata getMediaMM(ParsedURL purl, String tagName) {
    MetaMetadata result = null;
    if (purl != null && !purl.isFile()) {
      result = mediaRepositoryByURL.get(purl.noAnchorNoQueryPageString());

      if (result == null) {
        String protocolStrippedURL = purl.toString().split("://")[1];

        String key =
            purl.url().getProtocol()
                + "://"
                + urlprefixCollection.getMatchingPhrase(protocolStrippedURL, '/');

        result = mediaRepositoryByURL.get(key);

        if (result == null) {
          String domain = purl.domain();
          if (domain != null) {
            ArrayList<RepositoryPatternEntry> entries = mediaRepositoryByPattern.get(domain);
            if (entries != null) {
              for (RepositoryPatternEntry entry : entries) {
                Matcher matcher = entry.getPattern().matcher(purl.toString());
                if (matcher.find()) {
                  result = entry.getMetaMetadata();
                }
              }
            }
          }
        }
      }
    }
    return (result != null) ? result : getByTagName(tagName);
  }
  /**
   * Get MetaMetadata. First, try matching by url_base. If this fails, including if the attribute is
   * null, then try by url_prefix. If this fails, including if the attribute is null, then try by
   * url_pattern (regular expression).
   *
   * <p>If that lookup fails, then lookup by tag name, to acquire the default.
   *
   * @param purl
   * @param tagName
   * @return
   */
  public MetaMetadata getDocumentMM(ParsedURL purl, String tagName) {
    MetaMetadata result = null;
    if (purl != null) {
      if (!purl.isFile()) {
        result = documentRepositoryByURL.get(purl.noAnchorNoQueryPageString());

        if (result == null) {
          String protocolStrippedURL = purl.toString().split("://")[1];
          String matchingPhrase = urlprefixCollection.getMatchingPhrase(protocolStrippedURL, '/');
          // FIXME -- andruid needs abhinav to explain this code better and make more clear!!!
          if (matchingPhrase != null) {
            String key = purl.url().getProtocol() + "://" + matchingPhrase;

            result = documentRepositoryByURL.get(key);
          }
        }

        if (result == null) {
          String domain = purl.domain();
          if (domain != null) {
            ArrayList<RepositoryPatternEntry> entries = documentRepositoryByPattern.get(domain);
            if (entries != null) {
              for (RepositoryPatternEntry entry : entries) {
                Matcher matcher = entry.getPattern().matcher(purl.toString());
                if (matcher.find()) {
                  result = entry.getMetaMetadata();
                }
              }
            }
          }
        }
      }
      // Lastly, check for MMD by suffix
      if (result == null) {
        String suffix = purl.suffix();

        if (suffix != null) result = getMMBySuffix(suffix);
      }
    }

    return (result != null) ? result : getByTagName(tagName);
  }
  /**
   * Initializes HashMaps for MetaMetadata selectors by URL or pattern. Uses the Media and Document
   * base classes to ensure that maps are only filled with appropriate matching MetaMetadata.
   */
  private void initializeLocationBasedMaps() {
    // 1st pass -- resolve nested and collection types as needed -- fill in all child metadata
    // fields
    /*
     * for (MetaMetadata metaMetadata : repositoryByTagName) { metaMetadata.bindNonScalarChildren();
     * }
     */

    for (MetaMetadata metaMetadata : repositoryByTagName) {
      metaMetadata.inheritMetaMetadata(this);
      Class<? extends Metadata> metadataClass = metaMetadata.getMetadataClass(metadataTScope);
      if (metadataClass == null) {
        error(metaMetadata + "\tCan't resolve in TranslationScope " + metadataTScope);
        continue;
      }

      HashMap<String, MetaMetadata> repositoryByPURL;
      HashMap<String, ArrayList<RepositoryPatternEntry>> repositoryByPattern;

      if (Media.class.isAssignableFrom(metadataClass)) {
        repositoryByPURL = mediaRepositoryByURL;
        repositoryByPattern = mediaRepositoryByPattern;
      } else if (Document.class.isAssignableFrom(metadataClass)) {
        repositoryByPURL = documentRepositoryByURL;
        repositoryByPattern = documentRepositoryByPattern;
      } else continue;

      ParsedURL purl = metaMetadata.getUrlBase();
      if (purl != null) repositoryByPURL.put(purl.noAnchorNoQueryPageString(), metaMetadata);
      else {
        ParsedURL urlPrefix = metaMetadata.getUrlPrefix();
        if (urlPrefix != null) {
          urlprefixCollection.add(urlPrefix);
          repositoryByPURL.put(urlPrefix.toString(), metaMetadata);
        } else {
          String domain = metaMetadata.getDomain();
          Pattern urlPattern = metaMetadata.getUrlRegex();
          if (domain != null && urlPattern != null) {
            ArrayList<RepositoryPatternEntry> bucket = repositoryByPattern.get(domain);
            if (bucket == null) {
              bucket = new ArrayList<RepositoryPatternEntry>(2);
              repositoryByPattern.put(domain, bucket);
            }
            bucket.add(new RepositoryPatternEntry(urlPattern, metaMetadata));
          }
        }
      }
    }
  }
 /** @return What to tell the user about what is being downloaded. */
 public String message() {
   return purl.toString();
 }