File tree Expand file tree Collapse file tree 3 files changed +14
-73
lines changed
metafacture-biblio/src/main/java/org/metafacture/biblio/marc21
metafacture-commons/src/main/java/org/metafacture/commons
metafacture-xml/src/main/java/org/metafacture/xml Expand file tree Collapse file tree 3 files changed +14
-73
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import java .util .Collections ;
19
19
20
+ import org .metafacture .commons .XmlUtil ;
20
21
import org .metafacture .framework .FluxCommand ;
21
22
import org .metafacture .framework .MetafactureException ;
22
23
import org .metafacture .framework .ObjectReceiver ;
@@ -235,39 +236,7 @@ private void writeRaw(final String str) {
235
236
236
237
/** Writes a escaped sequence */
237
238
private void writeEscaped (final String str ) {
238
- final int len = str .length ();
239
- for (int i = 0 ; i < len ; ++i ) {
240
- final char c = str .charAt (i );
241
- final String entityName ;
242
- switch (c ) {
243
- case '&' :
244
- entityName = "amp" ;
245
- break ;
246
- case '<' :
247
- entityName = "lt" ;
248
- break ;
249
- case '>' :
250
- entityName = "gt" ;
251
- break ;
252
- case '\'' :
253
- entityName = "apos" ;
254
- break ;
255
- case '"' :
256
- entityName = "quot" ;
257
- break ;
258
- default :
259
- entityName = null ;
260
- break ;
261
- }
262
-
263
- if (entityName == null ) {
264
- builder .append (c );
265
- } else {
266
- builder .append ('&' );
267
- builder .append (entityName );
268
- builder .append (';' );
269
- }
270
- }
239
+ builder .append (XmlUtil .escape (str , false ));
271
240
}
272
241
273
242
private void prettyPrintIndentation () {
Original file line number Diff line number Diff line change @@ -95,24 +95,28 @@ public static boolean isXmlMimeType(final String mimeType) {
95
95
mimeType .endsWith (XML_BASE_MIME_TYPE );
96
96
}
97
97
98
- public static String escape (String unescaped ) {
98
+ public static String escape (final String unescaped ) {
99
+ return escape (unescaped , true );
100
+ }
101
+
102
+ public static String escape (final String unescaped , final boolean escapeUnicode ) {
99
103
return unescaped .codePoints ()
100
- .mapToObj (XmlUtil :: escapeCodePoint )
104
+ .mapToObj (value -> escapeCodePoint ( value , escapeUnicode ) )
101
105
.collect (joining ());
102
106
}
103
-
104
- private static String escapeCodePoint (int codePoint ) {
107
+
108
+ private static String escapeCodePoint (final int codePoint , final boolean escapeUnicode ) {
105
109
final String entity = entityFor (codePoint );
106
110
if (entity != null ) {
107
111
return entity ;
108
112
}
109
- if (codePoint > 0x7f ) {
113
+ if (escapeUnicode && codePoint > 0x7f ) {
110
114
return "&#" + Integer .toString (codePoint ) + ";" ;
111
115
}
112
116
return Character .toString ((char ) codePoint );
113
117
}
114
118
115
- private static String entityFor (int ch ) {
119
+ private static String entityFor (final int ch ) {
116
120
switch (ch ) {
117
121
case '<' : return "<" ;
118
122
case '>' : return ">" ;
Original file line number Diff line number Diff line change 26
26
import java .util .Properties ;
27
27
28
28
import org .metafacture .commons .ResourceUtil ;
29
+ import org .metafacture .commons .XmlUtil ;
29
30
import org .metafacture .framework .FluxCommand ;
30
31
import org .metafacture .framework .MetafactureException ;
31
32
import org .metafacture .framework .ObjectReceiver ;
@@ -244,40 +245,7 @@ private void writeFooter() {
244
245
}
245
246
246
247
protected static void writeEscaped (final StringBuilder builder , final String str ) {
247
-
248
- final int len = str .length ();
249
- for (int i = 0 ; i < len ; ++i ) {
250
- final char c = str .charAt (i );
251
- final String entityName ;
252
- switch (c ) {
253
- case '&' :
254
- entityName = "amp" ;
255
- break ;
256
- case '<' :
257
- entityName = "lt" ;
258
- break ;
259
- case '>' :
260
- entityName = "gt" ;
261
- break ;
262
- case '\'' :
263
- entityName = "apos" ;
264
- break ;
265
- case '"' :
266
- entityName = "quot" ;
267
- break ;
268
- default :
269
- entityName = null ;
270
- break ;
271
- }
272
-
273
- if (entityName == null ) {
274
- builder .append (c );
275
- } else {
276
- builder .append ('&' );
277
- builder .append (entityName );
278
- builder .append (';' );
279
- }
280
- }
248
+ builder .append (XmlUtil .escape (str , false ));
281
249
}
282
250
283
251
/**
You can’t perform that action at this time.
0 commit comments