Source Code Cross Referenced for WabpABSearchTerm.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.Vector;
004:        import java.util.Properties;
005:        import java.util.Enumeration;
006:        import java.util.logging.Logger;
007:        import java.util.logging.Level;
008:        import java.lang.reflect.Field;
009:
010:        import com.sun.addressbook.ABSearchTerm;
011:        import com.sun.addressbook.ABStoreException;
012:        import com.sun.addressbook.ABLogger;
013:
014:        /**
015:         * Address Book SearchTerm does the recursive computation of the search
016:         * filter from a combination of search terms. It implements the compute
017:         * command of the ABSearchTerm.
018:         * The search terms can be nested in a tree structure and combined with
019:         * an 'and' or an 'or' e.g. "ln=doe & (fn=john | fn=joe)"
020:         *
021:         */
022:        public class WabpABSearchTerm extends ABSearchTerm {
023:
024:            // Create a Logger for this class
025:            private static Logger debugLogger = ABLogger
026:                    .getLogger("com.sun.portal.addressbook.wabp");
027:
028:            /**
029:             * Initializes the search term object. This constructor indicates this search term
030:             * is an end node and does not contain recursive search terms.
031:             *
032:             * @param name     Name of the attribute to search on.
033:             * @param value    Value of the attribute to search.
034:             * @param exact    Boolean indicating whether search is 'exact'(true) or
035:             *                 'contains'(false).
036:             */
037:            public WabpABSearchTerm(String name, String value, boolean exact) {
038:                super (name, value, exact);
039:            };
040:
041:            /**
042:             * Initializes the search term object. This constructor is used for the unary
043:             * operator NOT on the ABSearchTerm. Usage of this constructor means that ABSearchTerm
044:             * is recursive and is not the end node, and it will contain terms, op and not name,
045:             * value.
046:             *
047:             * @param   The recursive ABSearchTerm.
048:             * @param   Operator binding the recursive searchTerms. The value can only be NOT.
049:             */
050:            public WabpABSearchTerm(ABSearchTerm term, int op)
051:                    throws ABStoreException {
052:                super (term, op);
053:            };
054:
055:            /**
056:             * Initializes the search term object. This constructor is used for the binary
057:             * operators like AND and OR on the ABSearchTerms array. Usage of this constructor
058:             * means that ABSearchTerm is recursive and is not the end node, and it will
059:             * contain terms, op and not name, value.
060:             *
061:             * @param   The recursive ABSearchTerm array.
062:             * @param   Operator binding the recursive searchTerms. The values can be AND or OR.
063:             */
064:            public WabpABSearchTerm(ABSearchTerm[] terms, int op)
065:                    throws ABStoreException {
066:                super (terms, op);
067:            };
068:
069:            /**
070:             * Appends the search terms recursively. Also computes the exactness of each terms.
071:             *
072:             * @return The computed search Filter object.
073:             */
074:            public Object compute() throws ABStoreException {
075:
076:                String searchFilter = null;
077:                String operator = null;
078:
079:                // if the Search term is recursive then follow the recursion
080:                // 
081:                if (terms != null) {
082:                    if (op == NOT) {
083:                        searchFilter = "(!" + terms[0].compute() + ")";
084:                        return searchFilter;
085:
086:                    } else if (op == AND) {
087:                        operator = "&";
088:
089:                    } else if (op == OR) {
090:                        operator = "|";
091:
092:                    } else {
093:                        String msg = "WabpABSearchTerm: invalid operator: "
094:                                + op
095:                                + ". Operator can only be one of AND/OR/NOT";
096:                        throw new ABStoreException(msg);
097:                    }
098:
099:                    // Wabp only accepts a combination of two terms at a time
100:                    //searchFilter = "(" + operator ;
101:                    searchFilter = operator;
102:                    for (int i = 0; i < terms.length; i++) {
103:                        searchFilter += "(" + terms[i].compute() + ")";
104:                    }
105:                    //searchFilter += ")";
106:
107:                } else { // else compute the end node search term
108:                    searchFilter = computeTerm(this );
109:                }
110:
111:                debugLogger.log(Level.FINER, "PSJA_CSAW0001", searchFilter);
112:
113:                return searchFilter;
114:            }
115:
116:            private String computeTerm(ABSearchTerm searchTerm) {
117:
118:                String term = null;
119:                String newValue = null;
120:
121:                // check to see if the search is an exact or contains search.  if the search
122:                // type is contains, then wrap the value with wildcards, i.e.  '*<value>*'
123:                // 
124:                String searchVal = searchTerm.getValue();
125:
126:                if ((!searchTerm.isExact()) && (searchVal != null)
127:                        && (searchVal.indexOf('*') < 0)) {
128:                    newValue = "*" + searchVal + "*";
129:                } else {
130:                    newValue = searchVal;
131:                }
132:
133:                // check to see if the name of the attribute to search on is "any".  if it 
134:                // is then set the equivalent to "entry/displayname" for WABP filter.
135:                // 
136:                if (searchTerm.getName().equals("any")) {
137:                    term = WabpABConstants.WABP_ENTRY_DISPLAYNAME + "="
138:                            + newValue;
139:                    // 
140:                    // if the searchTerm is not "any", then check the searchTerm name and 
141:                    // perform the necessary translation to the corresponding WABP attribute
142:                    // name.  only specified the fields found in the Mobile Access Address 
143:                    // Book taglibs.  otherwise, the searchTerm name is not translated.
144:                    // 
145:                } else {
146:                    String key = searchTerm.getName();
147:
148:                    if (key.equals("fn")) {
149:                        key = WabpABConstants.WABP_PERSON_GIVENNAME;
150:                    } else if (key.equals("ln")) {
151:                        key = WabpABConstants.WABP_PERSON_SURNAME;
152:                    } else if (key.equals("cn")) {
153:                        key = WabpABConstants.WABP_ENTRY_DISPLAYNAME;
154:                    } else if (key.equals("em")) {
155:                        key = WabpABConstants.WABP_EMAIL;
156:                    } else if (key.equals("bp")) {
157:                        key = WabpABConstants.WABP_PHONE;
158:                    } else if (key.equals("fp")) {
159:                        key = WabpABConstants.WABP_PHONE;
160:                    } else if (key.equals("hp")) {
161:                        key = WabpABConstants.WABP_PHONE;
162:                    } else if (key.equals("mp")) {
163:                        key = WabpABConstants.WABP_PHONE;
164:                    } else if (key.equals("pp")) {
165:                        key = WabpABConstants.WABP_PHONE;
166:                    }
167:
168:                    //term = "(" + key + "=" + newValue + ")";
169:                    term = key + "=" + newValue;
170:                }
171:
172:                debugLogger.log(Level.FINER, "PSJA_CSAW0002", term);
173:                return term;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.