Commits

P_W999 committed 05a4318

- add method to allow other Tag implementations to be used by J-ExifTool

  • Participants
  • Parent commits dbd80ff

Comments (0)

Files changed (2)

File src/be/pw/jexif/JExifTool.java

 import org.slf4j.LoggerFactory;
 
 import be.pw.jexif.enums.Errors;
+import be.pw.jexif.enums.tag.ExifGPS;
+import be.pw.jexif.enums.tag.ExifIFD;
+import be.pw.jexif.enums.tag.IFD0;
 import be.pw.jexif.enums.tag.Tag;
 import be.pw.jexif.exception.ExifError;
 import be.pw.jexif.exception.JExifException;
 import be.pw.jexif.internal.thread.event.EventHandler;
 import be.pw.jexif.internal.util.Cal10nUtil;
 import be.pw.jexif.internal.util.GPSUtil;
+import be.pw.jexif.internal.util.TagUtil;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
      */
     @Beta
     public JExifTool() {
+    	TagUtil.register(IFD0.class);
+    	TagUtil.register(ExifIFD.class);
+    	TagUtil.register(ExifGPS.class);
         this.start();
     }
 

File src/be/pw/jexif/internal/util/TagUtil.java

 
 import be.pw.jexif.enums.DataType;
 import be.pw.jexif.enums.Errors;
-import be.pw.jexif.enums.tag.ExifIFD;
-import be.pw.jexif.enums.tag.ExifGPS;
-import be.pw.jexif.enums.tag.IFD0;
 import be.pw.jexif.enums.tag.Tag;
 import be.pw.jexif.exception.JExifException;
 import be.pw.jexif.exception.JExifValidationException;
     /**
      * Look-up map for quick String-to-Enum conversion.
      */
-    private static final Map<String, Tag> TAG_LOOKUP_MAP;
+    private static final Map<String, Tag> TAG_LOOKUP_MAP = new HashMap<>(246);	//at v0.0.3, the supported tag count is 246
     /**
      * The minimum value for an Unsigned Int8
      */
     private static final Float MAX_INT32U = 4294967295F;
 
     /**
-     * Initializer used to init the static final tag/name lookup map used by all instances of this class.
+     * Registers an implementation of {@link Tag} .<br /> 
+     * Registering a Tag implementation allows J-ExifTool to parse it's value correctly from the ExifTool output.
+     *  
+     * @param tagClass the class to register.
      */
-    static { // TODO: make this nicer, allow user to add custom tags and stuff
-        Tag[] exifIFDValues = ExifIFD.values();
-        Tag[] ifd0Values = IFD0.values();
-        Tag[] gpsValues = ExifGPS.values();
-        TAG_LOOKUP_MAP = new HashMap<>(exifIFDValues.length + ifd0Values.length);
+    public static void register(Class<? extends Tag> tagClass) {
+    	 Tag[] values = tagClass.getEnumConstants();
 
-        for (Tag tag : exifIFDValues) {
-            TAG_LOOKUP_MAP.put(tag.getName(), tag);
-        }
-
-        for (Tag tag : ifd0Values) {
-            TAG_LOOKUP_MAP.put(tag.getName(), tag);
-        }
-        
-        for (Tag tag : gpsValues) {
-            TAG_LOOKUP_MAP.put(tag.getName(), tag);
-        }
+         for (Tag tag : values) {
+             TAG_LOOKUP_MAP.put(tag.getName(), tag);
+         }
     }
 
     /**