Package org.apache.poi.openxml4j.opc

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


     *   {@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(new XSSFPictureData(data.getPackagePart(), rel));
        return rel;
    }
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();
        }
        log.log(POILogger.WARN, "No part " + _defaultName + " found");
        return null;
View Full Code Here

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

View Full Code Here

     * @throws InvalidFormatException
     */
    public int getNextPicNameNumber(int format) throws InvalidFormatException{
      int img = getAllPackagePictures().size()+1;
       String proposal = XWPFPictureData.RELATIONS[format].getFileName(img);
       PackagePartName createPartName = PackagingURIHelper.createPartName(proposal);
    while (this.getPackage().getPart(createPartName)!= null){
      img++;
      proposal = XWPFPictureData.RELATIONS[format].getFileName(img);
      createPartName = PackagingURIHelper.createPartName(proposal);
    }
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 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

   * [M1.11]
   */
  public void testPartNameDerivationAdditionFailure() {
    OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
    try {
      PackagePartName name = PackagingURIHelper
          .createPartName("/word/document.xml");
      PackagePartName nameDerived = PackagingURIHelper
          .createPartName("/word/document.xml/image1.gif");
      pkg.createPart(name, ContentTypes.XML);
      pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
    } catch (InvalidOperationException e) {
      pkg.revert();
View Full Code Here

   * implementers shall neither create nor recognize packages with equivalent
   * part names.
   */
  public void testAddPackageAlreadyAddFailure() throws Exception {
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    PackagePartName name1 = null;
    PackagePartName name2 = null;
    try {
      name1 = PackagingURIHelper.createPartName("/word/document.xml");
      name2 = PackagingURIHelper.createPartName("/word/document.xml");
    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
View Full Code Here

   * implementers shall neither create nor recognize packages with equivalent
   * part names.
   */
  public void testAddPackageAlreadyAddFailure2() throws Exception {
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    PackagePartName partName = null;
    try {
      partName = PackagingURIHelper.createPartName("/word/document.xml");
    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
    }
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.