001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Aug 3, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.ui.portlet;
018:
019: import javax.portlet.PortletMode;
020: import javax.portlet.PortletURL;
021: import javax.portlet.RenderResponse;
022: import javax.portlet.WindowState;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.pentaho.core.ui.IPentahoUrl;
027: import org.pentaho.core.ui.IPentahoUrlFactory;
028: import org.pentaho.messages.Messages;
029: import org.pentaho.ui.UIException;
030:
031: /**
032: * Factories up implementations of IPentahoUrl. In this case, the implementation
033: * is org.pentaho.ui.portlet.PortletUrl.
034: *
035: * Warning: do not hold on to instances of this class beyond the current request/response
036: * cycle. This class maintains a reference to the RenderResponse, which is only valid
037: * in the request/response cycle in which it was created.
038: *
039: * Note: this class uses two similarly named classes: PortletURL and PortletUrl.
040: * Don't let this confuse you as you read the code.
041: *
042: * @author James Dixon, mods by Steven Barkdull
043: *
044: */
045: public class PortletUrlFactory implements IPentahoUrlFactory {
046: private static final Log log = LogFactory
047: .getLog(PortletUrlFactory.class);
048:
049: private RenderResponse portletResponse;
050:
051: private WindowState state;
052:
053: private PortletMode mode;
054:
055: public PortletUrlFactory(RenderResponse portletResponse,
056: WindowState state, PortletMode mode) {
057: this .portletResponse = portletResponse;
058: this .state = state;
059: this .mode = mode;
060: }
061:
062: /**
063: * Get a URL builder that is appropriate for building action URLs.
064: *
065: * @throws UIException when one of the underlying PortletURL's set methods
066: * throw an exception. See docs for PortletURL:
067: * http://docs.jboss.org/jbportal/v2.0Final/javadoc/javax/portlet/PortletURL.html
068: */
069: public IPentahoUrl getActionUrlBuilder() {
070: PortletURL portletUrl = portletResponse.createActionURL();
071: try {
072: portletUrl.setPortletMode(mode);
073: portletUrl.setWindowState(state);
074: portletUrl.setSecure(false);
075: } catch (Exception e) {
076: String msg = Messages
077: .getString("PortletUrlFactory.ERROR_0000_GETACTIONURLBUILDER_FAILED") + mode; //$NON-NLS-1$
078: log.error(msg);
079: throw new UIException(msg, e);
080: }
081: return new PortletUrl(portletUrl);
082: }
083:
084: /**
085: * Get a URL builder that is appropriate for building render URLs.
086: *
087: * @throws UIException when one of the underlying PortletURL's set methods
088: * throw an exception. See docs for PortletURL:
089: * http://docs.jboss.org/jbportal/v2.0Final/javadoc/javax/portlet/PortletURL.html
090: */
091: public IPentahoUrl getDisplayUrlBuilder() {
092: PortletURL portletUrl = portletResponse.createRenderURL();
093: try {
094: portletUrl.setPortletMode(mode);
095: portletUrl.setWindowState(state);
096: portletUrl.setSecure(false);
097: } catch (Exception e) {
098: String msg = Messages
099: .getString("PortletUrlFactory.ERROR_0001_GETDISPLAYURLBUILDER_FAILED") + mode; //$NON-NLS-1$
100: log.error(msg);
101: throw new UIException(msg, e);
102: }
103: return new PortletUrl(portletUrl);
104: }
105: }
|