< prev index next >
jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/bind/marshaller/MinimumEscapeHandler.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -46,14 +46,14 @@
// that the escaping occurs rarely.
// profiling revealed that this is faster than the naive code.
int limit = start+length;
for (int i = start; i < limit; i++) {
char c = ch[i];
- if(c == '&' || c == '<' || c == '>' || c == '\r' || (c == '\"' && isAttVal) ) {
- if(i!=start)
- out.write(ch,start,i-start);
- start = i+1;
+ if (c == '&' || c == '<' || c == '>' || c == '\r' || (c == '\n' && isAttVal) || (c == '\"' && isAttVal)) {
+ if (i != start)
+ out.write(ch, start, i - start);
+ start = i + 1;
switch (ch[i]) {
case '&':
out.write("&");
break;
case '<':
@@ -63,10 +63,18 @@
out.write(">");
break;
case '\"':
out.write(""");
break;
+ case '\n':
+ case '\r':
+ out.write("&#");
+ out.write(Integer.toString(c));
+ out.write(';');
+ break;
+ default:
+ throw new IllegalArgumentException("Cannot escape: '" + c + "'");
}
}
}
if( start!=limit )
< prev index next >