|
@@ -1,15 +1,15 @@ |
1 |
1 |
|
package com.temp.shared.utils; |
2 |
2 |
|
|
3 |
3 |
|
public enum HtmlEntity { |
4 |
|
- |
AMP('&', "&"), // |
5 |
|
- |
LT('<', "<"), // |
6 |
|
- |
GT('>', ">"), // |
7 |
|
- |
QUOT('"', """); |
|
4 |
+ |
AMP( '&', "&" ), // |
|
5 |
+ |
LT( '<', "<" ), // |
|
6 |
+ |
GT( '>', ">" ), // |
|
7 |
+ |
QUOT( '"', """ ); |
8 |
8 |
|
|
9 |
9 |
|
private char character; |
10 |
10 |
|
private String string; |
11 |
11 |
|
|
12 |
|
- |
private HtmlEntity(char character, String string) { |
|
12 |
+ |
private HtmlEntity( char character, String string ) { |
13 |
13 |
|
this.character = character; |
14 |
14 |
|
this.string = string; |
15 |
15 |
|
} |
|
@@ -22,62 +22,67 @@ |
22 |
22 |
|
return string; |
23 |
23 |
|
} |
24 |
24 |
|
|
25 |
|
- |
public boolean wouldMatch(String entity) { |
26 |
|
- |
return string.equalsIgnoreCase(entity); |
|
25 |
+ |
public boolean wouldMatch( String entity ) { |
|
26 |
+ |
return string.equalsIgnoreCase( entity ); |
27 |
27 |
|
} |
28 |
28 |
|
|
29 |
|
- |
public static void append(char c, StringBuilder sb) { |
30 |
|
- |
switch (c) { |
|
29 |
+ |
public static void append( char c, StringBuilder sb ) { |
|
30 |
+ |
switch ( c ) { |
31 |
31 |
|
case '&': |
32 |
|
- |
sb.append(AMP.getString()); |
|
32 |
+ |
sb.append( AMP.getString() ); |
33 |
33 |
|
break; |
34 |
34 |
|
case '<': |
35 |
|
- |
sb.append(LT.getString()); |
|
35 |
+ |
sb.append( LT.getString() ); |
36 |
36 |
|
break; |
37 |
37 |
|
case '>': |
38 |
|
- |
sb.append(GT.getString()); |
|
38 |
+ |
sb.append( GT.getString() ); |
39 |
39 |
|
break; |
40 |
40 |
|
case '"': |
41 |
|
- |
sb.append(QUOT.getString()); |
|
41 |
+ |
sb.append( QUOT.getString() ); |
42 |
42 |
|
break; |
43 |
43 |
|
default: |
44 |
|
- |
if ((c == '\n') || ((' ' <= c) && (c <= 126))) { |
45 |
|
- |
sb.append(c); |
|
44 |
+ |
if ( (c == '\n') || ((' ' <= c) && (c <= 126)) ) { |
|
45 |
+ |
sb.append( c ); |
46 |
46 |
|
} else { |
47 |
|
- |
sb.append(toDecimalForm(c)); |
|
47 |
+ |
sb.append( toDecimalForm( c ) ); |
48 |
48 |
|
} |
49 |
49 |
|
break; |
50 |
50 |
|
} |
51 |
51 |
|
} |
52 |
52 |
|
|
53 |
|
- |
public static char fromStringForm(String entity) { |
54 |
|
- |
if (AMP.wouldMatch(entity)) |
|
53 |
+ |
public static char fromStringForm( String entity ) { |
|
54 |
+ |
if ( AMP.wouldMatch( entity ) ) { |
55 |
55 |
|
return AMP.getCharacter(); |
56 |
|
- |
if (LT.wouldMatch(entity)) |
|
56 |
+ |
} |
|
57 |
+ |
if ( LT.wouldMatch( entity ) ) { |
57 |
58 |
|
return LT.getCharacter(); |
58 |
|
- |
if (GT.wouldMatch(entity)) |
|
59 |
+ |
} |
|
60 |
+ |
if ( GT.wouldMatch( entity ) ) { |
59 |
61 |
|
return GT.getCharacter(); |
60 |
|
- |
if (QUOT.wouldMatch(entity)) |
|
62 |
+ |
} |
|
63 |
+ |
if ( QUOT.wouldMatch( entity ) ) { |
61 |
64 |
|
return QUOT.getCharacter(); |
62 |
|
- |
return fromDecimalForm(entity); |
|
65 |
+ |
} |
|
66 |
+ |
return fromDecimalForm( entity ); |
63 |
67 |
|
} |
64 |
68 |
|
|
65 |
|
- |
public static String toDecimalForm(char c) { |
|
69 |
+ |
public static String toDecimalForm( char c ) { |
66 |
70 |
|
return "&#" + ((int) c) + ';'; |
67 |
71 |
|
} |
68 |
72 |
|
|
69 |
|
- |
public static char fromDecimalForm(String decimalForm) { |
70 |
|
- |
if ((decimalForm != null) && (decimalForm.length() > 3) && decimalForm.startsWith("&#") && decimalForm.endsWith(";")) { |
|
73 |
+ |
public static char fromDecimalForm( String decimalForm ) { |
|
74 |
+ |
if ( (decimalForm != null) && (decimalForm.length() > 3) && decimalForm.startsWith( "&#" ) && decimalForm.endsWith( ";" ) ) { |
71 |
75 |
|
try { |
72 |
|
- |
int value = Integer.parseInt(decimalForm.substring(2, decimalForm.length() - 1)); |
73 |
|
- |
if ((Character.MIN_VALUE <= value) && (value <= Character.MAX_VALUE)) { |
|
76 |
+ |
int value = Integer.parseInt( decimalForm.substring( 2, decimalForm.length() - 1 ) ); |
|
77 |
+ |
if ( (Character.MIN_VALUE <= value) && (value <= Character.MAX_VALUE) ) { |
74 |
78 |
|
return (char) value; |
75 |
79 |
|
} |
76 |
|
- |
} catch (NumberFormatException whatever) { |
|
80 |
+ |
} |
|
81 |
+ |
catch ( NumberFormatException whatever ) { |
77 |
82 |
|
// Fall Thru |
78 |
83 |
|
} |
79 |
84 |
|
} |
80 |
|
- |
throw new IllegalArgumentException("Not a Html Decimal Entity: '" + decimalForm + "'"); |
|
85 |
+ |
throw new IllegalArgumentException( "Not a Html Decimal Entity: '" + decimalForm + "'" ); |
81 |
86 |
|
} |
82 |
87 |
|
|
83 |
88 |
|
public static final String NBSP = " "; |