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


001:        package com.sun.portal.app.wiki;
002:
003:        //import com.ecyrd.jspwiki.plugin.PortletThread;
004:
005:        import javax.portlet.*;
006:
007:        import javax.servlet.*;
008:        import javax.servlet.http.*;
009:
010:        import java.util.*;
011:        import java.io.*;
012:
013:        // XXX Need to ditch JspPortlet and switch to res bundles
014:        public class WikiPortlet extends JspPortlet {
015:
016:            // edit form literals
017:            public static String EDIT_FINISHED = "finished";
018:            public static String EDIT_CANCEL = "cancel";
019:            public static String PREF_PREFIX = "pref."; // XXX because some arg names are swallowed by the desktop
020:
021:            private PortletContext pContext;
022:
023:            public void init(PortletConfig config) throws PortletException {
024:                super .init(config);
025:                pContext = config.getPortletContext();
026:            }
027:
028:            public void doView(RenderRequest request, RenderResponse response)
029:                    throws PortletException, IOException {
030:
031:                response.setContentType(request.getResponseContentType());
032:
033:                try {
034:
035:                    PortletPreferences prefs = request.getPreferences();
036:
037:                    PortletSession ps = request.getPortletSession(true);
038:
039:                    if ("true".equals(ps.getAttribute("wiki.clearstate"))) {
040:                        // an action has been performed - clear all sticky page state
041:                        ps.setAttribute("wiki.redirect", null);
042:                        ps.setAttribute("wiki.clearstate", null);
043:                    }
044:
045:                    String dispatchURL;
046:
047:                    String contextPath = request.getContextPath();
048:                    String redirect = (String) ps.getAttribute("wiki.redirect");
049:                    if (redirect != null) {
050:                        // redirects from the webapp are treated as sticky
051:                        if (redirect.indexOf(contextPath) != -1) {
052:                            // strip the servlet context prefix for dispatch
053:                            redirect = redirect.substring(redirect
054:                                    .indexOf(contextPath)
055:                                    + contextPath.length());
056:                        }
057:                        dispatchURL = redirect;
058:                    } else {
059:                        // no redirect - use the current navigation args
060:                        String page = request.getParameter("page");
061:                        if (page == null)
062:                            page = request.getParameter("wikipage"); // wikipage deprecated in 71u1
063:                        if (page == null)
064:                            page = prefs.getValue("wikiPage", "Main");
065:                        String wikijsp = request.getParameter("wikijsp");
066:                        if (wikijsp == null)
067:                            wikijsp = "Wiki.jsp";
068:                        dispatchURL = "/" + wikijsp + "?page=" + page;
069:                    }
070:
071:                    // set up the wiki portlet context which makes
072:                    // porlet and prefs info available to the JSPWiki webapp
073:                    WikiPortletContext.init(request, response);
074:
075:                    // hopefully we can simplify this and just add the prefs map to the wikicontext
076:                    WikiPortletContext.put("wikiTemplate", prefs.getValue(
077:                            "wikiTemplate", null));
078:                    WikiPortletContext.put("editorType", prefs.getValue(
079:                            "editorType", null));
080:                    WikiPortletContext.put("editorOptions", prefs.getValues(
081:                            "editorOptions", null));
082:                    WikiPortletContext.put("availablePortlets", prefs
083:                            .getValues("availablePortlets", null));
084:
085:                    // dispatch to jspwiki
086:                    PortletRequestDispatcher dispatcher = pContext
087:                            .getRequestDispatcher(dispatchURL);
088:                    dispatcher = pContext.getRequestDispatcher(dispatchURL);
089:                    dispatcher.include(request, response);
090:
091:                    // check if there is a new redirect fomr jspwiki
092:                    String newredirect = (String) WikiPortletContext
093:                            .get("wiki.redirect");
094:                    if (newredirect != null) {
095:                        if (newredirect.indexOf(contextPath) != -1) {
096:                            // strip the servlet context prefix for dispatch
097:                            newredirect = newredirect.substring(newredirect
098:                                    .indexOf(contextPath)
099:                                    + contextPath.length());
100:                            if (newredirect.indexOf("%3A") != -1) {
101:                                // due to bug in portlet request dispatcher not decoding its args
102:                                newredirect = newredirect
103:                                        .replaceAll("%3A", ":");
104:                            }
105:                        }
106:                        dispatchURL = newredirect;
107:
108:                        // make the redirect sticky
109:                        // XXX there should be a way to reset render args...
110:                        ps.setAttribute("wiki.redirect", dispatchURL);
111:
112:                        dispatcher = pContext.getRequestDispatcher(dispatchURL);
113:                        dispatcher.include(request, response);
114:
115:                    }
116:
117:                    WikiPortletContext.cleanup();
118:                } catch (Exception e) {
119:                    e.printStackTrace();
120:                    throw new PortletException(e);
121:                }
122:
123:            }
124:
125:            public void processAction(ActionRequest request,
126:                    ActionResponse response) throws PortletException,
127:                    java.io.IOException {
128:
129:                try {
130:
131:                    // There are two types of action...
132:
133:                    // ... 1) saving preferences from the edit page
134:                    if (request.getPortletMode().equals(PortletMode.EDIT)) {
135:                        savePreferences(request, response);
136:                        response.setPortletMode(PortletMode.VIEW);
137:                        return;
138:                    }
139:
140:                    // ... 2) a portlet action url
141:                    response.setRenderParameters(request.getParameterMap());
142:                    // tell render to clear its state
143:                    PortletSession ps = request.getPortletSession(true);
144:                    ps.setAttribute("wiki.clearstate", "true");
145:                    ps.setAttribute("wiki.redirect", null);
146:                } catch (Exception e) {
147:                    System.out.println(e); // XXX
148:                    throw new PortletException(e);
149:                }
150:
151:            }
152:
153:            void savePreferences(PortletRequest request,
154:                    PortletResponse response) throws PortletException {
155:
156:                try {
157:
158:                    String finished = request.getParameter(EDIT_FINISHED);
159:                    String cancel = request.getParameter(EDIT_CANCEL);
160:
161:                    if (cancel != null) {
162:                        // user cancelled - do nothing
163:                        return;
164:                    } else if (finished != null) {
165:
166:                        PortletPreferences prefs = request.getPreferences();
167:                        boolean needstore = false;
168:                        // check if any prefs have changed
169:                        for (Enumeration e = request.getParameterNames(); e
170:                                .hasMoreElements();) {
171:                            String paramname = (String) e.nextElement();
172:                            if (!paramname.startsWith(PREF_PREFIX))
173:                                continue;
174:                            String name = paramname.substring(PREF_PREFIX
175:                                    .length());
176:                            String[] newvalues = request
177:                                    .getParameterValues(paramname);
178:                            String[] oldvalues = prefs.getValues(name,
179:                                    new String[] {});
180:                            String[] newPrefs = compareValues(newvalues,
181:                                    oldvalues);
182:                            if (newPrefs != null) {
183:                                prefs.setValues(name, newPrefs);
184:                                needstore = true;
185:                            }
186:                        }
187:                        if (needstore) {
188:                            // prefs have changed - save them
189:                            prefs.store();
190:                        }
191:                        return;
192:                    } else {
193:                        // shouldn't happen
194:                        return;
195:                    }
196:                } catch (Exception e) {
197:                    System.out.println("exception: " + e); // XXX
198:                    throw new PortletException(e);
199:                }
200:            }
201:
202:            // returns a new String[] if prefs changed, or null if no change
203:            private String[] compareValues(String[] n, String[] o) {
204:
205:                // remove holes from n
206:                List vl = new ArrayList();
207:                for (int i = 0; i < n.length; ++i) {
208:                    if (n[i] != null && !n[i].equals("")) {
209:                        vl.add(n[i]);
210:                    }
211:                }
212:                n = (String[]) vl.toArray(new String[0]);
213:
214:                // remove holes from o
215:                vl = new ArrayList();
216:                for (int i = 0; i < o.length; ++i) {
217:                    if (o[i] != null && !o[i].equals("")) {
218:                        vl.add(o[i]);
219:                    }
220:                }
221:                o = (String[]) vl.toArray(new String[0]);
222:
223:                if (n.length != o.length) {
224:                    return n;
225:                }
226:
227:                for (int i = 0; i < n.length; ++i) {
228:                    if (!n[i].equals(o[i])) {
229:                        return n;
230:                    }
231:                }
232:                return null;
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.