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


001:        // QuotationProvider.java
002:        //   This is a sample desktop provider application used to display
003:        //   famous/humorous quotations on the desktop.
004:        //
005:        //   It shows how to use the BaseProvider API to:
006:        //     - display html content on the desktop
007:        //     - allow the user to edit attributes
008:        //
009:
010:        // Where the QuotationProvider.class file can be found.
011:        package samples.quotation;
012:
013:        // Use some basic Java classes
014:        import java.lang.*;
015:        import java.io.*;
016:        import java.util.*;
017:        import java.net.*;
018:
019:        // Use some basic Java Servlet classes
020:        import javax.servlet.*;
021:        import javax.servlet.http.*;
022:
023:        // Use some iPS classes
024:        import com.sun.portal.providers.*;
025:
026:        // The QuotationProvider Class
027:        public class QuotationProvider extends ProfileProviderAdapter {
028:            // The constructor - don't need to do any special initialization
029:            // so just invoke the ProfileProviderAdapter's constructor
030:            public QuotationProvider() {
031:                super ();
032:            }
033:
034:            // Generate the HTML that will be displayed in this content provider's
035:            // area on the desktop
036:            public StringBuffer getContent(HttpServletRequest req,
037:                    HttpServletResponse res) throws ProviderException {
038:
039:                StringBuffer content = new StringBuffer(); // Contains the HTML to be
040:                //   displayed
041:                Hashtable quotesHash = new Hashtable(); // A Hash of quote vectors,
042:                //   one vector per category
043:                BufferedReader quotesReader; // Used to read the quotes
044:                String quote; // A single quotation
045:                Random randomGenerator = new Random(); // To randomly pick quotes
046:
047:                // Read in the quotations into a Hashtable of Vectors, each containg
048:                // the quotations of a specific category. If we can't read the
049:                // quotations file it's okay - we just won't display any quotes later.
050:                // The category and quotation are separated by a "|" in the quotations
051:                // file.
052:
053:                try {
054:                    String quotationFileName = getStringProperty("fileLocation");
055:                    quotesReader = new BufferedReader(new FileReader(new File(
056:                            quotationFileName)));
057:                    while ((quote = quotesReader.readLine()) != null) {
058:                        String type = quote.substring(0, quote.indexOf('|'));
059:                        if (!quotesHash.containsKey(type)) {
060:                            quotesHash.put(type, new Vector());
061:                        }
062:                        ((Vector) (quotesHash.get(type))).addElement(quote
063:                                .substring(quote.indexOf('|') + 1));
064:                    }
065:                } catch (Exception e) {
066:                }
067:
068:                // Determine is user's preference is to display the category along with
069:                // a quotation.
070:                boolean displayCategories = getBooleanProperty("displayCategories");
071:
072:                // Get the possible quotation categories.
073:                List categoriesSel = getListProperty("selectedCategories");
074:
075:                // Print a quotation for each category selected by the user.
076:                for (int i = 0; i < categoriesSel.size(); i++) {
077:                    String category = (String) categoriesSel.get(i);
078:
079:                    // If the user wanted to display the category along with the
080:                    // quotation then do so.
081:                    if (displayCategories) {
082:                        content.append("<B><I>");
083:                        content.append(category);
084:                        content.append("</B></I>");
085:                    }
086:
087:                    // If there are any quotations for this category, pick a random
088:                    // one and display it, otherwise note that we didn't find one.
089:                    if (quotesHash.containsKey(category)) {
090:                        Vector quoteVector = (Vector) quotesHash.get(category);
091:                        int whichQuoteIndex = Math.abs(randomGenerator
092:                                .nextInt())
093:                                % (quoteVector).size();
094:                        content.append("<UL>");
095:                        content.append("<LI>");
096:                        content.append((String) (quoteVector
097:                                .elementAt(whichQuoteIndex)));
098:                        content.append("</LI>");
099:                        content.append("</UL>");
100:                    } else {
101:                        content.append("<UL>");
102:                        content.append("<LI>");
103:                        content.append("(no quotes of this type found)");
104:                        content.append("</LI>");
105:                        content.append("</UL>");
106:                    }
107:                }
108:
109:                // Now return the HTML we have constructed.
110:                return content;
111:            }
112:
113:            // Generate the HTML that will be displayed to let the user set
114:            // his/her preferneces.
115:            public StringBuffer getEdit(HttpServletRequest req,
116:                    HttpServletResponse res) throws ProviderException {
117:                // Contains the HTML to be displayed        
118:                StringBuffer content = new StringBuffer();
119:
120:                // Display things in a single column table - so things line up.
121:                content.append("<P><TABLE>");
122:
123:                // Let the user choose which categories s/he wants.
124:                content.append("<TR>");
125:                content.append("<TD VALIGN=\"top\" HALIGN=\"left\">");
126:                content.append("Types of Quotes to Display");
127:                content.append("</TD>");
128:
129:                // Get the user's selected categories
130:                List selectedCategories = getListProperty("selectedCategories");
131:
132:                // List the possible categories, marking those that have already
133:                // been selected by the user.
134:                content.append("<TD VALIGN=\"top\" HALIGN=\"left\">");
135:                List possibleCategories = getListProperty("possibleCategories");
136:
137:                for (int i = 0; i < possibleCategories.size(); i++) {
138:                    String category = (String) possibleCategories.get(i);
139:                    content.append("<INPUT TYPE=\"checkbox\" NAME=\"category-");
140:                    content.append(category);
141:                    content.append("\" VALUE=\"");
142:                    content.append(category);
143:                    content.append("\"");
144:                    if (selectedCategories.contains(category)) {
145:                        content.append(" CHECKED");
146:                    }
147:                    content.append(">");
148:                    content.append(category);
149:                    content.append("<BR>");
150:                }
151:                content.append("</TD>");
152:                content.append("</TR>");
153:
154:                // Let the user decide if they want to display a category with
155:                // each quotation.
156:                content.append("<TR>");
157:                content.append("<TD VALIGN=\"top\" HALIGN=\"left\">");
158:                content
159:                        .append("<INPUT TYPE=\"checkboX\" NAME=\"display_categories\" VALUE=\"yes\"");
160:
161:                if (getBooleanProperty("displayCategories")) {
162:                    content.append(" CHECKED");
163:                }
164:                content
165:                        .append(">Display the Category Along With the Quotation");
166:                content.append("</TD>");
167:                content.append("</TR>");
168:
169:                content.append("</TABLE>");
170:
171:                return content;
172:            }
173:
174:            // Handle the submittal of the edit form.
175:            public URL processEdit(HttpServletRequest req,
176:                    HttpServletResponse res) throws ProviderException {
177:
178:                List categorySelections = new ArrayList(); // Categories user picked
179:                boolean displayCategories = false; // Display category too ?
180:
181:                for (Enumeration e = req.getParameterNames(); e
182:                        .hasMoreElements();) {
183:
184:                    // Check all the passed parameters and add the selected categories
185:                    // as well as check to see if user opted to display categories.
186:                    String parameter = (String) e.nextElement();
187:                    if (parameter.equals("display_categories")) {
188:                        displayCategories = true;
189:                    } else if (parameter.startsWith("category-")) {
190:                        String[] category = (String[]) req
191:                                .getParameterValues(parameter);
192:                        categorySelections.add(category[0]);
193:                    }
194:                }
195:
196:                // Set the list of selected categories for later storing in the
197:                // profile database.
198:                setListProperty("selectedCategories", categorySelections);
199:
200:                // Set whether the user wants to display categories or not for later
201:                // storing in the profile database.
202:                setBooleanProperty("displayCategories", displayCategories);
203:
204:                return null;
205:
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.