@POST
  @Path("setPreference")
  public synchronized void setPreference(
    @FormParam("preferencename") String preferenceName,
    @FormParam("preferencevalue") String preferenceValue) {
    if ((preferenceName == null) || (preferenceValue == null))
      return;
    Object newValue = null;
    // Validate boolean preferences
    String[] booleanPrefs = {"advanced-mode", "allow-anonymous-usage-tracking", "fs-reverse"};
    if (Arrays.asList(booleanPrefs).contains(preferenceName)){
      switch (preferenceValue){
        case "true":
          newValue = Boolean.TRUE;
          break;
        case "false":
          newValue = Boolean.FALSE;
          break;
        default:
          return;
      }
      if (preferenceName.equals("advanced-mode"))
        this.isUseAdvancedMode = (Boolean) newValue;
      else if (preferenceName == "allow")
        this.isAllowAnonymousTracking = (Boolean) newValue;
    }
    // Validate edit mode
    else if (preferenceName.equals("edit-mode")){
      String[] validModes = {"vim", "emacs", "default"};
      if (Arrays.asList(validModes).contains(preferenceValue)){
        newValue = preferenceValue;
        this.editMode = preferenceValue;
      }
    }
    // Validate edit mode
    else if (preferenceName.equals("fs-order-by")){
      String[] validModes = {"uri", "modified"};
      if (Arrays.asList(validModes).contains(preferenceValue)){
        newValue = preferenceValue;
      }
    }
    final String preferenceFileUrl = this.bkConfig.getPreferenceFileUrl();
    // TODO, assume the url is a file path for now.
    // System.out.println(preferenceFileUrl + " url!!!!\n");
    // Use a temporary for atomic writing
    java.nio.file.Path preferenceFileTmp = Paths.get(preferenceFileUrl + ".tmp");
    java.nio.file.Path preferenceFile = Paths.get(preferenceFileUrl);
    try {
      ObjectMapper om = new ObjectMapper();
      TypeReference readType = new TypeReference<HashMap<String, Object>>() {
      };
      Map<String, Object> prefs = om.readValue(preferenceFile.toFile(), readType);
      Object oldValue = (Object) prefs.get(preferenceName);
      // If value changed, write it to the file too
      if (!Objects.equals(newValue, oldValue)) {
        Files.deleteIfExists(preferenceFileTmp);
        prefs.put(preferenceName, newValue);
        om.writerWithDefaultPrettyPrinter().writeValue(preferenceFileTmp.toFile(), prefs);
        // Move tmp to normal
        Files.move(preferenceFileTmp, preferenceFile, REPLACE_EXISTING);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
@POST
  @Path("setPreference")
  public synchronized void setPreference(
    @FormParam("preferencename") String preferenceName,
    @FormParam("preferencevalue") String preferenceValue) {
    if ((preferenceName == null) || (preferenceValue == null))
      return;
    Object newValue = null;
   
    String[] booleanPrefs = {"advanced-mode", "allow-anonymous-usage-tracking", "fs-reverse"};
    if (Arrays.asList(booleanPrefs).contains(preferenceName)){
      switch (preferenceValue){
        case "true":
          newValue = Boolean.TRUE;
          break;
        case "false":
          newValue = Boolean.FALSE;
          break;
        default:
          return;
      }
      if (preferenceName.equals("advanced-mode"))
        this.isUseAdvancedMode = (Boolean) newValue;
      else if (preferenceName == "allow")
        this.isAllowAnonymousTracking = (Boolean) newValue;
    }
   
    else if (preferenceName.equals("edit-mode")){
      String[] validModes = {"vim", "emacs", "default"};
      if (Arrays.asList(validModes).contains(preferenceValue)){
        newValue = preferenceValue;
        this.editMode = preferenceValue;
      }
    }
   
    else if (preferenceName.equals("fs-order-by")){
      String[] validModes = {"uri", "modified"};
      if (Arrays.asList(validModes).contains(preferenceValue)){
        newValue = preferenceValue;
      }
    }
    final String preferenceFileUrl = this.bkConfig.getPreferenceFileUrl();
   
   
   
    java.nio.file.Path preferenceFileTmp = Paths.get(preferenceFileUrl + ".tmp");
    java.nio.file.Path preferenceFile = Paths.get(preferenceFileUrl);
    try {
      ObjectMapper om = new ObjectMapper();
      TypeReference readType = new TypeReference<HashMap<String, Object>>() {
      };
      Map<String, Object> prefs = om.readValue(preferenceFile.toFile(), readType);
      Object oldValue = (Object) prefs.get(preferenceName);
     
      if (!Objects.equals(newValue, oldValue)) {
        Files.deleteIfExists(preferenceFileTmp);
        prefs.put(preferenceName, newValue);
        om.writerWithDefaultPrettyPrinter().writeValue(preferenceFileTmp.toFile(), prefs);
       
        Files.move(preferenceFileTmp, preferenceFile, REPLACE_EXISTING);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
@post @path("setpreference") public synchronized void setpreference( @formparam("preferencename") string preferencename, @formparam("preferencevalue") string preferencevalue) { if ((preferencename == null) || (preferencevalue == null)) return; object newvalue = null; string[] booleanprefs = {"advanced-mode", "allow-anonymous-usage-tracking", "fs-reverse"}; if (arrays.aslist(booleanprefs).contains(preferencename)){ switch (preferencevalue){ case "true": newvalue = boolean.true; break; case "false": newvalue = boolean.false; break; default: return; } if (preferencename.equals("advanced-mode")) this.isuseadvancedmode = (boolean) newvalue; else if (preferencename == "allow") this.isallowanonymoustracking = (boolean) newvalue; } else if (preferencename.equals("edit-mode")){ string[] validmodes = {"vim", "emacs", "default"}; if (arrays.aslist(validmodes).contains(preferencevalue)){ newvalue = preferencevalue; this.editmode = preferencevalue; } } else if (preferencename.equals("fs-order-by")){ string[] validmodes = {"uri", "modified"}; if (arrays.aslist(validmodes).contains(preferencevalue)){ newvalue = preferencevalue; } } final string preferencefileurl = this.bkconfig.getpreferencefileurl(); java.nio.file.path preferencefiletmp = paths.get(preferencefileurl + ".tmp"); java.nio.file.path preferencefile = paths.get(preferencefileurl); try { objectmapper om = new objectmapper(); typereference readtype = new typereference<hashmap<string, object>>() { }; map<string, object> prefs = om.readvalue(preferencefile.tofile(), readtype); object oldvalue = (object) prefs.get(preferencename); if (!objects.equals(newvalue, oldvalue)) { files.deleteifexists(preferencefiletmp); prefs.put(preferencename, newvalue); om.writerwithdefaultprettyprinter().writevalue(preferencefiletmp.tofile(), prefs); files.move(preferencefiletmp, preferencefile, replace_existing); } } catch (ioexception e) { e.printstacktrace(); } }