<commit_before>/*
 * Copyright 2006-2015 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with MZmine 2; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 * USA
 */

package net.sf.mzmine.parameters.parametertypes;

import net.sf.mzmine.main.MZmineCore;
import net.sf.mzmine.parameters.UserParameter;
import net.sf.mzmine.util.exceptions.DecryptionException;
import net.sf.mzmine.util.exceptions.EncryptionException;
import org.w3c.dom.Element;

import javax.swing.*;
import java.util.Collection;

/**
 * Password parameter
 * 
 * @author <NAME> (<EMAIL>)
 */
public class PasswordParameter implements UserParameter<String, PasswordComponent> {

  private String name, description, value;
  private int inputsize = 20;
  private boolean valueRequired = true;

  public PasswordParameter(String name, String description) {
    this(name, description, null);
  }

  public PasswordParameter(String name, String description, int inputsize) {
    this.name = name;
    this.description = description;
    this.inputsize = inputsize;
  }

  public PasswordParameter(String name, String description, String defaultValue) {
    this.name = name;
    this.description = description;
    this.value = defaultValue;
  }

  public PasswordParameter(String name, String description, boolean valueRequired) {
    this.name = name;
    this.description = description;
    this.valueRequired = valueRequired;
  }

  public PasswordParameter(String name, String description, String defaultValue,
      boolean valueRequired) {
    this.name = name;
    this.description = description;
    this.value = defaultValue;
    this.valueRequired = valueRequired;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public String getValue() {
    return value;
  }

  @Override
  public void setValue(String newValue) {
    this.value = newValue;
  }

  @Override
  public boolean checkValue(Collection<String> errorMessages) {
    if (!valueRequired)
      return true;
    if ((value == null) || (value.isEmpty())) { //white spaces can be valid in pw. So no trim
      errorMessages.add(name + " is not set properly");
      return false;
    }
    return true;
  }

  @Override
  public void loadValueFromXML(Element xmlElement) {
    try {
      final String nuValue = xmlElement.getTextContent();
      if (nuValue == null || nuValue.isEmpty())
        return;

      value = MZmineCore.getConfiguration().getEncrypter().decrypt(nuValue);
    } catch (DecryptionException e) {
      e.printStackTrace();
    }
  }<commit_msg>reinserted empty password check<commit_after>/*
 * Copyright 2006-2015 The MZmine 2 Development Team
 * 
 * This file is part of MZmine 2.
 * 
 * MZmine 2 is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * MZmine 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with MZmine 2; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 * USA
 */

package net.sf.mzmine.parameters.parametertypes;

import net.sf.mzmine.main.MZmineCore;
import net.sf.mzmine.parameters.UserParameter;
import net.sf.mzmine.util.exceptions.DecryptionException;
import net.sf.mzmine.util.exceptions.EncryptionException;
import org.w3c.dom.Element;

import javax.swing.*;
import java.util.Collection;

/**
 * Password parameter
 * 
 * @author <NAME> (<EMAIL>)
 */
public class PasswordParameter implements UserParameter<String, PasswordComponent> {

  private String name, description, value;
  private int inputsize = 20;
  private boolean valueRequired = true;

  public PasswordParameter(String name, String description) {
    this(name, description, null);
  }

  public PasswordParameter(String name, String description, int inputsize) {
    this.name = name;
    this.description = description;
    this.inputsize = inputsize;
  }

  public PasswordParameter(String name, String description, String defaultValue) {
    this.name = name;
    this.description = description;
    this.value = defaultValue;
  }

  public PasswordParameter(String name, String description, boolean valueRequired) {
    this.name = name;
    this.description = description;
    this.valueRequired = valueRequired;
  }

  public PasswordParameter(String name, String description, String defaultValue,
      boolean valueRequired) {
    this.name = name;
    this.description = description;
    this.value = defaultValue;
    this.valueRequired = valueRequired;
  }

  @Override
  public String getName() {
    return name;
  }

  @Override
  public String getValue() {
    return value;
  }

  @Override
  public void setValue(String newValue) {
    this.value = newValue;
  }

  @Override
  public boolean checkValue(Collection<String> errorMessages) {
    if (!valueRequired)
      return true;
    if ((value == null) || (value.trim().isEmpty())) {
      errorMessages.add(name + " is not set properly");
      return false;
    }
    return true;
  }

  @Override
  public void loadValueFromXML(Element xmlElement) {
    try {
      final String nuValue = xmlElement.getTextContent();
      if (nuValue == null || nuValue.trim().isEmpty())
        return;

      value = MZmineCore.getConfiguration().getEncrypter().decrypt(nuValue);
    } catch (DecryptionException e) {
      e.printStackTrace();
    }
  }
{'fraction_non_alphanumeric': 0.08897637795275591, 'fraction_numerical': 0.008818897637795276, 'mean_word_length': 3.625637290604516, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3318760', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1723, 'n_words': 601}