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

Last change on this file was 2232, checked in by pharms, 7 years ago
  • solved some findbugs issues
  • Property svn:mime-type set to text/plain
File size: 2.9 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.List;
19
20import de.ugoe.cs.autoquest.plugin.html.HTMLLogQueryDeleter;
21import de.ugoe.cs.util.console.Command;
22import de.ugoe.cs.util.console.Console;
23
24/**
25 * <p>
26 * removes all queries in URL paths from a set of HTML recordings. For this, the command traverses
27 * a given directory structure. In each directory it treats the contained files as HTML log files.
28 * It parses them, copies all GUI elements and events and but removes query paramters from those
29 * GUI elements that contain them. The result is a copy of each treated log file. The origins are
30 * deleted. The copies are named as the origins.
31 * </p>
32 *
33 * @author Patrick Harms
34 * @version 1.0
35 */
36public class CMDdeleteHTMLQueries implements Command {
37
38    /* (non-Javadoc)
39     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
40     */
41    @Override
42    public void run(List<Object> parameters) {
43        String path;
44       
45        try {
46            path = (String) parameters.get(0);
47        }
48        catch (Exception e) {
49            throw new IllegalArgumentException("illegal parameters provided: " + e);
50        }
51
52        File directory = new File(path);
53        if (!directory.isDirectory()) {
54            Console.printerrln(path + " is not a directory");
55            return;
56        }
57
58        deleteHTMLQueriesInDirectory(directory);
59
60    }
61
62    /**
63     * <p>
64     * convenience method to traverse the directory structure
65     * </p>
66     *
67     * @param directory the directory to be treated next
68     */
69    private void deleteHTMLQueriesInDirectory(File directory) {
70        if (directory.isDirectory()) {
71            File[] children = directory.listFiles();
72           
73            if (children != null) {
74                for (File child : children) {
75                    deleteHTMLQueriesInDirectory(child);
76                }
77            }
78        }
79        else if (directory.isFile()) {
80            new HTMLLogQueryDeleter().deleteQueries(directory);
81        }
82    }
83
84    /*
85     * (non-Javadoc)
86     *
87     * @see de.ugoe.cs.util.console.Command#help()
88     */
89    @Override
90    public String help() {
91        return "deleteHTMLQueries <directory>";
92    }
93
94}
Note: See TracBrowser for help on using the repository browser.