KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > UsernamePasswordCredentials


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java,v 1.11.2.1 2004/02/22 18:21:13 olegk Exp $
3  * $Revision: 1.11.2.1 $
4  * $Date: 2004/02/22 18:21:13 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ====================================================================
22  *
23  * This software consists of voluntary contributions made by many
24  * individuals on behalf of the Apache Software Foundation. For more
25  * information on the Apache Software Foundation, please see
26  * <http://www.apache.org/>.
27  *
28  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient;
33
34 /**
35  * <p>Username and password {@link Credentials}.</p>
36  *
37  * @author <a HREF="mailto:remm@apache.org">Remy Maucherat</a>
38  * @author Sean C. Sullivan
39  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
40  *
41  * @version $Revision: 1.11.2.1 $ $Date: 2004/02/22 18:21:13 $
42  *
43  */

44 public class UsernamePasswordCredentials implements Credentials {
45
46     // ----------------------------------------------------------- Constructors
47

48     /**
49      * Default constructor.
50      */

51     public UsernamePasswordCredentials() {
52     }
53
54
55     /**
56      * The constructor with the username and password combined string argument.
57      *
58      * @param usernamePassword the username:password formed string
59      * @see #toString
60      */

61     public UsernamePasswordCredentials(String JavaDoc usernamePassword) {
62         int atColon = usernamePassword.indexOf(':');
63         if (atColon >= 0) {
64             this.userName = usernamePassword.substring(0, atColon);
65             this.password = usernamePassword.substring(atColon + 1);
66         } else {
67             this.userName = usernamePassword;
68         }
69     }
70
71
72     /**
73      * The constructor with the username and password arguments.
74      *
75      * @param userName the user name
76      * @param password the password
77      */

78     public UsernamePasswordCredentials(String JavaDoc userName, String JavaDoc password) {
79         this.userName = userName;
80         this.password = password;
81     }
82
83     // ----------------------------------------------------- Instance Variables
84

85     /**
86      * User name.
87      */

88     private String JavaDoc userName;
89
90
91     /**
92      * Password.
93      */

94     private String JavaDoc password;
95
96
97     // ------------------------------------------------------------- Properties
98

99
100     /**
101      * User name property setter.
102      *
103      * @param userName
104      * @see #getUserName()
105      */

106     public void setUserName(String JavaDoc userName) {
107         this.userName = userName;
108     }
109
110
111     /**
112      * User name property getter.
113      *
114      * @return the userName
115      * @see #setUserName(String)
116      */

117     public String JavaDoc getUserName() {
118         return userName;
119     }
120
121
122     /**
123      * Password property setter.
124      *
125      * @param password
126      * @see #getPassword()
127      */

128     public void setPassword(String JavaDoc password) {
129         this.password = password;
130     }
131
132
133     /**
134      * Password property getter.
135      *
136      * @return the password
137      * @see #setPassword(String)
138      */

139     public String JavaDoc getPassword() {
140         return password;
141     }
142
143     
144     /**
145      * Get this object string.
146      *
147      * @return the username:password formed string
148      */

149     public String JavaDoc toString() {
150         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
151         result.append((this.userName == null) ? "null" : this.userName);
152         result.append(":");
153         result.append((this.password == null) ? "null" : this.password);
154         return result.toString();
155     }
156
157 }
158
159
Popular Tags