comment editing and cosmetic improvements
This commit is contained in:
@@ -56,28 +56,33 @@ import java.util.logging.Logger;
|
|||||||
public class ZUGFeRDImporter {
|
public class ZUGFeRDImporter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var if metadata has been found
|
* if metadata has been found
|
||||||
*/
|
*/
|
||||||
private boolean containsMeta = false;
|
private boolean containsMeta = false;
|
||||||
/**
|
/**
|
||||||
* @var the reference (i.e. invoice number) of the sender
|
* map filenames of additional XML files to their contents
|
||||||
*/
|
*/
|
||||||
private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
|
private HashMap<String, byte[]> additionalXMLs = new HashMap<>();
|
||||||
/**
|
/**
|
||||||
* Raw XML form of the extracted data - may be directly obtained.
|
* Raw XML form of the extracted data - may be directly obtained.
|
||||||
*/
|
*/
|
||||||
private byte[] rawXML = null;
|
private byte[] rawXML = null;
|
||||||
|
/**
|
||||||
|
* XMP metadata
|
||||||
|
*/
|
||||||
private String xmpString = null; // XMP metadata
|
private String xmpString = null; // XMP metadata
|
||||||
|
/**
|
||||||
|
* parsed Document
|
||||||
|
*/
|
||||||
private Document document;
|
private Document document;
|
||||||
|
|
||||||
public ZUGFeRDImporter(String pdfFilename) {
|
public ZUGFeRDImporter(String pdfFilename) {
|
||||||
|
|
||||||
try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) {
|
try (InputStream bis = Files.newInputStream(Paths.get(pdfFilename), StandardOpenOption.READ)) {
|
||||||
extractLowLevel(bis);
|
extractLowLevel(bis);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||||
throw new ZUGFeRDExportException(e);
|
throw new ZUGFeRDExportException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZUGFeRDImporter(InputStream pdfStream) {
|
public ZUGFeRDImporter(InputStream pdfStream) {
|
||||||
@@ -133,8 +138,7 @@ public class ZUGFeRDImporter {
|
|||||||
PDComplexFileSpecification fileSpec = names.get(alias);
|
PDComplexFileSpecification fileSpec = names.get(alias);
|
||||||
String filename=fileSpec.getFilename();
|
String filename=fileSpec.getFilename();
|
||||||
/**
|
/**
|
||||||
* currently (in the release candidate of version 1) only one attached file with
|
* filenames for invoice data (ZUGFeRD v1 and v2, Factur-X)
|
||||||
* the name ZUGFeRD-invoice.xml is allowed
|
|
||||||
*/
|
*/
|
||||||
if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) || filename.equals("factur-x.xml"))) { //$NON-NLS-1$
|
if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) || filename.equals("factur-x.xml"))) { //$NON-NLS-1$
|
||||||
containsMeta = true;
|
containsMeta = true;
|
||||||
@@ -153,10 +157,8 @@ public class ZUGFeRDImporter {
|
|||||||
// fos.close();
|
// fos.close();
|
||||||
}
|
}
|
||||||
if (filename.startsWith("additional_data")) {
|
if (filename.startsWith("additional_data")) {
|
||||||
|
|
||||||
PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
|
PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
|
||||||
additionalXMLs.put(filename, embeddedFile.toByteArray());
|
additionalXMLs.put(filename, embeddedFile.toByteArray());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +178,16 @@ public class ZUGFeRDImporter {
|
|||||||
System.err.println(output);
|
System.err.println(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Document getDocument() { return document; }
|
private Document getDocument() { return document; }
|
||||||
|
|
||||||
|
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
||||||
|
DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance();
|
||||||
|
xmlFact.setNamespaceAware(false);
|
||||||
|
DocumentBuilder builder = xmlFact.newDocumentBuilder();
|
||||||
|
ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
||||||
|
is.skip(guessBOMSize(is));
|
||||||
|
document = builder.parse(is);
|
||||||
|
}
|
||||||
|
|
||||||
public void setRawXML(byte[] rawXML) throws IOException {
|
public void setRawXML(byte[] rawXML) throws IOException {
|
||||||
this.rawXML = rawXML;
|
this.rawXML = rawXML;
|
||||||
@@ -188,15 +199,6 @@ public class ZUGFeRDImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDocument() throws ParserConfigurationException, IOException, SAXException {
|
|
||||||
DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance();
|
|
||||||
xmlFact.setNamespaceAware(false);
|
|
||||||
DocumentBuilder builder = xmlFact.newDocumentBuilder();
|
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream(rawXML);
|
|
||||||
is.skip(guessBOMSize(is));
|
|
||||||
document = builder.parse(is);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips over a BOM at the beginning of the given ByteArrayInputStream, if one exists.
|
* Skips over a BOM at the beginning of the given ByteArrayInputStream, if one exists.
|
||||||
* @param is the ByteArrayInputStream used
|
* @param is the ByteArrayInputStream used
|
||||||
|
|||||||
Reference in New Issue
Block a user