KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tags > BaseHrefTag


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tags/BaseHrefTag.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:28 $
10
// $Revision: 1.39 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tags;
28
29 import org.htmlparser.lexer.Page;
30 import org.htmlparser.nodes.TagNode;
31 import org.htmlparser.util.ParserException;
32
33 /**
34  * BaseHrefTag represents an <Base> tag.
35  * It extends a basic tag by providing an accessor to the HREF attribute.
36  */

37 public class BaseHrefTag
38     extends
39         TagNode
40 {
41     /**
42      * The set of names handled by this tag.
43      */

44     private static final String JavaDoc[] mIds = new String JavaDoc[] {"BASE"};
45
46     /**
47      * Create a new base tag.
48      */

49     public BaseHrefTag ()
50     {
51     }
52
53     /**
54      * Return the set of names handled by this tag.
55      * @return The names to be matched that create tags of this type.
56      */

57     public String JavaDoc[] getIds ()
58     {
59         return (mIds);
60     }
61
62     /**
63      * Get the value of the HREF attribute, if any.
64      * @return The HREF value, with the last slash removed, if any.
65      */

66     public String JavaDoc getBaseUrl()
67     {
68         String JavaDoc base;
69
70         base = getAttribute ("HREF");
71         if (base != null && base.length() > 0)
72             base = base.trim ();
73         base = (null == base) ? "" : base;
74         
75         return (base);
76     }
77
78     public void setBaseUrl (String JavaDoc base)
79     {
80         setAttribute ("HREF", base);
81     }
82
83     /**
84      * Perform the meaning of this tag.
85      * This sets the base URL to use for the rest of the page.
86      */

87     public void doSemanticAction () throws ParserException
88     {
89         Page page;
90         
91         page = getPage ();
92         if (null != page)
93         {
94             page.setBaseUrl (getBaseUrl ());
95         }
96     }
97 }
98
Popular Tags