use of org.apache.xmlbeans.XmlException in project poi by apache.
the class Office2010SignatureFacet method postSign.
@Override
public void postSign(Document document) throws MarshalException {
// check for XAdES-BES
NodeList nl = document.getElementsByTagNameNS(XADES_132_NS, "QualifyingProperties");
if (nl.getLength() != 1) {
throw new MarshalException("no XAdES-BES extension present");
}
QualifyingPropertiesType qualProps;
try {
qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), DEFAULT_XML_OPTIONS);
} catch (XmlException e) {
throw new MarshalException(e);
}
// create basic XML container structure
UnsignedPropertiesType unsignedProps = qualProps.getUnsignedProperties();
if (unsignedProps == null) {
unsignedProps = qualProps.addNewUnsignedProperties();
}
UnsignedSignaturePropertiesType unsignedSigProps = unsignedProps.getUnsignedSignatureProperties();
if (unsignedSigProps == null) {
/* unsignedSigProps = */
unsignedProps.addNewUnsignedSignatureProperties();
}
Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true);
nl.item(0).getParentNode().replaceChild(n, nl.item(0));
}
use of org.apache.xmlbeans.XmlException in project poi by apache.
the class XDGFPageContents method onDocumentRead.
@Override
protected void onDocumentRead() {
try {
try {
_pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
} catch (XmlException e) {
throw new POIXMLException(e);
} catch (IOException e) {
throw new POIXMLException(e);
}
for (POIXMLDocumentPart part : getRelations()) {
if (!(part instanceof XDGFMasterContents))
continue;
//throw new POIXMLException("Unexpected page relation: " + part);
XDGFMaster master = ((XDGFMasterContents) part).getMaster();
_masters.put(master.getID(), master);
}
super.onDocumentRead();
for (XDGFShape shape : _shapes.values()) {
if (shape.isTopmost())
shape.setupMaster(this, null);
}
} catch (POIXMLException e) {
throw XDGFException.wrap(this, e);
}
}
use of org.apache.xmlbeans.XmlException in project poi by apache.
the class XDGFPages method onDocumentRead.
@Override
protected void onDocumentRead() {
try {
try {
_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
} catch (XmlException e) {
throw new POIXMLException(e);
} catch (IOException e) {
throw new POIXMLException(e);
}
// this iteration is ordered by page number
for (PageType pageSettings : _pagesObject.getPageArray()) {
String relId = pageSettings.getRel().getId();
POIXMLDocumentPart pageContentsPart = getRelationById(relId);
if (pageContentsPart == null)
throw new POIXMLException("PageSettings relationship for " + relId + " not found");
if (!(pageContentsPart instanceof XDGFPageContents))
throw new POIXMLException("Unexpected pages relationship for " + relId + ": " + pageContentsPart);
XDGFPageContents contents = (XDGFPageContents) pageContentsPart;
XDGFPage page = new XDGFPage(pageSettings, contents, _document, this);
contents.onDocumentRead();
_pages.add(page);
}
} catch (POIXMLException e) {
throw XDGFException.wrap(this, e);
}
}
use of org.apache.xmlbeans.XmlException in project poi by apache.
the class ExtractorFactory method getEmbededDocsTextExtractors.
/**
* Returns an array of text extractors, one for each of
* the embedded documents in the file (if there are any).
* If there are no embedded documents, you'll get back an
* empty array. Otherwise, you'll get one open
* {@link POITextExtractor} for each embedded file.
*/
public static POITextExtractor[] getEmbededDocsTextExtractors(POIOLE2TextExtractor ext) throws IOException, OpenXML4JException, XmlException {
// All the embedded directories we spotted
ArrayList<Entry> dirs = new ArrayList<Entry>();
// For anything else not directly held in as a POIFS directory
ArrayList<InputStream> nonPOIFS = new ArrayList<InputStream>();
// Find all the embedded directories
DirectoryEntry root = ext.getRoot();
if (root == null) {
throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
}
if (ext instanceof ExcelExtractor) {
// These are in MBD... under the root
Iterator<Entry> it = root.getEntries();
while (it.hasNext()) {
Entry entry = it.next();
if (entry.getName().startsWith("MBD")) {
dirs.add(entry);
}
}
} else if (ext instanceof WordExtractor) {
// These are in ObjectPool -> _... under the root
try {
DirectoryEntry op = (DirectoryEntry) root.getEntry("ObjectPool");
Iterator<Entry> it = op.getEntries();
while (it.hasNext()) {
Entry entry = it.next();
if (entry.getName().startsWith("_")) {
dirs.add(entry);
}
}
} catch (FileNotFoundException e) {
logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
// ignored here
}
//} else if(ext instanceof PowerPointExtractor) {
// Tricky, not stored directly in poifs
// TODO
} else if (ext instanceof OutlookTextExtactor) {
// Stored in the Attachment blocks
MAPIMessage msg = ((OutlookTextExtactor) ext).getMAPIMessage();
for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
if (attachment.getAttachData() != null) {
byte[] data = attachment.getAttachData().getValue();
nonPOIFS.add(new ByteArrayInputStream(data));
} else if (attachment.getAttachmentDirectory() != null) {
dirs.add(attachment.getAttachmentDirectory().getDirectory());
}
}
}
// Create the extractors
if (dirs.size() == 0 && nonPOIFS.size() == 0) {
return new POITextExtractor[0];
}
ArrayList<POITextExtractor> textExtractors = new ArrayList<POITextExtractor>();
for (Entry dir : dirs) {
textExtractors.add(createExtractor((DirectoryNode) dir));
}
for (InputStream nonPOIF : nonPOIFS) {
try {
textExtractors.add(createExtractor(nonPOIF));
} catch (IllegalArgumentException e) {
// Ignore, just means it didn't contain
// a format we support as yet
logger.log(POILogger.INFO, "Format not supported yet", e.getLocalizedMessage());
} catch (XmlException e) {
throw new IOException(e.getMessage(), e);
} catch (OpenXML4JException e) {
throw new IOException(e.getMessage(), e);
}
}
return textExtractors.toArray(new POITextExtractor[textExtractors.size()]);
}
use of org.apache.xmlbeans.XmlException in project poi by apache.
the class ExtractorFactory method createExtractor.
public static POITextExtractor createExtractor(File f) throws IOException, OpenXML4JException, XmlException {
NPOIFSFileSystem fs = null;
try {
fs = new NPOIFSFileSystem(f);
POIOLE2TextExtractor extractor = createExtractor(fs);
extractor.setFilesystem(fs);
return extractor;
} catch (OfficeXmlFileException e) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ));
} catch (NotOLE2FileException ne) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
} catch (OpenXML4JException e) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw e;
} catch (XmlException e) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw e;
} catch (IOException e) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw e;
} catch (RuntimeException e) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw e;
}
}
Aggregations