You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2007/03/03 04:29:35 UTC
svn commit: r514061 - in /portals/pluto/trunk:
pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld
Author: esm
Date: Fri Mar 2 19:29:35 2007
New Revision: 514061
URL: http://svn.apache.org/viewvc?view=rev&rev=514061
Log:
[PLUTO-318]: Adding PortletWindowStateAnchorTag
Added:
portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java (with props)
Modified:
portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld
Added: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java?view=auto&rev=514061
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java (added)
+++ portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java Fri Mar 2 19:29:35 2007
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.driver.tags;
+
+import java.io.IOException;
+
+import javax.portlet.WindowState;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.driver.AttributeKeys;
+import org.apache.pluto.driver.config.DriverConfiguration;
+import org.apache.pluto.driver.core.PortalRequestContext;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
+
+/**
+ * The tag is used to render a portlet mode anchor specified by the portlet ID and mode.
+ * This is designed to live inside of a <pluto:portlet/> tag.
+ *
+ * <pluto:windowStateAnchor portletId="" windowState="maximized"/>
+ *
+ * @author <a href="mailto:esm@apache.org">Elliot Metsger</a>
+ */
+public class PortletWindowStateAnchorTag extends BodyTagSupport {
+
+ /** Logger. */
+ private static final Log LOG = LogFactory.getLog(PortletWindowStateAnchorTag.class);
+
+
+ // Private Member Variables ------------------------------------------------
+ private String state = null;
+
+ /** The portlet ID attribute obtained from parent tag. */
+ private String portletId = null;
+
+ /** The evaluated value of the portlet ID attribute. */
+ private String evaluatedPortletId = null;
+
+ // BodyTagSupport Impl -----------------------------------------------------
+
+ /**
+ * Method invoked when the start tag is encountered.
+ * @throws JspException if an error occurs.
+ */
+ public int doStartTag() throws JspException {
+
+ // Ensure that the modeAnchor tag resides within a portlet tag.
+ PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(
+ this, PortletTag.class);
+ if (parentTag == null) {
+ throw new JspException("Portlet window controls may only reside "
+ + "within a pluto:portlet tag.");
+ }
+
+ portletId = parentTag.getPortletId();
+ // Evaluate portlet ID attribute.
+ evaluatePortletId();
+
+ // Retrieve the portlet window config for the evaluated portlet ID.
+ ServletContext servletContext = pageContext.getServletContext();
+ DriverConfiguration driverConfig = (DriverConfiguration)
+ servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG);
+
+ if (isWindowStateAllowed(driverConfig, state)) {
+ // Retrieve the portal environment.
+ PortalRequestContext portalEnv = PortalRequestContext.getContext(
+ (HttpServletRequest) pageContext.getRequest());
+
+ PortalURL portalUrl = portalEnv.createPortalURL();
+ portalUrl.setWindowState(evaluatedPortletId, new WindowState(state));
+
+ // Build a string buffer containing the anchor tag
+ StringBuffer tag = new StringBuffer();
+ tag.append("<a class=\"" + ToolTips.CSS_CLASS_NAME + "\" href=\"" + portalUrl.toString() + "\">");
+ tag.append("<span class=\"" + state + "\"></span>");
+ tag.append("<span class=\"" + ToolTips.CSS_CLASS_NAME + "\">");
+ tag.append(ToolTips.forWindowState(new WindowState(state)));
+ tag.append("</span></a>");
+
+ // Print the mode anchor tag.
+ try {
+ JspWriter out = pageContext.getOut();
+ out.print(tag.toString());
+ } catch (IOException ex) {
+ throw new JspException(ex);
+ }
+ }
+
+
+ // Continue to evaluate the tag body.
+ return EVAL_BODY_INCLUDE;
+ }
+
+
+ // Package Methods ---------------------------------------------------------
+
+ /**
+ * Returns the evaluated portlet ID.
+ * @return the evaluated portlet ID.
+ */
+ String getEvaluatedPortletId() {
+ return evaluatedPortletId;
+ }
+
+
+
+ // Private Methods ---------------------------------------------------------
+
+ /**
+ * Evaluates the portlet ID attribute passed into this tag. This method
+ * evaluates the member variable <code>portletId</code> and saves the
+ * evaluated result to <code>evaluatedPortletId</code>
+ * @throws JspException if an error occurs.
+ */
+ private void evaluatePortletId() throws JspException {
+ Object obj = ExpressionEvaluatorManager.evaluate(
+ "portletId", portletId, String.class, this, pageContext);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Evaluated portletId to: " + obj);
+ }
+ evaluatedPortletId = (String) obj;
+ }
+
+ /**
+ * @return the portletMode
+ */
+ public String getWindowState() {
+ return state;
+ }
+
+ /**
+ * @param portletMode the portletMode to set
+ */
+ public void setWindowState(String state) {
+ this.state = state;
+ }
+
+ private boolean isWindowStateAllowed(DriverConfiguration config, String state) {
+ LOG.debug("Testing if PortletWindowConfig [" + getEvaluatedPortletId() + "] supports window state [" + state + "]");
+ return config.isWindowStateSupported(getEvaluatedPortletId(), state);
+ }
+
+
+}
\ No newline at end of file
Propchange: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/pluto/trunk/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld?view=diff&rev=514061&r1=514060&r2=514061
==============================================================================
--- portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld (original)
+++ portals/pluto/trunk/pluto-portal/src/main/webapp/WEB-INF/tld/pluto.tld Fri Mar 2 19:29:35 2007
@@ -51,6 +51,17 @@
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
+
+ <tag>
+ <name>windowStateAnchor</name>
+ <tagclass>org.apache.pluto.driver.tags.PortletWindowStateAnchorTag</tagclass>
+ <bodycontent>empty</bodycontent>
+ <attribute>
+ <name>windowState</name>
+ <required>true</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ </tag>
<tag>
<name>title</name>