KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > StaticLink


1 package org.tigris.scarab.util;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 // Turbine
50
import org.apache.turbine.RunData;
51 import org.apache.turbine.services.pull.ApplicationTool;
52 import org.apache.fulcrum.pool.InitableRecyclable;
53
54
55 /**
56  * A pull tool to render links to static content.
57  *
58  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
59  * @version $Id: StaticLink.java 3461 2002-02-13 05:18:24Z jmcnally $
60  */

61 public class StaticLink
62     implements InitableRecyclable, ApplicationTool
63 {
64     private RunData data;
65     private String JavaDoc path;
66
67     /**
68      * Constructor.
69      */

70     public StaticLink()
71     {
72     }
73
74     /**
75      * This will initialise a StaticLink object that was
76      * constructed with the default constructor (ApplicationTool
77      * method).
78      *
79      * @param data assumed to be a RunData object
80      */

81     public void init(Object JavaDoc data)
82     {
83         // we just blithely cast to RunData as if another object
84
// or null is passed in we'll throw an appropriate runtime
85
// exception.
86
this.data = (RunData)data;
87     }
88
89     /**
90      * Implementation of ApplicationTool interface.
91      *
92      */

93     public void refresh()
94     {
95         path = null;
96     }
97
98     /**
99      * Path to a file. The path will be relative to the directory returned
100      * by getPrefix().
101      *
102      * @param t A String with the file name.
103      * @return A StaticLink.
104      */

105     public StaticLink setPath(String JavaDoc t)
106     {
107         path = t;
108         return this;
109     }
110      
111     /**
112      * Prints out the url.
113      *
114      * @return a <code>String</code> url
115      */

116     public String JavaDoc toString()
117     {
118         String JavaDoc prefix = getPrefix();
119         return new StringBuffer JavaDoc(prefix.length()+path.length())
120             .append(prefix).append(path).toString();
121     }
122
123     /**
124      * Prefix that will be added to the path given in setPage.
125      * This implementation returns the context path.
126      *
127      * @return a <code>String</code> value
128      */

129     protected String JavaDoc getPrefix()
130     {
131         return data.getRequest().getContextPath();
132     }
133
134     /**
135      * Give subclasses access to the RunData, so they do not have to
136      * reimplement the pooling code, just to get at it.
137      */

138     protected RunData getRunData()
139     {
140         return data;
141     }
142
143     // ****************************************************************
144
// ****************************************************************
145
// Implementation of Recyclable
146
// ****************************************************************
147
// ****************************************************************
148

149     private boolean disposed = false;
150
151     /**
152      * Recycles the object by removing its disposed flag.
153      */

154     public void recycle()
155     {
156         disposed = false;
157     }
158
159     /**
160      * Disposes the object by setting its disposed flag.
161      */

162     public void dispose()
163     {
164         data = null;
165         refresh();
166         disposed = true;
167     }
168
169     /**
170      * Checks whether the object is disposed.
171      *
172      * @return true, if the object is disposed.
173      */

174     public boolean isDisposed()
175     {
176         return disposed;
177     }
178 }
179
Popular Tags