Example usage for org.apache.poi.openxml4j.opc PackageRelationship getSourceURI

List of usage examples for org.apache.poi.openxml4j.opc PackageRelationship getSourceURI

Introduction

In this page you can find the example usage for org.apache.poi.openxml4j.opc PackageRelationship getSourceURI.

Prototype

public URI getSourceURI() 

Source Link

Usage

From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.AbstractOOXMLExtractor.java

License:Apache License

private void handleEmbeddedParts(ContentHandler handler) throws TikaException, IOException, SAXException {
    try {//from  w  ww  .ja va2 s. c o  m
        for (PackagePart source : getMainDocumentParts()) {
            for (PackageRelationship rel : source.getRelationships()) {

                URI sourceURI = rel.getSourceURI();
                String sourceDesc;
                if (sourceURI != null) {
                    sourceDesc = getJustFileName(sourceURI.getPath());
                    if (sourceDesc.startsWith("slide")) {
                        sourceDesc += "_";
                    } else {
                        sourceDesc = "";
                    }
                } else {
                    sourceDesc = "";
                }
                if (rel.getTargetMode() == TargetMode.INTERNAL) {
                    PackagePart target;

                    try {
                        target = source.getRelatedPart(rel);
                    } catch (IllegalArgumentException ex) {
                        continue;
                    }

                    String type = rel.getRelationshipType();
                    if (RELATION_OLE_OBJECT.equals(type) && TYPE_OLE_OBJECT.equals(target.getContentType())) {
                        handleEmbeddedOLE(target, handler, sourceDesc + rel.getId());
                    } else if (RELATION_AUDIO.equals(type) || RELATION_IMAGE.equals(type)
                            || RELATION_PACKAGE.equals(type) || RELATION_OLE_OBJECT.equals(type)) {
                        handleEmbeddedFile(target, handler, sourceDesc + rel.getId());
                    }
                }
            }
        }
    } catch (InvalidFormatException e) {
        throw new TikaException("Broken OOXML file", e);
    }
}