KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > web > util > ImagesHomeDisplayHelper


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 2.1 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. >
17  * http://www.gnu.org/copyleft/lesser.html >
18  * http://www.opensource.org/licenses/lgpl-license.php
19  */

20 package net.mlw.vlh.web.util;
21
22 import javax.servlet.jsp.PageContext JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /**
28  *
29  * The ImagesHomeDisplayHelper can be used by adding the folloing in the spring
30  * config file:
31  *
32  * <pre>
33  *
34  *
35  * &lt;bean id=&quot;myLook&quot; singleton=&quot;true&quot; class=&quot;net.mlw.vlh.web.ValueListConfigBean&quot;&gt;
36  * &lt;property name=&quot;displayHelper&quot;&gt;
37  * &lt;bean class=&quot;net.mlw.vlh.web.util.ImagesHomeDisplayHelper&quot; /&gt;
38  * &lt;/property&gt;
39  * ...
40  * &lt;/bean&gt;
41  *
42  *
43  * </pre>
44  *
45  * This ImagesHomeDisplayHelper simply takes the value of your key and replace
46  * any occurrences of the text <code>@IMAGES_HOME@</code> with <b>html </b> DisplayProvider's images home.
47  *
48  * @author Andrej Zachar
49  * @version $Revision: 1.3 $ $Date: 2005/05/23 17:44:55 $
50  */

51 public final class ImagesHomeDisplayHelper implements DisplayHelper
52 {
53     /**
54      * Logger for this class
55      */

56     private static final Log LOGGER = LogFactory
57             .getLog(ImagesHomeDisplayHelper.class);
58
59     /**
60      * Attribute key used in pageContext to store imagesHome dir. This usage
61      * will be 100% changed in the future!
62      *
63      * @TODO do not swallow this!
64      */

65     public static final String JavaDoc IMAGES_HOME_ATTRIBUTE_KEY = "VALUELIST_IMAGE_HOME_ATTRIBUTE_KEY";
66
67     /**
68      * @see net.mlw.vlh.web.util.DisplayHelper#help(javax.servlet.jsp.PageContext,
69      * java.lang.String)
70      */

71     public String JavaDoc help(PageContext JavaDoc pageContext, String JavaDoc key)
72     {
73         if (LOGGER.isDebugEnabled())
74         {
75             LOGGER.debug("Replacing images home '"
76                     + (String JavaDoc) pageContext
77                             .getAttribute(IMAGES_HOME_ATTRIBUTE_KEY)
78                     + "' in key '" + key + "'");
79         }
80
81         return key.replaceAll("@IMAGES_HOME@", (String JavaDoc) pageContext
82                 .getAttribute(IMAGES_HOME_ATTRIBUTE_KEY));
83     }
84 }
Popular Tags