Package org.apache.poi.openxml4j.exceptions

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


  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

   * Validates the package compliance with the OPC specifications.
   *
   * @return <b>true</b> if the package is valid else <b>false</b>
   */
  public boolean validatePackage(OPCPackage pkg) throws InvalidFormatException {
    throw new InvalidOperationException("Not implemented yet !!!");
  }
View Full Code Here

    this.throwExceptionIfReadOnly();
   
    // You shouldn't save the the same file, do a close instead
    if(targetFile.exists() &&
            targetFile.getAbsolutePath().equals(this.originalPackagePath)) {
        throw new InvalidOperationException(
                "You can't call save(File) to save to the currently open " +
                "file. To save to the current file, please just call close()"
        );
    }
   
View Full Code Here

    if (PackagingURIHelper.PACKAGE_ROOT_URI.getPath() == partName.getURI()
        .getPath())
      return PackagingURIHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME;

    if (partName.isRelationshipPartURI())
      throw new InvalidOperationException("Can't be a relationship part");

    String fullPath = partName.getURI().getPath();
    String filename = getFilename(partName.getURI());
    fullPath = fullPath.substring(0, fullPath.length() - filename.length());
    fullPath = combine(fullPath,
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.