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

Last change on this file since 2210 was 1352, checked in by pharms, 10 years ago
  • improved pseudomization to include search and file input fields
File size: 4.0 KB
RevLine 
[1242]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.HTMLLogTextInputPseudomizer;
21import de.ugoe.cs.util.console.Command;
22import de.ugoe.cs.util.console.Console;
23
24/**
25 * <p>
[1276]26 * replaces all text inputs in a directory structure with MD5 hashes of the text input. If the
27 * text input is already hashed, it stays unchanged. For this, the command traverses the directory
28 * structure. In each directory it treats the contained files as HTML log files. It parses them,
29 * copies all GUI elements and events and replaces the entered text of text input events. The result
30 * is a copy of each treated log file. The origins are deleted. The copies are named as the origins.
[1242]31 * </p>
32 *
33 * @author Patrick Harms
34 * @version 1.0
35 */
36public class CMDpseudomizeHTMLTextInputs implements Command {
37
[1276]38    /* (non-Javadoc)
[1242]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;
[1352]44        boolean pseudomizeSearchInputs = false;
45        boolean pseudomizeFileInputs = false;
[1242]46
47        try {
48            path = (String) parameters.get(0);
[1352]49           
50            for (int i = 1; i < parameters.size(); i++) {
51                if ("includeSearchInputs".equals(parameters.get(i))) {
52                    pseudomizeSearchInputs = true;
53                }
54                else if ("includeFileInputs".equals(parameters.get(i))) {
55                    pseudomizeFileInputs = true;
56                }
57                else {
58                    throw new IllegalArgumentException("unknown parameter: " + parameters.get(i));
59                }
60            }
[1242]61        }
62        catch (Exception e) {
63            throw new IllegalArgumentException("illegal parameters provided: " + e);
64        }
65
66        File directory = new File(path);
67        if (!directory.isDirectory()) {
68            Console.printerrln(path + " is not a directory");
69            return;
70        }
71
[1352]72        pseudomizeTextInputsInDirectory(directory, pseudomizeSearchInputs, pseudomizeFileInputs);
[1242]73
74    }
75
76    /**
[1276]77     * <p>
78     * convenience method to traverse the directory structure
79     * </p>
[1242]80     *
[1276]81     * @param directory the directory to be treated next
[1242]82     */
[1352]83    private void pseudomizeTextInputsInDirectory(File    directory,
84                                                 boolean pseudomizeSearchInputs,
85                                                 boolean pseudomizeFileInputs)
86    {
[1242]87        if (directory.isDirectory()) {
88            File[] children = directory.listFiles();
89           
90            for (File child : children) {
[1352]91                pseudomizeTextInputsInDirectory
92                    (child, pseudomizeSearchInputs, pseudomizeFileInputs);
[1242]93            }
94        }
95        else if (directory.isFile()) {
[1352]96            HTMLLogTextInputPseudomizer pseudomizer =
97                new HTMLLogTextInputPseudomizer(pseudomizeSearchInputs, pseudomizeFileInputs);
[1242]98            pseudomizer.pseudomizeFile(directory);
99        }
100    }
101
102    /*
103     * (non-Javadoc)
104     *
105     * @see de.ugoe.cs.util.console.Command#help()
106     */
107    @Override
108    public String help() {
[1352]109        return "pseudomizeHTMLTextInputs <directory> [includeFileInputs] [includeSearchInputs]";
[1242]110    }
111
112}
Note: See TracBrowser for help on using the repository browser.