Source Code Cross Referenced for SearchQuery.java in  » Content-Management-System » openedit » com » openedit » hittracker » 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 » Content Management System » openedit » com.openedit.hittracker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Jul 19, 2006
003:         */
004:        package com.openedit.hittracker;
005:
006:        import java.util.ArrayList;
007:        import java.util.Date;
008:        import java.util.HashMap;
009:        import java.util.Iterator;
010:        import java.util.List;
011:        import java.util.Map;
012:
013:        import com.openedit.OpenEditRuntimeException;
014:
015:        public class SearchQuery {
016:            protected List fieldTerms = new ArrayList();
017:            protected boolean fieldAndTogether = true;
018:            protected Map fieldInputs;
019:            protected String fieldSortBy;
020:
021:            public void addGroup(SearchQuery inGroup) {
022:                fieldTerms.add(inGroup);
023:            }
024:
025:            public List getTerms() {
026:                return fieldTerms;
027:            }
028:
029:            public void addAfter(String inFieldId, Date inDate,
030:                    String inFriendly) {
031:                //not supported
032:            }
033:
034:            public void addBetween(String inFieldId, Date inLowDate,
035:                    Date inHighDate, String inFriendlyFieldName) {
036:                //not supported
037:            }
038:
039:            public void addBefore(String inFieldId, Date inDate,
040:                    String inFriendly) {
041:                //throw exception
042:            }
043:
044:            //	public void addAnd(String inString)
045:            //	{
046:            //		if (out.length() > 0)
047:            // 		{
048:            //			out.append("AND ");
049:            //		}
050:            //		out.append(inString);
051:            //		out.append(" ");
052:            //	}
053:
054:            public void addOrsGroup(String inField, String inValue,
055:                    String inFriendly) {
056:                Term term = new Term() {
057:                    public String toQuery() {
058:                        StringBuffer orString = new StringBuffer();
059:                        String[] orwords = getValue().split("\\s");
060:                        if (orwords.length > 0) {
061:                            orString.append("(");
062:                            for (int i = 0; i < orwords.length - 1; i++) {
063:                                orString.append(orwords[i]);
064:                                orString.append(" OR ");
065:                            }
066:                            orString.append(orwords[orwords.length - 1]);
067:                            orString.append(")");
068:                        }
069:                        return orString.toString();
070:                    }
071:                };
072:                term.setId(inField);
073:
074:                term.setValue(inValue);
075:                term.setFriendly(inFriendly);
076:                getTerms().add(term);
077:            }
078:
079:            public void addNots(String inId, String inNots, String inFriendly) {
080:                Term term = new Term() {
081:                    public String toQuery() {
082:                        StringBuffer orString = new StringBuffer();
083:
084:                        String[] notwords = getValue().split("\\s");
085:                        if (notwords.length > 0) {
086:                            for (int i = 0; i < notwords.length; i++) {
087:                                orString.append(" NOT " + notwords[i]);
088:                            }
089:                        }
090:                        return orString.toString();
091:                    }
092:                };
093:                term.setId(inId);
094:                term.setValue(inNots);
095:                term.setFriendly(inFriendly);
096:                getTerms().add(term);
097:            }
098:
099:            public void addNot(String inNot) {
100:
101:                addNots(null, inNot, "not " + inNot);
102:                //fieldTerms.add("NOT " + inNot);
103:            }
104:
105:            //	public void addDayRangeBeforeToday(String inDaterange)
106:            //	{
107:            //		GregorianCalendar d = new GregorianCalendar();
108:            //		SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
109:            //		String end = format.format(d.getTime());
110:            //		int less = Integer.parseInt(inDaterange);
111:            //		int m = 0 - less ;
112:            //		d.add(GregorianCalendar.DAY_OF_YEAR,m);
113:            //		//var start =  d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear();
114:            //		String start = format.format(d.getTime());
115:            //		
116:            //		String fin = "date:[" + start + " TO " + end + "]";
117:            //		//alert( );
118:            //		//query.value = query.value + ' AND ' + fin;
119:            //		
120:            //		fieldTerms.add(fin);
121:            //	}
122:            //
123:            //	public void addMonthRangeBeforeToday(String inMonths)
124:            //	{
125:            //		int less = Integer.parseInt(inMonths);
126:            //		int m = 0 - less ;
127:            //		GregorianCalendar d = new GregorianCalendar();
128:            //		//var start =  d.getMonth() + '/' + d.getDate() + '/' + d.getFullYear();
129:            //		SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
130:            //		String end = format.format(d.getTime());
131:            //		d.add(GregorianCalendar.MONTH,m);
132:            //		String start = format.format(d.getTime());
133:            //		
134:            //		//Is this right? Looks like wrong format
135:            //		String fin = "date:[" + start + " TO " + end + "]";
136:            //		fieldTerms.add(fin);
137:            //	}
138:
139:            public String toString() {
140:                return toQuery();
141:            }
142:
143:            public String toQuery() {
144:                String op = " OR ";
145:                if (isAndTogether()) {
146:                    op = "+";
147:                }
148:                StringBuffer done = new StringBuffer();
149:                for (int i = 0; i < fieldTerms.size(); i++) {
150:                    Term field = (Term) fieldTerms.get(i);
151:                    String q = field.toQuery();
152:                    if (i > 0 && !q.startsWith("+") && !q.startsWith("-")) {
153:                        done.append(op);
154:                    }
155:                    done.append(q);
156:                    if (i + 1 < fieldTerms.size()) {
157:                        done.append(" ");
158:                    }
159:                }
160:                return done.toString();
161:            }
162:
163:            public String toFriendly() {
164:                String op = " or ";
165:                if (isAndTogether()) {
166:                    op = " and ";
167:                }
168:                StringBuffer done = new StringBuffer();
169:                for (int i = 0; i < fieldTerms.size(); i++) {
170:                    Term field = (Term) fieldTerms.get(i);
171:                    String q = field.getFriendly();
172:                    if (!q.startsWith("+") && !q.startsWith("-")) {
173:                        done.append(q);
174:                        if (i + 1 < fieldTerms.size()) {
175:                            done.append(" ");
176:                        }
177:                    }
178:                }
179:                return done.toString();
180:
181:            }
182:
183:            public void addExact(String inId, String inValue, String inFriendly) {
184:                Term term = new Term() {
185:                    public String toQuery() {
186:                        return getId() + ":\"" + getValue() + "\"";
187:                    }
188:                };
189:                term.setId(inId);
190:                term.setValue(inValue);
191:                term.setFriendly(inFriendly);
192:                getTerms().add(term);
193:
194:            }
195:
196:            public void addExact(String inValue, String inFriendly) {
197:                Term term = new Term() {
198:                    public String toQuery() {
199:                        return "\"" + getValue() + "\"";
200:                    }
201:                };
202:
203:                term.setValue(inValue);
204:                term.setFriendly(inFriendly);
205:                getTerms().add(term);
206:
207:            }
208:
209:            public boolean isAndTogether() {
210:                return fieldAndTogether;
211:            }
212:
213:            public void setAndTogether(boolean inAndTogether) {
214:                fieldAndTogether = inAndTogether;
215:            }
216:
217:            public void addMatches(String inValue) {
218:                addMatches(null, inValue, null);
219:            }
220:
221:            public void addMatches(String inField, String inVal,
222:                    String inFriendly) {
223:                Term term = new Term() {
224:                    public String toQuery() {
225:                        return getValue();
226:                    }
227:                };
228:                term.setId(inField);
229:                term.setValue(inVal);
230:                term.setFriendly(inFriendly);
231:                getTerms().add(term);
232:                //fieldTerms.add(inField + ":" + inVal);		
233:            }
234:
235:            public boolean isEmpty() {
236:                return fieldTerms.isEmpty();
237:            }
238:
239:            public void addNot(String inField, String inVal, String inFriendly) {
240:                Term term = new Term() {
241:                    public String toQuery() {
242:                        return "-" + getId() + ":" + getValue();
243:                    }
244:                };
245:                term.setId(inField);
246:                term.setValue(inVal);
247:                term.setFriendly(inFriendly);
248:                fieldTerms.add(term);
249:                //fieldTerms.add("-" + inField + ":" + inVal);		
250:            }
251:
252:            public void addStartsWith(String inField, String inVal) {
253:                addStartsWith(inField, inVal, null);
254:            }
255:
256:            public void addStartsWith(String inField, String inVal,
257:                    String inFriendlyFieldName) {
258:                throw new OpenEditRuntimeException("Not supported");
259:            }
260:
261:            public void putInput(String inKey, String inValue) {
262:                getInputs().put(inKey, new String[] { inValue });
263:            }
264:
265:            public void putInput(String inKey, String[] inValues) {
266:                getInputs().put(inKey, inValues);
267:            }
268:
269:            public String getInput(String inKey) {
270:                Object input = getInputs().get(inKey);
271:                if (input != null) {
272:                    if (input instanceof  String) {
273:                        return (String) input;
274:                    } else {
275:                        String[] vals = (String[]) input;
276:                        return vals[0];
277:                    }
278:                }
279:                return null;
280:            }
281:
282:            public String[] getInputs(String inKey) {
283:                Object input = getInputs().get(inKey);
284:                if (input != null) {
285:                    if (input instanceof  String) {
286:                        String[] results = { (String) input };
287:                        return results;
288:                    } else {
289:                        String[] vals = (String[]) input;
290:                        return vals;
291:                    }
292:                }
293:
294:                return null;
295:            }
296:
297:            protected Map getInputs() {
298:                if (fieldInputs == null) {
299:                    fieldInputs = new HashMap();
300:                }
301:                return fieldInputs;
302:            }
303:
304:            public String getSortBy() {
305:                return fieldSortBy;
306:            }
307:
308:            public void setSortBy(String inSortBy) {
309:                fieldSortBy = inSortBy;
310:            }
311:
312:            public void addQuery(String inId, String inFilter, String inFriendly) {
313:                if (inFilter != null && inFilter.length() > 1) {
314:                    Term term = new Term() {
315:                        public String toQuery() {
316:                            return getValue();
317:                        }
318:                    };
319:                    term.setId(inId);
320:                    term.setValue(inFilter);
321:                    term.setFriendly(inFriendly);
322:                    fieldTerms.add(term);
323:                }
324:            }
325:
326:            public void addCategoryFilter(List inRemaining, String inFriendly) {
327:                // TODO Auto-generated method stub
328:                throw new OpenEditRuntimeException("Not implemented");
329:            }
330:
331:            public void removeTerm(Term inTerm) {
332:                fieldTerms.remove(inTerm);
333:            }
334:
335:            public void removeTerms(String inId) {
336:                List terms = new ArrayList(getTerms());
337:                for (Iterator iter = terms.iterator(); iter.hasNext();) {
338:                    Term term = (Term) iter.next();
339:                    if (term.getId().equals(inId)) {
340:                        removeTerm(term);
341:                    }
342:                }
343:
344:            }
345:
346:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.