ParsedURLTest | Line # 42 | 31 | 7 | 90.9% |
0.90909094
|
No Tests | |||
1 | /* | |
2 | * Copyright (c) 2000-2005, University of Salford | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * Redistributions of source code must retain the above copyright notice, this | |
9 | * list of conditions and the following disclaimer. | |
10 | * | |
11 | * Redistributions in binary form must reproduce the above copyright notice, | |
12 | * this list of conditions and the following disclaimer in the documentation | |
13 | * and/or other materials provided with the distribution. | |
14 | * | |
15 | * Neither the name of the University of Salford nor the names of its | |
16 | * contributors may be used to endorse or promote products derived from this | |
17 | * software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | package issrg.test; | |
33 | ||
34 | /** | |
35 | * This class parses a number of URLs on standard input, and produces the parsed | |
36 | * versions of them on standard output. It can be given one or two files | |
37 | * as parameters: the first one is the input file, the second one is the output | |
38 | * file. Compare the output file with the earlier version: if they are not the | |
39 | * same, then the URLs are parsed differently. | |
40 | */ | |
41 | ||
42 | public class ParsedURLTest { | |
43 | 1 | public static void main(String [] a) throws Exception { |
44 | 1 | System.setProperty("line.separator", "\r\n"); |
45 | 1 | java.io.InputStream is = System.in; |
46 | 1 | java.io.PrintStream out = System.out; |
47 | ||
48 | 1 | if (a.length>0) is = new java.io.FileInputStream(a[0]); |
49 | 1 | if (a.length>1) out = new java.io.PrintStream(new java.io.FileOutputStream(a[1])); |
50 | ||
51 | 1 | java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(is)); |
52 | ||
53 | 1 | String s; |
54 | 0 | while ((s=br.readLine())!=null){ |
55 | 15 | out.println("* "+s); |
56 | 15 | issrg.utils.ParsedURL pu=issrg.utils.ParsedURL.parseURL(s); |
57 | 15 | if (pu==null){ |
58 | 5 | out.println("- not a URL"); |
59 | } else { | |
60 | 10 | out.println("+ good URL:"); |
61 | 10 | out.println("\tprotocol: "+pu.getProtocol()); |
62 | 10 | out.println("\tuser: "+pu.getUserName()); |
63 | 10 | out.println("\tpassword: "+pu.getPassword()); |
64 | 10 | out.println("\thost: "+pu.getHost()); |
65 | 10 | out.println("\tport: "+pu.getPort()); |
66 | 10 | out.println("\tanchor: "+pu.getAnchor()); |
67 | 10 | out.println("\tquery: "+pu.getQuery()); |
68 | 10 | out.print("\tpath: "); |
69 | ||
70 | 10 | String [] p = pu.getPath(); |
71 | 10 | if (p.length==0) out.print("null"); |
72 | 16 | else for (int i=0; i<p.length; i++) |
73 | { | |
74 | 10 | out.println(p[i]); |
75 | 10 | out.print("\t\t"); |
76 | } | |
77 | ||
78 | 10 | out.println(); |
79 | } | |
80 | } | |
81 | 1 | out.close(); |
82 | } | |
83 | } |
|