KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > BenchmarkP


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/BenchmarkP.java,v 1.3 2004/02/18 22:49:56 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 package org.htmlparser.tests;
21
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24
25 import org.htmlparser.*;
26 import org.htmlparser.scanners.*;
27 import org.htmlparser.tags.*;
28 import org.htmlparser.util.*;
29
30
31 /**
32  * Title: Apache Jakarta JMeter<br>
33  * Copyright: Copyright (c) Apache<br>
34  * Company: Apache<br>
35  * License:<br>
36  * <br>
37  * The license is at the top!<br>
38  * <br>
39  * Description:<br>
40  * <br>
41  * <p>
42  * Author: pete<br>
43  * Version: 0.1<br>
44  * Created on: Sep 30, 2003<br>
45  * Last Modified: 4:45:28 PM<br>
46  */

47
48 public class BenchmarkP
49 {
50
51     /**
52      *
53      */

54     public BenchmarkP()
55     {
56         super();
57     }
58
59     public static void main(String JavaDoc[] args)
60     {
61         if (args != null && args.length > 0)
62         {
63             String JavaDoc strurl = args[0];
64             boolean addLink = true;
65             if (args.length == 2)
66             {
67                 if (args[1].equals("f"))
68                 {
69                     addLink = false;
70                 }
71             }
72             if (strurl.indexOf("http") < 0)
73             {
74                 File JavaDoc input = new File JavaDoc(strurl);
75                 try
76                 {
77                     strurl = input.toURL().toString();
78                     System.out.println("file converted to URL: " + args[0]);
79                 }
80                 catch (MalformedURLException JavaDoc e)
81                 {
82                     e.printStackTrace();
83                 }
84             }
85             try
86             {
87                 Parser parser = new Parser(strurl, new DefaultParserFeedback());
88
89                 LinkScanner linkScanner =
90                     new LinkScanner(LinkTag.LINK_TAG_FILTER);
91                 if (addLink)
92                 {
93                     parser.addScanner(linkScanner);
94                 }
95                 parser.addScanner(
96                     linkScanner.createImageScanner(ImageTag.IMAGE_TAG_FILTER));
97                 parser.addScanner(new BodyScanner());
98                 long start = System.currentTimeMillis();
99                 for (NodeIterator e = parser.elements(); e.hasMoreNodes();)
100                 {
101                     Node node = e.nextNode();
102                     if (node instanceof BodyTag)
103                     {
104                         BodyTag btag = (BodyTag) node;
105                         System.out.println(
106                             "body url: " + btag.getAttribute("background"));
107                         for (NodeIterator ee = btag.elements();
108                             ee.hasMoreNodes();
109                             )
110                         {
111                             Node cnode = ee.nextNode();
112                             if (cnode instanceof ImageTag)
113                             {
114                                 ImageTag iTag = (ImageTag) cnode;
115                                 System.out.println(
116                                     "image url: " + iTag.getImageURL());
117                             }
118                         }
119                     }
120                 }
121                 System.out.println(
122                     "Elapsed Time ms: " + (System.currentTimeMillis() - start));
123             }
124             catch (Exception JavaDoc e)
125             {
126                 e.printStackTrace();
127             }
128         }
129     }
130 }
131
Popular Tags