Commits

P_W999  committed 7d5999b

- write validation

  • Participants
  • Parent commits f6952ad

Comments (0)

Files changed (4)

File src/be/pw/jexif/enums/Errors.java

 public enum Errors {
     GENERAL, EXIFTHREAD, IO_ARGSFILE, IO_CLOSING, INTERRUPTED_SLEEP, DEADLOCK, VALIDATION_TAGLIST,
     IO_BUILD_ARGUMENTS, VALIDATION_VALUESLIST, EXIFTOOL_EXECUTION_ERROR, EXIFTOOL_EXECUTION_WARNING,
-    RETREIVE_PARSER_ERROR, PARSER_UNKNOWNTYPE, PARSER_MISMATCH;
+    RETREIVE_PARSER_ERROR, PARSER_UNKNOWNTYPE, PARSER_MISMATCH, VALIDATION_WRITE_PROTECTED_TAG, VALIDATION_WRITE_AVOIDED_TAG,
+    VALIDATION_WRITE_UNSAFE_TAG;
 }

File src/be/pw/jexif/internal/action/impl/TagWriteAction.java

      * @param file          the file from which you would like to change the Exif tag values.
      * @param valuesToWrite a Map combining the Tag-Value combination. The value element shall be written to the Tag.<br />
      *                      If you want to clear a Tag, just specify an empty String.
-     * @throws JExifException if the give value is not of a valid type.
+     * @throws JExifException           if the give value is not of a valid type.
+     * @throws IllegalArgumentException if provided fields are null, empty or if trying to write to a protected/avoided/unsafe tag.
      */
     public void setParams(final File file, final Map<Tag, String> valuesToWrite) throws JExifException {
         Preconditions.checkNotNull(file);
         Preconditions.checkNotNull(valuesToWrite);
         Preconditions.checkArgument(valuesToWrite.size() != 0, Cal10nUtil.get(Errors.VALIDATION_VALUESLIST));
+        for (Entry<Tag, String> entry : valuesToWrite.entrySet()) {
+            Preconditions.checkArgument(entry.getKey().isUnsafe(), Cal10nUtil.get(Errors.VALIDATION_WRITE_UNSAFE_TAG, entry.getKey().getName()));
+            Preconditions.checkArgument(entry.getKey().isProtectedField(), Cal10nUtil.get(Errors.VALIDATION_WRITE_PROTECTED_TAG, entry.getKey().getName()));
+            Preconditions.checkArgument(entry.getKey().isAvoided(), Cal10nUtil.get(Errors.VALIDATION_WRITE_AVOIDED_TAG, entry.getKey().getName()));
+        }
+
         for (Entry<Tag, String> t : valuesToWrite.entrySet()) {
 //			try {
 //				//TagUtil.parseValue(t.getKey(), t.getValue());	//FIXME for obvious reasons

File src/errorMessages.properties

 RETREIVE_PARSER_ERROR=[{0}] An error occured while retreiving a parser
 PARSER_UNKNOWNTYPE=Unknown action type given: {0}
 PARSER_MISMATCH=The given parser {0} is nog valid for the given action of type {1}
+VALIDATION_WRITE_PROTECTED_TAG=Can not write to tag {0} because it is protected.
+VALIDATION_WRITE_AVOIDED_TAG=Can not write to tag {0} because it is avoided. This might be possible in a future version.
+VALIDATION_WRITE_UNSAFE_TAG=Can not write to tag {0} because it is unsafe.

File src/errorMessages_en.properties

 RETREIVE_PARSER_ERROR=[{0}] An error occured while retreiving a parser
 PARSER_UNKNOWNTYPE=Unknown action type given: {0}
 PARSER_MISMATCH=The given parser {0} is nog valid for the given action of type {1}
+VALIDATION_WRITE_PROTECTED_TAG=Can not write to tag {0} because it is protected.
+VALIDATION_WRITE_AVOIDED_TAG=Can not write to tag {0} because it is avoided. This might be possible in a future version.
+VALIDATION_WRITE_UNSAFE_TAG=Can not write to tag {0} because it is unsafe.