/Users/lyon/j4p/src/xml/adbk/Address.java

1    package xml.adbk; 
2     
3    import java.awt.Color; 
4    import java.beans.XMLEncoder; 
5    import java.io.ByteArrayOutputStream; 
6    import java.io.Serializable; 
7     
8    /** 
9     * <!ELEMENT Address ( 
10    * (title | firstName| lastName)*, 
11    * (streetAddress|address1 | address2| address3 )*, 
12    * (homePage | emailAddress)*, 
13    * (homePhone | businessPhone | faxPhone)*, 
14    * city, 
15    * state, 
16    * zip?)> 
17    */ 
18   // xml.adbk.Address 
19   public class Address implements Comparable, 
20           Serializable { 
21       private String title = null; 
22       private String userId = null; 
23       private String password = null; 
24       private String firstName = null; 
25       private String lastName = null; 
26       private String street = null; 
27       private String company = null; 
28       private String address1 = null; 
29       private String address2 = null; 
30       private String address3 = null; 
31       private String homePage = null; 
32       private String emailAddress = null; 
33       private String homePhone = null; 
34       private String businessPhone = null; 
35       private String faxPhone = null; 
36       private String city = null; 
37       private String state = null; 
38       private String zip = null; 
39       private Color backGroundColor = null; 
40    
41       public int compareTo(Object o1) { 
42           Address a = (Address) o1; 
43           String hisLastName = a.lastName.toLowerCase(); 
44           String lastNameMine = getLastName().toLowerCase(); 
45           return lastNameMine.compareTo(hisLastName); 
46       } 
47    
48       public static void main(String args[]) { 
49           /*      sb.append(title + ","); 
50          sb.append(address1 + ","); 
51          sb.append(userId + ","); 
52          sb.append(password + ","); 
53          sb.append(firstName + ","); 
54          sb.append(lastName + ","); 
55          sb.append(street + ","); 
56          sb.append(city + ","); 
57          sb.append(state + ","); 
58          sb.append(zip); 
59          */ 
60           Address a = new Address(); 
61           a.setZip("066430"); 
62           a.setLastName("Lyon"); 
63           a.setCity("FFirfield"); 
64           System.out.println("a=" + a); 
65       } 
66    
67       public static Address getSample() { 
68           Address a = new Address(); 
69           a.setAddress1("1313 Mocking bird lane"); 
70           a.setCity("munsterville"); 
71           a.setState("ny"); 
72           a.setZip("12181"); 
73           return a; 
74       } 
75    
76       public String toString() { 
77           return this.toXml(); 
78       } 
79    
80       public Address() { 
81       } 
82    
83       public Address(String s[]) { 
84           if (s.length == 8) 
85               setFirst8(s); 
86           if (s.length == 6) 
87               setFirst6(s); 
88       } 
89    
90       public void setFirst8(String s[]) { 
91           //title,firstName,lastName,company, street, city, state, zip 
92           title = s[0]; 
93           firstName = s[1]; 
94           lastName = s[2]; 
95           company = s[3]; 
96           street = s[4]; 
97           city = s[5]; 
98           state = s[6]; 
99           zip = s[7]; 
100      } 
101   
102      public void setFirst6(String s[]) { 
103          // lastName,streetAddress,address1,homePhone,businessPhone,faxPhone 
104          lastName = s[0]; 
105          street = s[1]; 
106          address1 = s[2]; 
107          homePhone = s[3]; 
108          businessPhone = s[4]; 
109          faxPhone = s[5]; 
110      } 
111   
112      public void setAddress2(String s) { 
113          address2 = s; 
114      } 
115   
116      public void setAddress3(String s) { 
117          address3 = s; 
118      } 
119   
120      public void setEmailAddress(String s) { 
121          emailAddress = s; 
122      } 
123   
124      public void setHomePhone(String s) { 
125          homePhone = s; 
126      } 
127   
128      public void setHomePage(String s) { 
129          homePage = s; 
130      } 
131   
132      public void setBusinessPhone(String s) { 
133          businessPhone = s; 
134      } 
135   
136      public void setFaxPhone(String s) { 
137          faxPhone = s; 
138      } 
139   
140      public void setCompany(String s) { 
141          company = s; 
142      } 
143   
144      public void setAddress1(String s) { 
145          address1 = s; 
146      } 
147   
148      public void setTitle(String s) { 
149          title = s; 
150      } 
151   
152      public void setFirstName(String s) { 
153          firstName = s; 
154      } 
155   
156      public void setLastName(String s) { 
157          lastName = s; 
158      } 
159   
160      public void setUserId(String s) { 
161          userId = s; 
162      } 
163   
164      public void setPassword(String s) { 
165          password = s; 
166      } 
167   
168      public void setStreet(String s) { 
169          street = s; 
170      } 
171   
172      public void setCity(String s) { 
173          city = s; 
174      } 
175   
176      public void setState(String s) { 
177          state = s; 
178      } 
179   
180      public boolean match(String ss) { 
181          String s = toCsv(); 
182          return s.indexOf(ss) >= 0; 
183      } 
184   
185      public void setZip(String s) { 
186          zip = s; 
187      } 
188   
189      public String toHtml() { 
190          StringBuffer sb = new StringBuffer(""); 
191          if (title != null) 
192              sb.append("\n\t<td>" + title + "</td>"); 
193          if (company != null) 
194              sb.append("\n\t<td>" + company + "</td>"); 
195          if (userId != null) 
196              sb.append("\n\t<td>" + userId + "</td>"); 
197          if (password != null) 
198              sb.append("\n\t<td>" + password + "</td>"); 
199          if (firstName != null) 
200              sb.append("\n\t<td>" + firstName + "</td>"); 
201          if (lastName != null) 
202              sb.append("\n\t<td>" + lastName + "</td>"); 
203          if (street != null) 
204              sb.append("\n\t<td>" + street + "</td>"); 
205          if (city != null) 
206              sb.append("\n\t<td>" + city + "</td>"); 
207          if (state != null) 
208              sb.append("\n\t<td>" + state + "</td>"); 
209          if (zip != null) 
210              sb.append("\n\t<td>" + zip + "</td>\n"); 
211          return "\n<tr>" 
212                  + sb.toString() 
213                  + "\n</tr>"; 
214      } 
215   
216      public String toCsv() { 
217          StringBuffer sb = new StringBuffer(""); 
218          sb.append(title + ","); 
219          sb.append(address1 + ","); 
220          sb.append(userId + ","); 
221          sb.append(password + ","); 
222          sb.append(firstName + ","); 
223          sb.append(lastName + ","); 
224          sb.append(street + ","); 
225          sb.append(city + ","); 
226          sb.append(state + ","); 
227          sb.append(zip); 
228          return sb.toString() + "\n"; 
229      } 
230   
231      public String toXml() { 
232          ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
233          XMLEncoder e = new XMLEncoder(baos); 
234          e.writeObject(this); 
235          e.flush(); 
236          return baos.toString(); 
237      } 
238   
239      public String toXmlOld() { 
240          StringBuffer sb = new StringBuffer(""); 
241          if (title != null) 
242              sb.append("\n\t<title>" + title + "</title>"); 
243          if (firstName != null) 
244              sb.append("\n\t<firstName>" + firstName + "</firstName>"); 
245          if (lastName != null) 
246              sb.append("\n\t<lastName>" + lastName + "</lastName>"); 
247          if (company != null) 
248              sb.append("\n\t<company>" + company + "</company>"); 
249          if (address1 != null) 
250              sb.append("\n\t<address1>" + address1 + "</address1>"); 
251          if (userId != null) 
252              sb.append("\n\t<userId>" + userId + "</userId>"); 
253          if (password != null) 
254              sb.append("\n\t<password>" + password + "</password>"); 
255          if (street != null) 
256              sb.append("\n\t<street>" + street + "</street>"); 
257          if (city != null) 
258              sb.append("\n\t<city>" + city + "</city>"); 
259          if (state != null) 
260              sb.append("\n\t<state>" + state + "</state>"); 
261          if (zip != null) 
262              sb.append("\n\t<zip>" + zip + "</zip>\n"); 
263          if (homePage != null) 
264              sb.append("\n\t<homePage>" + homePage + "</homePage>"); 
265          return "\n<Address>" 
266                  + sb.toString() 
267                  + "\n</Address>"; 
268      } 
269   
270      public String getTitle() { 
271          return title; 
272      } 
273   
274      public String getUserId() { 
275          return userId; 
276      } 
277   
278      public String getPassword() { 
279          return password; 
280      } 
281   
282      public String getFirstName() { 
283          return firstName; 
284      } 
285   
286      public String getLastName() { 
287          return lastName; 
288      } 
289   
290      public String getStreet() { 
291          return street; 
292      } 
293   
294      public String getCompany() { 
295          return company; 
296      } 
297   
298      public String getAddress1() { 
299          return address1; 
300      } 
301   
302      public String getAddress2() { 
303          return address2; 
304      } 
305   
306      public String getAddress3() { 
307          return address3; 
308      } 
309   
310      public String getHomePage() { 
311          return homePage; 
312      } 
313   
314      public String getEmailAddress() { 
315          return emailAddress; 
316      } 
317   
318      public String getHomePhone() { 
319          return homePhone; 
320      } 
321   
322      public String getBusinessPhone() { 
323          return businessPhone; 
324      } 
325   
326      public String getFaxPhone() { 
327          return faxPhone; 
328      } 
329   
330      public String getCity() { 
331          return city; 
332      } 
333   
334      public String getState() { 
335          return state; 
336      } 
337   
338      public String getZip() { 
339          return zip; 
340      } 
341   
342      public Color getBackGroundColor() { 
343          return backGroundColor; 
344      } 
345   
346      public void setBackGroundColor(Color backGroundColor) { 
347          this.backGroundColor = backGroundColor; 
348      } 
349  }