[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.io.File;
|
---|
[1012] | 18 | import java.util.Arrays;
|
---|
[950] | 19 | import java.util.Collection;
|
---|
| 20 | import java.util.List;
|
---|
| 21 | import java.util.logging.Level;
|
---|
| 22 |
|
---|
| 23 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 25 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
|
---|
| 26 | import de.ugoe.cs.autoquest.plugin.html.HTMLLogParser;
|
---|
| 27 | import de.ugoe.cs.util.console.Command;
|
---|
| 28 | import de.ugoe.cs.util.console.Console;
|
---|
| 29 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 30 |
|
---|
| 31 | /**
|
---|
| 32 | * <p>
|
---|
| 33 | * Command that tries to parse all files in a folder as if they were log files generated by the
|
---|
| 34 | * HTMLMonitor. The result is one set of sequences for all files (not one set of sequences for each
|
---|
| 35 | * file!).
|
---|
| 36 | * </p>
|
---|
| 37 | *
|
---|
| 38 | * @author Patrick Harms
|
---|
| 39 | * @version 1.0
|
---|
| 40 | */
|
---|
| 41 | public class CMDparseDirHTML implements Command {
|
---|
| 42 |
|
---|
| 43 | /*
|
---|
| 44 | * (non-Javadoc)
|
---|
| 45 | *
|
---|
| 46 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 47 | */
|
---|
| 48 | @Override
|
---|
| 49 | public void run(List<Object> parameters) {
|
---|
| 50 | String path;
|
---|
| 51 | String sequencesName = "sequences";
|
---|
| 52 |
|
---|
| 53 | try {
|
---|
| 54 | path = (String) parameters.get(0);
|
---|
| 55 | if (parameters.size() >= 2) {
|
---|
| 56 | sequencesName = (String) parameters.get(1);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | catch (Exception e) {
|
---|
[1087] | 60 | throw new IllegalArgumentException("illegal parameters provided: " + e);
|
---|
[950] | 61 | }
|
---|
| 62 |
|
---|
| 63 | File folder = new File(path);
|
---|
| 64 | if (!folder.isDirectory()) {
|
---|
| 65 | Console.printerrln(path + " is not a directory");
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | HTMLLogParser parser = new HTMLLogParser();
|
---|
| 70 |
|
---|
| 71 | String absolutPath = folder.getAbsolutePath();
|
---|
[1012] | 72 | String[] files = folder.list();
|
---|
| 73 | Arrays.sort(files);
|
---|
| 74 |
|
---|
| 75 | for (String filename : files) {
|
---|
[950] | 76 | String source = absolutPath + "/" + filename;
|
---|
| 77 | Console.traceln(Level.INFO, "Processing file: " + source);
|
---|
| 78 |
|
---|
| 79 | parser.parseFile(source);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | Collection<List<Event>> sequences = parser.getSequences();
|
---|
| 83 |
|
---|
| 84 | GUIModel targets = parser.getGuiModel();
|
---|
| 85 |
|
---|
| 86 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
| 87 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) {
|
---|
| 91 | CommandHelpers.dataOverwritten(sequencesName + "_targets");
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | /*
|
---|
| 96 | * (non-Javadoc)
|
---|
| 97 | *
|
---|
| 98 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 99 | */
|
---|
| 100 | @Override
|
---|
| 101 | public String help() {
|
---|
| 102 | return "parseDirHTML <directory> {<sequencesName>}";
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | }
|
---|