JAL-629 added setprop. More filename based substitutions enabled. Test for these.
[jalview.git] / src / jalview / bin / argparser / ArgValuesMap.java
index 22d85a8..2117ee9 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.bin.argparser;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -7,6 +8,7 @@ import java.util.Map;
 import java.util.Set;
 
 import jalview.bin.argparser.Arg.Opt;
+import jalview.util.FileUtils;
 
 /**
  * Helper class to allow easy extraction of information about specific argument
@@ -190,4 +192,39 @@ public class ArgValuesMap
     ArgValues avs = this.getArgValues(a);
     return avs == null ? null : avs.getId(id);
   }
+
+  /*
+   * This method returns the basename of the first --open or --opennew value. 
+   * Used primarily for substitutions in output filenames.
+   */
+  public String getBasename()
+  {
+    return getDirOrBasename(false);
+  }
+
+  /*
+   * This method returns the dirname of the first --open or --opennew value. 
+   * Used primarily for substitutions in output filenames.
+   */
+  public String getDirname()
+  {
+    return getDirOrBasename(true);
+  }
+
+  public String getDirOrBasename(boolean dirname)
+  {
+    String filename = null;
+    String openVal = getValue(Arg.OPEN);
+    String opennewVal = getValue(Arg.OPENNEW);
+    if (openVal != null)
+      filename = openVal;
+    if (filename == null && opennewVal != null)
+      filename = opennewVal;
+    if (filename == null)
+      return null;
+
+    File file = new File(filename);
+    return dirname ? FileUtils.getDirname(file)
+            : FileUtils.getBasename(file);
+  }
 }