You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ds...@apache.org on 2004/10/05 01:18:42 UTC

cvs commit: jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/link PopupLinkRenderer.java

dsolis      2004/10/04 16:18:42

  Added:       contrib/src/java/org/apache/tapestry/contrib/link
                        PopupLinkRenderer.java
  Log:
  Add PopupLinkRenderer to contrib.
  
  Revision  Changes    Path
  1.1                  jakarta-tapestry/contrib/src/java/org/apache/tapestry/contrib/link/PopupLinkRenderer.java
  
  Index: PopupLinkRenderer.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // Licensed 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.tapestry.contrib.link;
  
  import org.apache.tapestry.IRequestCycle;
  import org.apache.tapestry.engine.ILink;
  import org.apache.tapestry.link.DefaultLinkRenderer;
  
  /**
   *  This renderer emits javascript to launch the link in a window.
   *
   *  @author David Solis
   *  @since 3.0.1
   **/
  public class PopupLinkRenderer extends DefaultLinkRenderer
  {
  
  	private String _windowName;
  
  	private String _features;
  
  	public PopupLinkRenderer()
  	{
  	}
  
  	/**
  	 * Initializes the name and features for javascript window.open function.
  	 *
  	 * @param windowName the window name
  	 * @param features   the window features
  	 */
  	public PopupLinkRenderer(String windowName, String features)
  	{
  		_windowName = windowName;
  		_features = features;
  	}
  
  	/**
  	 * @see DefaultLinkRenderer#constructURL(org.apache.tapestry.engine.ILink, String, org.apache.tapestry.IRequestCycle)
  	 */
  	protected String constructURL(ILink link, String anchor, IRequestCycle cycle)
  	{
  		String url = link.getURL(anchor, true);
  		return "javascript: w = window.open(" + normalizeString(url) + ", " + normalizeString(getWindowName()) + ", " + normalizeString(getFeatures()) + "); w.focus();";
  	}
  
  	private String normalizeString(String str)
  	{
  		return str == null ? "''" : "'" + str + "'";
  	}
  
  	public String getWindowName()
  	{
  		return _windowName;
  	}
  
  	public void setWindowName(String windowName)
  	{
  		_windowName = windowName;
  	}
  
  	public String getFeatures()
  	{
  		return _features;
  	}
  
  	public void setFeatures(String features)
  	{
  		_features = features;
  	}
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org