Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/MultiModule/common/src/org/litesoft/sandbox/infrastructure/client/SafeHtmlizer.java

Diff revisions: vs.
  @@ -4,10 +4,8 @@
4 4
5 5 import com.google.gwt.safehtml.shared.*;
6 6
7 - public class SafeHtmlizer
8 - {
9 - public static SafeHtmlizer getInstance()
10 - {
7 + public class SafeHtmlizer {
8 + public static SafeHtmlizer getInstance() {
11 9 SafeHtmlizer zInstance = sInstance; // Snag the reference
12 10 return (zInstance != null) ? zInstance : new SafeHtmlizer(); // Force Registration
13 11 }
  @@ -24,8 +22,7 @@
24 22 *
25 23 * @return Processed pText as a SafeHtml object.
26 24 */
27 - public SafeHtml noEmpty1stLine( String pText )
28 - {
25 + public SafeHtml noEmpty1stLine( String pText ) {
29 26 return escapeAndSanitize( insureNotEmpty( only1stLine( eliminateLeadingEmptyLines( tabsToSpaces( normalizeNewLines( deNull( pText ) ) ) ) ) ) );
30 27 }
31 28
  @@ -41,13 +38,11 @@
41 38 *
42 39 * @return Processed pText as a SafeHtml object.
43 40 */
44 - public SafeHtml noEmpty( String pText )
45 - {
41 + public SafeHtml noEmpty( String pText ) {
46 42 return escapeAndSanitize( insureNotEmpty( eliminateLeadingEmptyLines( tabsToSpaces( normalizeNewLines( deNull( pText ) ) ) ) ) );
47 43 }
48 44
49 - protected String deNull( String pText )
50 - {
45 + protected String deNull( String pText ) {
51 46 return (pText == null) ? "" : pText;
52 47 }
53 48
  @@ -56,8 +51,7 @@
56 51 *
57 52 * @param pText !null
58 53 */
59 - protected String normalizeNewLines( String pText )
60 - {
54 + protected String normalizeNewLines( String pText ) {
61 55 // switch "CR LF" -> LF & then switch CR -> LF & then switch FF -> LF
62 56 return convertCRNL( pText ).replace( '\r', '\n' ).replace( '\f', '\n' );
63 57 }
  @@ -67,8 +61,7 @@
67 61 *
68 62 * @param pText !null
69 63 */
70 - protected String tabsToSpaces( String pText )
71 - {
64 + protected String tabsToSpaces( String pText ) {
72 65 return pText.replace( '\t', ' ' );
73 66 }
74 67
  @@ -77,17 +70,14 @@
77 70 *
78 71 * @param pText !null
79 72 */
80 - protected String eliminateLeadingEmptyLines( String pText )
81 - {
73 + protected String eliminateLeadingEmptyLines( String pText ) {
82 74 Integer justPastNewLine = null;
83 75 int at = 0;
84 - while ( at < pText.length() )
85 - {
76 + while ( at < pText.length() ) {
86 77 char c = pText.charAt( at++ );
87 78 if ( c != ' ' ) // Leading whitespace
88 79 {
89 - if ( c != '\n' )
90 - {
80 + if ( c != '\n' ) {
91 81 break;
92 82 }
93 83 justPastNewLine = at;
  @@ -101,8 +91,7 @@
101 91 *
102 92 * @param pText !null
103 93 */
104 - protected String only1stLine( String pText )
105 - {
94 + protected String only1stLine( String pText ) {
106 95 int at = pText.indexOf( '\n' );
107 96 return (at == -1) ? pText : pText.substring( 0, at );
108 97 }
  @@ -112,8 +101,7 @@
112 101 *
113 102 * @param pText !null
114 103 */
115 - protected String insureNotEmpty( String pText )
116 - {
104 + protected String insureNotEmpty( String pText ) {
117 105 return pText.isEmpty() ? " " : pText;
118 106 }
119 107
  @@ -122,16 +110,13 @@
122 110 *
123 111 * @param pText !null
124 112 */
125 - protected String convertCRNL( String pText )
126 - {
113 + protected String convertCRNL( String pText ) {
127 114 int at = pText.indexOf( Constants.CRNL );
128 - if ( at == -1 )
129 - {
115 + if ( at == -1 ) {
130 116 return pText;
131 117 }
132 118 StringBuilder sb = new StringBuilder( pText );
133 - do
134 - {
119 + do {
135 120 sb.deleteCharAt( at );
136 121 }
137 122 while ( -1 != (at = pText.indexOf( Constants.CRNL )) );
  @@ -150,14 +135,11 @@
150 135 *
151 136 * @return Processed pText as a SafeHtml object.
152 137 */
153 - protected SafeHtml escapeAndSanitize( String pText )
154 - {
138 + protected SafeHtml escapeAndSanitize( String pText ) {
155 139 StringBuilder sb = new StringBuilder();
156 - for ( int i = 0; i < pText.length(); i++ )
157 - {
140 + for ( int i = 0; i < pText.length(); i++ ) {
158 141 char c = pText.charAt( i );
159 - switch ( c )
160 - {
142 + switch ( c ) {
161 143 case 160: // Hi-bit Space
162 144 case ' ':
163 145 sb.append( Constants.NBSP );
  @@ -200,8 +182,7 @@
200 182
201 183 private static volatile SafeHtmlizer sInstance;
202 184
203 - protected SafeHtmlizer()
204 - {
185 + protected SafeHtmlizer() {
205 186 sInstance = this;
206 187 }
207 188 }