1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.plugin.html.commands;
|
---|
16 |
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.List;
|
---|
19 | import java.util.regex.Matcher;
|
---|
20 | import java.util.regex.Pattern;
|
---|
21 |
|
---|
22 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
23 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
24 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
|
---|
25 | import de.ugoe.cs.autoquest.plugin.html.HTMLLogParser;
|
---|
26 | import de.ugoe.cs.util.console.Command;
|
---|
27 | import de.ugoe.cs.util.console.Console;
|
---|
28 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * Command to parse a file with sessions monitored by AutoQUESTs HTML monitor.
|
---|
33 | * </p>
|
---|
34 | *
|
---|
35 | * @author Patrick Harms
|
---|
36 | * @version 1.0
|
---|
37 | */
|
---|
38 | public class CMDparseHTML implements Command {
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * (non-Javadoc)
|
---|
42 | *
|
---|
43 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
44 | */
|
---|
45 | @Override
|
---|
46 | public void run(List<Object> parameters) {
|
---|
47 | String filename = null;
|
---|
48 | String sequencesName = null;
|
---|
49 | String parseParamFile = null;
|
---|
50 |
|
---|
51 | try {
|
---|
52 | for (int i = 0; i < parameters.size(); i++) {
|
---|
53 | String param = (String) parameters.get(i);
|
---|
54 | if (!param.startsWith("-")) {
|
---|
55 | if (filename == null) {
|
---|
56 | filename = param;
|
---|
57 | }
|
---|
58 | else if (sequencesName == null) {
|
---|
59 | sequencesName = param;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | else {
|
---|
63 | Pattern parseParamPattern = Pattern.compile("-(\\w*)=([\\w/\\.-]*)");
|
---|
64 | Matcher matcher = parseParamPattern.matcher(param);
|
---|
65 |
|
---|
66 | if (matcher.matches()) {
|
---|
67 | String key = matcher.group(1);
|
---|
68 | if (!"parseParamFile".equals(key)) {
|
---|
69 | String message = "unknown parameter: " + key;
|
---|
70 | Console.printerrln(message);
|
---|
71 | throw new IllegalArgumentException(message);
|
---|
72 | }
|
---|
73 |
|
---|
74 | parseParamFile = matcher.group(2);
|
---|
75 | }
|
---|
76 | else {
|
---|
77 | String message = "parameter does not follow format: -<key>=<value>";
|
---|
78 | Console.printerrln(message);
|
---|
79 | throw new IllegalArgumentException(message);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | catch (Exception e) {
|
---|
85 | throw new IllegalArgumentException("illegal parameters provided: " + e);
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (sequencesName == null) {
|
---|
89 | sequencesName = "sequences";
|
---|
90 | }
|
---|
91 |
|
---|
92 | HTMLLogParser parser = new HTMLLogParser(parseParamFile);
|
---|
93 |
|
---|
94 | try {
|
---|
95 | parser.parseFile(filename);
|
---|
96 | }
|
---|
97 | catch (Exception e) {
|
---|
98 | Console.printerrln("Could not parse " + filename + ": " + e.getMessage());
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
103 |
|
---|
104 | GUIModel targets = parser.getGuiModel();
|
---|
105 |
|
---|
106 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
107 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) {
|
---|
111 | CommandHelpers.dataOverwritten(sequencesName + "_targets");
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * (non-Javadoc)
|
---|
117 | *
|
---|
118 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
119 | */
|
---|
120 | @Override
|
---|
121 | public String help() {
|
---|
122 | return "parseHTML <filename> [<sequencesName>] {-parseParams=path/to/parseParamsFile}";
|
---|
123 | }
|
---|
124 |
|
---|
125 | }
|
---|