Source Code Cross Referenced for FilePortletCreator.java in  » Portal » stringbeans-3.5 » com » nabhinc » portlet » portletadmin » 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 » stringbeans 3.5 » com.nabhinc.portlet.portletadmin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc. 
003:         * 
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License 
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:         * 
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of 
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
012:         * GNU General Public License for more details.
013:         * 
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software 
016:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:         * 
018:         */
019:        package com.nabhinc.portlet.portletadmin;
020:
021:        import java.io.IOException;
022:        import java.util.HashMap;
023:        import java.util.Hashtable;
024:        import java.util.Vector;
025:
026:        import javax.portlet.ActionRequest;
027:        import javax.portlet.ActionResponse;
028:        import javax.portlet.PortletException;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import com.nabhinc.core.MimeTypes;
033:        import com.nabhinc.portal.config.PortletType;
034:        import com.nabhinc.portal.container.PortletRequestImpl;
035:        import com.nabhinc.portal.container.PortletResponseImpl;
036:        import com.nabhinc.portal.core.PortalServlet;
037:        import com.nabhinc.portal.core.PortletConfigInfo;
038:        import com.nabhinc.portlet.portletadmin.PortletUtil;
039:        import com.nabhinc.portlet.base.BasePortlet;
040:        import com.nabhinc.portlet.file.FilePortlet;
041:        import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
042:        import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
043:        import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
044:        import com.nabhinc.util.StringUtil;
045:
046:        /**
047:         * 
048:         *
049:         * @author Padmanabh Dabke
050:         * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
051:         * @since 2.4.1
052:         */
053:        public class FilePortletCreator extends BaseRequestProcessor implements 
054:                ActionProcessor {
055:
056:            /* (non-Javadoc)
057:             * @see com.nabhinc.portlet.mvcportlet.core.ActionProcessor#process(javax.portlet.ActionRequest, javax.portlet.ActionResponse, com.nabhinc.portlet.mvcportlet.core.ActionConfig)
058:             */
059:            public String process(ActionRequest request,
060:                    ActionResponse response, ActionConfig actionConfig)
061:                    throws PortletException, IOException {
062:
063:                final String PORTLET_TYPE = "com.nabhinc.portlet.file.FilePortlet";
064:
065:                final String VIEW_MODE = "view";
066:                final String EDIT_MODE = "edit";
067:                final String HELP_MODE = "help";
068:                final String ADMIN_MODE = "admin";
069:
070:                boolean isEdit = "true".equals(request.getParameter("edit"));
071:                String portletIndex = request.getParameter("portlet_index");
072:                int pIndex = portletIndex == null ? -1 : Integer
073:                        .parseInt(portletIndex);
074:
075:                //HTML mime type is supported by default
076:                boolean isHTMLMimeTypeSupported = true; //rReq.getParameter("html_mime_type") != null;
077:                boolean isHTMLEditSupported = request
078:                        .getParameter("html_edit_mode") != null;
079:                boolean isHTMLHelpSupported = request
080:                        .getParameter("html_help_mode") != null;
081:                boolean isXHTMLMimeTypeSupported = false;
082:                boolean isWMLMimeTypeSupported = false;
083:                boolean isHTMLAdminSupported = false;
084:
085:                String pName = request.getParameter("pname");
086:                String title = request.getParameter("title");
087:                String keywordsStr = request.getParameter("keywords");
088:                String shortTitle = request.getParameter("short_title");
089:                String expCache = request.getParameter("exp_cache");
090:                String resourceBundleName = request
091:                        .getParameter("resource_bundle");
092:                String supportedLocales = request
093:                        .getParameter("supported_locales");
094:
095:                String totalSecRoles = request.getParameter("sec_roles_total");
096:                String totalDescrLang = request
097:                        .getParameter("descr_lang_total");
098:                String totalDispLang = request
099:                        .getParameter("display_lang_total");
100:
101:                int numOfSecRoles = Integer.parseInt(totalSecRoles);
102:                int numOfDescrLangs = Integer.parseInt(totalDescrLang);
103:                int numOfDispLangs = Integer.parseInt(totalDispLang);
104:
105:                //String filePath = request.getParameter("file_path");
106:                String htmlFilePath = request.getParameter("html_file_path");
107:                String xhtmlFilePath = request.getParameter("xhtml_file_path");
108:                String wmlFilePath = request.getParameter("wml_file_path");
109:
110:                String editPath = request.getParameter("edit_path");
111:                String adminPath = request.getParameter("admin_path");
112:                String helpPath = request.getParameter("help_path");
113:
114:                String error = "";
115:                if (pName == null || "".equals(pName.trim())) {
116:                    error += "You must provide portlet name.<br/>";
117:                } else if (PortalServlet.getInstance().isPortletExists(pName)) {
118:                    if (!isEdit
119:                            || !pName.equals(((PortletConfigInfo) PortalServlet
120:                                    .getInstance().getPortletConfigInfoList()
121:                                    .elementAt(pIndex)).name)) {
122:                        error += "Duplicate portlet name.<br/>";
123:                    }
124:                }
125:                if (title == null || "".equals(title.trim())) {
126:                    error += "You must provide portlet title.<br/>";
127:                }
128:                if (htmlFilePath == null || "".equals(htmlFilePath.trim())) {
129:                    error += "You must provide path for the file to be displayed.<br/>";
130:                } else if (htmlFilePath.indexOf("://") != -1) {
131:                    error += "Invalid file path. Consider to use URL portlet instead.<br/>";
132:                }
133:                if (xhtmlFilePath != null && xhtmlFilePath.indexOf("://") != -1) {
134:                    error += "Invalid XHTML document path. Consider to use URL portlet instead.<br/>";
135:                }
136:                if (wmlFilePath != null && wmlFilePath.indexOf("://") != -1) {
137:                    error += "Invalid WML document path. Consider to use URL portlet instead.<br/>";
138:                }
139:                if (expCache != null && !expCache.trim().equals("")) {
140:                    try {
141:                        Integer.parseInt(expCache);
142:                    } catch (Exception ex) {
143:                        error += "Expiration cache must be a number.<br/>";
144:                    }
145:                }
146:
147:                if (!error.equals("")) {
148:                    response.setRenderParameter("error", error);
149:                    if (isEdit)
150:                        response.setRenderParameter("edit", "true");
151:                    return "failure";
152:                }
153:
154:                PortletType pType = PortletUtil.createPortletType(pName,
155:                        PORTLET_TYPE);
156:                PortletUtil.setTitle(title, pType);
157:                PortletUtil.setShortTitle(shortTitle, pType);
158:                PortletUtil.setResourceBundle(resourceBundleName, pType);
159:
160:                HashMap descrMap = new HashMap();
161:                for (int i = 0; i < numOfDescrLangs; i++) {
162:                    String lang = request.getParameter("descr_lang" + i);
163:                    String descr = request.getParameter("descr" + i);
164:                    if (descrMap.containsKey(lang))
165:                        continue;
166:                    descrMap.put(lang, descr);
167:                }
168:                PortletUtil.setDescription(descrMap, pType);
169:
170:                HashMap displayMap = new HashMap();
171:                for (int i = 0; i < numOfDispLangs; i++) {
172:                    String lang = request.getParameter("display_lang" + i);
173:                    String displayName = request.getParameter("display_name"
174:                            + i);
175:                    if (displayMap.containsKey(lang))
176:                        continue;
177:                    displayMap.put(lang, displayName);
178:                }
179:                PortletUtil.setDisplayName(displayMap, pType);
180:
181:                if (expCache != null && !expCache.trim().equals(""))
182:                    PortletUtil.setExpirationCache(Integer.parseInt(expCache),
183:                            pType);
184:
185:                Hashtable initParams = new Hashtable();
186:                /*
187:                if (filePath.indexOf("://") == -1) {
188:                    if(! filePath.startsWith("/")) {
189:                        filePath = "/" + filePath;
190:                    }
191:                    initParams.put(FilePortlet.FILE_PATH, filePath);
192:                }
193:                 */
194:                if (!htmlFilePath.startsWith("/")) {
195:                    htmlFilePath = "/" + htmlFilePath;
196:                }
197:                initParams.put(FilePortlet.HTML_FILE_PATH, htmlFilePath);
198:
199:                if (xhtmlFilePath != null && !xhtmlFilePath.trim().equals("")) {
200:                    if (!xhtmlFilePath.startsWith("/")) {
201:                        xhtmlFilePath = "/" + xhtmlFilePath;
202:                    }
203:                    initParams.put(FilePortlet.XHTML_FILE_PATH, xhtmlFilePath);
204:                    isXHTMLMimeTypeSupported = true;
205:                }
206:
207:                if (wmlFilePath != null && !wmlFilePath.trim().equals("")) {
208:                    if (!wmlFilePath.startsWith("/")) {
209:                        wmlFilePath = "/" + wmlFilePath;
210:                    }
211:                    initParams.put(FilePortlet.WML_FILE_PATH, wmlFilePath);
212:                    isWMLMimeTypeSupported = true;
213:                }
214:
215:                if (editPath != null && !editPath.trim().equals("")) {
216:                    if (editPath.indexOf("://") == -1
217:                            && !editPath.startsWith("/")) {
218:                        editPath = "/" + editPath;
219:                    }
220:                    initParams.put(BasePortlet.EDIT_JSP_PARAM, editPath);
221:                    isHTMLEditSupported = true;
222:                }
223:
224:                if (adminPath != null && !adminPath.trim().equals("")) {
225:                    if (adminPath.indexOf("://") == -1
226:                            && !adminPath.startsWith("/")) {
227:                        adminPath = "/" + adminPath;
228:                    }
229:                    initParams.put(FilePortlet.ADMIN_PAGE_PARAM, adminPath);
230:                    isHTMLAdminSupported = true;
231:                }
232:                if (helpPath != null && !helpPath.trim().equals("")) {
233:                    if (helpPath.indexOf("://") == -1
234:                            && !helpPath.startsWith("/")) {
235:                        helpPath = "/" + helpPath;
236:                    }
237:                    initParams.put(BasePortlet.HELP_JSP_PARAM, helpPath);
238:                    isHTMLHelpSupported = true;
239:                }
240:
241:                PortletUtil.setInitParams(initParams, pType);
242:
243:                PortletUtil.setKeywords(keywordsStr, pType);
244:
245:                if (isHTMLMimeTypeSupported) {
246:                    Vector modeList = new Vector();
247:
248:                    if (isHTMLEditSupported) {
249:                        modeList.add(EDIT_MODE);
250:                    }
251:                    if (isHTMLHelpSupported) {
252:                        modeList.add(HELP_MODE);
253:                    }
254:                    if (isHTMLAdminSupported) {
255:                        modeList.add(ADMIN_MODE);
256:                    }
257:                    String[] supportedModes = new String[modeList.size()];
258:                    modeList.copyInto(supportedModes);
259:
260:                    PortletUtil.setSupports(supportedModes, MimeTypes.HTML,
261:                            pType);
262:                }
263:
264:                if (isXHTMLMimeTypeSupported) {
265:                    String[] supportedModes = new String[0];
266:                    PortletUtil.setSupports(supportedModes, MimeTypes.XHTML_MP,
267:                            pType);
268:                }
269:
270:                if (isWMLMimeTypeSupported) {
271:                    String[] supportedModes = new String[0];
272:                    PortletUtil.setSupports(supportedModes, MimeTypes.WML,
273:                            pType);
274:                }
275:
276:                if (supportedLocales != null
277:                        && !"".equals(supportedLocales.trim())) {
278:                    String[] locales = StringUtil.split(supportedLocales, ",");
279:                    PortletUtil.setSupportedLocales(locales, pType);
280:                }
281:
282:                HashMap secRoleMap = new HashMap();
283:                for (int i = 0; i < numOfSecRoles; i++) {
284:                    String roleName = request.getParameter("role_name" + i);
285:                    if (roleName != null && !"".equals(roleName.trim())) {
286:                        secRoleMap.put(roleName, request
287:                                .getParameter("role_link" + i));
288:                    }
289:                }
290:                PortletUtil.setSecurityRoleReference(secRoleMap, pType);
291:
292:                try {
293:                    if (isEdit) {
294:                        HttpServletRequest req = ((PortletRequestImpl) request)
295:                                .getHttpServletRequest();
296:                        HttpServletResponse res = ((PortletResponseImpl) response)
297:                                .getHttpServletResponse();
298:                        PortalServlet.getInstance().replacePortlet(pType,
299:                                pIndex, req, res);
300:                    } else {
301:                        PortalServlet.getInstance().addPortlet(pType);
302:                    }
303:                    PortalServlet.getInstance().savePortletConfiguration();
304:                } catch (Exception ex) {
305:                    throw new PortletException(
306:                            "Failed to create File portlet.", ex);
307:                }
308:                return "success";
309:            }
310:
311:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.