1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
package issrg.test; |
33 |
|
|
34 |
|
import issrg.utils.RFC2253NameParser; |
35 |
|
import issrg.utils.RFC2253ParsingException; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
|
|
| 88.7% |
Uncovered Elements: 8 (71) |
Complexity: 16 |
Complexity Density: 0.36 |
|
41 |
|
public class RFC2253Test{ |
42 |
|
public final static String HELP_SCREEN = "This application test how the RFC2253NameParser works.\n(c) 2001, by Sassa\n\nusage: RFC2253test <testfile> [<logfile> [<input/output charset name>]]\n\n\ttestfile is the file where each line is a DN to parse\n\tlogfile is a file where to output the result of parsing\n\t\tThe console is used by default.\n"; |
43 |
|
|
|
|
| 88.6% |
Uncovered Elements: 8 (70) |
Complexity: 16 |
Complexity Density: 0.36 |
|
44 |
1
|
public static void main(String [] a){... |
45 |
1
|
System.setProperty("line.separator", "\r\n"); |
46 |
1
|
java.io.PrintWriter out=new java.io.PrintWriter(System.out); |
47 |
1
|
if (a.length<1 || a.length>3){ |
48 |
0
|
out.println(HELP_SCREEN); |
49 |
0
|
System.exit(0); |
50 |
|
} |
51 |
|
|
52 |
1
|
java.io.BufferedReader br=null; |
53 |
|
|
54 |
1
|
try{ |
55 |
1
|
String charset = "UTF-8"; |
56 |
1
|
if (a.length>1){ |
57 |
1
|
if (a.length>2){ |
58 |
1
|
charset = a[2]; |
59 |
|
} |
60 |
1
|
out=new java.io.PrintWriter(a[1], charset); |
61 |
|
} |
62 |
|
|
63 |
1
|
br = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(a[0]), charset)); |
64 |
|
|
65 |
36
|
while(br.ready()){ |
66 |
35
|
String s = br.readLine(); |
67 |
35
|
if(s.length() <= 2) |
68 |
2
|
continue; |
69 |
|
|
70 |
33
|
out.println(s+":"); |
71 |
33
|
try{ |
72 |
33
|
String [][][] dn = (String [][][])RFC2253NameParser.distinguishedName(s); |
73 |
|
|
74 |
23
|
StringBuffer newDN = new StringBuffer(); |
75 |
|
|
76 |
56
|
for (int i=0; i<dn.length; i++){ |
77 |
33
|
if (i!=0) newDN.append(RFC2253NameParser.COMMA_CHAR); |
78 |
|
|
79 |
33
|
out.println("\tRDN:"); |
80 |
68
|
for (int j=0; j<dn[i].length; j++){ |
81 |
35
|
if (j!=0) newDN.append(RFC2253NameParser.PLUS_CHAR); |
82 |
35
|
newDN.append(dn[i][j][0]); |
83 |
35
|
newDN.append(RFC2253NameParser.ASSIGN_CHAR); |
84 |
35
|
newDN.append(dn[i][j][1]==null?dn[i][j][2]:RFC2253NameParser.escapeString(dn[i][j][1])); |
85 |
|
|
86 |
35
|
out.println("\t\tAVA: "+dn[i][j][0]+" = "+(dn[i][j][1]==null?dn[i][j][2]:dn[i][j][1])); |
87 |
|
} |
88 |
33
|
out.println(); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
23
|
out.println("\nCompiled into: "+newDN); |
93 |
23
|
out.println("\n\n"); |
94 |
|
}catch(RFC2253ParsingException ex){ |
95 |
115
|
for (int i=ex.getErrorPos(); i-->0; ) out.print(" "); |
96 |
|
|
97 |
10
|
out.println("^\n"+ex.getMessage()+". "+ex.getEmbedded().getMessage()+"\n"); |
98 |
|
|
99 |
|
} |
100 |
|
} |
101 |
1
|
out.close(); |
102 |
|
}catch (Exception e){ |
103 |
0
|
out.println(e.getMessage()); |
104 |
0
|
e.printStackTrace(); |
105 |
|
}finally{ |
106 |
1
|
try{ |
107 |
1
|
if (br!=null) br.close(); |
108 |
|
}catch (java.io.IOException ioe){ |
109 |
|
} |
110 |
|
} |
111 |
|
} |
112 |
|
} |