+ req = parseConditions(requires);
+ pt = parsePropertyTemplates(include);
+ }
+
+ public static class PropertyTemplate implements Comparable<PropertyTemplate> {
+
+ private boolean required = true;
+
+ private boolean multiple = false;
+
+ private String base;
+
+ public PropertyTemplate(String inc) {
+ if (inc.endsWith("?") || inc.endsWith("*") || inc.endsWith("+")) {
+ char sfx = inc.charAt(inc.length() - 1);
+ if (sfx == '?') {
+ required = false;
+ } else if (sfx == '*') {
+ multiple = true;
+ required = false;
+ } else {
+ multiple = true;
+ }
+ inc = inc.substring(0, inc.length() - 1);
+ }
+ this.base = inc;
+ }
+
+ public String getBase() {
+ return base;
+ }
+
+ public boolean isMultiple() {
+ return multiple;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((base == null) ? 0 : base.hashCode());
+ result = prime * result + (multiple ? 1231 : 1237);
+ result = prime * result + (required ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ PropertyTemplate other = (PropertyTemplate) obj;
+ if (base == null) {
+ if (other.base != null) {
+ return false;
+ }
+ } else if ( !base.equals(other.base)) {
+ return false;
+ }
+ if (multiple != other.multiple) {
+ return false;
+ }
+ if (required != other.required) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return base + (multiple ? (required ? "+" : "*") : (required ? "" : "?"));
+ }
+
+ @Override
+ public int compareTo(PropertyTemplate o) {
+ return toString().compareTo(o.toString());
+ }
+
+ }
+
+ private CertificateProfile(File f) throws IOException {
+ Properties p = new Properties();
+ try (FileInputStream inStream = new FileInputStream(f)) {
+ p.load(inStream);
+ }
+ String[] parts = f.getName().split("\\.")[0].split("-", 2);
+ id = Integer.parseInt(parts[0]);
+ keyName = parts[1];
+ visibleName = "";
+ pt = parsePropertyTemplates(p.getProperty("include"));
+ req = parseConditions(p.getProperty("requires", ""));
+ }
+
+ private List<String> parseConditions(String property) {
+ String[] split2 = property.split(",");
+ if (split2.length == 1 && split2[0].equals("")) {
+ split2 = new String[0];
+ }
+ return Collections.unmodifiableList(Arrays.asList(split2));
+ }
+
+ private Map<String, PropertyTemplate> parsePropertyTemplates(String property) {
+ String[] split = property.split(",");
+ HashMap<String, PropertyTemplate> map = new HashMap<>(split.length);
+ for (int i = 0; i < split.length; i++) {
+
+ PropertyTemplate value = new PropertyTemplate(split[i]);
+
+ map.put(value.getBase(), value);
+ }
+ return Collections.unmodifiableMap(map);