fixes after depedency update
This commit is contained in:
66
mustang/dependency-reduced-pom.xml
Normal file
66
mustang/dependency-reduced-pom.xml
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||
<artifactId>mustang</artifactId>
|
||||
<name>Mustang</name>
|
||||
<version>2.0.0.0</version>
|
||||
<description>The Mustang project is a java library to read and write ZUGFeRD meta data inside your invoice PDFs</description>
|
||||
<url>http://www.mustangproject.org/</url>
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>User List</name>
|
||||
<archive>https://groups.google.com/forum/?hl=de#!forum/mustangproject</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Jochen St<53>rk</name>
|
||||
<email>jstaerk@usegroup.de</email>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Alexander Schmidt</name>
|
||||
<email>schmidt.alexander@mail.de</email>
|
||||
<roles>
|
||||
<role>developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>A business-friendly OSS license</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<excludes />
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -1,14 +1,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>com.github.rayman2200</groupId>
|
||||
<artifactId>mustang-sample-project</artifactId>
|
||||
<version>1.3.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.mustangproject.ZUGFeRD</groupId>
|
||||
<artifactId>mustang</artifactId>
|
||||
<version>1.3.0.1-SNAPSHOT</version>
|
||||
<version>1.4.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Mustang</name>
|
||||
@@ -56,12 +50,17 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>preflight</artifactId>
|
||||
<version>1.8.8</version>
|
||||
<version>2.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>1.8.8</version>
|
||||
<version>2.0.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -83,7 +82,7 @@
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Jochen Stärk</name>
|
||||
<name>Jochen Stärk</name>
|
||||
<email>jstaerk@usegroup.de</email>
|
||||
<roles>
|
||||
<role>architect</role>
|
||||
|
||||
@@ -7,163 +7,88 @@ package org.mustangproject.ZUGFeRD;
|
||||
* @version 1.2.0
|
||||
* @author jstaerk
|
||||
* */
|
||||
import org.apache.jempbox.impl.XMLUtil;
|
||||
import org.apache.jempbox.xmp.XMPSchemaBasic;
|
||||
import org.w3c.dom.Element;
|
||||
import org.apache.xmpbox.XMPMetadata;
|
||||
import org.apache.xmpbox.XmpConstants;
|
||||
import org.apache.xmpbox.schema.PDFAExtensionSchema;
|
||||
import org.apache.xmpbox.type.ArrayProperty;
|
||||
import org.apache.xmpbox.type.Attribute;
|
||||
import org.apache.xmpbox.type.Cardinality;
|
||||
import org.apache.xmpbox.type.ChoiceType;
|
||||
import org.apache.xmpbox.type.DefinedStructuredType;
|
||||
import org.apache.xmpbox.type.PDFAPropertyType;
|
||||
import org.apache.xmpbox.type.PDFASchemaType;
|
||||
import org.apache.xmpbox.type.StructuredType;
|
||||
import org.apache.xmpbox.type.TextType;
|
||||
|
||||
|
||||
/**
|
||||
* Additionally to adding a RDF namespace with a indication which file
|
||||
* attachment if Zugferd, this namespace has to be described in a PDFA
|
||||
* Extension Schema.
|
||||
*
|
||||
* I know there is a PDFAExtensionSchema in the context of PDFBox' XMPBOX
|
||||
* but I have been using PDFBox' JempBOX so far because I could not find out
|
||||
* how to write XMPBOX XMPMetadata to a PDF file.
|
||||
*
|
||||
* So this is my version of PDFAExtensionSchema
|
||||
* for PDFBox' jempbox XMPMetadata
|
||||
* Additionally to adding a RDF namespace with a indication which file attachment if Zugferd, this namespace has to be described in a PDFA Extension Schema. I
|
||||
* know there is a PDFAExtensionSchema in the context of PDFBox' XMPBOX but I have been using PDFBox' JempBOX so far because I could not find out how to write
|
||||
* XMPBOX XMPMetadata to a PDF file. So this is my version of PDFAExtensionSchema for PDFBox' jempbox XMPMetadata
|
||||
*
|
||||
* @author jstaerk
|
||||
*
|
||||
*/
|
||||
public class XMPSchemaPDFAExtensions extends XMPSchemaBasic {
|
||||
|
||||
private void addProperty(Element listNode, String name, String type,
|
||||
String category, String description) {
|
||||
Element nameNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaProperty:name"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(nameNode, name);
|
||||
listNode.appendChild(nameNode);
|
||||
|
||||
Element typeNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaProperty:valueType"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(typeNode, type);
|
||||
listNode.appendChild(typeNode);
|
||||
@StructuredType(preferedPrefix = "pdfaExtension", namespace = "http://www.aiim.org/pdfa/ns/extension/")
|
||||
public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
|
||||
|
||||
Element categoryNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaProperty:category"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(categoryNode, category);
|
||||
listNode.appendChild(categoryNode);
|
||||
public final String xmlns_pdfaSchema = "http://www.aiim.org/pdfa/ns/schema#";
|
||||
public final String prefix_pdfaSchema = "pdfaSchema";
|
||||
public final String xmlns_pdfaProperty = "http://www.aiim.org/pdfa/ns/property#";
|
||||
public final String prefix_pdfaProperty = "pdfaProperty";
|
||||
|
||||
Element descriptionNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaProperty:description"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(descriptionNode, description);
|
||||
listNode.appendChild(descriptionNode);
|
||||
private DefinedStructuredType addProperty(ArrayProperty parent, String name, String type, String category, String description) {
|
||||
XMPMetadata metadata = getMetadata();
|
||||
|
||||
DefinedStructuredType li = new DefinedStructuredType(metadata, getNamespace(), getPrefix(), XmpConstants.LIST_NAME);
|
||||
li.setAttribute(new Attribute(getNamespace(), XmpConstants.PARSE_TYPE, XmpConstants.RESOURCE_NAME));
|
||||
|
||||
ChoiceType pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.NAME, name);
|
||||
li.addProperty(pdfa2);
|
||||
|
||||
pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.VALUETYPE, type);
|
||||
li.addProperty(pdfa2);
|
||||
|
||||
pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.CATEGORY, category);
|
||||
li.addProperty(pdfa2);
|
||||
|
||||
pdfa2 = new ChoiceType(metadata, xmlns_pdfaProperty, prefix_pdfaProperty, PDFAPropertyType.DESCRIPTION, description);
|
||||
li.addProperty(pdfa2);
|
||||
|
||||
parent.addProperty(li);
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
public XMPSchemaPDFAExtensions(XMPMetadata metadata) {
|
||||
|
||||
super(metadata);
|
||||
|
||||
public XMPSchemaPDFAExtensions(org.apache.jempbox.xmp.XMPMetadata parent) {
|
||||
super(parent);
|
||||
addNamespace(xmlns_pdfaSchema, prefix_pdfaSchema);
|
||||
addNamespace(xmlns_pdfaProperty, prefix_pdfaProperty);
|
||||
|
||||
// add some namespaces
|
||||
schema.setAttributeNS(NS_NAMESPACE, "xmlns:pdfaExtension", //$NON-NLS-1$
|
||||
"http://www.aiim.org/pdfa/ns/extension/"); //$NON-NLS-1$
|
||||
ArrayProperty newBag = createArrayProperty(SCHEMAS, Cardinality.Bag);
|
||||
DefinedStructuredType li = new DefinedStructuredType(metadata, getNamespace(), getPrefix(), XmpConstants.LIST_NAME);
|
||||
li.setAttribute(new Attribute(getNamespace(), XmpConstants.PARSE_TYPE, XmpConstants.RESOURCE_NAME));
|
||||
newBag.addProperty(li);
|
||||
addProperty(newBag);
|
||||
|
||||
schema.setAttributeNS(NS_NAMESPACE, "xmlns:pdfaSchema", //$NON-NLS-1$
|
||||
"http://www.aiim.org/pdfa/ns/schema#"); //$NON-NLS-1$
|
||||
TextType pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.SCHEMA, "ZUGFeRD PDFA Extension Schema");
|
||||
li.addProperty(pdfa1);
|
||||
|
||||
schema.setAttributeNS(NS_NAMESPACE, "xmlns:pdfaProperty", //$NON-NLS-1$
|
||||
"http://www.aiim.org/pdfa/ns/property#"); //$NON-NLS-1$
|
||||
pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.NAMESPACE_URI, "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#");
|
||||
li.addProperty(pdfa1);
|
||||
|
||||
// the superclass includes this two namespaces we don't need
|
||||
schema.removeAttributeNS(NS_NAMESPACE, "xapGImg"); //$NON-NLS-1$
|
||||
schema.removeAttributeNS(NS_NAMESPACE, "xmp"); //$NON-NLS-1$
|
||||
pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.PREFIX, "zf");
|
||||
li.addProperty(pdfa1);
|
||||
|
||||
/*
|
||||
*What we attach is basically this:
|
||||
*pdfaExtension:schemas-node
|
||||
*+--bag
|
||||
* +--rdf:li
|
||||
* +--some text node (multiple)
|
||||
* +--property node
|
||||
* +--rdf:Seq
|
||||
* +--rdf:li (multiple) attribute node
|
||||
* +--some attribute property description text node (multiple)
|
||||
*/
|
||||
Element schemasNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaExtension:schemas"); //$NON-NLS-1$
|
||||
|
||||
Element bagNode = schema.getOwnerDocument()
|
||||
.createElement("rdf:Bag"); //$NON-NLS-1$
|
||||
|
||||
Element bagListNode = schema.getOwnerDocument().createElement(
|
||||
"rdf:li"); //$NON-NLS-1$
|
||||
|
||||
bagListNode.setAttribute("rdf:parseType", "Resource"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
Element schemaInfoNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaSchema:schema"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(schemaInfoNode,
|
||||
"ZUGFeRD PDFA Extension Schema"); //$NON-NLS-1$
|
||||
bagListNode.appendChild(schemaInfoNode);
|
||||
|
||||
Element nsInfoNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaSchema:namespaceURI"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(nsInfoNode, "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#"); //$NON-NLS-1$
|
||||
bagListNode.appendChild(nsInfoNode);
|
||||
|
||||
Element prefixInfoNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaSchema:prefix"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(prefixInfoNode, "zf"); //$NON-NLS-1$
|
||||
bagListNode.appendChild(prefixInfoNode);
|
||||
|
||||
Element propertyNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaSchema:property"); //$NON-NLS-1$
|
||||
|
||||
Element valueTypeNode = schema.getOwnerDocument().createElement(
|
||||
"pdfaSchema:valueType"); //$NON-NLS-1$
|
||||
|
||||
Element seqListValueType = schema.getOwnerDocument().createElement(
|
||||
"rdf:Seq"); //$NON-NLS-1$
|
||||
|
||||
Element sequenceNode = schema.getOwnerDocument().createElement(
|
||||
"rdf:Seq"); //$NON-NLS-1$
|
||||
|
||||
Element seqList1Node = schema.getOwnerDocument().createElement(
|
||||
"rdf:li"); //$NON-NLS-1$
|
||||
|
||||
seqList1Node.setAttribute("rdf:parseType", "Resource"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
addProperty(seqList1Node, "DocumentFileName", "Text", "external", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"The name of the embedded Zugferd XML invoice file"); //$NON-NLS-1$
|
||||
|
||||
sequenceNode.appendChild(seqList1Node);
|
||||
|
||||
Element seqList2Node = schema.getOwnerDocument().createElement(
|
||||
"rdf:li"); //$NON-NLS-1$
|
||||
seqList2Node.setAttribute("rdf:parseType", "Resource"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
addProperty(seqList2Node, "DocumentType", "Text", "external", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"INVOICE"); //$NON-NLS-1$
|
||||
sequenceNode.appendChild(seqList2Node);
|
||||
|
||||
Element seqList3Node = schema.getOwnerDocument().createElement(
|
||||
"rdf:li"); //$NON-NLS-1$
|
||||
seqList3Node.setAttribute("rdf:parseType", "Resource"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
addProperty(seqList3Node, "Version", "Text", "external", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"The version of the ZUGFeRD data"); //$NON-NLS-1$
|
||||
sequenceNode.appendChild(seqList3Node);
|
||||
|
||||
Element seqList4Node = schema.getOwnerDocument().createElement(
|
||||
"rdf:li"); //$NON-NLS-1$
|
||||
seqList4Node.setAttribute("rdf:parseType", "Resource"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
addProperty(seqList4Node, "ConformanceLevel", "Text", "external", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"The conformance level of the ZUGFeRD data, i.e. BASIC or EXTENDED"); //$NON-NLS-1$
|
||||
sequenceNode.appendChild(seqList4Node);
|
||||
|
||||
propertyNode.appendChild(sequenceNode);
|
||||
|
||||
bagListNode.appendChild(propertyNode);
|
||||
|
||||
valueTypeNode.appendChild(seqListValueType);
|
||||
bagListNode.appendChild(valueTypeNode);
|
||||
|
||||
bagNode.appendChild(bagListNode);
|
||||
schemasNode.appendChild(bagNode);
|
||||
|
||||
schema.appendChild(schemasNode);
|
||||
ArrayProperty newSeq = new ArrayProperty(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.PROPERTY, Cardinality.Seq);
|
||||
li.addProperty(newSeq);
|
||||
|
||||
addProperty(newSeq, "DocumentFileName", "Text", "external", "name of the embedded XML invoice file");
|
||||
addProperty(newSeq, "DocumentType", "Text", "external", "INVOICE");
|
||||
addProperty(newSeq, "Version", "Text", "external", "The actual version of the ZUGFeRD XML schema");
|
||||
addProperty(newSeq, "ConformanceLevel", "Text", "external", "The conformance level of the embedded ZUGFeRD data");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,53 +7,22 @@ package org.mustangproject.ZUGFeRD;
|
||||
* @version 1.2.0s
|
||||
* @author jstaerk
|
||||
* */
|
||||
import org.apache.jempbox.impl.XMLUtil;
|
||||
import org.apache.jempbox.xmp.XMPSchemaBasic;
|
||||
import org.w3c.dom.Element;
|
||||
import org.apache.xmpbox.XMPMetadata;
|
||||
import org.apache.xmpbox.schema.XMPSchema;
|
||||
|
||||
|
||||
public class XMPSchemaZugferd extends XMPSchemaBasic
|
||||
{
|
||||
|
||||
private String conformanceLevel = "EXTENDED";
|
||||
public class XMPSchemaZugferd extends XMPSchema {
|
||||
|
||||
/**
|
||||
* This is what needs to be added to the RDF metadata - basically the name of the embedded
|
||||
* Zugferd file
|
||||
* */
|
||||
public XMPSchemaZugferd(org.apache.jempbox.xmp.XMPMetadata parent, String conformanceLevel)
|
||||
{
|
||||
super(parent);
|
||||
* This is what needs to be added to the RDF metadata - basically the name of the embedded Zugferd file
|
||||
*/
|
||||
public XMPSchemaZugferd(XMPMetadata metadata, String conformanceLevel) {
|
||||
super(metadata, "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#", "zf", "ZUGFeRD Schema");
|
||||
|
||||
if (conformanceLevel != null)
|
||||
{
|
||||
this.conformanceLevel = conformanceLevel;
|
||||
setAboutAsSimple("");
|
||||
|
||||
setTextPropertyValue("ConformanceLevel", conformanceLevel);
|
||||
setTextPropertyValue("DocumentType", "INVOICE");
|
||||
setTextPropertyValue("DocumentFileName", "ZUGFeRD-invoice.xml");
|
||||
setTextPropertyValue("Version", "1.0");
|
||||
}
|
||||
|
||||
schema.setAttributeNS(NS_NAMESPACE, "xmlns:zf", //$NON-NLS-1$
|
||||
"urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#"); //$NON-NLS-1$
|
||||
// the superclass includes this two namespaces we don't need
|
||||
schema.removeAttributeNS(NS_NAMESPACE, "xapGImg"); //$NON-NLS-1$
|
||||
schema.removeAttributeNS(NS_NAMESPACE, "xmp"); //$NON-NLS-1$
|
||||
Element textNode = schema.getOwnerDocument().createElement(
|
||||
"zf:DocumentType"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(textNode, "INVOICE"); //$NON-NLS-1$
|
||||
schema.appendChild(textNode);
|
||||
|
||||
textNode = schema.getOwnerDocument().createElement(
|
||||
"zf:DocumentFileName"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(textNode, "ZUGFeRD-invoice.xml"); //$NON-NLS-1$
|
||||
schema.appendChild(textNode);
|
||||
|
||||
textNode = schema.getOwnerDocument().createElement("zf:Version"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(textNode, "1.0"); //$NON-NLS-1$
|
||||
schema.appendChild(textNode);
|
||||
|
||||
textNode = schema.getOwnerDocument().createElement(
|
||||
"zf:ConformanceLevel"); //$NON-NLS-1$
|
||||
XMLUtil.setStringValue(textNode, this.conformanceLevel); //$NON-NLS-1$
|
||||
schema.appendChild(textNode);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ package org.mustangproject.ZUGFeRD;
|
||||
*/
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -24,6 +25,8 @@ import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBContext;
|
||||
@@ -32,22 +35,21 @@ import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.apache.jempbox.xmp.XMPMetadata;
|
||||
import org.apache.jempbox.xmp.XMPSchemaBasic;
|
||||
import org.apache.jempbox.xmp.XMPSchemaDublinCore;
|
||||
import org.apache.jempbox.xmp.XMPSchemaPDF;
|
||||
import org.apache.jempbox.xmp.pdfa.XMPSchemaPDFAId;
|
||||
|
||||
import org.apache.xmpbox.XMPMetadata;
|
||||
import org.apache.xmpbox.schema.XMPBasicSchema;
|
||||
import org.apache.xmpbox.schema.DublinCoreSchema;
|
||||
import org.apache.xmpbox.schema.AdobePDFSchema;
|
||||
import org.apache.xmpbox.schema.PDFAIdentificationSchema;
|
||||
import org.apache.pdfbox.cos.COSArray;
|
||||
import org.apache.pdfbox.cos.COSBase;
|
||||
import org.apache.pdfbox.cos.COSDictionary;
|
||||
import org.apache.pdfbox.cos.COSName;
|
||||
import org.apache.pdfbox.exceptions.COSVisitorException;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
|
||||
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
|
||||
import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary;
|
||||
import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.COSObjectable;
|
||||
import org.apache.pdfbox.pdmodel.common.PDMetadata;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
|
||||
@@ -56,6 +58,8 @@ import org.apache.pdfbox.preflight.ValidationResult;
|
||||
import org.apache.pdfbox.preflight.exception.ValidationException;
|
||||
import org.apache.pdfbox.preflight.parser.PreflightParser;
|
||||
import org.apache.pdfbox.preflight.utils.ByteArrayDataSource;
|
||||
import org.apache.xmpbox.type.BadFieldValueException;
|
||||
import org.apache.xmpbox.xml.XmpSerializer;
|
||||
import org.mustangproject.ZUGFeRD.model.*;
|
||||
|
||||
public class ZUGFeRDExporter {
|
||||
@@ -398,33 +402,13 @@ public class ZUGFeRDExporter {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
TextType name = xmlFactory.createTextType();
|
||||
name.setValue("RECHNUNG");
|
||||
document.getName().add(name);
|
||||
|
||||
if (trans.getOwnOrganisationFullPlaintextInfo() != null) {
|
||||
NoteType regularInfo = xmlFactory.createNoteType();
|
||||
CodeType regularInfoSubjectCode = xmlFactory.createCodeType();
|
||||
regularInfoSubjectCode.setValue(NoteType.REGULARINFO);
|
||||
regularInfo.setSubjectCode(regularInfoSubjectCode);
|
||||
TextType regularInfoContent = xmlFactory.createTextType();
|
||||
regularInfoContent.setValue(trans.getOwnOrganisationFullPlaintextInfo());
|
||||
regularInfo.getContent().add(regularInfoContent);
|
||||
document.getIncludedNote().add(regularInfo);
|
||||
}
|
||||
if (trans.getReferenceNumber() != null && !new String().equals(trans.getReferenceNumber())){
|
||||
NoteType referenceInfo = xmlFactory.createNoteType();
|
||||
TextType referenceInfoContent = xmlFactory.createTextType();
|
||||
referenceInfoContent.setValue("Ursprungsbeleg: " + trans.getReferenceNumber());
|
||||
referenceInfo.getContent().add(referenceInfoContent);
|
||||
document.getIncludedNote().add(referenceInfo);
|
||||
}
|
||||
|
||||
public void loadPDFA3(String filename) {
|
||||
|
||||
try {
|
||||
doc = PDDocument.load(filename);
|
||||
|
||||
doc = PDDocument.load(new File(filename));
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
@@ -493,20 +477,18 @@ public class ZUGFeRDExporter {
|
||||
PDDocumentCatalog cat = doc.getDocumentCatalog();
|
||||
PDMetadata metadata = new PDMetadata(doc);
|
||||
cat.setMetadata(metadata);
|
||||
// we're using the jempbox org.apache.jempbox.xmp.XMPMetadata version,
|
||||
// not the xmpbox one
|
||||
XMPMetadata xmp = new XMPMetadata();
|
||||
XMPMetadata xmp = XMPMetadata.createXMPMetadata();
|
||||
|
||||
|
||||
PDFAIdentificationSchema pdfaid = new PDFAIdentificationSchema(xmp);
|
||||
|
||||
XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp);
|
||||
pdfaid.setAbout(""); //$NON-NLS-1$
|
||||
xmp.addSchema(pdfaid);
|
||||
|
||||
XMPSchemaDublinCore dc = xmp.addDublinCoreSchema();
|
||||
dc.addCreator(creator);
|
||||
dc.setAbout(""); //$NON-NLS-1$
|
||||
DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
|
||||
|
||||
XMPSchemaBasic xsb = xmp.addBasicSchema();
|
||||
xsb.setAbout(""); //$NON-NLS-1$
|
||||
dc.addCreator(creator);
|
||||
|
||||
XMPBasicSchema xsb = xmp.createAndAddXMPBasicSchema();
|
||||
|
||||
xsb.setCreatorTool(creator);
|
||||
xsb.setCreateDate(GregorianCalendar.getInstance());
|
||||
@@ -516,9 +498,8 @@ public class ZUGFeRDExporter {
|
||||
pdi.setAuthor(creator);
|
||||
doc.setDocumentInformation(pdi);
|
||||
|
||||
XMPSchemaPDF pdf = xmp.addPDFSchema();
|
||||
AdobePDFSchema pdf = xmp.createAndAddAdobePDFSchema();
|
||||
pdf.setProducer(fullProducer);
|
||||
pdf.setAbout(""); //$NON-NLS-1$
|
||||
|
||||
/*
|
||||
* // Mandatory: PDF/A3-a is tagged PDF which has to be expressed using
|
||||
@@ -532,7 +513,11 @@ public class ZUGFeRDExporter {
|
||||
* can not guarantee that the user correctly tagged the templates for
|
||||
* the PDF.
|
||||
*/
|
||||
try {
|
||||
pdfaid.setConformance(conformanceLevel);//$NON-NLS-1$ //$NON-NLS-1$
|
||||
} catch (BadFieldValueException ex) {
|
||||
Logger.getLogger(ZUGFeRDExporter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
pdfaid.setPart(3);
|
||||
|
||||
@@ -546,7 +531,11 @@ public class ZUGFeRDExporter {
|
||||
|
||||
}
|
||||
|
||||
metadata.importXMPMetadata(xmp);
|
||||
XmpSerializer serializer = new XmpSerializer();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
serializer.serialize(xmp, baos, false);
|
||||
metadata.importXMPMetadata( baos.toByteArray() );
|
||||
|
||||
return cat;
|
||||
}
|
||||
|
||||
@@ -638,6 +627,14 @@ public class ZUGFeRDExporter {
|
||||
document.getIncludedNote().add(regularInfo);
|
||||
}
|
||||
|
||||
if (trans.getReferenceNumber() != null && !new String().equals(trans.getReferenceNumber())){
|
||||
NoteType referenceInfo = xmlFactory.createNoteType();
|
||||
TextType referenceInfoContent = xmlFactory.createTextType();
|
||||
referenceInfoContent.setValue("Ursprungsbeleg: " + trans.getReferenceNumber());
|
||||
referenceInfo.getContent().add(referenceInfoContent);
|
||||
document.getIncludedNote().add(referenceInfo);
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
@@ -1417,12 +1414,8 @@ public class ZUGFeRDExporter {
|
||||
public void export(String ZUGFeRDfilename) {
|
||||
try {
|
||||
doc.save(ZUGFeRDfilename);
|
||||
} catch (COSVisitorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1441,6 +1434,7 @@ public class ZUGFeRDExporter {
|
||||
* type of the data e.g. could be "text/xml" - mime like
|
||||
* @param data
|
||||
* the binary data of the file/attachment
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void PDFAttachGenericFile(PDDocument doc, String filename,
|
||||
String relationship, String description, String subType, byte[] data)
|
||||
@@ -1448,7 +1442,8 @@ public class ZUGFeRDExporter {
|
||||
PDComplexFileSpecification fs = new PDComplexFileSpecification();
|
||||
fs.setFile(filename);
|
||||
|
||||
COSDictionary dict = fs.getCOSDictionary();
|
||||
|
||||
COSDictionary dict = fs.getCOSObject();
|
||||
dict.setName("AFRelationship", relationship);
|
||||
dict.setString("UF", filename);
|
||||
dict.setString("Desc", description);
|
||||
@@ -1464,7 +1459,7 @@ public class ZUGFeRDExporter {
|
||||
fs.setEmbeddedFile(ef);
|
||||
|
||||
// In addition make sure the embedded file is set under /UF
|
||||
dict = fs.getCOSDictionary();
|
||||
dict = fs.getCOSObject();
|
||||
COSDictionary efDict = (COSDictionary) dict
|
||||
.getDictionaryObject(COSName.EF);
|
||||
COSBase lowerLevelFile = efDict.getItem(COSName.F);
|
||||
@@ -1478,8 +1473,9 @@ public class ZUGFeRDExporter {
|
||||
efTree = new PDEmbeddedFilesNameTreeNode();
|
||||
}
|
||||
|
||||
Map<String, COSObjectable> namesMap = new HashMap<String, COSObjectable>();
|
||||
Map<String, COSObjectable> oldNamesMap = efTree.getNames();
|
||||
Map<String, PDComplexFileSpecification> namesMap = new HashMap<String, PDComplexFileSpecification>();
|
||||
|
||||
Map<String, PDComplexFileSpecification> oldNamesMap = efTree.getNames();
|
||||
if (oldNamesMap != null) {
|
||||
for (String key : oldNamesMap.keySet()) {
|
||||
namesMap.put(key, oldNamesMap.get(key));
|
||||
@@ -1493,16 +1489,16 @@ public class ZUGFeRDExporter {
|
||||
|
||||
// AF entry (Array) in catalog with the FileSpec
|
||||
COSArray cosArray = (COSArray) doc.getDocumentCatalog()
|
||||
.getCOSDictionary().getItem("AF");
|
||||
.getCOSObject().getItem("AF");
|
||||
if (cosArray == null) {
|
||||
cosArray = new COSArray();
|
||||
}
|
||||
cosArray.add(fs);
|
||||
COSDictionary dict2 = doc.getDocumentCatalog().getCOSDictionary();
|
||||
COSDictionary dict2 = doc.getDocumentCatalog().getCOSObject();
|
||||
COSArray array = new COSArray();
|
||||
array.add(fs.getCOSDictionary()); // see below
|
||||
array.add(fs.getCOSObject()); // see below
|
||||
dict2.setItem("AF",array);
|
||||
doc.getDocumentCatalog().getCOSDictionary().setItem("AF", cosArray);
|
||||
doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1538,11 +1534,11 @@ public class ZUGFeRDExporter {
|
||||
|
||||
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata,
|
||||
this.ZUGFeRDConformanceLevel);
|
||||
zf.setAbout(""); //$NON-NLS-1$
|
||||
|
||||
metadata.addSchema(zf);
|
||||
|
||||
XMPSchemaPDFAExtensions pdfaex = new XMPSchemaPDFAExtensions(metadata);
|
||||
pdfaex.setAbout(""); //$NON-NLS-1$
|
||||
|
||||
metadata.addSchema(pdfaex);
|
||||
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class ZUGFeRDImporter {
|
||||
doc.close();
|
||||
return;
|
||||
}
|
||||
Map<String, COSObjectable> efMap = etn.getNames();
|
||||
Map<String, PDComplexFileSpecification> efMap = etn.getNames();
|
||||
// String filePath = "/tmp/";
|
||||
for (String filename : efMap.keySet()) {
|
||||
/**
|
||||
@@ -109,7 +109,8 @@ public class ZUGFeRDImporter {
|
||||
// ByteArrayOutputStream fileBytes=new
|
||||
// ByteArrayOutputStream();
|
||||
// FileOutputStream fos = new FileOutputStream(file);
|
||||
rawXML = embeddedFile.getByteArray();
|
||||
|
||||
rawXML = embeddedFile.toByteArray();
|
||||
setMeta(new String(rawXML));
|
||||
extracted=true;
|
||||
// fos.write(embeddedFile.getByteArray());
|
||||
|
||||
@@ -14,7 +14,6 @@ import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
@@ -129,9 +128,9 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
public IZUGFeRDExportableItem[] getZFItems()
|
||||
{
|
||||
Item[] allItems = new Item[3];
|
||||
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", new BigDecimal("7.000000"));
|
||||
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", new BigDecimal("7.000000"));
|
||||
Product balloonProduct = new Product("", "Luftballon: Bunt, ca. 500ml", "C62", new BigDecimal("19.000000"));
|
||||
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
|
||||
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
|
||||
|
||||
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
|
||||
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("400"), balloonProduct);
|
||||
@@ -141,7 +140,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
|
||||
|
||||
@Override
|
||||
public String getOwnPaymentInfoText() {
|
||||
return "Überweisung";
|
||||
return "Überweisung";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user