source: release-kits/wirk3/ant-scripts/tasks/antelope/src/ise/antelope/tasks/PasswordHandlerTask.java@ 15023

Last change on this file since 15023 was 15023, checked in by oranfry, 16 years ago

did the bulk of the work on wirk3

File size: 2.3 KB
Line 
1package ise.antelope.tasks;
2
3import java.util.regex.*;
4
5import org.apache.tools.ant.BuildException;
6
7import org.apache.tools.ant.Task;
8
9import ise.antelope.tasks.password.*;
10
11/**
12 * Copyright 2003
13 *
14 * @version $Revision: 1.3 $
15 */
16public class PasswordHandlerTask extends Task {
17
18 private String in = null;
19 private String out = null;
20 private String mode = null;
21 private String seed = null;
22
23 /**
24 * Sets the name of a property containing the password to encrypt or decrypt.
25 *
26 * @param string The new in value
27 */
28 public void setIn(String string) {
29 in = string;
30 }
31
32 /**
33 * Sets the name of a property to receive the encrypted or decrypted password.
34 *
35 * @param string out the property name
36 */
37 public void setOut(String string) {
38 out = string;
39 }
40
41 /**
42 * One of "encrypt" or "decrypt", if not explicitly set, assumes "decrypt".
43 *
44 * @param mode one of "encrypt" or "decrypt".
45 */
46 public void setMode(String mode) {
47 if (mode == null || (!mode.equals("encrypt") && !mode.equals("decrypt")))
48 throw new BuildException("Invalid mode, must be either 'encrypt' or 'decrypt'");
49 this.mode = mode;
50 }
51
52 public void setSeed(String seed) {
53 this.seed = seed;
54 }
55
56
57 /** Description of the Method */
58 public void execute() {
59 if (in == null)
60 throw new BuildException("'in' is required");
61 if (out == null)
62 throw new BuildException("'out' is required");
63 if (mode == null)
64 mode = "decrypt";
65
66 try {
67 PasswordHandler ph = null;
68 if (seed != null)
69 ph = new PasswordHandler(seed);
70 else
71 ph = new PasswordHandler();
72
73 String answer = "";
74 if (mode.equals("encrypt")) {
75 answer = ph.encrypt(in);
76 }
77 else if (mode.equals("decrypt")) {
78 answer = ph.decrypt(in);
79 }
80 else {
81 throw new BuildException("Invalid mode, must be either 'encrypt' or 'decrypt'");
82 }
83 getProject().setUserProperty(out, answer);
84 }
85 catch(Exception e) {
86 throw new BuildException(e.getMessage());
87 }
88 }
89}
90
Note: See TracBrowser for help on using the repository browser.