Source Code Cross Referenced for PageCustomizerInterceptor.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » core » aspects » controller » 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 » jboss portal 2.6.4 » org.jboss.portal.core.aspects.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.core.aspects.controller;
023:
024:        import org.apache.log4j.Logger;
025:        import org.jboss.portal.Mode;
026:        import org.jboss.portal.WindowState;
027:        import org.jboss.portal.api.PortalURL;
028:        import org.jboss.portal.core.aspects.controller.node.Navigation;
029:        import org.jboss.portal.core.controller.Controller;
030:        import org.jboss.portal.core.controller.ControllerCommand;
031:        import org.jboss.portal.core.controller.ControllerContext;
032:        import org.jboss.portal.core.controller.ControllerInterceptor;
033:        import org.jboss.portal.core.controller.ControllerRequestDispatcher;
034:        import org.jboss.portal.core.controller.ControllerResponse;
035:        import org.jboss.portal.core.controller.command.SignOutCommand;
036:        import org.jboss.portal.core.impl.api.node.PortalNodeImpl;
037:        import org.jboss.portal.core.model.CustomizationManager;
038:        import org.jboss.portal.core.model.instance.command.action.InvokePortletInstanceRenderCommand;
039:        import org.jboss.portal.core.model.instance.command.render.RenderPortletInstanceCommand;
040:        import org.jboss.portal.core.model.portal.Page;
041:        import org.jboss.portal.core.model.portal.Portal;
042:        import org.jboss.portal.core.model.portal.PortalObject;
043:        import org.jboss.portal.core.model.portal.PortalObjectContainer;
044:        import org.jboss.portal.core.model.portal.PortalObjectId;
045:        import org.jboss.portal.core.model.portal.PortalObjectPath;
046:        import org.jboss.portal.core.model.portal.PortalObjectPermission;
047:        import org.jboss.portal.core.model.portal.command.PageCommand;
048:        import org.jboss.portal.core.model.portal.command.action.ImportPageToDashboardCommand;
049:        import org.jboss.portal.core.model.portal.command.render.RenderPageCommand;
050:        import org.jboss.portal.core.model.portal.command.view.ViewContextCommand;
051:        import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
052:        import org.jboss.portal.core.model.portal.command.view.ViewPortalCommand;
053:        import org.jboss.portal.core.theme.PageRendition;
054:        import org.jboss.portal.identity.User;
055:        import org.jboss.portal.portlet.PortletParametersStateString;
056:        import org.jboss.portal.security.PortalSecurityException;
057:        import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
058:        import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
059:        import org.jboss.portal.server.config.ServerConfig;
060:        import org.jboss.portal.server.request.URLContext;
061:        import org.jboss.portal.server.request.URLFormat;
062:        import org.jboss.portal.theme.ThemeConstants;
063:        import org.jboss.portal.theme.impl.render.dynamic.DynaRenderOptions;
064:        import org.jboss.portal.theme.page.Region;
065:        import org.jboss.portal.theme.page.WindowContext;
066:        import org.jboss.portal.theme.page.WindowResult;
067:
068:        import java.util.Collections;
069:        import java.util.HashMap;
070:        import java.util.Map;
071:
072:        /**
073:         * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
074:         * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
075:         * @version $Revision: 9072 $
076:         */
077:        public class PageCustomizerInterceptor extends ControllerInterceptor {
078:
079:            /** . */
080:            private static Logger log = Logger
081:                    .getLogger(PageCustomizerInterceptor.class);
082:
083:            /** . */
084:            private static final PortalObjectId defaultPortalId = PortalObjectId
085:                    .parse("/", PortalObjectPath.CANONICAL_FORMAT);
086:
087:            /** . */
088:            private static PortalObjectId adminPortalId = PortalObjectId.parse(
089:                    "/admin", PortalObjectPath.CANONICAL_FORMAT);
090:
091:            /** . */
092:            private String targetContextPath;
093:
094:            /** . */
095:            private String headerPath;
096:
097:            /** . */
098:            private String tabsPath;
099:
100:            /** . */
101:            private String loginNamespace;
102:
103:            /** . */
104:            private ServerConfig config;
105:
106:            /** . */
107:            private PortalAuthorizationManagerFactory portalAuthorizationManagerFactory;
108:
109:            /** . */
110:            private PortalObjectContainer portalObjectContainer;
111:
112:            public PortalAuthorizationManagerFactory getPortalAuthorizationManagerFactory() {
113:                return portalAuthorizationManagerFactory;
114:            }
115:
116:            public void setPortalAuthorizationManagerFactory(
117:                    PortalAuthorizationManagerFactory portalAuthorizationManagerFactory) {
118:                this .portalAuthorizationManagerFactory = portalAuthorizationManagerFactory;
119:            }
120:
121:            public PortalObjectContainer getPortalObjectContainer() {
122:                return portalObjectContainer;
123:            }
124:
125:            public void setPortalObjectContainer(
126:                    PortalObjectContainer portalObjectContainer) {
127:                this .portalObjectContainer = portalObjectContainer;
128:            }
129:
130:            public ControllerResponse invoke(ControllerCommand cmd)
131:                    throws Exception {
132:                ControllerResponse resp = (ControllerResponse) cmd.invokeNext();
133:
134:                // Insert navigation portlet in the page
135:                if (resp instanceof  PageRendition) {
136:                    PageRendition rendition = (PageRendition) resp;
137:
138:                    //
139:                    if (cmd instanceof  PageCommand) {
140:                        PageCommand rpc = (PageCommand) cmd;
141:
142:                        //
143:                        String tabbedNav = injectTabbedNav(rpc);
144:                        if (tabbedNav != null) {
145:                            Map windowProps = new HashMap();
146:                            windowProps.put(
147:                                    ThemeConstants.PORTAL_PROP_WINDOW_RENDERER,
148:                                    "emptyRenderer");
149:                            windowProps
150:                                    .put(
151:                                            ThemeConstants.PORTAL_PROP_DECORATION_RENDERER,
152:                                            "emptyRenderer");
153:                            windowProps
154:                                    .put(
155:                                            ThemeConstants.PORTAL_PROP_PORTLET_RENDERER,
156:                                            "emptyRenderer");
157:                            WindowResult res = new WindowResult("", tabbedNav,
158:                                    Collections.EMPTY_MAP, windowProps, null,
159:                                    WindowState.NORMAL, Mode.VIEW);
160:                            WindowContext blah = new WindowContext("BLAH",
161:                                    "navigation", "0", res);
162:                            rendition.getPageResult().addWindowContext(blah);
163:
164:                            //
165:                            Region region = rendition.getPageResult()
166:                                    .getRegion2("navigation");
167:                            DynaRenderOptions.NO_AJAX.setOptions(region
168:                                    .getProperties());
169:                        }
170:                    }
171:
172:                    //
173:                    String dashboardNav = injectDashboardNav(cmd);
174:                    if (dashboardNav != null) {
175:                        Map windowProps = new HashMap();
176:                        windowProps.put(
177:                                ThemeConstants.PORTAL_PROP_WINDOW_RENDERER,
178:                                "emptyRenderer");
179:                        windowProps.put(
180:                                ThemeConstants.PORTAL_PROP_DECORATION_RENDERER,
181:                                "emptyRenderer");
182:                        windowProps.put(
183:                                ThemeConstants.PORTAL_PROP_PORTLET_RENDERER,
184:                                "emptyRenderer");
185:                        WindowResult res = new WindowResult("", dashboardNav,
186:                                Collections.EMPTY_MAP, windowProps, null,
187:                                WindowState.NORMAL, Mode.VIEW);
188:                        WindowContext bluh = new WindowContext("BLUH",
189:                                "dashboardnav", "0", res);
190:                        rendition.getPageResult().addWindowContext(bluh);
191:
192:                        //
193:                        Region region = rendition.getPageResult().getRegion2(
194:                                "dashboardnav");
195:                        DynaRenderOptions.NO_AJAX.setOptions(region
196:                                .getProperties());
197:                    }
198:                }
199:
200:                //
201:                return resp;
202:            }
203:
204:            public String injectDashboardNav(ControllerCommand cc) {
205:                ControllerContext controllerCtx = cc.getControllerContext();
206:                ControllerRequestDispatcher rd = controllerCtx
207:                        .getRequestDispatcher(targetContextPath, headerPath);
208:
209:                //
210:                if (rd != null) {
211:                    // Get user
212:                    Controller controller = controllerCtx.getController();
213:                    User user = controllerCtx.getUser();
214:                    rd.setAttribute("org.jboss.portal.header.USER", user);
215:
216:                    if (user == null) {
217:                        PortalURL portalURL = null;
218:
219:                        String configNamespace = config
220:                                .getProperty("core.login.namespace");
221:                        if (loginNamespace == null) {
222:                            loginNamespace = configNamespace;
223:                        }
224:
225:                        if (loginNamespace != null
226:                                && !loginNamespace.toLowerCase().trim().equals(
227:                                        "default")) {
228:                            ViewContextCommand vcc = new ViewContextCommand(
229:                                    new PortalObjectId(loginNamespace,
230:                                            new PortalObjectPath()));
231:                            portalURL = new PortalURLImpl(vcc, controllerCtx,
232:                                    Boolean.TRUE, null);
233:                        } else {
234:                            portalURL = new PortalURLImpl(cc, controllerCtx,
235:                                    Boolean.TRUE, null);
236:                        }
237:                        String securedLogin = config
238:                                .getProperty("core.login.secured");
239:                        if (securedLogin != null
240:                                && "true".equals(securedLogin.toLowerCase())) {
241:                            portalURL.setSecure(Boolean.TRUE);
242:                        }
243:                        rd.setAttribute("org.jboss.portal.header.LOGIN_URL",
244:                                portalURL);
245:                    }
246:
247:                    // Edit dashboard page || Copy to dashboard link
248:                    boolean isDashboard = false;
249:                    if (cc instanceof  RenderPageCommand) {
250:                        RenderPageCommand rpc = (RenderPageCommand) cc;
251:                        Page page = rpc.getPage();
252:                        String pageName = page.getName();
253:                        isDashboard = rpc.isDashboard();
254:
255:                        //
256:                        if (isDashboard) {
257:                            // Edit page
258:                            PortletParametersStateString navState = new PortletParametersStateString();
259:                            navState.setValue("editPageSelect", pageName);
260:                            InvokePortletInstanceRenderCommand command = new InvokePortletInstanceRenderCommand(
261:                                    "DashboardConfigPortletInstance", navState);
262:                            rd
263:                                    .setAttribute(
264:                                            "org.jboss.portal.header.EDIT_DASHBOARD_URL",
265:                                            new PortalURLImpl(command,
266:                                                    controllerCtx, null, null));
267:                        } else {
268:                            //
269:                            if (user != null) {
270:                                CustomizationManager cm = controller
271:                                        .getCustomizationManager();
272:                                Portal dashboard = cm.getDashboard(user);
273:                                if (dashboard.getChild(pageName) == null) {
274:                                    ImportPageToDashboardCommand iptdc = new ImportPageToDashboardCommand(
275:                                            page.getId());
276:                                    rd
277:                                            .setAttribute(
278:                                                    "org.jboss.portal.header.COPY_TO_DASHBOARD_URL",
279:                                                    new PortalURLImpl(iptdc,
280:                                                            controllerCtx,
281:                                                            null, null));
282:                                }
283:                            }
284:
285:                        }
286:                    }
287:
288:                    //
289:                    if (!isDashboard && user != null) {
290:                        Portal dashboard = controller.getCustomizationManager()
291:                                .getDashboard(user);
292:                        if (dashboard != null) {
293:                            ViewPortalCommand vdc = new ViewPortalCommand(
294:                                    dashboard.getId());
295:                            rd.setAttribute(
296:                                    "org.jboss.portal.header.DASHBOARD_URL",
297:                                    new PortalURLImpl(vdc, controllerCtx, null,
298:                                            null));
299:                        }
300:
301:                    }
302:
303:                    //
304:                    boolean admin = false;
305:                    if (cc instanceof  RenderPageCommand) {
306:                        RenderPageCommand rpc = (RenderPageCommand) cc;
307:                        PortalObject portalObject = rpc.getPage().getPortal();
308:                        admin = "admin"
309:                                .equalsIgnoreCase(portalObject.getName());
310:                    }
311:
312:                    //
313:                    if (!admin || isDashboard) {
314:                        PortalObjectPermission perm = new PortalObjectPermission(
315:                                adminPortalId, PortalObjectPermission.VIEW_MASK);
316:                        try {
317:                            if (controller
318:                                    .getPortalAuthorizationManagerFactory()
319:                                    .getManager().checkPermission(perm)) {
320:                                ViewPageCommand showadmin = new ViewPageCommand(
321:                                        adminPortalId);
322:                                rd
323:                                        .setAttribute(
324:                                                "org.jboss.portal.header.ADMIN_PORTAL_URL",
325:                                                new PortalURLImpl(showadmin,
326:                                                        controllerCtx, null,
327:                                                        null));
328:                            }
329:                        } catch (PortalSecurityException e) {
330:                            log.error("", e);
331:                        }
332:                    }
333:
334:                    //
335:                    if (admin || isDashboard
336:                            || cc instanceof  RenderPortletInstanceCommand) {
337:                        // Link to default page of default portal
338:                        // Cannot use defaultPortalId in 2.6.x because the default context doesn't have the view right.
339:                        // Upgrading from 2.6.1 to 2.6.2 would break.
340:                        ViewPageCommand vpc = new ViewPageCommand(
341:                                portalObjectContainer.getContext()
342:                                        .getDefaultPortal().getId());
343:                        rd.setAttribute(
344:                                "org.jboss.portal.header.DEFAULT_PORTAL_URL",
345:                                new PortalURLImpl(vpc, controllerCtx, null,
346:                                        null));
347:                    }
348:
349:                    //
350:                    SignOutCommand cmd = new SignOutCommand();
351:                    rd.setAttribute("org.jboss.portal.header.SIGN_OUT_URL",
352:                            new PortalURLImpl(cmd, controllerCtx,
353:                                    Boolean.FALSE, null));
354:
355:                    //
356:                    rd.include();
357:                    return rd.getMarkup();
358:                }
359:
360:                //
361:                return null;
362:            }
363:
364:            public String injectTabbedNav(PageCommand rpc) {
365:                ControllerContext controllerCtx = rpc.getControllerContext();
366:                ControllerRequestDispatcher rd = controllerCtx
367:                        .getRequestDispatcher(targetContextPath, tabsPath);
368:
369:                //
370:                if (rd != null) {
371:                    Page page = rpc.getPage();
372:                    PortalAuthorizationManager pam = portalAuthorizationManagerFactory
373:                            .getManager();
374:                    PortalNodeImpl node = new PortalNodeImpl(pam, page);
375:
376:                    //
377:                    rd.setAttribute("org.jboss.portal.api.PORTAL_NODE", node);
378:                    rd.setAttribute(
379:                            "org.jboss.portal.api.PORTAL_RUNTIME_CONTEXT",
380:                            Navigation.getPortalRuntimeContext());
381:
382:                    //
383:                    rd.include();
384:                    return rd.getMarkup();
385:                }
386:
387:                //
388:                return null;
389:            }
390:
391:            public String getHeaderPath() {
392:                return headerPath;
393:            }
394:
395:            public void setHeaderPath(String headerPath) {
396:                this .headerPath = headerPath;
397:            }
398:
399:            public String getTargetContextPath() {
400:                return targetContextPath;
401:            }
402:
403:            public void setTargetContextPath(String context) {
404:                targetContextPath = context;
405:            }
406:
407:            public String getTabsPath() {
408:                return tabsPath;
409:            }
410:
411:            public void setTabsPath(String tabsPath) {
412:                this .tabsPath = tabsPath;
413:            }
414:
415:            private static class PortalURLImpl implements  PortalURL {
416:
417:                /** . */
418:                private ControllerCommand command;
419:
420:                /** . */
421:                private ControllerContext context;
422:
423:                /** . */
424:                private Boolean wantAuthenticated;
425:
426:                /** . */
427:                private Boolean wantSecure;
428:
429:                /** . */
430:                private boolean relative;
431:
432:                /** . */
433:                private String value;
434:
435:                public PortalURLImpl(ControllerCommand command,
436:                        ControllerContext context, Boolean wantAuthenticated,
437:                        Boolean wantSecure) {
438:                    this .command = command;
439:                    this .context = context;
440:                    this .wantAuthenticated = wantAuthenticated;
441:                    this .wantSecure = wantSecure;
442:                    this .relative = false;
443:                    this .value = null;
444:                }
445:
446:                public void setAuthenticated(Boolean wantAuthenticated) {
447:                    this .wantAuthenticated = wantAuthenticated;
448:                    this .value = null;
449:                }
450:
451:                public void setSecure(Boolean wantSecure) {
452:                    this .wantSecure = wantSecure;
453:                    this .value = null;
454:                }
455:
456:                public void setRelative(boolean relative) {
457:                    this .relative = relative;
458:                    this .value = null;
459:                }
460:
461:                public String toString() {
462:                    if (value == null) {
463:                        URLContext urlContext = context.getServerInvocation()
464:                                .getServerContext().getURLContext();
465:                        urlContext = urlContext.withAuthenticated(
466:                                wantAuthenticated).withSecured(wantSecure);
467:                        value = context.renderURL(command, urlContext,
468:                                URLFormat.newInstance(relative, true));
469:                    }
470:                    return value;
471:                }
472:            }
473:
474:            public String getLoginNamespace() {
475:                return loginNamespace;
476:            }
477:
478:            public void setLoginNamespace(String loginNamespace) {
479:                this .loginNamespace = loginNamespace;
480:            }
481:
482:            public ServerConfig getConfig() {
483:                return config;
484:            }
485:
486:            public void setConfig(ServerConfig config) {
487:                this.config = config;
488:            }
489:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.