BaseHrefTag.java
1 // HTMLParser Library $Name: v1_6_20060319 $ - 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: 2005/04/10 23:20:45 $ 10 // $Revision: 1.40 $ 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[] mIds = new String[] {"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[] getIds () 58 { 59 return (mIds); 60 } 61 62 /** 63 * Get the value of the <code>HREF</code> attribute, if any. 64 * @return The <code>HREF</code> value, with the leading and trailing whitespace removed, if any. 65 */ 66 public String getBaseUrl() 67 { 68 String 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 /** 79 * Set the value of the <code>HREF</code> attribute. 80 * @param base The new <code>HREF</code> value. 81 */ 82 public void setBaseUrl (String base) 83 { 84 setAttribute ("HREF", base); 85 } 86 87 /** 88 * Perform the meaning of this tag. 89 * This sets the base URL to use for the rest of the page. 90 * @exception ParserException If setting the base URL fails. 91 */ 92 public void doSemanticAction () throws ParserException 93 { 94 Page page; 95 96 page = getPage (); 97 if (null != page) 98 page.setBaseUrl (getBaseUrl ()); 99 } 100 }