KickJava   Java API By Example, From Geeks To Geeks.

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


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/MetaTag.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/09/06 17:12:59 $
10
// $Revision: 1.38 $
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.Attribute;
30 import org.htmlparser.lexer.Page;
31 import org.htmlparser.nodes.TagNode;
32 import org.htmlparser.util.ParserException;
33
34 /**
35  * A Meta Tag
36  */

37 public class MetaTag
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[] {"META"};
45
46     /**
47      * Create a new meta tag.
48      */

49     public MetaTag ()
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     public String JavaDoc getHttpEquiv ()
63     {
64         return (getAttribute ("HTTP-EQUIV"));
65     }
66
67     public String JavaDoc getMetaContent ()
68     {
69         return (getAttribute ("CONTENT"));
70     }
71
72     public String JavaDoc getMetaTagName ()
73     {
74         return (getAttribute ("NAME"));
75     }
76
77     public void setHttpEquiv(String JavaDoc httpEquiv)
78     {
79         Attribute equiv;
80         equiv = getAttributeEx ("HTTP-EQUIV");
81         if (null != equiv)
82             equiv.setValue (httpEquiv);
83         else
84             getAttributesEx ().add (new Attribute ("HTTP-EQUIV", httpEquiv));
85     }
86
87     public void setMetaTagContents(String JavaDoc metaTagContents)
88     {
89         Attribute content;
90         content = getAttributeEx ("CONTENT");
91         if (null != content)
92             content.setValue (metaTagContents);
93         else
94             getAttributesEx ().add (new Attribute ("CONTENT", metaTagContents));
95     }
96
97     public void setMetaTagName(String JavaDoc metaTagName)
98     {
99         Attribute name;
100         name = getAttributeEx ("NAME");
101         if (null != name)
102             name.setValue (metaTagName);
103         else
104             getAttributesEx ().add (new Attribute ("NAME", metaTagName));
105     }
106     
107     /**
108      * Check for a charset directive, and if found, set the charset for the page.
109      */

110     public void doSemanticAction () throws ParserException
111     {
112         String JavaDoc httpEquiv;
113         String JavaDoc charset;
114
115         httpEquiv = getHttpEquiv ();
116         if ("Content-Type".equalsIgnoreCase (httpEquiv))
117         {
118             charset = Page.getCharset (getAttribute ("CONTENT"));
119             getPage ().setEncoding (charset);
120         }
121     }
122 }
123
Popular Tags