|
From: Jeremias M. <jm...@us...> - 2011-05-04 08:18:51
|
Update of /cvsroot/barcode4j/barcode4j/examples/webapp/java/org/krysalis/barcode4j/webapp
In directory vz-cvs-2.sog:/tmp/cvs-serv15963/examples/webapp/java/org/krysalis/barcode4j/webapp
Modified Files:
BarcodeRequestBean.java
Log Message:
Fixed a refactoring mistake in the barcode web application which caused a NullPointerException.
Improved XHTML production to make the XHTML more compatible with current browsers.
Index: BarcodeRequestBean.java
===================================================================
RCS file: /cvsroot/barcode4j/barcode4j/examples/webapp/java/org/krysalis/barcode4j/webapp/BarcodeRequestBean.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** BarcodeRequestBean.java 25 Oct 2010 09:28:47 -0000 1.6
--- BarcodeRequestBean.java 4 May 2011 08:18:48 -0000 1.7
***************
*** 17,20 ****
--- 17,22 ----
import java.io.UnsupportedEncodingException;
+ import java.text.CharacterIterator;
+ import java.text.StringCharacterIterator;
import org.krysalis.barcode4j.servlet.BarcodeServlet;
***************
*** 291,297 ****
}
! private String encode(String text) {
try {
! return java.net.URLEncoder.encode(humanReadableFont, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Incompatible JVM: " + e.getMessage(), e);
--- 293,303 ----
}
! public String toXMLSafeURL() {
! return escapeForXML(toURL());
! }
!
! private static String encode(String text) {
try {
! return java.net.URLEncoder.encode(text, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Incompatible JVM: " + e.getMessage(), e);
***************
*** 299,301 ****
--- 305,331 ----
}
+ public static String escapeForXML(String text) {
+ final StringBuilder result = new StringBuilder();
+ final StringCharacterIterator iterator = new StringCharacterIterator(text);
+ char character = iterator.current();
+ while (character != CharacterIterator.DONE) {
+ if (character == '<') {
+ result.append("<");
+ } else if (character == '>') {
+ result.append(">");
+ } else if (character == '\"') {
+ result.append(""");
+ } else if (character == '\'') {
+ result.append("'");
+ } else if (character == '&') {
+ result.append("&");
+ } else {
+ // the char is not a special one
+ // add it to the result as is
+ result.append(character);
+ }
+ character = iterator.next();
+ }
+ return result.toString();
+ }
}
|