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[] {
302 * Construct a Configuration with the defult type:
303 * <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
306 public Configuration() {
307 this(PHPHelpPlugin.HTTP_QUERY); // default type
311 * Construct a Configuration with a type
312 * @param type Example: <code>net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin.HTTP_QUERY</code>
314 * @see net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin
316 public Configuration(String type) {
320 public String getId() {
324 public String getName() {
328 public String getURL() {
332 public String getPassword() {
339 * @see org.eclipse.monitor.internal.IConfiguration#getLocalPort()
341 public String getUser() {
347 public String getType() {
354 * @see org.eclipse.monitor.internal.IConfiguration#isRunning()
356 public boolean isActive() {
357 return ConfigurationManager.getInstance().isActive(this);
360 public void delete() {
361 ConfigurationManager.getInstance().removeConfiguration(this);
364 public boolean isWorkingCopy() {
368 public IConfigurationWorkingCopy getWorkingCopy() {
369 return new ConfigurationWorkingCopy(this);
372 protected void setInternal(IConfiguration monitor) {
373 fId = monitor.getId();
374 fName = monitor.getName();
375 fUrl = monitor.getURL();
376 fPassword = monitor.getPassword();
377 fUser = monitor.getUser();
378 fType = monitor.getType();
381 protected void save(IMemento memento) {
382 memento.putString(MEMENTO_ID, fId);
383 memento.putString(MEMENTO_NAME, fName);
384 memento.putString(MEMENTO_TYPE_ID, fType);
385 memento.putString(MEMENTO_USER, fUser);
386 memento.putString(MEMENTO_URL, fUrl);
387 String result = 'A' + scramblePassword(fPassword);
388 memento.putString(MEMENTO_PASSWORD, result);
391 protected void load(IMemento memento) {
392 fId = memento.getString(MEMENTO_ID);
396 fName = memento.getString(MEMENTO_NAME);
400 fType = memento.getString(MEMENTO_TYPE_ID);
404 fUser = memento.getString(MEMENTO_USER);
408 fUrl = memento.getString(MEMENTO_URL);
412 String result = memento.getString(MEMENTO_PASSWORD);
414 if (result == null) {
417 fPassword = scramblePassword(result.substring(1));
424 * @see java.lang.Object#toString()
426 public String toString() {
427 StringBuffer buffer = new StringBuffer();
428 buffer.append(fName);
429 buffer.append(" - ");
430 buffer.append(fUser);
431 buffer.append(" - ");
433 buffer.append(" - ");
434 buffer.append(fType);
435 return buffer.toString();
441 * @see java.lang.Comparable#compareTo(java.lang.Object)
443 public int compareTo(Object o) {
444 if (o instanceof IConfiguration) {
445 return fName.compareTo(((IConfiguration) o).getName());
450 private static String scramblePassword(String password) {
451 int length = password.length();
452 char[] out = new char[length];
453 for (int i = 0; i < length; i++) {
454 char value = password.charAt(i);
455 out[i] = SCRAMBLING_TABLE[value];
457 return new String(out);
460 public boolean isUserComplete() {
461 if (fUser == null || fUser.equals("")) {
464 if (fPassword == null || fPassword.equals("")) {
473 * @see java.lang.Object#equals(java.lang.Object)
475 public boolean equals(Object obj) {
476 if (obj instanceof Configuration) {
477 if (fName == null || ((Configuration) obj).fName == null) {
480 return fName.equals(((Configuration) obj).fName);