コード例 #1
0
 /**
  * Sets the given value for the supplied property key. Nothing is set if the value is empty or
  * null. If the supplied value is a String, it is passed through the I18NConvert.compose method
  * before being set.
  */
 public static void set(Map<FilePropertyKey, Object> map, FilePropertyKey property, Object value) {
   // Insert nothing if value is null|empty.
   if (value != null && !value.toString().isEmpty()) {
     if (value instanceof String) {
       if (FilePropertyKey.isLong(property)) {
         value = CommonUtils.parseLongNoException((String) value);
       } else {
         value = I18NConvert.instance().compose((String) value).intern();
       }
     }
     map.put(property, value);
   }
 }
コード例 #2
0
  public static void populateProperties(
      String fileName,
      long fileSize,
      long creationTime,
      Map<FilePropertyKey, Object> properties,
      LimeXMLDocument doc) {

    properties.put(FilePropertyKey.NAME, ""); // Make sure name defaults to empty.
    set(properties, FilePropertyKey.NAME, FileUtils.getFilenameNoExtension(fileName));
    set(properties, FilePropertyKey.DATE_CREATED, creationTime);
    set(properties, FilePropertyKey.FILE_SIZE, fileSize);

    String extension = FileUtils.getFileExtension(fileName);
    Category category = CategoryConverter.categoryForExtension(extension);

    if (doc != null) {
      for (FilePropertyKey filePropertyKey : FilePropertyKey.values()) {
        set(properties, doc, category, filePropertyKey);
      }

      Long bitrate, length;
      Integer quality;
      switch (category) {
        case AUDIO:
          bitrate = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.AUDIO_BITRATE));
          length = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.AUDIO_SECONDS));
          quality = toAudioQualityScore(extension, fileSize, bitrate, length);
          set(properties, FilePropertyKey.QUALITY, quality);
          break;
        case VIDEO:
          bitrate = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.VIDEO_BITRATE));
          length = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.VIDEO_LENGTH));
          Long height = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.VIDEO_HEIGHT));
          Long width = CommonUtils.parseLongNoException(doc.getValue(LimeXMLNames.VIDEO_WIDTH));
          quality = toVideoQualityScore(extension, fileSize, bitrate, length, height, width);
          set(properties, FilePropertyKey.QUALITY, quality);
          break;
      }
    }
  }