|
From: <de...@us...> - 2012-10-19 11:00:51
|
Revision: 7766
http://fudaa.svn.sourceforge.net/fudaa/?rev=7766&view=rev
Author: deniger
Date: 2012-10-19 11:00:40 +0000 (Fri, 19 Oct 2012)
Log Message:
-----------
Modified Paths:
--------------
trunk/framework/ctulu-common/pom.xml
Added Paths:
-----------
trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/
trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/UnicodeInputStream.java
trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/XmlVersionFinder.java
Modified: trunk/framework/ctulu-common/pom.xml
===================================================================
--- trunk/framework/ctulu-common/pom.xml 2012-10-19 10:44:51 UTC (rev 7765)
+++ trunk/framework/ctulu-common/pom.xml 2012-10-19 11:00:40 UTC (rev 7766)
@@ -1,52 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.fudaa.framework</groupId>
- <artifactId>fudaa-framework</artifactId>
- <version>1.4-SNAPSHOT</version>
- </parent>
- <groupId>org.fudaa.framework.ctulu</groupId>
- <artifactId>ctulu-common</artifactId>
- <name>ctulu-common</name>
- <dependencies>
- <dependency>
- <groupId>${ctuluGroupId}</groupId>
- <artifactId>ctulu-bu</artifactId>
- </dependency>
- <dependency>
- <groupId>jep</groupId>
- <artifactId>jep-fudaa</artifactId>
- </dependency>
- <dependency>
- <groupId>trove</groupId>
- <artifactId>trove</artifactId>
- </dependency>
- <dependency>
- <groupId>net.sourceforge.jexcelapi</groupId>
- <artifactId>jxl</artifactId>
- </dependency>
-
- <dependency>
- <groupId>PDFRenderer</groupId>
- <artifactId>PDFRenderer</artifactId>
- </dependency>
- <dependency>
- <groupId>com.lowagie</groupId>
- <artifactId>itext</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.measure</groupId>
- <artifactId>jsr-275</artifactId>
- </dependency>
- <dependency>
- <groupId>com.db4o</groupId>
- <artifactId>db4o-java5</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.fudaa.framework</groupId>
+ <artifactId>fudaa-framework</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </parent>
+ <groupId>org.fudaa.framework.ctulu</groupId>
+ <artifactId>ctulu-common</artifactId>
+ <name>ctulu-common</name>
+ <dependencies>
+ <dependency>
+ <groupId>${ctuluGroupId}</groupId>
+ <artifactId>ctulu-bu</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jep</groupId>
+ <artifactId>jep-fudaa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>trove</groupId>
+ <artifactId>trove</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jexcelapi</groupId>
+ <artifactId>jxl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>PDFRenderer</groupId>
+ <artifactId>PDFRenderer</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.lowagie</groupId>
+ <artifactId>itext</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.measure</groupId>
+ <artifactId>jsr-275</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.db4o</groupId>
+ <artifactId>db4o-java5</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
Copied: trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/UnicodeInputStream.java (from rev 7736, trunk/soft/fudaa-crue/crue-server/src/main/java/org/fudaa/dodico/crue/io/UnicodeInputStream.java)
===================================================================
--- trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/UnicodeInputStream.java (rev 0)
+++ trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/UnicodeInputStream.java 2012-10-19 11:00:40 UTC (rev 7766)
@@ -0,0 +1,124 @@
+package org.fudaa.ctulu.xml;
+/**
+ version: 1.1 / 2007-01-25
+ - changed BOM recognition ordering (longer boms first)
+
+ Original pseudocode : Thomas Weidenfeller
+ Implementation tweaked: Aki Nieminen
+
+ http://www.unicode.org/unicode/faq/utf_bom.html
+ BOMs in byte length ordering:
+ 00 00 FE FF = UTF-32, big-endian
+ FF FE 00 00 = UTF-32, little-endian
+ EF BB BF = UTF-8,
+ FE FF = UTF-16, big-endian
+ FF FE = UTF-16, little-endian
+
+ Win2k Notepad:
+ Unicode format = UTF-16LE
+***/
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+
+/**
+ * This inputstream will recognize unicode BOM marks
+ * and will skip bytes if getEncoding() method is called
+ * before any of the read(...) methods.
+ *
+ * Usage pattern:
+ String enc = "ISO-8859-1"; // or NULL to use systemdefault
+ FileInputStream fis = new FileInputStream(file);
+ UnicodeInputStream uin = new UnicodeInputStream(fis, enc);
+ enc = uin.getEncoding(); // check and skip possible BOM bytes
+ InputStreamReader in;
+ if (enc == null) in = new InputStreamReader(uin);
+ else in = new InputStreamReader(uin, enc);
+ */
+public class UnicodeInputStream extends InputStream {
+ PushbackInputStream internalIn;
+ boolean isInited = false;
+ String defaultEnc;
+ String encoding;
+
+ private static final int BOM_SIZE = 4;
+
+ public UnicodeInputStream(InputStream in, String defaultEnc) {
+ internalIn = new PushbackInputStream(in, BOM_SIZE);
+ this.defaultEnc = defaultEnc;
+ }
+
+ public String getDefaultEncoding() {
+ return defaultEnc;
+ }
+
+ public String getEncoding() {
+ if (!isInited) {
+ try {
+ init();
+ } catch (IOException ex) {
+ IllegalStateException ise = new IllegalStateException("Init method failed.");
+ ise.initCause(ise);
+ throw ise;
+ }
+ }
+ return encoding;
+ }
+
+ /**
+ * Read-ahead four bytes and check for BOM marks. Extra bytes are
+ * unread back to the stream, only BOM bytes are skipped.
+ */
+ public void init() throws IOException {
+ if (isInited) {
+ return;
+ }
+
+ byte bom[] = new byte[BOM_SIZE];
+ int n, unread;
+ n = internalIn.read(bom, 0, bom.length);
+
+ if ( (bom[0] == (byte)0x00) && (bom[1] == (byte)0x00) &&
+ (bom[2] == (byte)0xFE) && (bom[3] == (byte)0xFF) ) {
+ encoding = "UTF-32BE";
+ unread = n - 4;
+ } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) &&
+ (bom[2] == (byte)0x00) && (bom[3] == (byte)0x00) ) {
+ encoding = "UTF-32LE";
+ unread = n - 4;
+ } else if ( (bom[0] == (byte)0xEF) && (bom[1] == (byte)0xBB) &&
+ (bom[2] == (byte)0xBF) ) {
+ encoding = "UTF-8";
+ unread = n - 3;
+ } else if ( (bom[0] == (byte)0xFE) && (bom[1] == (byte)0xFF) ) {
+ encoding = "UTF-16BE";
+ unread = n - 2;
+ } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) ) {
+ encoding = "UTF-16LE";
+ unread = n - 2;
+ } else {
+ // Unicode BOM mark not found, unread all bytes
+ encoding = defaultEnc;
+ unread = n;
+ }
+
+ if (unread > 0) {
+ internalIn.unread(bom, (n - unread), unread);
+ }
+
+ isInited = true;
+ }
+
+ @Override
+ public void close() throws IOException {
+ isInited = true;
+ internalIn.close();
+ }
+
+ @Override
+ public int read() throws IOException {
+ isInited = true;
+ return internalIn.read();
+ }
+}
Copied: trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/XmlVersionFinder.java (from rev 7736, trunk/soft/fudaa-crue/crue-server/src/main/java/org/fudaa/dodico/crue/common/XmlVersionFinder.java)
===================================================================
--- trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/XmlVersionFinder.java (rev 0)
+++ trunk/framework/ctulu-common/src/main/java/org/fudaa/ctulu/xml/XmlVersionFinder.java 2012-10-19 11:00:40 UTC (rev 7766)
@@ -0,0 +1,57 @@
+package org.fudaa.ctulu.xml;
+
+import java.io.InputStream;
+import java.net.URL;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.apache.commons.lang.StringUtils;
+import org.fudaa.ctulu.CtuluLibFile;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class XmlVersionFinder extends DefaultHandler {
+
+ String versionFound;
+ public static final String ENCODING = "UTF-8";
+
+ public String getVersion(final URL url) {
+ versionFound = null;
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setValidating(false);
+ UnicodeInputStream unicodeStream = null;
+ try {
+
+ InputStream resourceAsStream = url.openStream();
+ unicodeStream = new UnicodeInputStream(resourceAsStream, XmlVersionFinder.ENCODING);
+ unicodeStream.init();
+ SAXParser newSAXParser = factory.newSAXParser();
+ newSAXParser.parse(unicodeStream, this);
+ } catch (final Exception e) {
+ } finally {
+ CtuluLibFile.close(unicodeStream);
+ }
+ return versionFound;
+ }
+
+ @Override
+ public void startElement(final String uri, final String localName, final String qName, final Attributes attributes)
+ throws SAXException {
+ // we throw an event to stop the parsing
+ if (attributes != null) {
+ for (int i = attributes.getLength() - 1; i >= 0; i--) {
+ if ("xsi:schemaLocation".equals(attributes.getLocalName(i))) {
+ final String value = attributes.getValue(i);
+ if (value != null) {
+ final String last = StringUtils.substringAfterLast(value, "-");
+ versionFound = StringUtils.substringBeforeLast(last, ".");
+ }
+ throw new SAXException("ok");
+ }
+
+ }
+ }
+ throw new SAXException("notOk");
+
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|