Ejemplo n.º 1
0
 protected void initAuFeatureMap() {
   if (definitionMap.containsKey(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP)) {
     Map<String, ?> featMap = definitionMap.getMap(DefinableArchivalUnit.KEY_AU_FEATURE_URL_MAP);
     for (Map.Entry ent : featMap.entrySet()) {
       Object val = ent.getValue();
       if (val instanceof Map) {
         ent.setValue(MapUtil.expandAlternativeKeyLists((Map) val));
       }
     }
   }
 }
Ejemplo n.º 2
0
  public void testFindLeastFullRepository() throws Exception {
    Map repoMap =
        MapUtil.map(
            "local:one",
            new MyDF("/one", 1000),
            "local:two",
            new MyDF("/two", 3000),
            "local:three",
            new MyDF("/three", 2000));
    mgr.setRepoMap(repoMap);

    assertEquals("local:two", mgr.findLeastFullRepository());
  }
Ejemplo n.º 3
0
 public void testSubstanceState() {
   AuState aus = new AuState(mau, historyRepo);
   assertEquals(SubstanceChecker.State.Unknown, aus.getSubstanceState());
   assertFalse(aus.hasNoSubstance());
   aus.setSubstanceState(SubstanceChecker.State.Yes);
   assertEquals(1, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState());
   assertFalse(aus.hasNoSubstance());
   aus.setSubstanceState(SubstanceChecker.State.No);
   assertEquals(2, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.No, aus.getSubstanceState());
   assertTrue(aus.hasNoSubstance());
   assertNotEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance));
   mplug.setFeatureVersionMap(MapUtil.map(Plugin.Feature.Substance, "2"));
   aus.setSubstanceState(SubstanceChecker.State.Yes);
   // changing both the substance state and feature version should store
   // only once
   assertEquals(3, historyRepo.getAuStateStoreCount());
   assertEquals(SubstanceChecker.State.Yes, aus.getSubstanceState());
   assertEquals("2", aus.getFeatureVersion(Plugin.Feature.Substance));
 }
Ejemplo n.º 4
0
/** Describes the archive file types that should have their members exposed as pseudo-CachedUrls. */
public class ArchiveFileTypes {
  protected static Logger log = Logger.getLogger("ArchiveFileTypes");

  /** Default mime types and extensions for zip, tar, tgz. */
  private static final Map<String, String> DEFAULT_MAP =
      MapUtil.fromList(
          ListUtil.list(
              ".zip",
              ".zip",
              ".tar",
              ".tar",
              ".tgz",
              ".tgz",
              ".tar.gz",
              ".tar.gz",
              "application/zip",
              ".zip",
              "application/x-gtar",
              ".tar",
              "application/x-tar",
              ".tar"));

  public static final ArchiveFileTypes DEFAULT = new ArchiveFileTypes(DEFAULT_MAP);

  private Map<String, String> extMimeMap;

  public ArchiveFileTypes() {}

  public ArchiveFileTypes(Map<String, String> map) {
    extMimeMap = map;
  }

  public Map<String, String> getExtMimeMap() {
    return extMimeMap;
  }

  /**
   * Return the archive file type corresponding to the CU's MIME type or filename extension, or null
   * if none.
   */
  public String getFromCu(CachedUrl cu) throws MalformedURLException {
    String res = getFromMime(cu.getContentType());
    if (res == null) {
      res = getFromUrl(cu.getUrl());
    }
    return res;
  }

  /**
   * Return the archive file type corresponding to the filename extension in the URL, or null if
   * none.
   */
  public String getFromUrl(String url) throws MalformedURLException {
    if (StringUtil.endsWithIgnoreCase(url, ".tar.gz")) {
      return getExtMimeMap().get(".tar.gz");
    }
    String ext = UrlUtil.getFileExtension(url).toLowerCase();
    return getExtMimeMap().get("." + ext);
  }

  /** Return the archive file type corresponding to the MIME type, or null if none. */
  public String getFromMime(String contentType) {
    String mimeType = HeaderUtil.getMimeTypeFromContentType(contentType);
    if (mimeType == null) {
      return null;
    }
    return getExtMimeMap().get(mimeType.toLowerCase());
  }

  /**
   * Lookup the CU's archive file type in its AU's ArchiveFileTypes
   *
   * @return the file extension (including dot), or null if none found
   */
  public static String getArchiveExtension(CachedUrl cu) {
    ArchiveFileTypes aft = cu.getArchivalUnit().getArchiveFileTypes();
    if (aft == null) {
      return null;
    }
    try {
      return aft.getFromCu(cu);
    } catch (MalformedURLException e) {
      log.warning("isArchive(" + cu + ")", e);
      return null;
    }
  }
}