KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.*;
21 import javax.servlet.jsp.tagext.*;
22
23 /**
24  * UrlTag - JSP tag <b>url</b> is used for dynamically setting the url of the
25  * page that is going to be scraped by the tag library it is necessary
26  * the tag be nested within a <b>page</b> tag.
27  *
28  * <p>
29  * JSP Tag Lib Descriptor
30  * <p><pre>
31  * &lt;name&gt;url&lt;/name&gt;
32  * &lt;tagclass&gt;org.apache.taglibs.scrape.UrlTag&lt;/tagclass&gt;
33  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
34  * &lt;info&gt;
35  * Does the scraping of the page named in the parent page tag
36  * &lt;/info&gt;
37  * </pre></p></p>
38  *
39  * @author Rich Catlett
40  *
41  * @version 1.0
42  *
43  * @see ScrapeData
44  *
45  */

46 public class UrlTag extends BodyTagSupport {
47
48
49     /**
50      * implementation of the method from the tag interface that tells the JSP
51      * page what to do after the body of this tag
52      *
53      * @throws JSPException thrown when an error occurs while processing the
54      * body of this method
55      *
56      * @return SKIP_BODY int telling the tag handler to not evaluate the body
57      * of this tag again
58      *
59      */

60     public final int doAfterBody() throws JspException {
61
62     // parent tag must be a PageTag, gives access to methods in parent
63
PageTag myparent = (PageTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, PageTag.class);
64         String JavaDoc url; // the url for the page to be scraped
65

66     if (myparent == null)
67         throw new JspException("url tag not nested within page tag");
68         else {
69         if ((url = bodyContent.getString()) != null) {
70         myparent.setUrl(url); // set the url in the parent tag
71
myparent.getPage(); // get the pagedata object for this scrape
72
} else
73         throw new JspException("Url for the page to be scraped was not "
74                        + "provided");
75     }
76     return SKIP_BODY;
77     }
78 }
79
Popular Tags