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.controller.ajax;
023:
024: import org.jboss.portal.common.invocation.InvocationException;
025: import org.jboss.portal.core.controller.ControllerCommand;
026: import org.jboss.portal.core.controller.ControllerContext;
027: import org.jboss.portal.core.controller.ControllerInterceptor;
028: import org.jboss.portal.core.controller.ControllerResponse;
029: import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
030: import org.jboss.portal.core.theme.PageRendition;
031: import org.jboss.portal.server.AbstractServerURL;
032: import org.jboss.portal.server.ServerInvocationContext;
033: import org.jboss.portal.server.ServerURL;
034: import org.jboss.portal.server.request.URLFormat;
035: import org.jboss.portal.theme.impl.render.dynamic.DynaConstants;
036:
037: import java.util.Map;
038:
039: /**
040: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
041: * @author Luca Stancapiano
042: * @version $Revision: 8895 $
043: */
044: public class AjaxInterceptor extends ControllerInterceptor {
045: /**
046: * Luca Stancapiano - 29 - 09 -2007
047: * targetContextPath is used to assign a context path when
048: * default portal-ajax path cannot to be used or if it is changed through context-root property into jboss-web.xml
049: * */
050: private String targetContextPath = "/portal-ajax";
051:
052: public ControllerResponse invoke(ControllerCommand cmd)
053: throws Exception, InvocationException {
054: ControllerResponse response = (ControllerResponse) cmd
055: .invokeNext();
056:
057: // Configure ajax if needed
058: if (response instanceof PageRendition) {
059: ServerInvocationContext serverContext = cmd
060: .getControllerContext().getServerInvocation()
061: .getServerContext();
062:
063: //
064: ControllerContext controllerContext = cmd
065: .getControllerContext();
066:
067: //
068: PageRendition rendition = (PageRendition) response;
069: Map pageProps = rendition.getPageResult().getProperties();
070:
071: //
072: PortalObjectNavigationalStateContext ctx = (PortalObjectNavigationalStateContext) controllerContext
073: .getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
074: String viewId = ctx.getViewId();
075:
076: //
077: ServerURL baseServerURL = new AbstractServerURL();
078: baseServerURL.setPortalRequestPath("/");
079: String url = serverContext.renderURL(baseServerURL,
080: serverContext.getURLContext(), URLFormat
081: .newInstance(true, true));
082:
083: //
084: pageProps.put(DynaConstants.RESOURCE_BASE_URL,
085: targetContextPath + "/dyna");
086: pageProps.put(DynaConstants.SERVER_BASE_URL, url);
087: pageProps.put(DynaConstants.VIEW_STATE, viewId);
088:
089: // If user is logged in and is on dashboard we enable ajax
090: // if (cmd instanceof RenderPageCommand)
091: // {
092: // RenderPageCommand rpc = (RenderPageCommand)cmd;
093: // if (serverContext.getClientRequest().getRemoteUser() != null && rpc.isDashboard())
094: // {
095: // DynaRenderOptions.AJAX.setOptions(pageProps);
096: // }
097: // }
098: }
099:
100: //
101: return response;
102: }
103:
104: public String getTargetContextPath() {
105: return targetContextPath;
106: }
107:
108: public void setTargetContextPath(String context) {
109: targetContextPath = context;
110: }
111: }
|