View Javadoc
1 package org.apache.turbine.util.template; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import javax.servlet.http.HttpServletResponse; 58 59 import org.apache.turbine.services.pull.ApplicationTool; 60 61 import org.apache.turbine.util.DynamicURI; 62 import org.apache.turbine.util.RunData; 63 import org.apache.turbine.util.ServerData; 64 65 /*** 66 * A customized version of the DynamicURI to be used in Templates. 67 * This is automatically inserted into the template context by the 68 * appropriate templating service so page authors can create links 69 * in templates. Here's an example of its Velocity/WebMacro use: 70 * 71 * <p><code> 72 * $link.setPage("index.wm").addPathInfo("hello","world") 73 * This would return: http://foo.com/Turbine/template/index.wm/hello/world 74 * </code> 75 * 76 * @author <a href="mbryson@mont.mindspring.com">Dave Bryson</a> 77 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> 78 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 79 * @version $Id: TemplateLink.java,v 1.1.1.1 2001/08/16 05:10:01 jvanzyl Exp $ 80 */ 81 public class TemplateLink 82 extends DynamicURI 83 implements ApplicationTool 84 { 85 /*** the pathinfo key stored in the DynamicURI */ 86 private static final String TEMPLATE_KEY = "template"; 87 /*** cache of the template name for getPage() */ 88 private String template = null; 89 90 /*** 91 * Default constructor 92 * <p> 93 * The init method must be called before use. 94 */ 95 public TemplateLink() 96 { 97 } 98 99 /*** 100 * Constructor. 101 * 102 * @param data a Turbine RunData object. 103 */ 104 public TemplateLink(RunData data) 105 { 106 super(data); 107 } 108 109 /*** 110 * Constructor. 111 * 112 * @param data a Turbine ServerData object. 113 */ 114 public TemplateLink(ServerData data) 115 { 116 super(data); 117 } 118 119 /*** 120 * This will initialise a TemplateLink object that was 121 * constructed with the default constructor (ApplicationTool 122 * method). 123 * 124 * @param data assumed to be a RunData object 125 */ 126 public void init(Object data) 127 { 128 // we just blithely cast to RunData as if another object 129 // or null is passed in we'll throw an appropriate runtime 130 // exception. 131 super.init((RunData)data); 132 } 133 134 /*** 135 * Refresh method - does nothing 136 */ 137 public void refresh() 138 { 139 // empty 140 } 141 142 /*** 143 * This will turn off the execution of res.encodeURL() 144 * by making res == null. This is a hack for cases 145 * where you don't want to see the session information 146 */ 147 public TemplateLink setEncodeURLOff() 148 { 149 this.res = null; 150 return this; 151 } 152 153 /*** 154 * Sets the template variable used by the Template Service. 155 * 156 * @param t A String with the template name. 157 * @return A TemplateLink. 158 */ 159 public TemplateLink setPage(String t) 160 { 161 template = t; 162 addPathInfo(TEMPLATE_KEY,t); 163 return this; 164 } 165 166 /*** 167 * Gets the template variable used by the Template Service. 168 * It is only available after setPage() has been called. 169 * 170 * @return The template name. 171 */ 172 public String getPage() 173 { 174 return template; 175 } 176 177 /*** 178 * Returns the URI. After rendering the URI, it clears the 179 * pathInfo and QueryString portions of the DynamicURI. 180 * 181 * @return A String with the URI in the form 182 * http://foo.com/Turbine/template/index.wm/hello/world 183 */ 184 public String toString() 185 { 186 String output = super.toString(); 187 188 // This was added to allow multilple $link variables in one 189 // template. 190 removePathInfo(); 191 removeQueryData(); 192 193 return output; 194 } 195 196 /*** 197 * Returns the URI leaving the source intact. Wraps directly to the 198 * <code>DynamicURI.toString</code> method of the superclass 199 * (avoiding the local toString implementation). 200 * 201 * @return A String with the URI in the form 202 * http://foo.com/Turbine/template/index.wm/hello/world 203 */ 204 public String getURI() 205 { 206 return super.toString(); 207 } 208 }

This page was automatically generated by Maven