[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 |
|
---|
| 15 | package de.ugoe.cs.autoquest.plugin.html.commands;
|
---|
| 16 |
|
---|
| 17 | import java.io.File;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
| 20 | import de.ugoe.cs.autoquest.plugin.html.HTMLLogTextInputPseudomizer;
|
---|
| 21 | import de.ugoe.cs.util.console.Command;
|
---|
| 22 | import 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 | */
|
---|
| 36 | public 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;
|
---|
| 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 | pseudomizeTextInputsInDirectory(directory);
|
---|
| 59 |
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
[1276] | 63 | * <p>
|
---|
| 64 | * convenience method to traverse the directory structure
|
---|
| 65 | * </p>
|
---|
[1242] | 66 | *
|
---|
[1276] | 67 | * @param directory the directory to be treated next
|
---|
[1242] | 68 | */
|
---|
| 69 | private void pseudomizeTextInputsInDirectory(File directory) {
|
---|
| 70 | if (directory.isDirectory()) {
|
---|
| 71 | File[] children = directory.listFiles();
|
---|
| 72 |
|
---|
| 73 | for (File child : children) {
|
---|
| 74 | pseudomizeTextInputsInDirectory(child);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | else if (directory.isFile()) {
|
---|
| 78 | HTMLLogTextInputPseudomizer pseudomizer = new HTMLLogTextInputPseudomizer();
|
---|
| 79 | pseudomizer.pseudomizeFile(directory);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /*
|
---|
| 84 | * (non-Javadoc)
|
---|
| 85 | *
|
---|
| 86 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 87 | */
|
---|
| 88 | @Override
|
---|
| 89 | public String help() {
|
---|
| 90 | return "pseudomizeHTMLTextInputs <directory>";
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | }
|
---|