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.node;
023:
024: import org.jboss.portal.common.invocation.InvocationException;
025: import org.jboss.portal.core.controller.ControllerCommand;
026: import org.jboss.portal.core.controller.ControllerInterceptor;
027: import org.jboss.portal.core.controller.ControllerResponse;
028: import org.jboss.portal.core.impl.api.PortalRuntimeContextImpl;
029: import org.jboss.portal.core.impl.api.node.PortalNodeImpl;
030: import org.jboss.portal.core.model.portal.Page;
031: import org.jboss.portal.core.model.portal.Window;
032: import org.jboss.portal.core.model.portal.command.WindowCommand;
033: import org.jboss.portal.core.model.portal.command.render.RenderPageCommand;
034: import org.jboss.portal.security.spi.auth.PortalAuthorizationManager;
035: import org.jboss.portal.security.spi.auth.PortalAuthorizationManagerFactory;
036:
037: /**
038: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
039: * @version $Revision: 8786 $
040: */
041: public class PortalNodeInterceptor extends ControllerInterceptor {
042:
043: /** . */
044: private PortalAuthorizationManagerFactory portalAuthorizationManagerFactory;
045:
046: public PortalAuthorizationManagerFactory getPortalAuthorizationManagerFactory() {
047: return portalAuthorizationManagerFactory;
048: }
049:
050: public void setPortalAuthorizationManagerFactory(
051: PortalAuthorizationManagerFactory portalAuthorizationManagerFactory) {
052: this .portalAuthorizationManagerFactory = portalAuthorizationManagerFactory;
053: }
054:
055: public ControllerResponse invoke(ControllerCommand cmd)
056: throws Exception, InvocationException {
057: // Get the next node
058: PortalNodeImpl next = getNode(cmd);
059:
060: // Save previous node temporarily
061: PortalNodeImpl previous = Navigation.getCurrentNode();
062:
063: // Whether or not we inherit from an existing factory
064: boolean noFactory = Navigation.getPortalRuntimeContext() == null;
065:
066: try {
067: // Set next node
068: Navigation.setCurrentNode(next);
069:
070: //
071: if (noFactory) {
072: Navigation
073: .setPortalRuntimeContext(new PortalRuntimeContextImpl(
074: cmd.getControllerContext()));
075: }
076:
077: // Invoke
078: return (ControllerResponse) cmd.invokeNext();
079: } finally {
080: // Set previous node back
081: Navigation.setCurrentNode(previous);
082:
083: //
084: if (noFactory) {
085: Navigation.setPortalRuntimeContext(null);
086: }
087: }
088: }
089:
090: private PortalNodeImpl getNode(ControllerCommand cmd) {
091: PortalAuthorizationManager pam = portalAuthorizationManagerFactory
092: .getManager();
093: PortalNodeImpl next = null;
094:
095: //
096: if (cmd instanceof WindowCommand) {
097: WindowCommand windowCmd = (WindowCommand) cmd;
098: Window window = windowCmd.getWindow();
099: next = new PortalNodeImpl(pam, window);
100: } else if (cmd instanceof RenderPageCommand) {
101: RenderPageCommand rpCmd = (RenderPageCommand) cmd;
102: Page page = rpCmd.getPage();
103: next = new PortalNodeImpl(pam, page);
104: }
105:
106: //
107: return next;
108: }
109: }
|