Package org.apache.poi.openxml4j.opc

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


        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();
        }
        log.log(POILogger.WARN, "No part " + _defaultName + " found");
        return null;
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

      return false;
    }

    // Saving relationship part
    if (part.hasRelationships()) {
      PackagePartName relationshipPartName = PackagingURIHelper
          .getRelationshipPartName(part.getPartName());

      marshallRelationshipPart(part.getRelationships(),
          relationshipPartName, zos);
View Full Code Here

   */
  public void commit() throws IOException{

        if(extPart == null && !NEW_EXT_INSTANCE.toString().equals(ext.props.toString())){
            try {
                PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/app.xml");
                pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
                extPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.extended-properties+xml");
            } catch (InvalidFormatException e){
                throw new POIXMLException(e);
            }
        }
        if(custPart == null && !NEW_CUST_INSTANCE.toString().equals(cust.props.toString())){
            try {
                PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/custom.xml");
                pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties");
                custPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.custom-properties+xml");
            } catch (InvalidFormatException e){
                throw new POIXMLException(e);
            }
View Full Code Here

   */
  public void testPartNameComparaison() throws Exception {
    String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
    String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml", "/rels/.rels" };
    for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
      PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
      PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
      assertTrue(p1.equals(p2));
      assertTrue(p1.compareTo(p2) == 0);
      assertTrue(p1.hashCode() == p2.hashCode());
    }
  }
View Full Code Here

   */
  public void testPartNameComparaisonFailure() throws Exception {
    String[] partName1 = { "/word/document.xml", "/docProps/core.xml", "/rels/.rels" };
    String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml", "/rels/rels" };
    for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
      PackagePartName p1 = PackagingURIHelper.createPartName(partName1[i]);
      PackagePartName p2 = PackagingURIHelper.createPartName(partName2[i]);
      assertFalse(p1.equals(p2));
      assertFalse(p1.compareTo(p2) == 0);
      assertFalse(p1.hashCode() == p2.hashCode());
    }
  }
View Full Code Here

     *   {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
     */
    protected PackageRelationship addPictureReference(int pictureIndex){
        XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
        XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
        PackagePartName ppName = data.getPackagePart().getPartName();
        PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
        addRelation(rel.getId(),new XSSFPictureData(data.getPackagePart(), rel));
        return rel;
    }
View Full Code Here

     */
    protected static OPCPackage newPackage() {
        try {
            OPCPackage pkg = OPCPackage.create(new ByteArrayOutputStream());
            // 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

   */
  public void commit() throws IOException{

    if(extPart == null && !NEW_EXT_INSTANCE.toString().equals(ext.props.toString())){
      try {
        PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/app.xml");
        pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
        extPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.extended-properties+xml");
      } catch (InvalidFormatException e){
        throw new POIXMLException(e);
      }
    }
    if(custPart == null && !NEW_CUST_INSTANCE.toString().equals(cust.props.toString())){
      try {
        PackagePartName prtname = PackagingURIHelper.createPartName("/docProps/custom.xml");
        pkg.addRelationship(prtname, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties");
        custPart = pkg.createPart(prtname, "application/vnd.openxmlformats-officedocument.custom-properties+xml");
      } catch (InvalidFormatException e){
        throw new POIXMLException(e);
      }
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.