[jsword-svn] r2112 - in trunk/jsword/src/main/java/org/crosswire: common/xml jsword/book/filter/thml
dmsmith at crosswire.org
dmsmith at crosswire.org
Thu Mar 10 18:29:40 MST 2011
Author: dmsmith
Date: 2011-03-10 18:29:39 -0700 (Thu, 10 Mar 2011)
New Revision: 2112
Modified:
trunk/jsword/src/main/java/org/crosswire/common/xml/XMLUtil.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/IgnoreTag.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/THMLFilter.java
Log:
Modified: trunk/jsword/src/main/java/org/crosswire/common/xml/XMLUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/common/xml/XMLUtil.java 2011-03-08 14:05:54 UTC (rev 2111)
+++ trunk/jsword/src/main/java/org/crosswire/common/xml/XMLUtil.java 2011-03-11 01:29:39 UTC (rev 2112)
@@ -230,7 +230,7 @@
}
/**
- * Remove all invalid characters in the input. XML has stringent
+ * Remove all invalid characters in the input, replacing them with a space. XML has stringent
* requirements as to which characters are or are not allowed. The set of
* allowable characters are:<br />
* #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]<br/>
@@ -241,7 +241,7 @@
* @return the cleaned string
*/
public static String cleanAllCharacters(String broken) {
- return invalidCharacterPattern.matcher(broken).replaceAll("");
+ return invalidCharacterPattern.matcher(broken).replaceAll(" ");
}
/**
@@ -321,10 +321,9 @@
}
}
- // So we have the end of the tag, delete it ...
- // DataPolice.report("discarding tag: " + working.substring(lt, i +
- // 1));
- working = working.substring(0, lt) + working.substring(i + 1);
+ // So we have the end of the tag, delete it, but leave a space in it's place
+ // DataPolice.report("discarding tag: " + working.substring(lt, i + 1));
+ working = working.substring(0, lt) + " " + working.substring(i + 1);
}
return working;
@@ -350,7 +349,8 @@
return replace;
}
- return "";
+ // replace unknown entities with a space
+ return " ";
}
// Map entities to their unicode equivalent
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/IgnoreTag.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/IgnoreTag.java 2011-03-08 14:05:54 UTC (rev 2111)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/IgnoreTag.java 2011-03-11 01:29:39 UTC (rev 2112)
@@ -50,6 +50,6 @@
// Replace the parent with this element
Element parent = ele.getParentElement();
parent.removeContent(ele);
- parent.addContent(ele.getChildren());
+ parent.addContent(ele.removeContent());
}
}
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/THMLFilter.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/THMLFilter.java 2011-03-08 14:05:54 UTC (rev 2111)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/filter/thml/THMLFilter.java 2011-03-11 01:29:39 UTC (rev 2112)
@@ -131,8 +131,8 @@
private Element parse(Book book, Key key, String plain, String failMessage) {
Exception ex = null;
// We need to create a root element to house our document fragment
- StringBuilder buf = new StringBuilder(15 + plain.length()); // 15 for the
- // tags we add
+ // 15 for the tags we add
+ StringBuilder buf = new StringBuilder(15 + plain.length());
buf.append('<').append(RootTag.TAG_ROOT).append('>').append(plain).append("</").append(RootTag.TAG_ROOT).append('>');
finalInput = buf.toString();
try {
@@ -152,7 +152,13 @@
ex = e;
} catch (ParserConfigurationException e) {
ex = e;
- }
+ } catch (IllegalArgumentException e) {
+ // JDOM has a few exceptions which are all derived from this.
+ ex = e;
+ } catch (RuntimeException e) {
+ // Catch everything else so that we handle the exception properly within a Sw*ng callback
+ ex = e;
+ }
errorMessage = failMessage;
error = ex;
More information about the jsword-svn
mailing list