aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java')
-rw-r--r--moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java278
1 files changed, 139 insertions, 139 deletions
diff --git a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
index 661e418..ccab9a4 100644
--- a/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
+++ b/moaSig/moa-asic/src/main/java/at/gv/egiz/asic/api/ASiCFactory.java
@@ -1,16 +1,5 @@
package at.gv.egiz.asic.api;
-import at.gv.egiz.asic.exceptions.ASiCException;
-import at.gv.egiz.asic.impl.ASiCBaseFormatFactory;
-import at.gv.egiz.asic.impl.ASiCExtendedFormatFactory;
-import at.gv.egiz.asic.impl.ASiCSimpleFormatFactory;
-import at.gv.egiz.asic.impl.ZipCommentReaderStream;
-import at.gv.egovernment.moa.spss.MOAApplicationException;
-import at.gv.egovernment.moa.spss.MOAException;
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -18,147 +7,158 @@ import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.asic.impl.ASiCBaseFormatFactory;
+import at.gv.egiz.asic.impl.ASiCExtendedFormatFactory;
+import at.gv.egiz.asic.impl.ASiCSimpleFormatFactory;
+import at.gv.egiz.asic.impl.ZipCommentReaderStream;
+import at.gv.egovernment.moa.spss.MOAApplicationException;
+import at.gv.egovernment.moa.spss.MOAException;
+
/**
* Created by afitzek on 6/15/16.
*/
public class ASiCFactory {
- private static final Logger logger = LoggerFactory.getLogger(ASiCFactory.class);
-
- private static final String MIMETYPE_FORMAT_E = "application/vnd.etsi.asic-e+zip";
- private static final String MIMETYPE_FORMAT_S = "application/vnd.etsi.asic-s+zip";
-
- public static ASiC parseASiC(InputStream is, ASiCFormat format) throws MOAException {
-
- InputStream newInputStream = is;
-
-
- // Try to determine the asic format!
- if (!newInputStream.markSupported()) {
- ByteArrayOutputStream asicContainer = new ByteArrayOutputStream();
-
- try {
- IOUtils.copy(newInputStream, asicContainer);
- } catch (IOException e) {
- throw new MOAApplicationException("asic.0003", null);
- }
- newInputStream = new ByteArrayInputStream(asicContainer.toByteArray());
- }
-
- String mimeTypeFile = null;
- ZipCommentReaderStream commentReaderStream = new ZipCommentReaderStream(newInputStream);
- byte[] buffer = new byte[8096];
- try {
- while (commentReaderStream.read(buffer) >= 0) {
- }
- newInputStream.reset();
- } catch (IOException e) {
- throw new MOAApplicationException("asic.0003", null);
- }
-
- ZipInputStream zipInputStream = new ZipInputStream(newInputStream);
-
- try {
- for (ZipEntry entry = zipInputStream.getNextEntry(); entry != null; entry = zipInputStream.getNextEntry()) {
- String entryName = entry.getName();
-
- if("mimetype".equalsIgnoreCase(entryName)) {
- if(mimeTypeFile == null) {
- mimeTypeFile = IOUtils.toString(zipInputStream, "UTF-8");
- } else {
- logger.warn("multiple mimetype files found in archiv");
- }
- }
- }
- newInputStream.reset();
- } catch (IOException e) {
- throw new MOAApplicationException("asic.0007", null);
- }
-
- String fileComment = commentReaderStream.getFileComment();
- ASiCFormat fileCommentFormat = null;
- if (fileComment != null) {
- logger.debug("Found file comment in ASiC {}", fileComment);
- if(fileComment.startsWith("mimetype=")) {
- String fileCommentMimeType = fileComment.substring("mimetype=".length());
- if(fileCommentMimeType.startsWith(MIMETYPE_FORMAT_E)) {
- fileCommentFormat = ASiCFormat.ASiCE;
- } else if(fileCommentMimeType.startsWith(MIMETYPE_FORMAT_S)) {
- fileCommentFormat = ASiCFormat.ASiCS;
- }
- }
- } else {
- logger.info("No file comment in ASiC");
- }
-
-
- ASiCFormat mimeTypeFileFormat = null;
- if (mimeTypeFile != null) {
- logger.debug("Found mimetype file in ASiC {}", mimeTypeFile);
- if(MIMETYPE_FORMAT_E.equalsIgnoreCase(mimeTypeFile)) {
- mimeTypeFileFormat = ASiCFormat.ASiCE;
- } else if(MIMETYPE_FORMAT_S.equalsIgnoreCase(mimeTypeFile)) {
- mimeTypeFileFormat = ASiCFormat.ASiCS;
- }
- } else {
- logger.info("No mimetype file in ASiC");
- }
-
- if (format == null) {
- if (fileCommentFormat != null && mimeTypeFileFormat != null) {
- // both are set
- if (fileCommentFormat == mimeTypeFileFormat) {
- format = fileCommentFormat;
- } else {
- throw new MOAApplicationException("asic.0009", null);
- }
- } else if (fileCommentFormat != null) {
- format = fileCommentFormat;
- } else if (mimeTypeFileFormat != null) {
- format = mimeTypeFileFormat;
- } else {
- throw new MOAApplicationException("asic.0008", null);
- }
- } else {
- // format is provided, only check for missmatches
- if (fileCommentFormat != null && fileCommentFormat != format) {
- logger.warn("ASiC format missmatch file comment {} vs provided {}", fileCommentFormat, format);
- throw new MOAApplicationException("asic.0009", null);
- }
- if (mimeTypeFileFormat != null && mimeTypeFileFormat != format) {
- logger.warn("ASiC format missmatch mimetype file {} vs provided {}", mimeTypeFileFormat, format);
- throw new MOAApplicationException("asic.0009", null);
- }
-
- if (fileCommentFormat != null && mimeTypeFileFormat != null) {
- // both are set
- if (fileCommentFormat != mimeTypeFileFormat) {
- logger.warn("ASiC format missmatch file comment {} vs mimetype file {}", fileCommentFormat, mimeTypeFileFormat);
- throw new MOAApplicationException("asic.0009", null);
- }
- }
- }
+ private static final Logger logger = LoggerFactory.getLogger(ASiCFactory.class);
- ASiCBaseFormatFactory formatFactory = null;
+ private static final String MIMETYPE_FORMAT_E = "application/vnd.etsi.asic-e+zip";
+ private static final String MIMETYPE_FORMAT_S = "application/vnd.etsi.asic-s+zip";
- if (format == null) {
- throw new MOAApplicationException("asic.0008", null);
+ public static ASiC parseASiC(InputStream is, ASiCFormat format) throws MOAException {
+
+ InputStream newInputStream = is;
+
+ // Try to determine the asic format!
+ if (!newInputStream.markSupported()) {
+ final ByteArrayOutputStream asicContainer = new ByteArrayOutputStream();
+
+ try {
+ IOUtils.copy(newInputStream, asicContainer);
+ } catch (final IOException e) {
+ throw new MOAApplicationException("asic.0003", null);
+ }
+ newInputStream = new ByteArrayInputStream(asicContainer.toByteArray());
+ }
+
+ String mimeTypeFile = null;
+ final ZipCommentReaderStream commentReaderStream = new ZipCommentReaderStream(newInputStream);
+ final byte[] buffer = new byte[8096];
+ try {
+ while (commentReaderStream.read(buffer) >= 0) {
+ }
+ newInputStream.reset();
+ } catch (final IOException e) {
+ throw new MOAApplicationException("asic.0003", null);
+ }
+
+ final ZipInputStream zipInputStream = new ZipInputStream(newInputStream);
+
+ try {
+ for (ZipEntry entry = zipInputStream.getNextEntry(); entry != null; entry = zipInputStream
+ .getNextEntry()) {
+ final String entryName = entry.getName();
+
+ if ("mimetype".equalsIgnoreCase(entryName)) {
+ if (mimeTypeFile == null) {
+ mimeTypeFile = IOUtils.toString(zipInputStream, "UTF-8");
+ } else {
+ logger.warn("multiple mimetype files found in archiv");
+ }
}
+ }
+ newInputStream.reset();
+ } catch (final IOException e) {
+ throw new MOAApplicationException("asic.0007", null);
+ }
- switch (format) {
- case ASiCE:
- formatFactory = new ASiCExtendedFormatFactory();
- break;
- case ASiCS:
- formatFactory = new ASiCSimpleFormatFactory();
- break;
+ final String fileComment = commentReaderStream.getFileComment();
+ ASiCFormat fileCommentFormat = null;
+ if (fileComment != null) {
+ logger.debug("Found file comment in ASiC {}", fileComment);
+ if (fileComment.startsWith("mimetype=")) {
+ final String fileCommentMimeType = fileComment.substring("mimetype=".length());
+ if (fileCommentMimeType.startsWith(MIMETYPE_FORMAT_E)) {
+ fileCommentFormat = ASiCFormat.ASiCE;
+ } else if (fileCommentMimeType.startsWith(MIMETYPE_FORMAT_S)) {
+ fileCommentFormat = ASiCFormat.ASiCS;
}
+ }
+ } else {
+ logger.info("No file comment in ASiC");
+ }
- if (formatFactory == null) {
- throw new MOAApplicationException("asic.0008", null);
+ ASiCFormat mimeTypeFileFormat = null;
+ if (mimeTypeFile != null) {
+ logger.debug("Found mimetype file in ASiC {}", mimeTypeFile);
+ if (MIMETYPE_FORMAT_E.equalsIgnoreCase(mimeTypeFile)) {
+ mimeTypeFileFormat = ASiCFormat.ASiCE;
+ } else if (MIMETYPE_FORMAT_S.equalsIgnoreCase(mimeTypeFile)) {
+ mimeTypeFileFormat = ASiCFormat.ASiCS;
+ }
+ } else {
+ logger.info("No mimetype file in ASiC");
+ }
+
+ if (format == null) {
+ if (fileCommentFormat != null && mimeTypeFileFormat != null) {
+ // both are set
+ if (fileCommentFormat == mimeTypeFileFormat) {
+ format = fileCommentFormat;
+ } else {
+ throw new MOAApplicationException("asic.0009", null);
}
+ } else if (fileCommentFormat != null) {
+ format = fileCommentFormat;
+ } else if (mimeTypeFileFormat != null) {
+ format = mimeTypeFileFormat;
+ } else {
+ throw new MOAApplicationException("asic.0008", null);
+ }
+ } else {
+ // format is provided, only check for missmatches
+ if (fileCommentFormat != null && fileCommentFormat != format) {
+ logger.warn("ASiC format missmatch file comment {} vs provided {}", fileCommentFormat, format);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+ if (mimeTypeFileFormat != null && mimeTypeFileFormat != format) {
+ logger.warn("ASiC format missmatch mimetype file {} vs provided {}", mimeTypeFileFormat, format);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+
+ if (fileCommentFormat != null && mimeTypeFileFormat != null) {
+ // both are set
+ if (fileCommentFormat != mimeTypeFileFormat) {
+ logger.warn("ASiC format missmatch file comment {} vs mimetype file {}", fileCommentFormat,
+ mimeTypeFileFormat);
+ throw new MOAApplicationException("asic.0009", null);
+ }
+ }
+ }
+
+ ASiCBaseFormatFactory formatFactory = null;
- return formatFactory.createASiC(newInputStream);
+ if (format == null) {
+ throw new MOAApplicationException("asic.0008", null);
}
+ switch (format) {
+ case ASiCE:
+ formatFactory = new ASiCExtendedFormatFactory();
+ break;
+ case ASiCS:
+ formatFactory = new ASiCSimpleFormatFactory();
+ break;
+ }
+
+ if (formatFactory == null) {
+ throw new MOAApplicationException("asic.0008", null);
+ }
+
+ return formatFactory.createASiC(newInputStream);
+ }
+
}