source: trunk/autoquest-plugin-html/src/main/java/de/ugoe/cs/autoquest/plugin/html/commands/CMDparseDirHTML.java @ 1178

Last change on this file since 1178 was 1178, checked in by pharms, 11 years ago
  • corrected path handling to include correct system dependent separator
File size: 3.3 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.html.commands;
16
17import java.io.File;
18import java.util.Arrays;
19import java.util.Collection;
20import java.util.List;
21import java.util.logging.Level;
22
23import de.ugoe.cs.autoquest.CommandHelpers;
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
26import de.ugoe.cs.autoquest.plugin.html.HTMLLogParser;
27import de.ugoe.cs.util.console.Command;
28import de.ugoe.cs.util.console.Console;
29import 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 */
41public 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) {
60            throw new IllegalArgumentException("illegal parameters provided: " + e);
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();
72        String[] files = folder.list();
73        Arrays.sort(files);
74       
75        for (String filename : files) {
76            String source = absolutPath + File.separator + 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}
Note: See TracBrowser for help on using the repository browser.