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


001:        /*
002:         * Please read the License Agreement and other supplemental license terms, if
003:         * any, accompanying this software package before using any of the software
004:         * provided.  If you do not agree to the terms of the License Agreement or any
005:         * other supplemental terms, please promptly destroy or return the software to
006:         * Sun Microsystems, Inc.
007:         *
008:         * "CONFIDENTIAL AND PROPRIETARY" Copyright ? 2001 Sun Microsystems, Inc.  All
009:         * rights reserved.
010:         */
011:        package com.sun.portal.providers.personalnote;
012:
013:        import java.net.URL;
014:        import java.net.URLEncoder;
015:        import java.net.MalformedURLException;
016:
017:        import java.util.Hashtable;
018:        import java.util.List;
019:        import java.util.ArrayList;
020:        import java.util.ResourceBundle;
021:        import java.util.logging.Logger;
022:        import java.util.logging.Level;
023:
024:        import javax.servlet.http.HttpServletRequest;
025:        import javax.servlet.http.HttpServletResponse;
026:
027:        import com.sun.portal.providers.ProfileProviderAdapter;
028:        import com.sun.portal.providers.ProviderException;
029:        import com.sun.portal.providers.InvalidEditFormDataException;
030:
031:        import com.sun.portal.providers.context.ProviderContext;
032:        import com.sun.portal.providers.context.ProviderContextException;
033:        import com.sun.portal.log.common.PortalLogger;
034:
035:        public class PersonalNoteProvider extends ProfileProviderAdapter {
036:            private static final String sccsID = "$Id: PersonalNoteProvider.java,v 1.12 2005/09/21 10:45:59 dg154973 Exp $";
037:
038:            private ResourceBundle bundle = null;
039:            private static Logger logger = PortalLogger
040:                    .getLogger(PersonalNoteProvider.class);
041:
042:            /**
043:             * Initialize provider
044:             * <p> Presentability of the provider to the desktop is based
045:             *     on the client type and content template retrieval</p>
046:             *
047:             * @param n Component name
048:             * @param req HTTP Servlet request
049:             */
050:            public void init(String n, HttpServletRequest req)
051:                    throws ProviderException {
052:                super .init(n, req);
053:
054:                bundle = getResourceBundle();
055:            }
056:
057:            /**
058:             * Set a list property for the provider.
059:             *
060:             * @param notes The value(s) for profile component.
061:             * @return List of the value(s) for the profile component.
062:             */
063:            private List setNotes(List notes) throws ProviderException {
064:                setListProperty("notes", notes);
065:
066:                return notes;
067:            }
068:
069:            /**
070:             * Get a list property for the provider.
071:             *
072:             * @return List of the value(s) for the profile component.
073:             */
074:            private List getNotes() throws ProviderException {
075:                return (getListProperty("notes"));
076:            }
077:
078:            /**
079:             * Retrieve Content for the Client.
080:             *
081:             * @return StringBuffer of the provider content.
082:             */
083:            public StringBuffer getContent(HttpServletRequest req,
084:                    HttpServletResponse res) throws ProviderException {
085:                StringBuffer content = new StringBuffer();
086:
087:                List pnotes = getNotes();
088:
089:                if (!pnotes.isEmpty()) {
090:                    int num_notes = pnotes.size();
091:
092:                    String text_color = bundle.getString("textColor");
093:                    String dark_color = bundle.getString("darkColor");
094:                    String light_color = bundle.getString("lightColor");
095:
096:                    String font_face = getStringProperty("fontFace1");
097:
098:                    String linebreak = getTemplate("linebreak.template")
099:                            .toString();
100:                    String msgSuffix = getTemplate("msgSuffix.template")
101:                            .toString();
102:
103:                    Hashtable tagTable = new Hashtable();
104:                    tagTable.put("textColor", text_color);
105:                    tagTable.put("fontFace1", font_face);
106:
107:                    for (int i = 0; i < num_notes; i++) {
108:                        String pnote = (String) pnotes.get(i).toString();
109:
110:                        tagTable.put("bgColor", ((i % 2) == 0) ? light_color
111:                                : dark_color);
112:                        StringBuffer msgPrefix = getTemplate(
113:                                "msgPrefix.template", tagTable);
114:
115:                        content.append(msgPrefix).append(encode(pnote)).append(
116:                                msgSuffix);
117:
118:                        if (i < num_notes - 1)
119:                            content.append(linebreak);
120:                    }
121:                    tagTable.clear();
122:
123:                    tagTable.put("note", content.toString());
124:                    tagTable.put("count", Integer.toString(num_notes));
125:                    content = getTemplate("content.template", tagTable);
126:                } else {
127:                    // we will use the noContent.template if there is one,
128:                    // otherwise, return empty string buffer as before
129:                    try {
130:                        content = getTemplate("noContent.template",
131:                                new Hashtable());
132:                    } catch (ProviderException e) {
133:                        logger.log(Level.FINEST, "PSDT_CSPPPN0001", e);
134:                    }
135:                }
136:
137:                return content;
138:            }
139:
140:            /**
141:             * Retrieve Edit Content for the Client.
142:             *
143:             * @return StringBuffer of the provider edit content.
144:             */
145:            public StringBuffer getEdit(HttpServletRequest req,
146:                    HttpServletResponse res) throws ProviderException {
147:                // The following are used for reconstructing the edit url from processEdit
148:                String editContainer = req.getParameter("provider");
149:                String container = req.getParameter("containerName");
150:
151:                Hashtable tagTable = new Hashtable();
152:                tagTable.put("fontFace1", getStringProperty("fontFace1"));
153:
154:                StringBuffer pnoteList = new StringBuffer("");
155:
156:                List pnotes = getNotes();
157:                int num_notes = pnotes.size();
158:                for (int i = 0; i < num_notes; i++) {
159:                    String pnote = (String) pnotes.get(i).toString();
160:
161:                    String string_i = String.valueOf(i);
162:                    tagTable.put("removeId", string_i);
163:                    tagTable.put("nameId", string_i);
164:
165:                    tagTable.put("note", pnote);
166:                    pnoteList.append(getTemplate(
167:                            "editNoteListWrapper.template", tagTable));
168:                    tagTable.remove("note");
169:                }
170:
171:                tagTable.put("noteCount", Integer.toString(num_notes));
172:                tagTable.put("noteList", pnoteList.toString());
173:                tagTable.put("container", container);
174:                tagTable.put("editContainer", editContainer);
175:
176:                return (getTemplate("edit.template", tagTable));
177:            }
178:
179:            /**
180:             * Evaluate the Edit Content received from the Client.
181:             *
182:             * @return URL for the next page
183:             */
184:            public URL processEdit(HttpServletRequest req,
185:                    HttpServletResponse res) throws ProviderException {
186:                getProviderContext().contentChanged(getName());
187:
188:                URL next = null;
189:
190:                int count = 0;
191:                String noteCount = req.getParameter("noteCount");
192:                if (noteCount != null) {
193:                    try {
194:                        count = Integer.parseInt(noteCount);
195:                    } catch (NumberFormatException e) {
196:                        String err = bundle.getString("linesNAN");
197:                        throw new InvalidEditFormDataException(err);
198:                    }
199:                }
200:
201:                ArrayList pnotes = new ArrayList();
202:
203:                for (int i = 0; i < count; i++) {
204:                    boolean remove_i = false;
205:                    String param = req.getParameter("remove" + i);
206:                    if (param != null) {
207:                        try {
208:                            remove_i = (Integer.parseInt(param) == 1);
209:                        } catch (NumberFormatException ne) {
210:                            logger.log(Level.FINEST, "PSDT_CSPPPN0002", ne);
211:                            throw new ProviderException(
212:                                    "PersonalNoteProvider.processEdit(): Non numeric value cannot be removed",
213:                                    ne);
214:                        }
215:
216:                    }
217:
218:                    /*
219:                     * if the checkbox was not checked then keep it in the
220:                     * note list and add it to the list
221:                     */
222:                    if (!remove_i) {
223:                        pnotes.add(req.getParameter("name" + i));
224:                    }
225:                }
226:
227:                /*
228:                 * Addition. Evaluate the new item to add.
229:                 *
230:                 * if the checkbox was not checked then keep it in the 
231:                 *  note list and add it to the hashtable
232:                 */
233:                String newNoteValue = req.getParameter("noteTextbox");
234:                if ((newNoteValue != null) && (!newNoteValue.equals(""))) {
235:                    pnotes.add(newNoteValue);
236:
237:                    String addMore = req.getParameter("add_more");
238:                    if ((addMore != null) && (addMore.length() > 0)) {
239:                        StringBuffer urlString = new StringBuffer();
240:                        urlString
241:                                .append(getProviderContext().getDesktopURL(req))
242:                                .append("?action=edit&provider=")
243:                                .append(
244:                                        URLEncoder.encode(req
245:                                                .getParameter("editContainer")))
246:                                .append("&targetprovider=").append(
247:                                        URLEncoder.encode(getName())).append(
248:                                        "&containerName=").append(
249:                                        URLEncoder.encode(req
250:                                                .getParameter("container")));
251:
252:                        try {
253:                            next = new URL(urlString.toString());
254:                        } catch (MalformedURLException me) {
255:                            throw new ProviderException(getName()
256:                                    + ".processEdit()", me);
257:                        }
258:                    }
259:                }
260:
261:                // Set the data hash
262:                pnotes.trimToSize();
263:                setNotes(pnotes);
264:
265:                // Window Preference
266:                String windowPref = req.getParameter("windowPref");
267:                if (windowPref != null) {
268:                    setStringProperty("windowPref", windowPref);
269:                }
270:
271:                return next;
272:            }
273:
274:            /**
275:             * Only html based clients are editable 
276:             *
277:             * @return boolean
278:             */
279:            public boolean isEditable() throws ProviderException {
280:                boolean editable = false;
281:
282:                if ((getTemplatePath("edit.template") != null)
283:                        && getBooleanProperty("isEditable")) {
284:                    editable = true;
285:                }
286:
287:                return editable;
288:            }
289:
290:            /**
291:             * Determine if the provider is presentable
292:             * @deprecated Use isPresentable(HttpServletRequest)
293:             *
294:             */
295:            public boolean isPresentable() {
296:                logger.log(Level.FINER, "PSDT_CSPPPN0003");
297:                return false;
298:            }
299:
300:            /**
301:             * Determine if the provider is presentable
302:             *
303:             */
304:            public boolean isPresentable(HttpServletRequest req) {
305:                boolean isPresentable = false;
306:                ProviderContext pc = getProviderContext();
307:                try {
308:                    if (getTemplatePath("content.template") != null) {
309:                        isPresentable = true;
310:                    }
311:                } catch (ProviderException pe) {
312:                    // Probable cause, channel/provider definition not found in dp
313:                    // log a warning and return false
314:                    logger.log(Level.FINE, "PSDT_CSPPPN0004");
315:                }
316:                return isPresentable;
317:            }
318:
319:            private String encode(String raw_data) throws ProviderException {
320:                String encoded_data = null;
321:
322:                try {
323:                    encoded_data = getProviderContext().escape(raw_data);
324:                } catch (ProviderContextException e) {
325:                    logger.log(Level.FINE, "PSDT_CSPPPN0005", e);
326:                    throw new ProviderException("Error escaping data", e);
327:                }
328:
329:                return (encoded_data);
330:            }
331:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.