[950] | 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;
|
---|
[1339] | 19 | import java.util.regex.Matcher;
|
---|
| 20 | import java.util.regex.Pattern;
|
---|
[950] | 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;
|
---|
[1179] | 27 | import de.ugoe.cs.util.console.Console;
|
---|
[950] | 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) {
|
---|
[1339] | 47 | String filename = null;
|
---|
| 48 | String sequencesName = null;
|
---|
[1496] | 49 | String parseParamFile = null;
|
---|
[950] | 50 |
|
---|
| 51 | try {
|
---|
[1339] | 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 {
|
---|
[1496] | 63 | Pattern parseParamPattern = Pattern.compile("-(\\w*)=([\\w/\\.-]*)");
|
---|
[1339] | 64 | Matcher matcher = parseParamPattern.matcher(param);
|
---|
| 65 |
|
---|
| 66 | if (matcher.matches()) {
|
---|
| 67 | String key = matcher.group(1);
|
---|
[1496] | 68 | if (!"parseParamFile".equals(key)) {
|
---|
| 69 | String message = "unknown parameter: " + key;
|
---|
| 70 | Console.printerrln(message);
|
---|
| 71 | throw new IllegalArgumentException(message);
|
---|
[1339] | 72 | }
|
---|
| 73 |
|
---|
[1496] | 74 | parseParamFile = matcher.group(2);
|
---|
[1339] | 75 | }
|
---|
| 76 | else {
|
---|
[1496] | 77 | String message = "parameter does not follow format: -<key>=<value>";
|
---|
[1339] | 78 | Console.printerrln(message);
|
---|
| 79 | throw new IllegalArgumentException(message);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[950] | 82 | }
|
---|
| 83 | }
|
---|
| 84 | catch (Exception e) {
|
---|
[1339] | 85 | throw new IllegalArgumentException("illegal parameters provided: " + e);
|
---|
[950] | 86 | }
|
---|
| 87 |
|
---|
[1339] | 88 | if (sequencesName == null) {
|
---|
| 89 | sequencesName = "sequences";
|
---|
| 90 | }
|
---|
[950] | 91 |
|
---|
[1496] | 92 | HTMLLogParser parser = new HTMLLogParser(parseParamFile);
|
---|
[1339] | 93 |
|
---|
[1179] | 94 | try {
|
---|
| 95 | parser.parseFile(filename);
|
---|
| 96 | }
|
---|
| 97 | catch (Exception e) {
|
---|
| 98 | Console.printerrln("Could not parse " + filename + ": " + e.getMessage());
|
---|
| 99 | return;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[950] | 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() {
|
---|
[1496] | 122 | return "parseHTML <filename> [<sequencesName>] {-parseParams=path/to/parseParamsFile}";
|
---|
[950] | 123 | }
|
---|
| 124 |
|
---|
| 125 | }
|
---|