KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > scannersTests > JspScannerTest


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/tests/scannersTests/JspScannerTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/09/02 02:28:07 $
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.tests.scannersTests;
28
29 import org.htmlparser.PrototypicalNodeFactory;
30 import org.htmlparser.tags.JspTag;
31 import org.htmlparser.tests.ParserTestCase;
32 import org.htmlparser.util.ParserException;
33
34 public class JspScannerTest extends ParserTestCase {
35
36     static
37     {
38         System.setProperty ("org.htmlparser.tests.scannersTests.JspScannerTest", "JspScannerTest");
39     }
40
41     private static final boolean JSP_TESTS_ENABLED = false;
42
43     public JspScannerTest(String JavaDoc name) {
44         super(name);
45     }
46
47     /**
48      * In response to bug report 621117, wherein jsp tags
49      * are not recognized if they occur within string nodes.
50      */

51     public void testScan() throws ParserException {
52         createParser(
53         "<h1>\n"+
54         "This is a <%=object%>\n"+
55         "</h1>");
56
57         parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ()));
58         parseAndAssertNodeCount(5);
59         // The first node should be an JspTag
60
assertTrue("Third should be an JspTag",node[2] instanceof JspTag);
61         JspTag tag = (JspTag)node[2];
62         assertEquals("tag contents","%=object%",tag.getText());
63     }
64
65     /**
66      * Testcase submitted by Johan Naudts, demonstrating bug
67      * 717573, <b>NullPointerException when unclosed HTML tag
68      * inside JSP tag</b>
69      * @throws ParserException
70      */

71     public void testUnclosedTagInsideJsp() throws ParserException {
72         if (JSP_TESTS_ENABLED)
73         {
74             createParser(
75                 "<%\n" +
76                 "public String getHref(String value) \n" +
77                 "{ \n" +
78                 "int indexs = value.indexOf(\"<A HREF=\");\n" +
79                 "int indexe = value.indexOf(\">\");\n" +
80                 "if (indexs != -1) {\n" +
81                 "return value.substring(indexs+9,indexe-2);\n" +
82                 "}\n" +
83                 "return value;\n" +
84                 "}\n" +
85                 "%>");
86             parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ()));
87             parseAndAssertNodeCount(1);
88         }
89     }
90 }
91
Popular Tags