1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.httpquery.config;
13 import net.sourceforge.phpdt.phphelp.PHPHelpPlugin;
18 public class Configuration implements IConfiguration, Comparable {
19 private static final String MEMENTO_ID = "id";
21 private static final String MEMENTO_NAME = "name";
23 private static final String MEMENTO_USER = "user";
25 private static final String MEMENTO_URL = "url";
27 private static final String MEMENTO_PASSWORD = "password";
29 private static final String MEMENTO_TYPE_ID = "type-id";
31 protected String fId = "";
33 protected String fName = "";
35 protected String fUrl = "";
37 protected String fPassword = "";
39 protected String fUser = "";
41 protected String fType = "";
43 private static final char[] SCRAMBLING_TABLE = new char[] { 0, 1, 2, 3, 4,
44 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
45 23, 24, 25, 26, 27, 28, 29, 30, 31, 114, 120, 53, 79, 96, 109, 72,
46 108, 70, 64, 76, 67, 116, 74, 68, 87, 111, 52, 75, 119, 49, 34, 82,
47 81, 95, 65, 112, 86, 118, 110, 122, 105, 41, 57, 83, 43, 46, 102,
48 40, 89, 38, 103, 45, 50, 42, 123, 91, 35, 125, 55, 54, 66, 124,
49 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, 36, 121, 117, 104,
50 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, 58, 113, 32, 90,
51 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85, 223, 225, 216, 187,
52 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190,
53 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213,
54 203, 226, 193, 174, 172, 228, 252, 217, 201, 131, 230, 197, 211,
55 145, 238, 161, 179, 160, 212, 207, 221, 254, 173, 202, 146, 224,
56 151, 140, 196, 205, 130, 135, 133, 143, 246, 192, 159, 244, 239,
57 185, 168, 215, 144, 139, 165, 180, 157, 147, 186, 214, 176, 227,
58 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177,
59 134, 127, 182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153,
60 251, 237, 236, 171, 195, 243, 233, 253, 240, 194, 250, 191, 155,
61 142, 137, 245, 235, 163, 242, 178, 152 };
64 * Construct a Configuration with the defult type:
65 * <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
68 public Configuration() {
69 this(PHPHelpPlugin.HTTP_QUERY); // default type
73 * Construct a Configuration with a type
77 * <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
79 * @see net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin
81 public Configuration(String type) {
85 public String getId() {
89 public String getName() {
93 public String getURL() {
97 public String getPassword() {
104 * @see org.eclipse.monitor.internal.IConfiguration#getLocalPort()
106 public String getUser() {
112 public String getType() {
119 * @see org.eclipse.monitor.internal.IConfiguration#isRunning()
121 public boolean isActive() {
122 return ConfigurationManager.getInstance().isActive(this);
125 public void delete() {
126 ConfigurationManager.getInstance().removeConfiguration(this);
129 public boolean isWorkingCopy() {
133 public IConfigurationWorkingCopy getWorkingCopy() {
134 return new ConfigurationWorkingCopy(this);
137 protected void setInternal(IConfiguration monitor) {
138 fId = monitor.getId();
139 fName = monitor.getName();
140 fUrl = monitor.getURL();
141 fPassword = monitor.getPassword();
142 fUser = monitor.getUser();
143 fType = monitor.getType();
146 protected void save(IMemento memento) {
147 memento.putString(MEMENTO_ID, fId);
148 memento.putString(MEMENTO_NAME, fName);
149 memento.putString(MEMENTO_TYPE_ID, fType);
150 memento.putString(MEMENTO_USER, fUser);
151 memento.putString(MEMENTO_URL, fUrl);
152 String result = 'A' + scramblePassword(fPassword);
153 memento.putString(MEMENTO_PASSWORD, result);
156 protected void load(IMemento memento) {
157 fId = memento.getString(MEMENTO_ID);
161 fName = memento.getString(MEMENTO_NAME);
165 fType = memento.getString(MEMENTO_TYPE_ID);
169 fUser = memento.getString(MEMENTO_USER);
173 fUrl = memento.getString(MEMENTO_URL);
177 String result = memento.getString(MEMENTO_PASSWORD);
179 if (result == null) {
182 fPassword = scramblePassword(result.substring(1));
189 * @see java.lang.Object#toString()
191 public String toString() {
192 StringBuffer buffer = new StringBuffer();
193 buffer.append(fName);
194 buffer.append(" - ");
195 buffer.append(fUser);
196 buffer.append(" - ");
198 buffer.append(" - ");
199 buffer.append(fType);
200 return buffer.toString();
206 * @see java.lang.Comparable#compareTo(java.lang.Object)
208 public int compareTo(Object o) {
209 if (o instanceof IConfiguration) {
210 return fName.compareTo(((IConfiguration) o).getName());
215 private static String scramblePassword(String password) {
216 int length = password.length();
217 char[] out = new char[length];
218 for (int i = 0; i < length; i++) {
219 char value = password.charAt(i);
220 out[i] = SCRAMBLING_TABLE[value];
222 return new String(out);
225 public boolean isUserComplete() {
226 if (fUser == null || fUser.equals("")) {
229 if (fPassword == null || fPassword.equals("")) {
238 * @see java.lang.Object#equals(java.lang.Object)
240 public boolean equals(Object obj) {
241 if (obj instanceof Configuration) {
242 if (fName == null || ((Configuration) obj).fName == null) {
245 return fName.equals(((Configuration) obj).fName);