Package org.apache.poi.openxml4j.exceptions

Examples of org.apache.poi.openxml4j.exceptions.InvalidOperationException


        "Can't use output stream to set properties !");
  }

  @Override
  public boolean save(OutputStream zos) throws OpenXML4JException {
    throw new InvalidOperationException("Operation not authorized");
  }
View Full Code Here


    throw new InvalidOperationException("Operation not authorized");
  }

  @Override
  public boolean load(InputStream ios) throws InvalidFormatException {
    throw new InvalidOperationException("Operation not authorized");
  }
View Full Code Here

            deleteDefaultContentTypeFlag = false;
            break;
          }
        }
      } catch (InvalidFormatException e) {
        throw new InvalidOperationException(e.getMessage());
      }
    }

    // Remove the default content type, no other part use this content type.
    if (deleteDefaultContentTypeFlag) {
      this.defaultContentType.remove(extensionToDelete);
    }

    /*
     * Check rule 2.4: The package implementer shall require that the
     * Content Types stream contain one of the following for every part in
     * the package: One matching Default element One matching Override
     * element Both a matching Default element and a matching Override
     * element, in which case the Override element takes precedence.
     */
    if (this.container != null) {
      try {
        for (PackagePart part : this.container.getParts()) {
          if (!part.getPartName().equals(partName)
              && this.getContentType(part.getPartName()) == null)
            throw new InvalidOperationException(
                "Rule M2.4 is not respected: Nor a default element or override element is associated with the part: "
                    + part.getPartName().getName());
        }
      } catch (InvalidFormatException e) {
        throw new InvalidOperationException(e.getMessage());
      }
    }
  }
View Full Code Here

  public static OPCPackage create(File file) {
    if (file == null || (file.exists() && file.isDirectory()))
      throw new IllegalArgumentException("file");

    if (file.exists()) {
      throw new InvalidOperationException(
          "This package (or file) already exists : use the open() method or delete the file.");
    }

    // Creates a new package
    OPCPackage pkg = null;
View Full Code Here

      try {
        thumbnailPartName = PackagingURIHelper
            .createPartName("/docProps/thumbnail"
                + path.substring(path.lastIndexOf(".") + 1));
      } catch (InvalidFormatException e2) {
        throw new InvalidOperationException(
            "Can't add a thumbnail file named '" + filename + "'");
      }
    }

    // Check if part already exist
    if (this.getPart(thumbnailPartName) != null)
      throw new InvalidOperationException(
          "You already add a thumbnail named '" + filename + "'");

    // Add the thumbnail part to this package.
    PackagePart thumbnailPart = this.createPart(thumbnailPartName,
        contentType, false);
View Full Code Here

   *             Throws if a writing operation is done on a read only package.
   * @see org.apache.poi.openxml4j.opc.PackageAccess
   */
  void throwExceptionIfReadOnly() throws InvalidOperationException {
    if (packageAccess == PackageAccess.READ)
      throw new InvalidOperationException(
          "Operation not allowed, document open in read only mode!");
  }
View Full Code Here

   *             Throws if a read operation is done on a write only package.
   * @see org.apache.poi.openxml4j.opc.PackageAccess
   */
  void throwExceptionIfWriteOnly() throws InvalidOperationException {
    if (packageAccess == PackageAccess.WRITE)
      throw new InvalidOperationException(
          "Operation not allowed, document open in write only mode!");
  }
View Full Code Here

    }

    // Check if the specified part name already exists
    if (partList.containsKey(partName)
        && !partList.get(partName).isDeleted()) {
      throw new InvalidOperationException(
          "A part with the name '"
              + partName.getName()
              + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
    }

    /* Check OPC compliance */

    // Rule [M4.1]: The format designer shall specify and the format
    // producer
    // shall create at most one core properties relationship for a package.
    // A format consumer shall consider more than one core properties
    // relationship for a package to be an error. If present, the
    // relationship shall target the Core Properties part.
    if (contentType.equals(ContentTypes.CORE_PROPERTIES_PART)) {
      if (this.packageProperties != null)
        throw new InvalidOperationException(
            "OPC Compliance error [M4.1]: you try to add more than one core properties relationship in the package !");
    }

    /* End check OPC compliance */

 
View Full Code Here

      throw new IllegalArgumentException("part");
    }

    if (partList.containsKey(part._partName)) {
      if (!partList.get(part._partName).isDeleted()) {
        throw new InvalidOperationException(
            "A part with the name '"
                + part._partName.getName()
                + "' already exists : Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
      }
      // If the specified partis flagged as deleted, we make it
View Full Code Here

    // A format consumer shall consider more than one core properties
    // relationship for a package to be an error. If present, the
    // relationship shall target the Core Properties part.
    if (relationshipType.equals(PackageRelationshipTypes.CORE_PROPERTIES)
        && this.packageProperties != null)
      throw new InvalidOperationException(
          "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.");

    /*
     * Check rule M1.25: The Relationships part shall not have relationships
     * to any other part. Package implementers shall enforce this
     * requirement upon the attempt to create such a relationship and shall
     * treat any such relationship as invalid.
     */
    if (targetPartName.isRelationshipPartURI()) {
      throw new InvalidOperationException(
          "Rule M1.25: The Relationships part shall not have relationships to any other part.");
    }

    /* End OPC compliance */

 
View Full Code Here

TOP

Related Classes of org.apache.poi.openxml4j.exceptions.InvalidOperationException

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.