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

Last change on this file since 2210 was 1276, checked in by pharms, 11 years ago
  • added some Java Docs
File size: 3.2 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.List;
20
21import de.ugoe.cs.autoquest.plugin.html.HTMLLogCompressor;
22import de.ugoe.cs.util.console.Command;
23import de.ugoe.cs.util.console.Console;
24
25/**
26 * <p>
27 * This command performs a compression of HTML log files. It traverse a directory structure. All
28 * files in the same directory are treated as HTML log files. They are parsed and all GUI elements
29 * and events contained in them are dumped into a new log file. No GUI element is dumped more than
30 * once. Through this, several log files containing duplicates of GUI elements are condensed to
31 * only one. The events are put at the end of the new log file and are sorted based on their time
32 * stamp.
33 * </p>
34 *
35 * @author Patrick Harms
36 * @version 1.0
37 */
38public class CMDcompressHTMLLogFiles implements Command {
39
40    /* (non-Javadoc)
41     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
42     */
43    @Override
44    public void run(List<Object> parameters) {
45        String path;
46
47        try {
48            path = (String) parameters.get(0);
49        }
50        catch (Exception e) {
51            throw new IllegalArgumentException("illegal parameters provided: " + e);
52        }
53
54        File directory = new File(path);
55        if (!directory.isDirectory()) {
56            Console.printerrln(path + " is not a directory");
57            return;
58        }
59
60        compressDirectory(directory);
61
62    }
63
64    /**
65     * <p>
66     * convenience method for recursively calling the {@link HTMLLogCompressor} for each directory
67     * </p>
68     *
69     * @param the directory to be traversed
70     */
71    private void compressDirectory(File directory) {
72        if (directory.isDirectory()) {
73            File[] children = directory.listFiles();
74            Arrays.sort(children);
75           
76            boolean containsAtLeastOneFile = false;
77            for (File child : children) {
78                compressDirectory(child);
79               
80                containsAtLeastOneFile |= child.isFile();
81            }
82           
83            if (containsAtLeastOneFile) {
84                HTMLLogCompressor compressor = new HTMLLogCompressor();
85                compressor.compressFilesInDirectory(directory);
86            }
87        }
88    }
89
90    /* (non-Javadoc)
91     * @see de.ugoe.cs.util.console.Command#help()
92     */
93    @Override
94    public String help() {
95        return "compressHTMLLogFiles <directory>";
96    }
97
98}
Note: See TracBrowser for help on using the repository browser.