KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > StringNode


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/StringNode.java,v 1.2.2.1 2004/10/24 01:22:59 sebb Exp $
2
/*
3  * ====================================================================
4  * Copyright 2002-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */

19
20 // The developers of JMeter and Apache are greatful to the developers
21
// of HTMLParser for giving Apache Software Foundation a non-exclusive
22
// license. The performance benefits of HTMLParser are clear and the
23
// users of JMeter will benefit from the hard work the HTMLParser
24
// team. For detailed information about HTMLParser, the project is
25
// hosted on sourceforge at http://htmlparser.sourceforge.net/.
26
//
27
// HTMLParser was originally created by Somik Raha in 2000. Since then
28
// a healthy community of users has formed and helped refine the
29
// design so that it is able to tackle the difficult task of parsing
30
// dirty HTML. Derrick Oswald is the current lead developer and was kind
31
// enough to assist JMeter.
32

33
34 package org.htmlparser;
35
36 import org.htmlparser.util.NodeList;
37 import org.htmlparser.visitors.NodeVisitor;
38
39 /**
40  * Normal text in the html document is identified and represented by this class.
41  */

42 public class StringNode extends Node
43 {
44     public static final String JavaDoc STRING_FILTER = "-string";
45     /**
46      * The text of the string.
47      */

48     protected StringBuffer JavaDoc textBuffer;
49
50     /**
51      * Constructor takes in the text string, beginning and ending posns.
52      * @param text The contents of the string line
53      * @param textBegin The beginning position of the string
54      * @param textEnd The ending positiong of the string
55      */

56     public StringNode(StringBuffer JavaDoc textBuffer, int textBegin, int textEnd)
57     {
58         super(textBegin, textEnd);
59         this.textBuffer = textBuffer;
60
61     }
62
63     /**
64      * Returns the text of the string line
65      */

66     public String JavaDoc getText()
67     {
68         return textBuffer.toString();
69     }
70     /**
71      * Sets the string contents of the node.
72      * @param The new text for the node.
73      */

74     public void setText(String JavaDoc text)
75     {
76         textBuffer = new StringBuffer JavaDoc(text);
77     }
78     public String JavaDoc toPlainTextString()
79     {
80         return textBuffer.toString();
81     }
82     public String JavaDoc toHtml()
83     {
84         return textBuffer.toString();
85     }
86     public String JavaDoc toString()
87     {
88         return "Text = "
89             + getText()
90             + "; begins at : "
91             + elementBegin()
92             + "; ends at : "
93             + elementEnd();
94     }
95     public void collectInto(NodeList collectionList, String JavaDoc filter)
96     {
97         if (filter.equals(STRING_FILTER))
98             collectionList.add(this);
99     }
100
101     public void accept(NodeVisitor visitor)
102     {
103         visitor.visitStringNode(this);
104     }
105
106 }
107
Popular Tags