KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > scrape > ResultTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.scrape;
18
19 import java.util.*;
20 import java.io.*;
21 import java.net.*;
22 import javax.servlet.jsp.*;
23 import javax.servlet.jsp.tagext.*;
24
25 /**
26  * ResultTag - JSP tag <b>result</b> returns the result of the scrape uniquely
27  * identified by a scrapeid.
28  *
29  * <p>
30  * JSP Tag Lib Descriptor
31  * <p><pre>
32  * &lt;name&gt;result&lt;/name&gt;
33  * &lt;tagclass&gt;org.apache.taglibs.scrape.ResultTag&lt;/tagclass&gt;
34  * &lt;bodycontent&gt;empty&lt;/bodycontent&gt;
35  * &lt;info&gt;Get the HTML extracted by the scrape of a page&lt;/info&gt;
36  *
37  * &lt;attribute&gt;
38  * &lt;name&gt;scrape&lt;/name&gt;
39  * &lt;required&gt;true&lt;/required&gt;
40  * &lt;rtexprval&gt;false&lt;/rtexprval&gt;
41  * &lt;/attribute&gt;
42  * </pre></p></p>
43  *
44  * @author Rich Catlett
45  *
46  * @version 1.0
47  *
48  * @see PageData
49  *
50  */

51 public class ResultTag extends TagSupport {
52
53     // the unique id for this scrape
54
private String JavaDoc scrape;
55
56     /**
57      * implementation of method from the Tag interface that tells the JSP
58      * what to do upon encountering the end tag for this tag
59      *
60      * @throws JSPException thrown when error occurs in processing the body
61      * of this method
62      *
63      * @return EVAL_PAGE int telling the tag handler that the rest of the jsp
64      * page is to be evaluated
65      */

66   public final int doEndTag() throws JspException {
67
68       String JavaDoc result; // holds the result for the scrape named by scrape
69

70       // get the result attribute from pagescope matched to scrape
71
if((result = (String JavaDoc)pageContext.getAttribute(scrape)) != null)
72       {
73           try {
74           pageContext.getOut().write(result); // write out result
75
} catch(IOException e) {
76             pageContext.getServletContext().log("Scrape taglib: Result tag: " +
77                    e.toString() + " Couldn't perform the write");
78           }
79       } else {
80       // write out nothing if scrape id is not matched
81
try {
82           pageContext.getOut().write("");
83       } catch(IOException e) {
84             pageContext.getServletContext().log("Scrape taglib: Result tag: " +
85                    " Couldn't perform the write scrape does not exist. " +
86                    e.toString());
87           }
88       }
89       return EVAL_PAGE;
90   }
91
92     /**
93      * setter method for scrapeid
94      *
95      * @param scrapeid the unique id for this scrape
96      *
97      */

98   public final void setScrape(String JavaDoc scrapeid) {
99       scrape = scrapeid;
100   }
101
102 }
103
Popular Tags