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