Source Code Cross Referenced for SearchDemo.java in  » Portal » Open-Portal » demo » 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 » demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2000 Sun Microsystems.  All Rights Reserved.
003:         */
004:
005:        package demo;
006:
007:        import soif.*;
008:
009:        import java.applet.Applet;
010:        import java.awt.Button;
011:        import java.awt.FlowLayout;
012:        import java.awt.Frame;
013:        import java.awt.Panel;
014:        import java.awt.TextField;
015:        import java.awt.Event;
016:        import java.awt.AWTEvent;
017:
018:        import java.io.*;
019:
020:        /**
021:         * Performs a simple search and displays its results.
022:         */
023:        class SimpleSearch {
024:            String RDMServer;
025:            CSID csid;
026:            String SOIFOutputFile;
027:
028:            /**
029:             * SimpleSearch constructor
030:             * @param rdm - url of rdm server, eg, http://compass_server:port
031:             * @param csid - the collection to search on this rdm server
032:             * if null, server will search its default csid
033:             */
034:            public SimpleSearch(String rdm, String csidstr) {
035:                System.out.println("Compass Java Search Demo");
036:
037:                RDMServer = rdm;
038:
039:                if (csidstr != null) {
040:                    csid = new CSID(csidstr);
041:                    if (csid.isValid() == false) {
042:                        System.out.println("Invalid CSID - Aborting");
043:                        System.exit(8);
044:                    }
045:                }
046:
047:            }
048:
049:            public boolean doSearch(String scope) {
050:
051:                /* Optionally manage HTML results look. */
052:                Results results = new Results();
053:                results.setDisplay("score,url,title,description");
054:                results.setDisplayAsLink("title", true);
055:                results.setScoreGif(0, 50, "tired.gif");
056:                results.setScoreGif(51, 100, "wired.gif");
057:
058:                /* The Search class encapsulates the search.
059:                 ** It's parameters are:
060:                 **  1) the search string
061:                 **  2) the attributes you want returned, comma delimited
062:                 **  3) sort order, comma delimited, - descending, + ascending
063:                 **  4) first hit
064:                 **  5) number of view Hits
065:                 **  6) query language, eg compass, taxonomy-basic, schema-basic, etc
066:                 **  7) CSID (Compass Server ID) instance
067:                 **  8) The rdm search interface, eg, http://compass_server/rdm/incoming
068:                 **     (if not supplied, it will be derived from the csid)
069:                 */
070:                Search search = new Search(scope,
071:                //results.getDisplay(),
072:                        "", "-score,+title", 1, 20, "compass", csid, RDMServer);
073:
074:                /* Execute the query. */
075:
076:                System.out.println("\nSearch results for \"" + scope + "\"");
077:
078:                DataOutputStream sos = null;
079:                if (SOIFOutputFile != null) {
080:                    try {
081:                        sos = new DataOutputStream(new FileOutputStream(
082:                                SOIFOutputFile));
083:                    } catch (Exception e1) {
084:                        System.out.println("<failed to create output file>");
085:                    }
086:                }
087:
088:                int pagenum = 1;
089:                int pagesize = 10;
090:                SOIF firstPageSOIF = null;
091:
092:                for (; pagenum <= 5; pagenum++) {
093:                    int firstHit = (pagenum - 1) * pagesize + 1;
094:
095:                    try {
096:                        search.doQuery(firstHit, pagesize);
097:                    } catch (Exception ex) {
098:                        ex.printStackTrace();
099:                        break;
100:                    }
101:
102:                    /* Check the result count.  -1 indicates an
103:                     ** error, which can also be discovered by
104:                     ** checking search.getStatus().
105:                     */
106:
107:                    if (search.getResultCount() <= 0)
108:                        break;
109:
110:                    System.out
111:                            .println("==========================================");
112:                    System.out
113:                            .println("page "
114:                                    + pagenum
115:                                    + ": hits "
116:                                    + search.getFirstHit()
117:                                    + " to "
118:                                    + (search.getFirstHit()
119:                                            + search.getResultCount() - 1)
120:                                    + " out of " + search.getHitCount()
121:                                    + " across " + search.getDocumentCount()
122:                                    + " documents");
123:                    System.out
124:                            .println("==========================================");
125:                    System.out.println();
126:
127:                    SOIF soif = search.getSOIFResult();
128:                    if (pagenum == 1)
129:                        firstPageSOIF = soif;
130:
131:                    /* Examine the results of the search.  The
132:                     ** results can also be returned as a string
133:                     ** using getResult(), but the SOIF version
134:                     ** parses the string for you.  The following
135:                     ** block loops through a list of SOIF instances.
136:                     */
137:                    for (soif = search.getSOIFResult(); soif != null; soif = soif.next) {
138:                        /* use the getValue() method to get
139:                         ** a value associated w/ the specified
140:                         ** attribute.
141:                         */
142:                        String u = soif.getValue("url");
143:                        String t = soif.getValue("title");
144:                        String d = soif.getValue("description");
145:                        String sc = soif.getValue("score");
146:
147:                        /* do something with the results */
148:                        System.out
149:                                .println("TITLE:       "
150:                                        + t
151:                                        + "\n"
152:                                        + "URL:         "
153:                                        + u
154:                                        + "\n"
155:                                        + "SCORE:       "
156:                                        + sc
157:                                        + "\n"
158:                                        + "DESCRIPTION: "
159:                                        + d
160:                                        + "\n"
161:                                        + "--------------------------------------------\n");
162:                        if (sos != null) {
163:                            try {
164:                                sos.writeBytes(soif.toString());
165:                            } catch (Exception e1) {
166:                                System.out
167:                                        .println("<failed to write to output file>");
168:                            }
169:                        }
170:
171:                    }
172:                }
173:
174:                if (firstPageSOIF == null)
175:                    System.out.println("No matching documents found.");
176:
177:                else if (!true) {
178:
179:                    /* Use results manager to format results. */
180:                    System.out
181:                            .println("Here is the first page as HTML-formatted text...");
182:                    System.out.println();
183:                    System.out.println(results.resultsToHTML(firstPageSOIF,
184:                            "<tr>\n", "</tr>\n\n", "<td>\n", "\n</td>\n"));
185:                }
186:
187:                return true;
188:            }
189:
190:            /**
191:             * @param filename - a file to dump raw SOIF results into - only
192:             * use if running from the comand line or an applet with file
193:             * system access
194:             */
195:            public void setSOIFfile(String filename) {
196:                SOIFOutputFile = filename;
197:            }
198:
199:        }
200:
201:        /**
202:         * A panel with a search box that calls the simple search class.
203:         */
204:        class SearchPanel extends Panel {
205:            Button searchBtn;
206:            TextField searchTF;
207:            SimpleSearch ss;
208:
209:            /** C'tor */
210:            public SearchPanel(SimpleSearch ss) {
211:                this .ss = ss;
212:                searchBtn = new Button("Search");
213:                searchTF = new TextField("java", 40);
214:                setLayout(new FlowLayout(FlowLayout.CENTER));
215:                add(searchTF);
216:                add(searchBtn);
217:            }
218:
219:            public void processEvent(AWTEvent e) {
220:                if (e.getID() == Event.ACTION_EVENT) {
221:                    searchTF.setEditable(false);
222:                    searchBtn.setEnabled(false);
223:                    ss.doSearch(searchTF.getText());
224:                    searchTF.setEditable(true);
225:                    searchBtn.setEnabled(true);
226:                } else
227:                    super .processEvent(e);
228:            }
229:        }
230:
231:        /**
232:         * Applet/application for simple query interface.  Can be used as an
233:         * example for those who want to create their own java interface.
234:         * This example demonstrates search only.  Browse, determining
235:         * the schema of the compass server and obtaining the taxonomy
236:         * of the compass server will be demonstrated in other examples.
237:         */
238:        public class SearchDemo extends Applet {
239:            /** Run as an applet. */
240:            public void init() {
241:                String rdm = getParameter("RDMServer");
242:                String csidstr = getParameter("CSID");
243:                SimpleSearch ss = new SimpleSearch(rdm, csidstr);
244:                SearchPanel sp = new SearchPanel(ss);
245:                setLayout(new FlowLayout(FlowLayout.CENTER));
246:                add(sp);
247:            }
248:
249:            /** Run as an application. */
250:            public static void main(String argv[]) {
251:                int args = argv.length;
252:                String SOIFOutputFile = null;
253:
254:                if (args != 1 && args != 2 && args != 3) {
255:                    System.out
256:                            .println("args: RDMServer [query] [soif_output_file_name]");
257:                    return;
258:                }
259:
260:                String rdm = argv[0]; // rdm server, eg, http://compass:port
261:                String csidstr = null; // server will use default csid
262:
263:                SimpleSearch ss = new SimpleSearch(rdm, csidstr);
264:
265:                if (args == 3) {
266:                    --args;
267:                    ss.setSOIFfile(argv[2]); // dump raw soif results to this file
268:                }
269:
270:                if (args == 1) {
271:                    // run from a search box
272:                    Frame f = new Frame();
273:                    SearchPanel sp = new SearchPanel(ss);
274:                    f.add(sp);
275:                    f.pack();
276:                    f.show();
277:                } else {
278:                    // run from command line
279:                    String query = argv[1];
280:                    ss.doSearch(query);
281:                }
282:            }
283:
284:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.