Пример #1
0
 protected static void convertMediaResourcesKeys(BaseReader reader, BaseWriter writer)
     throws Exception {
   Set<String> mediaKeys = reader.getMediaResourceKeys();
   MediaResourceInfo resourceInfo = new MediaResourceInfo(new MediaResourceKey(""), null);
   for (String mkey : mediaKeys) {
     resourceInfo.getKey().setResourceKey(mkey);
     writer.saveMediaResourceInfo(resourceInfo);
   }
 }
Пример #2
0
  protected static void convertMediaResources(
      BaseReader reader, BaseWriter writer, Observer observer, ProgressInfo progress)
      throws Exception {

    Set<String> keys = reader.getMediaResourceKeys();
    if (keys == null) {
      log.info("No media resources available");
      return;
    }

    log.info("Number of media resources: {}", keys.size());

    // Update progress
    observer.update(progress.setMessage("Sorting Media Resources"), null);

    ArrayList<String> sortedKeys = new ArrayList<String>(keys.size());
    for (String key : keys) {
      sortedKeys.add(key);
    }

    // Create Collator and sort articles
    Collator collator = createCollator(writer);
    if (collator != null) {
      Collections.sort(sortedKeys, collator);
    } else {
      log.warn("Collator couldn't be created, sorting of Media Resources is skipped");
    }

    // Update progress
    observer.update(progress.setMessage("Converting Media Resources"), null);

    for (Iterator<String> iterator = sortedKeys.iterator(); iterator.hasNext(); ) {
      String sortedKey = iterator.next();
      MediaResourceInfo mediaInfo = reader.getMediaResourceInfo(new MediaResourceKey(sortedKey));
      mediaInfo.getKey().setResourceKey(mediaInfo.getKey().getResourceKey());
      writer.saveMediaResourceInfo(mediaInfo);
    }

    writer.flush();
  }