summaryrefslogtreecommitdiff
path: root/BKUViewer/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'BKUViewer/src/main/java/at/gv/egiz')
-rw-r--r--BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java38
1 files changed, 11 insertions, 27 deletions
diff --git a/BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java b/BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java
index 485aa727..dee8ff2e 100644
--- a/BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java
+++ b/BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java
@@ -16,20 +16,21 @@
*/
package at.gv.egiz.bku.text;
+import at.gv.egiz.bku.gui.viewer.FontProviderException;
+import at.gv.egiz.bku.viewer.ResourceFontLoader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.viewer.ValidationException;
import at.gv.egiz.bku.viewer.Validator;
+import java.awt.Font;
public class TextValidator implements Validator {
@@ -37,7 +38,13 @@ public class TextValidator implements Validator {
* Logging facility.
*/
protected static Log log = LogFactory.getLog(TextValidator.class);
-
+
+ protected Font viewerFont;
+
+ public TextValidator() throws FontProviderException {
+ viewerFont = new ResourceFontLoader().getFont();
+ }
+
private void invalid(char c) throws ValidationException {
log.info("Invalid character (0x" + Integer.toHexString(c) + ") found.");
// TODO: localize
@@ -68,30 +75,7 @@ public class TextValidator implements Validator {
cb.flip();
for (int i = 0; i < l; i++) {
c = cb.get();
- if (c < '\u0020') {
- // C0 Controls and Basic Latin (0x000C-0x000D)
- if (c > '\r') invalid(c); if (c >= '\u000C') continue;
- // C0 Controls and Basic Latin (0x0009-0x000A)
- if (c > '\n') invalid(c); if (c >= '\t') continue;
- invalid(c);
- } else {
- // C0 Controls and Basic Latin (0x0020-0x007E)
- if (c <= '\u007E') continue;
- // C1 Controls and Latin-1 Supplement (0x00A1-0x00FF)
- if (c < '\u00A1') invalid(c); if (c <= '\u00FF') continue;
- // Latin Extended-A (0x0100-0x017F)
- if (c < '\u0100') invalid(c); if (c <= '\u017F') continue;
- // EURO Sign
- if (c == '\u20AC') continue;
- // Spacing Modifier Letters
- if (c == '\u02C7') continue;
- if (c == '\u02D8') continue;
- if (c == '\u02D9') continue;
- if (c == '\u02DB') continue;
- if (c == '\u02DD') continue;
- if (c == '\u2015') continue;
- invalid(c);
- }
+ if (!viewerFont.canDisplay(c)) invalid(c);
}
}
cb.clear();