initial contribution
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / blog / Configuration.java
1 package net.sourceforge.phpeclipse.wiki.blog;
2
3 import net.sourceforge.phpeclipse.wiki.preferences.AlternateUserValidationDialog;
4 import net.sourceforge.phpeclipse.wiki.preferences.UserValidationDialog;
5 import net.sourceforge.phpeclipse.wiki.preferences.Util;
6
7 import org.eclipse.jface.dialogs.Dialog;
8 import org.eclipse.swt.widgets.Shell;
9
10 public class Configuration {
11   String fUrl;
12
13   String fBlogID;
14
15   String fUser;
16
17   String fPassword;
18
19   public Configuration(String url, String blogId, String user, String password) {
20     fUrl = url;
21     fBlogID = blogId;
22     fUser = user;
23     fPassword = password;
24   }
25
26   /**
27    * @return Returns the blogID.
28    */
29   public String getBlogID() {
30     return fBlogID;
31   }
32
33   /**
34    * @param blogID
35    *          The blogID to set.
36    */
37   public void setBlogID(String blogID) {
38     fBlogID = blogID;
39   }
40
41   /**
42    * @return Returns the fPassword.
43    */
44   public String getPassword() {
45     return fPassword;
46   }
47
48   /**
49    * @param fPassword
50    *          The fPassword to set.
51    */
52   public void setPassword(String password) {
53     fPassword = password;
54   }
55
56   /**
57    * @return Returns the url.
58    */
59   public String getUrl() {
60     return fUrl;
61   }
62
63   /**
64    * @param url
65    *          The url to set.
66    */
67   public void setUrl(String url) {
68     fUrl = url;
69   }
70
71   /**
72    * @return Returns the fUser.
73    */
74   public String getUser() {
75     return fUser;
76   }
77
78   /**
79    * @param fUser
80    *          The fUser to set.
81    */
82   public void setUser(String user) {
83     fUser = user;
84   }
85
86   public boolean isUserComplete() {
87     if (fUser==null || fUser.equals("")) {
88       return false;
89     }
90     if (fPassword==null || fPassword.equals("")) {
91       return false;
92     }
93     return true;
94   }
95   /** 
96    * Special alternate prompting. Returns the fPassword. Username must be fixed.
97    * 
98    * 
99    * String passWord = Configuration.alternatePromptForPassword(config.getUser());
100    * if (passWord==null||passWord.equals("")) {
101    *   return;
102    * }
103    * config.setPassword(passWord);
104    */
105   public String alternatePromptForPassword(final String username) {
106     Shell shell = Util.findShell();
107     AlternateUserValidationDialog dialog = new AlternateUserValidationDialog(shell, (username == null) ? "" : username); //$NON-NLS-1$
108     dialog.setUsername(username);
109     int result = dialog.open();
110     if (result == Dialog.CANCEL)
111       return null;
112     return dialog.getPassword();
113   }
114
115   /**
116    * Asks the User to enter a Password. Places the results in the supplied string[]. result[0] must contain the username, result[1]
117    * must contain the fPassword. If the fUser canceled, both values must be zero.
118    * 
119    * @param location
120    *          the location to obtain the fPassword for
121    * @param username
122    *          the username
123    * @param message
124    *          a message to display to the fUser
125    * @param userMutable
126    *          whether the fUser can be changed in the dialog
127    * @param result
128    *          a String array of length two in which to put the result
129    */
130   public boolean promptForPassword(final String username, final String message, final boolean userMutable, final String[] result) {
131     if (isUserComplete()) {
132       result[0] = fUser;
133       result[1] = fPassword;
134       return false;
135     }
136     Shell shell = Util.findShell();
137     if (shell == null) {
138       return false;
139     }
140     String domain = "<test>"; //location == null ? null : location.getLocation();
141     UserValidationDialog dialog = new UserValidationDialog(shell, domain, (username == null) ? "" : username, message);//$NON-NLS-1$
142     dialog.setUsernameMutable(userMutable);
143     dialog.open();
144     result[0] = dialog.getUsername();
145     result[1] = dialog.getPassword();
146     return dialog.getAllowCaching();
147   }
148
149 }