+ Added form data validator in java Beans
parent
b80a2e22d2
commit
3dc9b97d1e
@ -0,0 +1,36 @@
|
||||
package fr.sixthemes.beans;
|
||||
|
||||
public class NetConf6 extends NetConf {
|
||||
|
||||
public NetConf6() {
|
||||
super();
|
||||
}
|
||||
|
||||
public NetConf6(String ipAddress, String gateway, String network, String configuration) {
|
||||
super(ipAddress, gateway, network, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfiguration(String configuration) {
|
||||
switch(configuration) {
|
||||
case "dhcp":
|
||||
case "static":
|
||||
case "slaac":
|
||||
case "empty":
|
||||
this.configuration = configuration;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.configuration = "dhcp";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setIPValidator() {
|
||||
ipRegex = "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))";
|
||||
|
||||
cidrRegex = "/([1-5]?[0-9]|6[0-4])";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package fr.sixthemes.beans;
|
||||
|
||||
import fr.sixthemes.utils.Utils;
|
||||
|
||||
public class SysConf {
|
||||
|
||||
/*
|
||||
* ╔════════════╗
|
||||
* ║ ATTRIBUTES ║
|
||||
* ╚════════════╝
|
||||
*/
|
||||
|
||||
protected String hostname;
|
||||
protected String cores;
|
||||
protected String ram;
|
||||
protected String disk;
|
||||
|
||||
/*
|
||||
* ╔══════════════╗
|
||||
* ║ CONSTRUCTORS ║
|
||||
* ╚══════════════╝
|
||||
*/
|
||||
|
||||
public SysConf() {
|
||||
this.setHostname("");
|
||||
this.setCores("");
|
||||
this.setRam("");
|
||||
this.setDisk("");
|
||||
}
|
||||
|
||||
public SysConf(String hostname, String cores, String ram, String disk) {
|
||||
this.setHostname(hostname);
|
||||
this.setCores(cores);
|
||||
this.setRam(ram);
|
||||
this.setDisk(disk);
|
||||
}
|
||||
|
||||
/*
|
||||
* ╔═════════╗
|
||||
* ║ GETTERS ║
|
||||
* ╚═════════╝
|
||||
*/
|
||||
|
||||
public String getHostname() {
|
||||
return this.hostname;
|
||||
}
|
||||
|
||||
public String getCores() {
|
||||
return this.cores;
|
||||
}
|
||||
|
||||
public String getRam() {
|
||||
return this.ram;
|
||||
}
|
||||
|
||||
public String getDisk() {
|
||||
return this.disk;
|
||||
}
|
||||
|
||||
/*
|
||||
* ╔═════════╗
|
||||
* ║ SETTERS ║
|
||||
* ╚═════════╝
|
||||
*/
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = !hostname.isEmpty() ? hostname : "default-hostname";
|
||||
}
|
||||
|
||||
public void setCores(String cores) {
|
||||
this.cores = Utils.isInteger(cores) ? cores : "2";
|
||||
}
|
||||
|
||||
public void setRam(String ram) {
|
||||
this.ram = Utils.isInteger(ram) ? ram : "1024";
|
||||
}
|
||||
|
||||
public void setDisk(String disk) {
|
||||
this.disk = Utils.isInteger(disk) ? disk : "16";
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +1,15 @@
|
||||
package fr.sixthemes.utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class Utils {
|
||||
|
||||
public static boolean isValidIP(String ipAddress) {
|
||||
public static boolean isInteger(String strNum) {
|
||||
if(strNum.isEmpty() || strNum == null) return false;
|
||||
|
||||
Pattern p = Pattern.compile("");
|
||||
Matcher m = p.matcher(ipAddress);
|
||||
|
||||
if(!m.find()) return false;
|
||||
Pattern p = Pattern.compile("^\\d*$");
|
||||
|
||||
return true;
|
||||
return p.matcher(strNum).matches();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue