KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > thauvin > google > taglibs > CachedPage


1 /*
2  * @(#)CachedPage.java
3  *
4  * Copyright (c) 2002-2003, Erik C. Thauvin (erik@thauvin.net)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the author nor the names of its contributors may be
19  * used to endorse or promote products derived from this software without
20  * specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id: CachedPage.java,v 1.2 2003/10/01 20:29:51 ethauvin Exp $
35  *
36  */

37 package net.thauvin.google.taglibs;
38
39 import net.thauvin.google.GoogleSearchBean;
40 import net.thauvin.google.TagUtility;
41
42 import javax.servlet.jsp.*;
43
44
45 /**
46  * A custom tag used to access and retrieve pages cached on Google.
47  *
48  * @author Erik C. Thauvin
49  * @created April 25, 2002
50  * @version $Revision: 1.2 $
51  * @since 1.0
52  */

53 public class CachedPage extends QuerySupport
54 {
55     /**
56      * doEndTag method.
57      *
58      * @return EVAL_PAGE
59      * @exception JspException
60      */

61     public int doEndTag()
62                  throws JspException
63     {
64         final String JavaDoc query = getQuery();
65
66         if (TagUtility.isValidString(query, true))
67         {
68             try
69             {
70                 final GoogleSearchBean bean = new GoogleSearchBean(getKey());
71
72                 bean.setProxyServer(pageContext.getServletContext()
73                                                .getInitParameter(TagUtility.GOOGLE_PROXY_HOST),
74                                     pageContext.getServletContext()
75                                                .getInitParameter(TagUtility.GOOGLE_PROXY_PORT),
76                                     pageContext.getServletContext()
77                                                .getInitParameter(TagUtility.GOOGLE_PROXY_USERNAME),
78                                     pageContext.getServletContext()
79                                                .getInitParameter(TagUtility.GOOGLE_PROXY_PASSWORD));
80
81                 // Output the body
82
pageContext.getOut().write(bean.getCachedPage(query));
83             }
84             catch (Exception JavaDoc e)
85             {
86                 throw TagUtility.outputError("cachedPage", e);
87             }
88         }
89
90         // Reset the values
91
reset();
92
93         return EVAL_PAGE;
94     }
95
96     /**
97      * Release method.
98      */

99     public void release()
100     {
101         super.release();
102
103         // Reset the values
104
reset();
105     }
106
107     /**
108      * Reset the values.
109      */

110     protected void reset()
111     {
112         super.reset();
113     }
114 }
115
Popular Tags