Source Code Cross Referenced for WabpAddressBook.java in  » Portal » Open-Portal » com » sun » addressbook » wabp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.addressbook.wabp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.addressbook.wabp;
002:
003:        import java.util.ArrayList;
004:        import java.util.Iterator;
005:        import java.util.logging.Logger;
006:        import java.util.logging.Level;
007:
008:        import com.iplanet.iabs.iabsapi.PStoreException;
009:        import com.iplanet.xslui.xslutil.XPathTools;
010:        import com.iplanet.xslui.xslutil.XSLProcessingException;
011:
012:        import org.w3c.dom.Node;
013:        import org.w3c.dom.NamedNodeMap;
014:
015:        import com.sun.addressbook.ABFilter;
016:        import com.sun.addressbook.ABSearchTerm;
017:        import com.sun.addressbook.ABStore;
018:        import com.sun.addressbook.ABStoreException;
019:        import com.sun.addressbook.AddressBook;
020:        import com.sun.addressbook.Element;
021:        import com.sun.addressbook.Entry;
022:        import com.sun.addressbook.Group;
023:        import com.sun.addressbook.OperationNotSupportedException;
024:        import com.sun.addressbook.ABLogger;
025:
026:        public class WabpAddressBook extends AddressBook implements 
027:                WabpABConstants {
028:
029:            protected WabpABStore abStore = null;
030:            protected String abStoreUser = null;
031:
032:            // Create a Logger for this class
033:            private static Logger debugLogger = ABLogger
034:                    .getLogger("com.sun.portal.addressbook.wabp");
035:
036:            /*
037:             * Constructor.  Responsible for setting the Address Book
038:             * store and default id.
039:             *
040:             * @param store  Address Book store
041:             * @param abId   default Address Book ID
042:             */
043:            public WabpAddressBook(ABStore store, String abID) {
044:                super (store, abID);
045:                abStore = (WabpABStore) store;
046:                abStoreUser = abStore.getStoreUser();
047:            }
048:
049:            /*
050:             * Run a search on the Address Book given the constraints and 
051:             * filters specified in the ABFilter argument.
052:             *
053:             * @param abFilter  Address Book Filter used in search
054:             * @returns Element[] of Address Book Elements
055:             */
056:            public Element[] fetch(ABFilter abFilter) throws ABStoreException,
057:                    OperationNotSupportedException {
058:                org.w3c.dom.Element element = null;
059:                ArrayList fetchedElements = null;
060:
061:                String filter = (String) abFilter.getSearchFilter();
062:                String sortBy = getWabpSearchEntrySort(abFilter);
063:                String[] types = getWabpSearchEntryType(abFilter);
064:                String[] returnAttrs = null;
065:                String filterInGroup = null;
066:
067:                // if the group is set in the filter, then only search
068:                // in the group.
069:                //
070:                if (abFilter.getGroup() != null) {
071:                    filterInGroup = "&(" + WabpABConstants.WABP_MEMBEROFGROUP
072:                            + "=" + abFilter.getGroup().getUn() + ")";
073:                    filter = filterInGroup + filter;
074:                    debugLogger.log(Level.FINER, "PSJA_CSAW0013", filter);
075:                }
076:
077:                try {
078:                    element = abStore.getWABPClientPStore().search(getAbID(),
079:                            filter, returnAttrs, types, sortBy);
080:
081:                    fetchedElements = convertNodeToElements((Node) element,
082:                            abFilter);
083:
084:                } catch (XSLProcessingException xpe) {
085:                    throw new ABStoreException(
086:                            "WabpAddressBook: xml fetch failed. " + xpe);
087:                } catch (Exception e) {
088:                    throw new ABStoreException(
089:                            "WabpAddressBook: fetch failed. " + e);
090:                }
091:
092:                return (Element[]) fetchedElements
093:                        .toArray(new Element[fetchedElements.size()]);
094:            }
095:
096:            /*
097:             * Add a new Element to the Address Book.
098:             *
099:             * @param element  Address Book Element to add to the Address Book.
100:             */
101:            public void add(Element element) throws ABStoreException,
102:                    OperationNotSupportedException {
103:
104:                String[] bookEntryIDs = { abID };
105:                WabpXmlUtil xmlutil = null;
106:                StringBuffer buf = null;
107:                String type = null;
108:                String id = null;
109:                String cn = element.getCn();
110:
111:                // check if the Entry is a Group
112:                if (element.getElementType() == Element.GROUP) {
113:                    xmlutil = new WabpXmlUtil((Group) element);
114:                    buf = xmlutil.getGroupXml();
115:                    type = WabpABConstants.WABP_GROUP;
116:
117:                    // otherwise default is an Entry
118:                } else {
119:
120:                    // adding check for cn, found that the cn needs to be set
121:                    // for the Entry to be created
122:                    if (cn == null) {
123:                        String fn = ((Entry) element).getFn();
124:                        String ln = ((Entry) element).getLn();
125:                        element.setCn(getFormattedCn(fn, ln));
126:                    }
127:
128:                    xmlutil = new WabpXmlUtil((Entry) element);
129:                    buf = xmlutil.getAbPersonXml();
130:                    type = WabpABConstants.WABP_ABPERSON;
131:                }
132:
133:                debugLogger.log(Level.FINER, "PSJA_CSAW0014", new String[] {
134:                        abStoreUser, bookEntryIDs[0], buf.toString() });
135:                id = wabpAddEntry(bookEntryIDs, buf, type);
136:
137:                if (id != null) {
138:                    debugLogger.log(Level.FINER, "PSJA_CSAW0015", new String[] {
139:                            abStoreUser, id });
140:                }
141:            }
142:
143:            /*
144:             * Add an element to an existing group in the address book.
145:             *
146:             * @param element  Element to be added to the existing group
147:             * @param group    Address Book group to add the Element to
148:             */
149:            public void addGroupMember(Element element, Group group)
150:                    throws ABStoreException, OperationNotSupportedException {
151:                String groupUn = group.getUn();
152:                String elementUn = element.getUn();
153:
154:                if (groupUn == null) {
155:                    throw new ABStoreException(
156:                            "WabpAddressBook: could not add group member "
157:                                    + "because group unique name is not defined.");
158:                }
159:                if (elementUn == null) {
160:                    throw new ABStoreException(
161:                            "WabpAddressBook: could not add group member "
162:                                    + "because element unique name is not defined.");
163:                }
164:
165:                try {
166:                    // complex case, if the element is of type GROUP then fetch all its members
167:                    // and add them to the group.
168:                    if (element.getElementType() == Element.GROUP) {
169:
170:                        // construct filter 
171:                        ABFilter gfilter = new ABFilter();
172:                        gfilter.setSortBy(ABFilter.CN);
173:                        gfilter.setSortOrder(ABFilter.ASCENDING);
174:
175:                        // fetch group members
176:                        Element[] elements = fetchGroupMembers(gfilter,
177:                                (Group) element);
178:                        ArrayList memberList = new ArrayList(elements.length);
179:
180:                        // add each group member to this group
181:                        for (int i = 0; i < elements.length; i++) {
182:                            Element member = elements[i];
183:
184:                            if (member == null) {
185:                                continue;
186:                            }
187:
188:                            memberList.add(member.getUn());
189:                        }
190:                        String[] mlist = (String[]) memberList
191:                                .toArray(new String[0]);
192:                        abStore.getWABPClientPStore().addGroupMember(abID,
193:                                groupUn, mlist);
194:                        debugLogger.log(Level.FINER, "PSJA_CSAW0016",
195:                                new String[] { abStoreUser,
196:                                        memberList.toString(), groupUn });
197:
198:                        // default, just add the entry as a member of the group
199:                    } else {
200:                        abStore.getWABPClientPStore().addGroupMember(abID,
201:                                groupUn, new String[] { elementUn });
202:
203:                        debugLogger
204:                                .log(Level.FINER, "PSJA_CSAW0016",
205:                                        new String[] { abStoreUser, elementUn,
206:                                                groupUn });
207:                    }
208:                } catch (PStoreException pse) {
209:                    throw new ABStoreException(
210:                            "WabpAddressBook: failed to add group member. "
211:                                    + pse);
212:                }
213:            }
214:
215:            /*
216:             * Delete an Element from the Address Book.
217:             *  
218:             * @param element  Element to be deleted from the Address Book.
219:             */
220:            public void delete(Element element) throws ABStoreException,
221:                    OperationNotSupportedException {
222:                String un = element.getUn();
223:
224:                if (un == null) {
225:                    throw new ABStoreException(
226:                            "WabpAddressBook: could not delete element "
227:                                    + "because unique name is not defined.");
228:                }
229:
230:                try {
231:                    abStore.getWABPClientPStore().deleteEntry(abID, un);
232:                } catch (PStoreException pse) {
233:                    throw new ABStoreException(
234:                            "WabpAddressBook: delete failed. " + pse);
235:                }
236:                debugLogger.log(Level.FINER, "PSJA_CSAW0017", new String[] {
237:                        abStoreUser, un });
238:            }
239:
240:            /*
241:             * Delete an Element from a Group in the Address Book.
242:             * 
243:             * @param element  Element to be deleted in the existing group
244:             * @param group    Address Book group to delete the Element from
245:             */
246:            public void deleteGroupMember(Element element, Group group)
247:                    throws ABStoreException, OperationNotSupportedException {
248:                String groupUn = group.getUn();
249:                String elementUn = element.getUn();
250:
251:                if (groupUn == null) {
252:                    throw new ABStoreException(
253:                            "WabpAddressBook: could not delete group "
254:                                    + "member because group unique name is not defined.");
255:                }
256:                if (elementUn == null) {
257:                    throw new ABStoreException(
258:                            "WabpAddressBook: could not delete group "
259:                                    + "member because element unique name is not defined.");
260:                }
261:
262:                try {
263:                    abStore.getWABPClientPStore().removeGroupMember(abID,
264:                            groupUn, new String[] { elementUn });
265:                } catch (PStoreException pse) {
266:                    throw new ABStoreException(
267:                            "WabpAddressBook: delete group member "
268:                                    + "failed. " + pse);
269:                }
270:                debugLogger.log(Level.FINER, "PSJA_CSAW0018", new String[] {
271:                        abStoreUser, elementUn });
272:            }
273:
274:            /*
275:             * Fetch the address book entries in the specified group.  This
276:             * method retrieves the Group's unique name (un) then defines the
277:             * ABFilter searchTerm.
278:             * 
279:             * @param filter  ABFilter to use.  The searchTerm will be overwritten.  
280:             * @param group   the Group to fetch members for.
281:             * @returns Element[] of Address Book Elements
282:             */
283:            public Element[] fetchGroupMembers(ABFilter filter, Group group)
284:                    throws ABStoreException, OperationNotSupportedException {
285:                String un = group.getUn();
286:
287:                if (un == null) {
288:                    throw new ABStoreException(
289:                            "WabpAddressBook: could not fetch group "
290:                                    + "members because the group's unique name is "
291:                                    + "not defined.");
292:                }
293:
294:                debugLogger.log(Level.FINER, "PSJA_CSAW0019", abStoreUser);
295:                filter.setSearchTerm(newABSearchTerm(WABP_MEMBEROFGROUP, un,
296:                        true));
297:
298:                filter.setGroup(group);
299:                Element[] elements = fetch(filter);
300:                filter.setGroup(null);
301:
302:                return elements;
303:            }
304:
305:            /*
306:             * Modify an Element in the Address Book.
307:             *  
308:             * @param oldElement  the existing element to modify.  only used
309:             *                    to retrieve unique name (un).
310:             * @param newElement  the new element to replace the old element.
311:             */
312:            public void modify(Element oldElement, Element newElement)
313:                    throws ABStoreException, OperationNotSupportedException {
314:                WabpXmlUtil xmlutil = null;
315:                StringBuffer buf = null;
316:                String type = null;
317:                String un = oldElement.getUn();
318:
319:                // check if the Entry is a Group
320:                if (newElement.getElementType() == Element.GROUP) {
321:                    xmlutil = new WabpXmlUtil((Group) newElement);
322:                    buf = xmlutil.getGroupXml();
323:                    type = WabpABConstants.WABP_GROUP;
324:
325:                    // otherwise default is an Entry
326:                } else {
327:                    xmlutil = new WabpXmlUtil((Entry) newElement);
328:                    buf = xmlutil.getAbPersonXml();
329:                    type = WabpABConstants.WABP_ABPERSON;
330:                }
331:
332:                debugLogger.log(Level.FINER, "PSJA_CSAW0020", new String[] {
333:                        abStoreUser, buf.toString() });
334:                wabpModifyEntry(un, buf, type);
335:
336:            }
337:
338:            /*
339:             * Return the ABSearchTerm object corresponding to the service type.
340:             *
341:             * @param name   Name of the attribute to search on
342:             * @param value  Value of the attribute to search (wildcard = '*')
343:             * @param exact  boolean indicating whether the search is 'exact' (true) 
344:             *               or 'contains' (false)
345:             * 
346:             * @return ABSearchTerm object corresponding to the service type.
347:             */
348:            public ABSearchTerm newABSearchTerm(String name, String value,
349:                    boolean exact) {
350:                return new WabpABSearchTerm(name, value, exact);
351:            }
352:
353:            /*
354:             * Return the ABSearchTerm object corresponding to the service type.
355:             *
356:             * @return ABSearchTerm object corresponding to the service type.
357:             */
358:            public ABSearchTerm newABSearchTerm(ABSearchTerm term, int op)
359:                    throws ABStoreException {
360:                return new WabpABSearchTerm(term, op);
361:            }
362:
363:            /**
364:             * Return the ABSearchTerm object corresponding to the service type.
365:             *
366:             * @return ABSearchTerm object corresponding to the service type.
367:             */
368:            public ABSearchTerm newABSearchTerm(ABSearchTerm[] terms, int op)
369:                    throws ABStoreException {
370:                return new WabpABSearchTerm(terms, op);
371:            }
372:
373:            /*
374:             * Responsible for retrieving the wabp XML document and  
375:             * using the WABP client api to add the Address Book entry.
376:             *
377:             * @param bookEntryIDs  The list of entryID of Books this entry belongs to.
378:             * @param xml           wabp XML document.
379:             * @param type          Address Book type.
380:             * @return entry id of the newly add entry. 
381:             */
382:            protected String wabpAddEntry(String[] bookEntryIDs,
383:                    StringBuffer xml, String type) throws ABStoreException {
384:                String id = null;
385:
386:                try {
387:                    org.w3c.dom.Element element = WabpXmlUtil
388:                            .getElementFromWabpXml(xml, type);
389:                    id = abStore.getWABPClientPStore().addEntry(bookEntryIDs,
390:                            element);
391:                } catch (PStoreException pse) {
392:                    throw new ABStoreException("WabpAddressBook: add failed. "
393:                            + pse);
394:                }
395:
396:                return id;
397:            }
398:
399:            /*
400:             * Responsible for retrieving the wabp XML document and
401:             * using the WABP client api to add the Address Book entry.
402:             *
403:             * @param un    The entryID of the Entry to modify.
404:             * @param xml   wabp XML document.
405:             * @param type  Address Book type.
406:             */
407:            public void wabpModifyEntry(String un, StringBuffer xml, String type)
408:                    throws ABStoreException {
409:
410:                try {
411:                    org.w3c.dom.Element element = WabpXmlUtil
412:                            .getElementFromWabpXml(xml, type);
413:                    abStore.getWABPClientPStore()
414:                            .modifyEntry(abID, un, element);
415:                } catch (PStoreException pse) {
416:                    throw new ABStoreException(
417:                            "WabpAddressBook: modify failed. " + pse);
418:                }
419:            }
420:
421:            /*
422:             * Converts a Node (wabp abperson or group) to their respective
423:             * JABAPI implementations (Entry or Group) and returns an array 
424:             * list of Elements
425:             *
426:             * @param node      Node of an abperson or group
427:             * @param abFilter  JABAPI Address Book Filter
428:             * @return an ArrayList of Elements
429:             */
430:            protected ArrayList convertNodeToElements(Node node,
431:                    ABFilter abFilter) throws XSLProcessingException {
432:                ArrayList convertedElements = new ArrayList();
433:                ArrayList nodeList = null;
434:                int index = 0;
435:
436:                if (abFilter.getElementType() == Element.ENTRY) {
437:                    nodeList = XPathTools.getNodesByXPath(node,
438:                            WabpABConstants.WABP_ABPERSON);
439:                } else if (abFilter.getElementType() == Element.GROUP) {
440:                    nodeList = XPathTools.getNodesByXPath(node,
441:                            WabpABConstants.WABP_GROUP);
442:
443:                } else {
444:                    nodeList = XPathTools.getNodesByXPath(node, "*");
445:                }
446:
447:                // iterate thru nodeList and convert to Entry or Group depending
448:                // on Node type.
449:                // 
450:                for (Iterator it = nodeList.iterator(); it.hasNext();) {
451:                    Node abNode = (Node) it.next();
452:
453:                    if (abNode != null) {
454:                        String abType = abNode.getNodeName();
455:                        Element element = null;
456:
457:                        if (abType.equals(WabpABConstants.WABP_GROUP)) {
458:                            element = (Element) convertNodeToGroup(abNode,
459:                                    index);
460:                        } else {
461:                            element = (Element) convertNodeToEntry(abNode,
462:                                    index);
463:                        }
464:
465:                        convertedElements.add(element);
466:                    }
467:
468:                    index++;
469:                }
470:
471:                return convertedElements;
472:            }
473:
474:            /*
475:             * Converts a Node (wabp <abperson>) to a JABAPI Entry.  The
476:             * conversion to an Entry is as follows:
477:             *
478:             * <entry entryID="efd1515927e5"/>
479:             *
480:             * converted to un (unique name)
481:             * 
482:             * <entry entryID="efd1515927e5">
483:             *   <displayname>Baggins, Frodo</displayname>
484:             *   <description>test</description>
485:             *   <creationdate>20040611190101Z</creationdate>
486:             *   <lastmodifieddate>20040615212250Z</lastmodifieddate>
487:             * </entry>
488:             *
489:             * converted to cn and description
490:             *
491:             * <person>
492:             *   <givenname>Frodo</givenname>
493:             *   <surname>Baggins</surname>
494:             *   <middlename>A</middlename>
495:             *   <date type="birthday">1001-01-01</date>
496:             * </person>
497:             *
498:             * converted to fn, ln, and dob
499:             *
500:             * <email priority="1" type="work">frodo@lotr.com</email>
501:             * <email priority="2" type="home">frodo@home.com</email>
502:             * <email priority="3" type="sms">frodo@sms.com</email>
503:             *
504:             * converted to em and smsId
505:             *
506:             * <phone priority="1" type="work">111 1111</phone>
507:             * <phone priority="2" type="home">111 4445</phone>
508:             * <phone priority="3" type="mobile">720 222 3333</phone>
509:             * <phone priority="4" type="pager">720 202 2022</phone>
510:             * <phone priority="5" type="fax">333 444 5555</phone>
511:             *
512:             * converted to bp, hp, mp, fp, and pp
513:             *
514:             * <postaladdress type="home">
515:             *   <street>500 Eldorado</street>
516:             *   <city>Broomfield</city>
517:             *   <postalcode>80234</postalcode>
518:             *   <state>CO</state>
519:             *   <country>USA</country>
520:             * </postaladdress>
521:             *
522:             * converted to homeStreet, homeCity, homeState, homeZip, and homeCountry
523:             *
524:             * <postaladdress type="work">
525:             *   <street>500 Hobbit Way</street>
526:             *   <city>Hobbiton</city>
527:             *   <postalcode>80021</postalcode>
528:             *   <state>Shire</state>
529:             *   <country>USA</country>
530:             * </postaladdress>
531:             *
532:             * converted to workStreet, workCity, workState, workZip, and workCountry
533:             *
534:             * <weburl priority="1">
535:             *   <urladdr>www.fastcars.com</urladdr>
536:             * </weburl>
537:             * <weburl priority="2">
538:             *   <urladdr>www.fastboats.com</urladdr>
539:             * </weburl>
540:             *
541:             * converted to uri
542:             *
543:             * <memberofbook>efd151293210</memberofbook>
544:             * <memberofgroup>efd24828a480</memberofgroup>
545:             *
546:             * converted to memberofpab, memberofpabgroup
547:             *
548:             * @param node Node of an abperson
549:             * @param index  used for Entry ID
550:             * @return an Address Book Entry
551:             */
552:            protected Entry convertNodeToEntry(Node node, int index)
553:                    throws XSLProcessingException {
554:                Entry entry = null;
555:
556:                // entry fields that will be populated with wabp node values
557:                // 
558:                String un = null;
559:                String fn = null;
560:                String ln = null;
561:                String cn = null;
562:                String em = null;
563:                String description = null;
564:                String bp = null;
565:                String hp = null;
566:                String mp = null;
567:                String homeStreet = null;
568:                String homeCity = null;
569:                String homeState = null;
570:                String homeZip = null;
571:                String homeCountry = null;
572:                String workStreet = null;
573:                String workCity = null;
574:                String workState = null;
575:                String workZip = null;
576:                String workCountry = null;
577:                String fp = null;
578:                String pp = null;
579:                String dob = null;
580:                String uri = null;
581:                String memberofpab = null;
582:                String memberofpabgroup = null;
583:                String smsId = null;
584:                String entryid = Integer.toString(index);
585:
586:                // <entry entryID="efd1515927e5"/>
587:                // convert to un (unique name)
588:                // 
589:                Node entryNode = XPathTools.getFirstNodeByXPath(node,
590:                        WabpABConstants.WABP_ENTRY);
591:                NamedNodeMap entryMap = entryNode.getAttributes();
592:                Node entryIDNode = entryMap
593:                        .getNamedItem(WabpABConstants.WABP_ENTRY_ID);
594:                un = entryIDNode.getNodeValue();
595:
596:                // <entry entryID="efd1515927e5">
597:                //   <displayname>Baggins, Frodo</displayname>
598:                //   <description>test</description>
599:                //   <creationdate>20040611190101Z</creationdate>
600:                //   <lastmodifieddate>20040615212250Z</lastmodifieddate>
601:                // </entry>
602:                //
603:                // convert to cn and description
604:                cn = XPathTools.getValueByXPath(node,
605:                        WabpABConstants.WABP_ENTRY_DISPLAYNAME);
606:                description = XPathTools.getValueByXPath(node,
607:                        WabpABConstants.WABP_ENTRY_DESCRIPTION);
608:
609:                // <person>
610:                //   <givenname>Frodo</givenname>
611:                //   <surname>Baggins</surname>
612:                //   <middlename>A</middlename>
613:                //   <date type="birthday">1001-01-01</date>
614:                // </person>
615:                // 
616:                // convert to fn, ln, and dob
617:                // 
618:                fn = XPathTools.getValueByXPath(node,
619:                        WabpABConstants.WABP_PERSON_GIVENNAME);
620:                ln = XPathTools.getValueByXPath(node,
621:                        WabpABConstants.WABP_PERSON_SURNAME);
622:                dob = XPathTools.getValueByXPath(node,
623:                        WabpABConstants.WABP_PERSON_DATE_BIRTHDAY);
624:
625:                // <email priority="1" type="work">frodo@lotr.com</email>
626:                // <email priority="2" type="home">frodo@home.com</email>
627:                // <email priority="3" type="sms">frodo@sms.com</email>
628:                //
629:                // convert to em and smsId
630:                em = XPathTools.getValueByXPath(node,
631:                        WabpABConstants.WABP_EMAIL_PRIMARY);
632:                smsId = XPathTools.getValueByXPath(node,
633:                        WabpABConstants.WABP_EMAIL_SMS);
634:
635:                // <phone priority="1" type="work">111 1111</phone>
636:                // <phone priority="2" type="home">111 4445</phone>
637:                // <phone priority="3" type="mobile">720 222 3333</phone>
638:                // <phone priority="4" type="pager">720 202 2022</phone>
639:                // <phone priority="5" type="fax">333 444 5555</phone>
640:                //
641:                // convert to bp, hp, mp, fp, and pp
642:                //
643:                bp = XPathTools.getValueByXPath(node,
644:                        WabpABConstants.WABP_PHONE_WORK);
645:                hp = XPathTools.getValueByXPath(node,
646:                        WabpABConstants.WABP_PHONE_HOME);
647:                mp = XPathTools.getValueByXPath(node,
648:                        WabpABConstants.WABP_PHONE_MOBILE);
649:                fp = XPathTools.getValueByXPath(node,
650:                        WabpABConstants.WABP_PHONE_FAX);
651:                pp = XPathTools.getValueByXPath(node,
652:                        WabpABConstants.WABP_PHONE_PAGER);
653:
654:                // <postaladdress type="home">
655:                //   <street>500 Eldorado</street>
656:                //   <city>Broomfield</city>
657:                //   <postalcode>80234</postalcode>
658:                //   <state>CO</state>
659:                //   <country>USA</country>
660:                // </postaladdress>
661:                // 
662:                // convert to homeStreet, homeCity, homeState, homeZip, and homeCountry
663:                // 
664:                homeStreet = XPathTools.getValueByXPath(node,
665:                        WabpABConstants.WABP_ADDRESS_HOME_STREET);
666:                homeCity = XPathTools.getValueByXPath(node,
667:                        WabpABConstants.WABP_ADDRESS_HOME_CITY);
668:                homeState = XPathTools.getValueByXPath(node,
669:                        WabpABConstants.WABP_ADDRESS_HOME_STATE);
670:                homeZip = XPathTools.getValueByXPath(node,
671:                        WabpABConstants.WABP_ADDRESS_HOME_ZIP);
672:                homeCountry = XPathTools.getValueByXPath(node,
673:                        WabpABConstants.WABP_ADDRESS_HOME_COUNTRY);
674:
675:                // <postaladdress type="work">
676:                //   <street>500 Hobbit Way</street>
677:                //   <city>Hobbiton</city>
678:                //   <postalcode>80021</postalcode>
679:                //   <state>Shire</state>
680:                //   <country>USA</country>
681:                // </postaladdress>
682:                // 
683:                // convert to workStreet, workCity, workState, workZip, and workCountry
684:                // 
685:                workStreet = XPathTools.getValueByXPath(node,
686:                        WabpABConstants.WABP_ADDRESS_WORK_STREET);
687:                workCity = XPathTools.getValueByXPath(node,
688:                        WabpABConstants.WABP_ADDRESS_WORK_CITY);
689:                workState = XPathTools.getValueByXPath(node,
690:                        WabpABConstants.WABP_ADDRESS_WORK_STATE);
691:                workZip = XPathTools.getValueByXPath(node,
692:                        WabpABConstants.WABP_ADDRESS_WORK_ZIP);
693:                workCountry = XPathTools.getValueByXPath(node,
694:                        WabpABConstants.WABP_ADDRESS_WORK_COUNTRY);
695:
696:                // <weburl priority="1">
697:                //   <urladdr>www.fastcars.com</urladdr>
698:                // </weburl>
699:                // <weburl priority="2">
700:                //   <urladdr>www.fastboats.com</urladdr>
701:                // </weburl>
702:                //
703:                // convert to uri
704:                // 
705:                uri = XPathTools.getValueByXPath(node,
706:                        WabpABConstants.WABP_WEBURL_PRIMARY);
707:
708:                // <memberofbook>efd151293210</memberofbook>
709:                // <memberofgroup>efd24828a480</memberofgroup>
710:                //
711:                // convert to memberofpab, memberofpabgroup
712:                // 
713:                memberofpab = XPathTools.getValueByXPath(node,
714:                        WabpABConstants.WABP_MEMBEROFBOOK);
715:                memberofpabgroup = XPathTools.getValueByXPath(node,
716:                        WabpABConstants.WABP_MEMBEROFGROUP);
717:
718:                entry = new Entry(un, fn, ln, cn, em, description, bp, hp, mp,
719:                        homeStreet, homeCity, homeState, homeZip, homeCountry,
720:                        workStreet, workCity, workState, workZip, workCountry,
721:                        fp, pp, dob, uri, memberofpab, memberofpabgroup, smsId,
722:                        entryid);
723:
724:                // debugging
725:                StringBuffer buf = new StringBuffer();
726:                buf.append("\n").append("\t un=").append(un).append("\n")
727:                        .append("\t fn=").append(fn).append("\n").append(
728:                                "\t ln=").append(ln).append("\n").append(
729:                                "\t cn=").append(cn).append("\n").append(
730:                                "\t em=").append(em).append("\n").append(
731:                                "\t description=").append(description).append(
732:                                "\n").append("\t bp=").append(bp).append("\n")
733:                        .append("\t bp=").append(bp).append("\n").append(
734:                                "\t hp=").append(hp).append("\n").append(
735:                                "\t mp=").append(mp).append("\n").append(
736:                                "\t homeStreet=").append(homeStreet).append(
737:                                "\n").append("\t homeState=").append(homeState)
738:                        .append("\n").append("\t homeZip=").append(homeZip)
739:                        .append("\n").append("\t homeCountry=").append(
740:                                homeCountry).append("\n").append(
741:                                "\t workStreet=").append(workStreet).append(
742:                                "\n").append("\t workCity=").append(workCity)
743:                        .append("\n").append("\t workState=").append(workState)
744:                        .append("\n").append("\t workZip=").append(workZip)
745:                        .append("\n").append("\t workCountry=").append(
746:                                workCountry).append("\n").append("\t fp=")
747:                        .append(fp).append("\n").append("\t pp=").append(pp)
748:                        .append("\n").append("\t dob=").append(dob)
749:                        .append("\n").append("\t uri=").append(uri)
750:                        .append("\n").append("\t memberofpab=").append(
751:                                memberofpab).append("\n").append(
752:                                "\t memberofpabgroup=")
753:                        .append(memberofpabgroup).append("\n").append(
754:                                "\t smsId=").append(smsId).append("\n").append(
755:                                "\t entryId=").append(entryid).append("\n");
756:
757:                debugLogger.log(Level.FINER, "PSJA_CSAW0021", new String[] {
758:                        abStoreUser, buf.toString() });
759:                entry.setElementType(Element.ENTRY);
760:
761:                return entry;
762:            }
763:
764:            /*
765:             * Converts a Node (wabp group) to a JABAPI Group.  The
766:             * conversion to a Group is as follows:
767:             *
768:             * <entry entryID="efd1515927e5"/>
769:             *
770:             * converted to un (unique name)
771:             *
772:             * <entry entryID="efd1515927e5">
773:             *   <displayname>Baggins, Frodo</displayname>
774:             *   <description>test</description>
775:             *   <creationdate>20040611190101Z</creationdate>
776:             *   <lastmodifieddate>20040615212250Z</lastmodifieddate>
777:             * </entry>
778:             *
779:             * converted to cn and description
780:             *
781:             * @param node Node of a group
782:             * @param index  used for Entry ID
783:             * @return an Address Book Entry
784:             */
785:            public Group convertNodeToGroup(Node node, int index)
786:                    throws XSLProcessingException {
787:                Group group = null;
788:
789:                // group fields that will be populated with wabp node values
790:                // 
791:                String un = null;
792:                String cn = null;
793:                String description = null;
794:                String entryid = Integer.toString(index);
795:
796:                // <entry entryID="efd1515927e5"/>
797:                // convert to un (unique name)
798:                // 
799:                Node entryNode = XPathTools.getFirstNodeByXPath(node,
800:                        WabpABConstants.WABP_ENTRY);
801:                NamedNodeMap entryMap = entryNode.getAttributes();
802:                Node entryIDNode = entryMap
803:                        .getNamedItem(WabpABConstants.WABP_ENTRY_ID);
804:                un = entryIDNode.getNodeValue();
805:
806:                // <entry entryID="efd1515927e5">
807:                //   <displayname>Baggins, Frodo</displayname>
808:                //   <description>test</description>
809:                //   <creationdate>20040611190101Z</creationdate>
810:                //   <lastmodifieddate>20040615212250Z</lastmodifieddate>
811:                // </entry>
812:                //
813:                // convert to cn and description
814:                cn = XPathTools.getValueByXPath(node,
815:                        WabpABConstants.WABP_ENTRY_DISPLAYNAME);
816:                description = XPathTools.getValueByXPath(node,
817:                        WabpABConstants.WABP_ENTRY_DESCRIPTION);
818:
819:                group = new Group(un, cn, description, entryid);
820:
821:                // debugging
822:                StringBuffer buf = new StringBuffer();
823:                buf.append("\n").append("\t un=").append(un).append("\n")
824:                        .append("\t cn=").append(cn).append("\n").append(
825:                                "\t description=").append(description).append(
826:                                "\n").append("\t entryId=").append(entryid)
827:                        .append("\n");
828:
829:                debugLogger.log(Level.FINER, "PSJA_CSAW0022", new String[] {
830:                        abStoreUser, buf.toString() });
831:                group.setElementType(Element.GROUP);
832:
833:                return group;
834:            }
835:
836:            /* 
837:             * Responsible for constructing the search_entry.wabp "type" parameter value
838:             * 
839:             * Command: search_entry.wabp 
840:             * Parameter: type  	
841:             * Type: string list
842:             * Description: comma separated list of types of entries to look for as defined 
843:             *              in the XML schema
844:             * Required: no
845:             * Default value: all types of entries
846:             * 
847:             * @param filter ABFilter 
848:             * @return type value for person and group
849:             */
850:            protected String[] getWabpSearchEntryType(ABFilter filter) {
851:
852:                String[] types = null;
853:
854:                if (filter.getElementType() == Element.ENTRY) {
855:                    types = new String[1];
856:                    types[0] = WabpABConstants.WABP_ABPERSON;
857:
858:                } else if (filter.getElementType() == Element.GROUP) {
859:                    types = new String[1];
860:                    types[0] = WabpABConstants.WABP_GROUP;
861:
862:                } else {
863:                    types = new String[2];
864:                    types[0] = WabpABConstants.WABP_ABPERSON;
865:                    types[1] = WabpABConstants.WABP_GROUP;
866:                }
867:
868:                return types;
869:            }
870:
871:            /* 
872:             * Responsible for constructing the search_entry.wabp "sort" parameter value
873:             * 
874:             * Command: search_entry.wabp 
875:             * Parameter: sort  	
876:             * Type: string
877:             * Description: XML element name to sort the entries by,  possibly with XPath
878:             *              'disambiguators'.
879:             *              A + (-) can be put in front of the XML element name to specify 
880:             *              that the sorting should be done in ascendant (descendant) order.
881:             * Required: no
882:             * Default value: no sorting done.
883:             * 
884:             * @param filter ABFilter 
885:             * @return sort value (incudes sort order and sort by)
886:             */
887:            protected String getWabpSearchEntrySort(ABFilter filter) {
888:
889:                String sort = "";
890:                String sortOrder = "";
891:                String sortBy = filter.getSortBy();
892:
893:                // determine sort order, if ascending there is no value
894:                //
895:                switch (filter.getSortOrder()) {
896:                case ABFilter.ASCENDING:
897:                    sortOrder = WabpABConstants.SORT_ASCENDING;
898:                    break;
899:                case ABFilter.DESCENDING:
900:                    sortOrder = WabpABConstants.SORT_DESCENDING;
901:                    break;
902:                default:
903:                    break;
904:                }
905:
906:                // determine sort by
907:                //
908:                if ((sortBy != null) && (sortBy.length() > 0)) {
909:                    sortBy = sortBy.trim();
910:
911:                    if (sortBy.equalsIgnoreCase(ABFilter.CN)) {
912:                        sortBy = WabpABConstants.WABP_ENTRY_DISPLAYNAME;
913:
914:                    } else if (sortBy.equalsIgnoreCase(ABFilter.FN)) {
915:                        sortBy = WabpABConstants.WABP_PERSON_GIVENNAME;
916:
917:                    } else if (sortBy.equalsIgnoreCase(ABFilter.LN)) {
918:                        sortBy = WabpABConstants.WABP_PERSON_SURNAME;
919:                    }
920:                } else {
921:                    sortBy = WabpABConstants.WABP_ENTRY_DISPLAYNAME;
922:                }
923:
924:                // construct sort
925:                //
926:                sort = sortOrder + sortBy;
927:
928:                return sort;
929:            }
930:
931:            public String getFormattedCn(String fn, String ln) {
932:                String str = " ";
933:
934:                if ((ln != null) && (fn != null)) {
935:                    str = ln + ", " + fn;
936:                } else if ((ln != null) && (fn == null)) {
937:                    str = ln;
938:                } else if ((fn != null) && (ln == null)) {
939:                    str = fn;
940:                }
941:
942:                return str;
943:            }
944:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.