Tue, 13 Aug 2019 21:54:17 +0200
yet another compatibility fix
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.unixwork.uwproj; import java.util.LinkedList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * * @author olaf */ public class Option { private String arg; LinkedList<OptionValue> values = new LinkedList<>(); LinkedList<OptionDefault> defaults = new LinkedList<>(); public static Option parse(Project project, Element element) throws Exception { Option opt = new Option(); String arg = element.getAttribute("arg"); if(arg.length() == 0) { throw new Exception("Option has no argument string"); } opt.setArgument(arg); NodeList nodes = element.getChildNodes(); for(int i=0;i<nodes.getLength();i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element elm = (Element)node; String n = elm.getNodeName(); if(n.equals("value")) { OptionValue value = new OptionValue(opt); value.setValue(elm.getAttribute("str")); value.setTargetData(TargetData.parse(elm)); opt.values.add(value); } else if(n.equals("default")) { String defValue = elm.getAttribute("value"); String defPlatform = elm.getAttribute(("platform")); OptionDefault def = new OptionDefault(opt); def.setValueName(defValue); if(defPlatform.length() > 0) { def.setPlatform(defPlatform); } opt.defaults.add(def); } } } return opt; } public String getArgument() { return arg; } public void setArgument(String arg) { this.arg = arg; } public String getVarName() { return "OPT_" + arg.toUpperCase(); } public String getArgValue() { return "${ARG:"+(3+arg.length())+"}"; } public List<OptionValue> getValues() { return values; } public List<OptionDefault> getDefaults() { return defaults; } public String getValueFunc(String value) { return "checkopt_"+arg+"_"+value; } public String getValuesString() { if(values.size() == 0) { return "()"; } else if(values.size() == 1) { return values.get(0).getValue(); } else { StringBuilder vs = new StringBuilder(); vs.append('('); for(int i=0;i<values.size();i++) { if(i < values.size()-1) { vs.append(values.get(i).getValue()); vs.append('|'); } else { vs.append(values.get(i).getValue()); } } vs.append(')'); return vs.toString(); } } }