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


001:        /*
002:         * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, are permitted provided that the following conditions
006:         * are met:
007:         *
008:         * - Redistributions of source code must retain the above copyright
009:         *   notice, this list of conditions and the following disclaimer.
010:         *
011:         * - Redistribution in binary form must reproduce the above copyright
012:         *   notice, this list of conditions and the following disclaimer in
013:         *   the documentation and/or other materials provided with the
014:         *   distribution.
015:         *
016:         * Neither the name of Sun Microsystems, Inc. or the names of
017:         * contributors may be used to endorse or promote products derived
018:         * from this software without specific prior written permission.
019:         *
020:         * This software is provided "AS IS," without a warranty of any
021:         * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022:         * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023:         * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024:         * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025:         * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026:         * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027:         * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028:         * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029:         * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030:         * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031:         * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032:         *
033:         * You acknowledge that Software is not designed, licensed or intended
034:         * any nuclear facility.
035:         */
036:
037:        package com.sun.portal.search.demo;
038:
039:        import com.sun.portal.search.soif.SOIF;
040:        import com.sun.portal.search.soif.SOIFInputStream;
041:        import com.sun.portal.search.soif.SOIFOutputStream;
042:        import java.io.IOException;
043:        import java.io.PrintWriter;
044:        import java.net.MalformedURLException;
045:        import java.net.URL;
046:        import java.net.URLConnection;
047:        import java.util.ArrayList;
048:        import java.util.List;
049:
050:        /**
051:         * This is a client side search database object.
052:         * It maps to the database on server side by given server url and database name.
053:         * If the database name is not specified, server uses the predefined default database name.
054:         * Application can use this object to exchange its data with search server.
055:         * Example:
056:         * <PRE>
057:         * public void submitSurveyToSearch(SurveyModel survey) throws Exception {
058:         *        SOIF soif = new SOIF("DOCUMENT", "survey::" + survey.getSurveyId());
059:         *        soif.insert("title", survey.getSurveyName());
060:         *        soif.insert("description", survey.getSurveyDescription());
061:         *        soif.insert("author", survey.getSurveyOwner());
062:         *        SearchDatabase db = new SearchDatabase(getSearchUrl() ,  getSearchDatabase());
063:         *        db.insert(soif);
064:         * }
065:         * public void deleteSurveyFromSearch(String surveyId) throws Exception {
066:         *        SearchDatabase db = new SearchDatabase(getSearchUrl() ,  getSearchDatabase());
067:         *        db.delete("survey::" + surveyId);
068:         * }
069:         * </PRE>
070:         */
071:        public class SearchDatabase {
072:
073:            // submit operations
074:            /**
075:             * fetch RDs filtered by submit-view
076:             */
077:            static final String SUBMIT_RETRIEVE = "retrieve";
078:            /**
079:             * insert/replace entire RDs
080:             */
081:            static final String SUBMIT_INSERT = "insert";
082:            /**
083:             * delete entire RDs
084:             */
085:            static final String SUBMIT_DELETE = "delete";
086:            /**
087:             * update the given RD attributes only, can also be filtered by submit-view
088:             */
089:            static final String SUBMIT_UPDATE = "update";
090:
091:            private URL searchUrl;
092:            private String database;
093:            private PrintWriter debugOut = null;
094:            private String submitType = "nonpersistent";
095:            private String submitView = null;
096:            private String SSOToken = null;
097:
098:            /**
099:             * Creates a new instance of SearchDatabase represent default database
100:             * @param searchUrl URL of the search server
101:             * @throws java.net.MalformedURLException 
102:             */
103:            public SearchDatabase(String searchUrl)
104:                    throws MalformedURLException {
105:                this .searchUrl = new URL(searchUrl);
106:            }
107:
108:            /**
109:             * Creates a new instance of SearchDatabase
110:             * @param searchUrl URL of the search server
111:             * @param database The name of the database.
112:             * @throws java.net.MalformedURLException 
113:             */
114:            public SearchDatabase(String searchUrl, String database)
115:                    throws MalformedURLException {
116:                this .searchUrl = new URL(searchUrl);
117:                this .database = database;
118:            }
119:
120:            /**
121:             * @param The access token from the portal server
122:             */
123:            public void setSessionID(String sessID) {
124:                SSOToken = sessID;
125:            }
126:
127:            private SOIF doSubmit(String operation, SOIF rd) throws IOException {
128:                SOIF hdr = new SOIF("RDMHEADER", "-");
129:                hdr.insert("rdm-type", "rd-submit-request");
130:                if (database != null)
131:                    hdr.insert("submit-database", database);
132:                if (SSOToken != null)
133:                    hdr.insert("rdm-access-token", SSOToken);
134:                SOIF req = new SOIF("Request", "-");
135:                req.insert("submit-type", submitType);
136:                req.insert("submit-operation", operation);
137:                if (this .submitView != null) {
138:                    req.insert("submit-view", submitView);
139:                }
140:                URLConnection pc = searchUrl.openConnection();
141:                pc.setAllowUserInteraction(true);
142:                pc.setUseCaches(false);
143:                pc.setDoOutput(true);
144:                pc.setDoInput(true);
145:                SOIFOutputStream sos = new SOIFOutputStream(pc
146:                        .getOutputStream());
147:                pc.connect();
148:                if (debugOut != null)
149:                    debugOut.println(">>> Request\n");
150:                sos.write(hdr);
151:                if (debugOut != null)
152:                    debugOut.print(hdr);
153:                sos.write(req);
154:                if (debugOut != null)
155:                    debugOut.print(req);
156:                sos.write(rd);
157:                if (debugOut != null)
158:                    debugOut.print(rd);
159:                sos.close();
160:                if (debugOut != null)
161:                    debugOut.println(">>> Response\n");
162:                SOIFInputStream sis = new SOIFInputStream(pc.getInputStream());
163:                SOIF s;
164:                while ((s = sis.readSOIF()) != null) {
165:                    if (debugOut != null)
166:                        debugOut.println(s);
167:                    if (s.getSchemaName().equalsIgnoreCase("DOCUMENT")) {
168:                        return s;
169:                    }
170:                }
171:                return null;
172:            }
173:
174:            /**
175:             * Retrieve a Resource Description in SOIF format.
176:             * @return Resource Description
177:             * @param documentId ID of the Resource Description to retrieve.
178:             * @throws java.io.IOException 
179:             */
180:            public SOIF fetch(String documentId) throws IOException {
181:                SOIF soif = new SOIF("DOCUMENT", documentId);
182:                return doSubmit(SUBMIT_RETRIEVE, soif);
183:            }
184:
185:            /**
186:             * Delete a Resource Description
187:             * @param documentId The ID of the RD to delete.
188:             * @throws java.io.IOException 
189:             */
190:            public void delete(String documentId) throws IOException {
191:                SOIF soif = new SOIF("DOCUMENT", documentId);
192:                doSubmit(SUBMIT_DELETE, soif);
193:            }
194:
195:            /**
196:             * Adding a new Resource Description
197:             * @param rd The new RD to insert.
198:             * @throws java.io.IOException 
199:             */
200:            public void insert(SOIF rd) throws IOException {
201:                doSubmit(SUBMIT_INSERT, rd);
202:            }
203:
204:            /**
205:             * Modify a Resource Description.
206:             * @param rd A RD contains only the attributes needed to be update.
207:             * @throws java.io.IOException 
208:             */
209:            public void update(SOIF rd) throws IOException {
210:                doSubmit(SUBMIT_UPDATE, rd);
211:            }
212:
213:            public static List getDatabaseList(String searchUrl)
214:                    throws MalformedURLException, IOException {
215:                URL url = new URL(searchUrl);
216:                SOIF hdr = new SOIF("RDMHEADER", "-");
217:                hdr.insert("rdm-type", "server-request");
218:                hdr.insert("dblist-request", "true");
219:
220:                URLConnection pc = url.openConnection();
221:                pc.setAllowUserInteraction(true);
222:                pc.setUseCaches(false);
223:                pc.setDoOutput(true);
224:                pc.setDoInput(true);
225:                SOIFOutputStream sos = new SOIFOutputStream(pc
226:                        .getOutputStream());
227:                pc.connect();
228:                sos.write(hdr);
229:
230:                SOIFInputStream sis = new SOIFInputStream(pc.getInputStream());
231:                SOIF s;
232:                ArrayList dbs = new ArrayList();
233:                while ((s = sis.readSOIF()) != null) {
234:                    if (s.getSchemaName().equalsIgnoreCase("Database")) {
235:                        dbs.add(s);
236:                    }
237:                }
238:                return dbs;
239:            }
240:
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.