Sat, 27 Jan 2024 12:29:50 +0100
update license URL to raw file
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | package de.unixwork.uwproj; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | import org.w3c.dom.Element; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | import org.w3c.dom.Node; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | import org.w3c.dom.NodeList; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
7 | import java.util.LinkedList; |
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
8 | import java.util.List; |
41 | 9 | import java.util.stream.Collectors; |
10 | ||
11 | import static de.unixwork.uwproj.Util.shId; | |
40
b42bfc9e9983
first minor code improvements
Mike Becker <universe@uap-core.de>
parents:
0
diff
changeset
|
12 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | public class Option { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | private String arg; |
41 | 15 | |
16 | private final LinkedList<OptionValue> values = new LinkedList<>(); | |
17 | private final LinkedList<OptionDefault> defaults = new LinkedList<>(); | |
18 | ||
19 | public static Option parse(Element element) throws Exception { | |
20 | var opt = new Option(); | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | String arg = element.getAttribute("arg"); |
41 | 22 | if (arg.isBlank()) { |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | throw new Exception("Option has no argument string"); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | opt.setArgument(arg); |
41 | 26 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | NodeList nodes = element.getChildNodes(); |
41 | 28 | for (int i = 0; i < nodes.getLength(); i++) { |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | Node node = nodes.item(i); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | if (node.getNodeType() == Node.ELEMENT_NODE) { |
41 | 31 | Element elm = (Element) node; |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | String n = elm.getNodeName(); |
41 | 33 | if (n.equals("value")) { |
34 | opt.values.add(new OptionValue(opt, | |
35 | elm.getAttribute("str"), | |
36 | TargetData.parse(elm) | |
37 | )); | |
38 | } else if (n.equals("default")) { | |
39 | var def = new OptionDefault(opt); | |
40 | def.setValueName(elm.getAttribute("value")); | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | String defPlatform = elm.getAttribute(("platform")); |
41 | 42 | if (!defPlatform.isBlank()) { |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | def.setPlatform(defPlatform); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | opt.defaults.add(def); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | } |
41 | 49 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | return opt; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | public String getArgument() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | return arg; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | public void setArgument(String arg) { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | this.arg = arg; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | } |
41 | 60 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | public String getVarName() { |
41 | 62 | return shId("OPT_" + arg.toUpperCase()); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | } |
41 | 64 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | public String getArgValue() { |
41 | 66 | return "${ARG:" + (3 + arg.length()) + "}"; |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
41 | 68 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | public List<OptionValue> getValues() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | return values; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | } |
41 | 72 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | public List<OptionDefault> getDefaults() { |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | return defaults; |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | } |
41 | 76 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | public String getValueFunc(String value) { |
41 | 78 | return shId("checkopt_" + arg + "_" + value); |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | } |
41 | 80 | |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | public String getValuesString() { |
41 | 82 | if (values.size() == 1) { |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | return values.get(0).getValue(); |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | } else { |
41 | 85 | return "(" + values.stream().map(OptionValue::getValue).collect(Collectors.joining("|")) + ")"; |
0
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
38775db5fdf5
add existing source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } |