Class AbstractInvoice
BG-0 Invoice — the root of a Factur-X (ZUGFeRD) Cross Industry Invoice
(/rsm:CrossIndustryInvoice), and the abstract base class of the five profile-specific
Invoice classes (MINIMUM, BASIC WL, BASIC, EN 16931 and EXTENDED). The concrete subclass
carries the business-term accessors for its profile; this base class provides the behaviour they
share:
- Serialization.
toXML(PrintStream)andtoXML(PrintWriter)write a Factur-X XML document that conforms to the profile's XML Schema, andgetXMLAsDataURL()returns that document as a base64data:URL. - Reading. The static factories
fromXMLFile(String,boolean)andfromPDFFile(String,boolean)parse an existing Factur-X XML document (or thefactur-x.xmlattachment of a hybrid PDF), detect the profile from its specification identifier, and return an instance of the matching subclass. - Computed fields.
setRecompute(boolean)selects whether computed fields (totals, tax amounts, and the like) are recomputed from the invoice contents or returned as they were read from the document. - Test generation.
toJUnitJavaSourceCode(PrintStream,String,String,String)emits JUnit source that rebuilds an identical invoice through API calls and compares its XML against a reference file.
main(String[]) is a command-line front end over these operations. It reads an invoice
from -xmlInput, -pdfInput or -input and performs the action named by
-action: xmlOutput and dataUrlOutput re-serialize the invoice,
rawXmlOutput copies the embedded XML verbatim, metadataOutput prints the PDF
metadata, JUnitJavaOutput emits a unit test, and validate (or the narrower
validateAgainstXSD / validateAgainstSchematronXSLT) validates the document against
the XML Schema and the Schematron rules. Validation needs the specification files, whose location
is given by the specification.directory system property; the specification.version
system property selects the release to validate against (1.09.2 by default, 1.0.07
and 1.0.06 are also known). Schematron warnings are reported but do not make a
document invalid or change the exit status.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanWhether the invoiced line net amountBT-131is computed by the API.static final booleanWhether the API emits debug tracing while it builds and serializes an invoice. -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractInvoicefromPDFFile(String fileName, boolean recompute) Creates an Invoice instance from a Factur-X hybrid PDF document.static AbstractInvoicefromXMLFile(String fileName, boolean recompute) Creates an Invoice instance from a Factur-X XML document.abstract AbstractInvoice.Profilestatic StringjoinVeryLongString(String[] chunks) Deprecated.static voidCommand-line entry point.static LocalDateDeprecated.UseUtil.parseDate(String)instead.voidsetRecompute(boolean value) Controls the computation of computed fields likeInvoice.getInvoiceTotalAmountWithoutVAT()By default the values are always computed but in the case that the values were explicitly set (e.g.abstract voidtoJUnitJavaSourceCode(PrintStream out, String packageName, String className, String referenceFilesDirectory) Creates JUnit Java source code that will construct an Invoice instance identical with this Invoice from API calls and compare the produced XML against a reference file.voidtoXML(PrintStream out) Serializes to a Factur-X XML document that matches the profile specific XML Schema.abstract voidtoXML(PrintWriter out) Serializes to a Factur-X XML document that matches the profile specific XML Schema.
-
Field Details
-
debug
public static final boolean debugWhether the API emits debug tracing while it builds and serializes an invoice. Whentrue, diagnostic lines prefixed with"FACTUR-X DEBUG"are written to standard output; whenfalse(the default), no such output is produced.The value is read once, at class initialization, from the
facturx.debugsystem property: it istrueonly when that property is set to"true"(for example-Dfacturx.debug=trueon the command line) andfalseotherwise. -
computeBT131
public static final boolean computeBT131Whether the invoiced line net amountBT-131is computed by the API. Whentrue(the default), each line'sBT-131is derived from its item net price and quantity and a value set through the corresponding setter is ignored unless recomputation is disabled; whenfalse,BT-131is not computed and the value you set is used as given.The value is read once, at class initialization, from the
facturx.computeBT131system property: it isfalseonly when that property is set to"false"(for example-Dfacturx.computeBT131=falseon the command line) andtrueotherwise.
-
-
Method Details
-
toXML
Serializes to a Factur-X XML document that matches the profile specific XML Schema.- Parameters:
out- the print stream to write to- Throws:
IOExceptionFacturXException
-
toXML
Serializes to a Factur-X XML document that matches the profile specific XML Schema.- Parameters:
out- the print stream to write to- Throws:
IOExceptionFacturXException
-
getProfile
-
getXMLAsDataURL
- Throws:
IOExceptionFacturXException
-
toJUnitJavaSourceCode
public abstract void toJUnitJavaSourceCode(PrintStream out, String packageName, String className, String referenceFilesDirectory) throws FacturXException Creates JUnit Java source code that will construct an Invoice instance identical with this Invoice from API calls and compare the produced XML against a reference file.- Parameters:
out- the print stream to write topackageName- the package name to use in the package declarationclassName- the name to use as class name for the test classreferenceFilesDirectory- the directory in which the test expects the reference output xml file that is namedclassName+".xml"- Throws:
FacturXException
-
main
Command-line entry point. It reads Factur-X documents and performs actions on them: one or more groups of the form-input <file>... -action <action>, processed left to right. Run it with-helpfor the usage text.The input is given by:
-input <file>...(alias-inputFileName)- one or more files, up to
the next option, for the following
-action; a.xmlname is read as XML and a.pdfname as a hybrid PDF. A name containing*or?in its last segment is expanded to the matching files, sorted by name (for shells that do not expand wildcards, such as the Windows command prompt); a pattern without a match is an error. -xmlInput <file>,-pdfInput <file>- older options: read one invoice
at once, for a following
-xmlOutputor-JUnitJavaOutput(also older) or an output action without-input
The action is selected by
-action <action>and performed on every input file:xmlOutput- re-serialize the invoice to Factur-X XML
dataUrlOutput- write the invoice as a base64
data:URL rawXmlOutput- copy the embedded XML verbatim, without re-serializing
metadataOutput- print the PDF metadata (PDF input only)
JUnitJavaOutput- emit JUnit source that rebuilds the invoice through API
calls (see
toJUnitJavaSourceCode(PrintStream,String,String,String)) validate,validateAgainstXSD,validateAgainstSchematronXSLT- validate the document against the XML Schema, the Schematron rules, or both
(
validate); the specification files used are those bundled with the product, or those below the directory given by thespecification.directorysystem property if it is set. Schematron warnings are reported but do not make the document invalid or change the exit status. With more than one input file, a summary line follows.
The remaining options tune the output:
-outputFileName <file>writes to a file instead of standard output (output actions, one input file only), and-packageName <name>,-className <name>and-referenceFilesDirectory <dir>supply the package, class name and reference-file directory used byJUnitJavaOutput.The order of the options matters, because they are processed left to right and
-actionacts immediately, on the state accumulated by the options that precede it: the input and every output option must therefore appear before the-actionthat uses them.A document that cannot be read or processed is reported and the remaining documents are still processed. The process exits with status
0if every action succeeded and every validated document is valid,1if a document is not valid or could not be processed, and2if the command line is wrong (unknown option or action, missing value, missing input); nothing is silently ignored.- Parameters:
args- the command-line arguments described above- Throws:
Exception- never in practice; errors are reported and turned into the exit status
-
setRecompute
public void setRecompute(boolean value) Controls the computation of computed fields likeInvoice.getInvoiceTotalAmountWithoutVAT()By default the values are always computed but in the case that the values were explicitly set (e.g. after creating and instance viafromXMLFile(String,boolean)), it might be desirable to obtain the explicitly set values instead.- Parameters:
value- whether or not to ignore explicitly set values of computed fields and work with computed values instead
-
fromXMLFile
Creates an Invoice instance from a Factur-X XML document.- Parameters:
fileName- the Factur-X XML file to read fromrecompute- specifies whether or not computed fields are computed or the values from the file are used instead- Throws:
IOException
-
fromPDFFile
Creates an Invoice instance from a Factur-X hybrid PDF document.- Parameters:
fileName- the Factur-X hybrid PDF file to read fromrecompute- specifies whether or not computed fields are computed or the values from the file are used instead- Returns:
- an Invoice instance or null if the PDF does not contain a file attachment named "factur-x.xml".
- Throws:
IOException
-
parseDate
Deprecated.UseUtil.parseDate(String)instead.parses dates in the Factur-x format YYYYMMDD- Throws:
DateTimeParseException
-
joinVeryLongString
-
Util.joinVeryLongString(String[])instead.