1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 package base.user;
21
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
24 import org.w3c.dom.Node;
25
26 import base.ICXmlTags;
27 import base.IXMLSaveable;
28
29 public class EAddress implements IXMLSaveable {
30
31 private int id;
32
33 private String userName;
34
35 private String hostName;
36
37 private String domainName;
38
39 private String description = "";
40
41 public EAddress(int id, String address) {
42 this.id = id;
43 this.userName = address.substring(0, address.indexOf("@"));
44 this.hostName = address.substring(address.indexOf("@") + 1, address
45 .lastIndexOf("."));
46 this.domainName = address.substring(address.lastIndexOf(".") + 1,
47 address.length());
48 }
49
50 /***
51 * @param id
52 * @param userName
53 * @param hostName
54 * @param domainName
55 * @param description
56 */
57 public EAddress(int id, String userName, String hostName,
58 String domainName, String description) {
59 super();
60
61 this.id = id;
62 this.userName = userName;
63 this.hostName = hostName;
64 this.domainName = domainName;
65 this.description = description;
66 }
67
68 public EAddress() {
69
70 }
71
72 /***
73 * @return Returns the description.
74 */
75 public String getDescription() {
76 return description;
77 }
78
79 /***
80 * @return Returns the domainName.
81 */
82 public String getDomainName() {
83 return domainName;
84 }
85
86 /***
87 * @return Returns the hostName.
88 */
89 public String getHostName() {
90 return hostName;
91 }
92
93 /***
94 * @return Returns the userName.
95 */
96 public String getUserName() {
97 return userName;
98 }
99
100
101
102
103
104
105 @Override
106 public String toString() {
107 return this.getUserName() + "@" + this.getHostName() + "."
108 + this.getDomainName();
109 }
110
111 /***
112 * @return Returns the id.
113 */
114 public int getId() {
115 return id;
116 }
117
118 /***
119 * @param id
120 * The id to set.
121 */
122 protected void setId(int id) {
123 this.id = id;
124 }
125
126 /***
127 * @param description
128 * The description to set.
129 */
130 public void setDescription(String description) {
131 this.description = description;
132 }
133
134 /***
135 * @param domainName
136 * The domainName to set.
137 */
138 protected void setDomainName(String domainName) {
139 this.domainName = domainName;
140 }
141
142 /***
143 * @param hostName
144 * The hostName to set.
145 */
146 protected void setHostName(String hostName) {
147 this.hostName = hostName;
148 }
149
150 /***
151 * @param userName
152 * The userName to set.
153 */
154 protected void setUserName(String userName) {
155 this.userName = userName;
156 }
157
158 public Node toXml(Document document) {
159 Element eAddressElement = document
160 .createElement(ICXmlTags.IC_EADDRESS_TAG);
161 eAddressElement.setAttribute(ICXmlTags.IC_EADDRESS_ID_ATTRIBUTE, ""
162 + this.id);
163 eAddressElement.setAttribute(
164 ICXmlTags.IC_EADDRESS_FULL_ADDRESS_ATTRIBUTE, this.toString());
165
166 Element descriptionElement = document
167 .createElement(ICXmlTags.IC_EADDRESS_DESCRIPTION_TAG);
168 descriptionElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
169 this.description);
170 eAddressElement.appendChild(descriptionElement);
171
172 return eAddressElement;
173 }
174
175 public EAddress fromXml(Node node) {
176
177 int id = Integer.parseInt(node.getAttributes().getNamedItem(ICXmlTags.IC_EADDRESS_ID_ATTRIBUTE).getNodeValue());
178
179 String fullAddress = node.getChildNodes().item(0).getAttributes().getNamedItem(ICXmlTags.IC_EADDRESS_FULL_ADDRESS_ATTRIBUTE).getNodeValue();
180
181 return new EAddress(id,fullAddress);
182 }
183
184 }