Exemple #1
0
  public static void delete(String servername) {
    XMLServers serversconfig = getCache();
    Iterator<XMLServer> servers = serversconfig.getServer().iterator();

    while (servers.hasNext()) {
      XMLServer server = servers.next();

      if (server.getName().equals(servername)) {
        serversconfig.getServer().remove(server);
        break;
      }
    }
    flash.success(Messages.get("DeleteServerSuccess"));
    list();
  }
Exemple #2
0
  /**
   * If the server class has a static method called gerServerProperties the default properties will
   * be used to create the list with default values. If this is the case the gui will not allow
   * deletion of properties or allowing to add additional properties. If the server class do not
   * have any
   *
   * @param servername
   */
  public static void edit(String servername) {
    XMLServers serversconfig = getCache();
    Iterator<XMLServer> servers = serversconfig.getServer().iterator();

    while (servers.hasNext()) {
      XMLServer server = servers.next();

      if (server.getName().equals(servername)) {

        List<String> serverclasses = Populate.getServerClasses();

        boolean hasdefaultproperties = replaceServerProperties(server);

        render(server, serverclasses, hasdefaultproperties);
      }
    }
    render();
  }
Exemple #3
0
  public static List sortByValue(Map map) {
    List list = new LinkedList(map.entrySet());
    Collections.sort(
        list,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o1)).getValue())
                .compareTo(((Map.Entry) (o2)).getValue());
          }
        });

    Map result = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext(); ) {
      Map.Entry entry = (Map.Entry) it.next();
      result.put(entry.getKey(), entry.getValue());
    }
    Collections.reverse(list);
    return list;
  }
Exemple #4
0
  public static void save() {
    String servername = params.get("servername");
    String classname = params.get("classname");

    XMLServers serversconfig = getCache();
    Iterator<XMLServer> servers = serversconfig.getServer().iterator();

    while (servers.hasNext()) {
      XMLServer server = servers.next();

      if (server.getName().equals(servername)) {
        if (!params.get("classname").equals(params.get("oldclassname"))) {
          server.setClazz(classname);
          /////////////////
          // Replace server properties
          replaceServerProperties(server);

          /////////////////
          flash.success(Messages.get("SaveServerSuccess"));
        }
        edit(servername);
      }
    }
    // New
    validation.required(servername);

    if (validation.hasErrors()) {
      // Used to identify the period that had the error
      validation.keep();
      add();
    }

    XMLServer server = new XMLServer();
    server.setName(servername);
    server.setClazz(classname);
    serversconfig.getServer().add(server);
    flash.success(Messages.get("SaveServerSuccess"));
    edit(servername);
  }
Exemple #5
0
  private static boolean replaceServerProperties(XMLServer server) {
    Class<?> serverclazz;

    try {
      serverclazz = Class.forName(server.getClazz());
    } catch (ClassNotFoundException e) {
      try {
        serverclazz = Class.forName("com.ingby.socbox.bischeck.servers." + server.getClazz());
      } catch (Exception ret) {
        return false;
      }
    }

    java.util.Properties defaultproperties = null;
    Method method;
    try {
      method = serverclazz.getMethod("getServerProperties");
      defaultproperties = (java.util.Properties) method.invoke(null);
    } catch (Exception ret) {
      return false;
    }

    Iterator<XMLProperty> iter = server.getProperty().iterator();
    // Update the default properties with what is currently set
    // in the server property
    while (iter.hasNext()) {
      XMLProperty xmlprop = iter.next();
      if (defaultproperties.containsKey(xmlprop.getKey()))
        defaultproperties.setProperty(xmlprop.getKey(), xmlprop.getValue());
    }

    // Create a new server property list
    List<XMLProperty> serverproperty = new ArrayList<XMLProperty>();
    Iterator<Object> keyiter = defaultproperties.keySet().iterator();

    while (keyiter.hasNext()) {
      String key = (String) keyiter.next();
      XMLProperty xmlprop = new XMLProperty();
      xmlprop.setKey(key);
      xmlprop.setValue((String) defaultproperties.get(key));
      serverproperty.add(xmlprop);
    }

    server.getProperty().clear();
    server.getProperty().addAll(serverproperty);

    return true;
  }
Exemple #6
0
  public static void deleteProperty(String servername, String key) {

    XMLServers serversconfig = getCache();
    Iterator<XMLServer> servers = serversconfig.getServer().iterator();

    while (servers.hasNext()) {
      XMLServer server = servers.next();

      if (server.getName().equals(servername)) {
        Iterator<XMLProperty> propertiesIter = server.getProperty().iterator();
        while (propertiesIter.hasNext()) {

          XMLProperty xmlprop = propertiesIter.next();
          if (xmlprop.getKey().equals(key)) {
            server.getProperty().remove(xmlprop);
            break;
          }
        }
      }
    }
    flash.success(Messages.get("DeleteServerPropertySuccess"));
    edit(servername);
  }
Exemple #7
0
  public static void saveProperty() {
    String servername = params.get("servername");
    String key = params.get("key");
    String value = params.get("value");

    boolean existingKey = false;
    XMLServers serversconfig = getCache();
    Iterator<XMLServer> servers = serversconfig.getServer().iterator();

    while (servers.hasNext()) {
      XMLServer server = servers.next();

      if (server.getName().equals(servername)) {

        Iterator<XMLProperty> propertiesIter = server.getProperty().iterator();
        while (propertiesIter.hasNext()) {

          XMLProperty xmlprop = propertiesIter.next();

          if (xmlprop.getKey().equals(key)) {
            existingKey = true;
            xmlprop.setValue(value);
          }
        }
        if (!existingKey) {
          List<XMLProperty> propertiesList = server.getProperty();
          XMLProperty property = new XMLProperty();
          property.setKey(key);
          property.setValue(value);
          propertiesList.add(property);
        }
        flash.success(Messages.get("SaveServerPropertySuccess"));
        edit(server.getName());
      }
    }
  }