From 66cfb865fbfa7af514e803003f928d77f1156e46 Mon Sep 17 00:00:00 2001 From: mcentner Date: Thu, 11 Sep 2008 12:16:35 +0000 Subject: Added to be signed data validation. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@32 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/text/TextValidator.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java (limited to 'BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java') 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 new file mode 100644 index 00000000..5108140d --- /dev/null +++ b/BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java @@ -0,0 +1,32 @@ +/* +* Copyright 2008 Federal Chancellery Austria and +* Graz University of Technology +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package at.gv.egiz.bku.text; + +import java.io.InputStream; + +import at.gv.egiz.bku.viewer.ValidationException; +import at.gv.egiz.bku.viewer.Validator; + +public class TextValidator implements Validator { + + @Override + public void validate(InputStream is, String charset) + throws ValidationException { + // TODO: implement character validation + } + +} -- cgit v1.2.3 From 9f441a0aaf0e55b50014e814410c61117f7330c4 Mon Sep 17 00:00:00 2001 From: mcentner Date: Fri, 12 Sep 2008 13:50:31 +0000 Subject: Add text validation. git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@35 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/text/TextValidator.java | 77 +++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) (limited to 'BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java') 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 5108140d..485aa727 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,17 +16,92 @@ */ package at.gv.egiz.bku.text; +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; public class TextValidator implements Validator { + /** + * Logging facility. + */ + protected static Log log = LogFactory.getLog(TextValidator.class); + + private void invalid(char c) throws ValidationException { + log.info("Invalid character (0x" + Integer.toHexString(c) + ") found."); + // TODO: localize + throw new ValidationException(); + } + @Override public void validate(InputStream is, String charset) throws ValidationException { - // TODO: implement character validation + + InputStreamReader reader; + if (charset != null) { + try { + reader = new InputStreamReader(is, charset); + } catch (UnsupportedEncodingException e) { + log.info("Charset '" + charset + "' not supported.", e); + // TODO: localize + throw new ValidationException(e); + } + } else { + reader = new InputStreamReader(is, Charset.forName("UTF-8")); + } + + try { + char c; + CharBuffer cb = CharBuffer.allocate(256); + for (int l; (l = reader.read(cb)) != -1;) { + 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); + } + } + } + cb.clear(); + } catch (IOException e) { + // TODO: localize + throw new ValidationException(e); + } + + + } } -- cgit v1.2.3 From 83e8c95ea7d257166d350a59bfd81e9833ec14fd Mon Sep 17 00:00:00 2001 From: clemenso Date: Thu, 5 Nov 2009 19:05:14 +0000 Subject: [#484] European Language support git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@535 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../java/at/gv/egiz/bku/text/TextValidator.java | 38 +++++++--------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'BKUViewer/src/main/java/at/gv/egiz/bku/text/TextValidator.java') 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(); -- cgit v1.2.3