Source code: org/htmlparser/scanners/BulletScanner.java
1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/scanners/BulletScanner.java,v 1.2 2004/02/10 13:41:09 woolfel 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 package org.htmlparser.scanners;
34
35 import java.util.Stack;
36
37 import org.htmlparser.tags.Bullet;
38 import org.htmlparser.tags.Tag;
39 import org.htmlparser.tags.data.CompositeTagData;
40 import org.htmlparser.tags.data.TagData;
41 import org.htmlparser.util.ParserException;
42
43 /**
44 * This scanner is created by BulletListScanner. It shares a stack to maintain the parent-child relationship
45 * with BulletListScanner. The rules implemented are :<br>
46 * [1] A <ul> can have <li> under it<br>
47 * [2] A <li> can have <ul> under it<br>
48 * [3] A <li> cannot have <li> under it<br>
49 * <p>
50 * These rules are implemented easily through the shared stack.
51 */
52 public class BulletScanner extends CompositeTagScanner
53 {
54 private static final String[] MATCH_STRING = { "LI" };
55 private final static String ENDERS[] = { "BODY", "HTML" };
56 private final static String END_TAG_ENDERS[] = { "UL" };
57 private Stack ulli;
58
59 public BulletScanner(Stack ulli)
60 {
61 this("", ulli);
62 }
63
64 public BulletScanner(String filter, Stack ulli)
65 {
66 super(filter, MATCH_STRING, ENDERS, END_TAG_ENDERS, false);
67 this.ulli = ulli;
68 }
69
70 public Tag createTag(TagData tagData, CompositeTagData compositeTagData)
71 throws ParserException
72 {
73 return new Bullet(tagData, compositeTagData);
74 }
75
76 public String[] getID()
77 {
78 return MATCH_STRING;
79 }
80
81 /**
82 * This is the logic that decides when a bullet tag can be allowed
83 */
84 public boolean shouldCreateEndTagAndExit()
85 {
86 if (ulli.size() == 0)
87 return false;
88 CompositeTagScanner parentScanner = (CompositeTagScanner) ulli.peek();
89 if (parentScanner == this)
90 {
91 ulli.pop();
92 return true;
93 }
94 else
95 return false;
96 }
97
98 public void beforeScanningStarts()
99 {
100 ulli.push(this);
101 }
102
103 }