Package org.apache.poi.openxml4j.opc

Examples of org.apache.poi.openxml4j.opc.PackagePartName


         
          // If it has drawings, return those too
          try {
             for(PackageRelationship rel : part.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation())) {
                if(rel.getTargetMode() == TargetMode.INTERNAL) {
                   PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                   parts.add( rel.getPackage().getPart(relName) );
                }
             }
             for(PackageRelationship rel : part.getRelationshipsByType(XSSFRelation.VML_DRAWINGS.getRelation())) {
                if(rel.getTargetMode() == TargetMode.INTERNAL) {
                   PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                   parts.add( rel.getPackage().getPart(relName) );
                }
             }
          } catch(InvalidFormatException e) {
             throw new TikaException("Broken OOXML file", e);
View Full Code Here


              if( rel.getRelationshipType().equals(RELATION_AUDIO) ||
                  rel.getRelationshipType().equals(RELATION_IMAGE) ||
                  rel.getRelationshipType().equals(RELATION_OLE_OBJECT) ||
                  rel.getRelationshipType().equals(RELATION_PACKAGE) ) {
                 if(rel.getTargetMode() == TargetMode.INTERNAL) {
                    PackagePartName relName;
                    try {
                       relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                    } catch(InvalidFormatException e) {
                       throw new TikaException("Broken OOXML file", e);
                    }
View Full Code Here

        PackageRelationship rel = workbookPart.getRelationship(relId);
        if(rel == null) {
            throw new IllegalArgumentException("No Sheet found with r:id " + relId);
        }

        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart sheet = pkg.getPart(relName);
        if(sheet == null) {
            throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
        }
        return sheet.getInputStream();
View Full Code Here

            try {
                //step 1. Map sheet's relationship Id and the corresponding PackagePart
                sheetMap = new HashMap<String, PackagePart>();
                for(PackageRelationship rel : wb.getRelationships()){
                    if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation())){
                        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                        sheetMap.put(rel.getId(), wb.getPackage().getPart(relName));
                    }
                }
                //step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator
                //Note, using XMLBeans might be expensive, consider refactoring to use SAX or a plain regexp search
View Full Code Here

     */
    protected static Package newPackage() {
        try {
            Package pkg = Package.create(PackageHelper.createTempFile());
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
            // Create main document part
            pkg.createPart(corePartName, XSSFRelation.WORKBOOK.getContentType());

View Full Code Here

        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(_relation);
        Iterator<PackageRelationship> it = prc.iterator();
        if(it.hasNext()) {
            PackageRelationship rel = it.next();
            PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
            PackagePart part = corePart.getPackage().getPart(relName);
            return part.getInputStream();
        } else {
          log.log(POILogger.WARN, "No part " + _defaultName + " found");
          return null;
View Full Code Here

      Iterator elementIteratorOverride = overrideTypes.iterator();
      while (elementIteratorOverride.hasNext()) {
        Element element = (Element) elementIteratorOverride.next();
        URI uri = new URI(element.attribute(PART_NAME_ATTRIBUTE_NAME)
            .getValue());
        PackagePartName partName = PackagingURIHelper
            .createPartName(uri);
        String contentType = element.attribute(
            CONTENT_TYPE_ATTRIBUTE_NAME).getValue();
        addOverrideContentType(partName, contentType);
      }
View Full Code Here

     */
    protected static OPCPackage newPackage() {
        try {
            OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
            // Create main document part
            pkg.createPart(corePartName, XSSFRelation.WORKBOOK.getContentType());

View Full Code Here

  /**
   * Test createPartName(String, y)
   */
  public void testCreatePartNameRelativeString()
      throws InvalidFormatException {
    PackagePartName partNameToValid = PackagingURIHelper
        .createPartName("/word/media/image1.gif");

    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    // Base part
    PackagePartName nameBase = PackagingURIHelper
        .createPartName("/word/document.xml");
    PackagePart partBase = pkg.createPart(nameBase, ContentTypes.XML);
    // Relative part name
    PackagePartName relativeName = PackagingURIHelper.createPartName(
        "media/image1.gif", partBase);
    assertTrue("The part name must be equal to "
        + partNameToValid.getName(), partNameToValid
        .equals(relativeName));
    pkg.revert();
View Full Code Here

  /**
   * Test createPartName(URI, y)
   */
  public void testCreatePartNameRelativeURI() throws Exception {
    PackagePartName partNameToValid = PackagingURIHelper
        .createPartName("/word/media/image1.gif");

    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    // Base part
    PackagePartName nameBase = PackagingURIHelper
        .createPartName("/word/document.xml");
    PackagePart partBase = pkg.createPart(nameBase, ContentTypes.XML);
    // Relative part name
    PackagePartName relativeName = PackagingURIHelper.createPartName(
        new URI("media/image1.gif"), partBase);
    assertTrue("The part name must be equal to "
        + partNameToValid.getName(), partNameToValid
        .equals(relativeName));
    pkg.revert();
View Full Code Here

TOP

Related Classes of org.apache.poi.openxml4j.opc.PackagePartName

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.