Package org.apache.poi.openxml4j.exceptions

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


    this.defaultContentType = new TreeMap<String, String>();
    if (in != null) {
      try {
        parseContentTypesFile(in);
      } catch (InvalidFormatException e) {
        throw new InvalidFormatException(
            "Can't read content types part !");
      }
    }
  }
View Full Code Here


        PackagePartName partName = PackagingURIHelper.createPartName(uri);
        String contentType = element.getAttribute(CONTENT_TYPE_ATTRIBUTE_NAME);
        addOverrideContentType(partName, contentType);
      }
    } catch (URISyntaxException urie) {
      throw new InvalidFormatException(urie.getMessage());
        } catch (SAXException e) {
            throw new InvalidFormatException(e.getMessage());
        } catch (IOException e) {
            throw new InvalidFormatException(e.getMessage());
        }
    }
View Full Code Here

      throw new IllegalArgumentException("partURI");

    String uriPath = partURI.getPath();
    if (uriPath.length() == 0
        || ((uriPath.length() == 1) && (uriPath.charAt(0) == PackagingURIHelper.FORWARD_SLASH_CHAR)))
      throw new InvalidFormatException(
          "A part name shall not be empty [M1.1]: "
              + partURI.getPath());
  }
View Full Code Here

    }

    // Split the URI into several part and analyze each
    String[] segments = partUri.toASCIIString().split("/");
    if (segments.length <= 1 || !segments[0].equals(""))
      throw new InvalidFormatException(
          "A part name shall not have empty segments [M1.3]: "
              + partUri.getPath());

    for (int i = 1; i < segments.length; ++i) {
      String seg = segments[i];
      if (seg == null || "".equals(seg)) {
        throw new InvalidFormatException(
            "A part name shall not have empty segments [M1.3]: "
                + partUri.getPath());
      }

      if (seg.endsWith(".")) {
        throw new InvalidFormatException(
            "A segment shall not end with a dot ('.') character [M1.9]: "
                + partUri.getPath());
      }

      if ("".equals(seg.replaceAll("\\\\.", ""))) {
        // Normally will never been invoked with the previous
        // implementation rule [M1.9]
        throw new InvalidFormatException(
            "A segment shall include at least one non-dot character. [M1.10]: "
                + partUri.getPath());
      }

      /*
 
View Full Code Here

      if (errorFlag && c == '%') {
        // We certainly found an encoded character, check for length
        // now ( '%' HEXDIGIT HEXDIGIT)
        if (((segment.length() - i) < 2)) {
          throw new InvalidFormatException("The segment " + segment
              + " contain invalid encoded character !");
        }

        // If not percent encoded character error occur then reset the
        // flag -> the character is valid
        errorFlag = false;

        // Decode the encoded character
        char decodedChar = (char) Integer.parseInt(segment.substring(
            i + 1, i + 3), 16);
        i += 2;

        /* Check rule M1.7 */
        if (decodedChar == '/' || decodedChar == '\\')
          throw new InvalidFormatException(
              "A segment shall not contain percent-encoded forward slash ('/'), or backward slash ('\') characters. [M1.7]");

        /* Check rule M1.8 */

        // Check for unreserved character like define in RFC3986
        if ((decodedChar >= 'A' && decodedChar <= 'Z')
            || (decodedChar >= 'a' && decodedChar <= 'z')
            || (decodedChar >= '0' && decodedChar <= '9'))
          errorFlag = true;

        // Check for unreserved character "-", ".", "_", "~"
        for (int j = 0; !errorFlag
            && j < RFC3986_PCHAR_UNRESERVED_SUP.length; ++j) {
          if (c == RFC3986_PCHAR_UNRESERVED_SUP[j].charAt(0)) {
            errorFlag = true;
            break;
          }
        }
        if (errorFlag)
          throw new InvalidFormatException(
              "A segment shall not contain percent-encoded unreserved characters. [M1.8]");
      }

      if (errorFlag)
        throw new InvalidFormatException(
            "A segment shall not hold any characters other than pchar characters. [M1.6]");
    }
  }
View Full Code Here

  private static void throwExceptionIfPartNameNotStartsWithForwardSlashChar(
      URI partUri) throws InvalidFormatException {
    String uriPath = partUri.getPath();
    if (uriPath.length() > 0
        && uriPath.charAt(0) != PackagingURIHelper.FORWARD_SLASH_CHAR)
      throw new InvalidFormatException(
          "A part name shall start with a forward slash ('/') character [M1.4]: "
              + partUri.getPath());
  }
View Full Code Here

  private static void throwExceptionIfPartNameEndsWithForwardSlashChar(
      URI partUri) throws InvalidFormatException {
    String uriPath = partUri.getPath();
    if (uriPath.length() > 0
        && uriPath.charAt(uriPath.length() - 1) == PackagingURIHelper.FORWARD_SLASH_CHAR)
      throw new InvalidFormatException(
          "A part name shall not have a forward slash as the last character [M1.5]: "
              + partUri.getPath());
  }
View Full Code Here

   *             Throws if the specified URI is absolute.
   */
  private static void throwExceptionIfAbsoluteUri(URI partUri)
      throws InvalidFormatException {
    if (partUri.isAbsolute())
      throw new InvalidFormatException("Absolute URI forbidden: "
          + partUri);
  }
View Full Code Here

      throws InvalidFormatException {
    URI partNameURI;
    try {
      partNameURI = new URI(partName);
    } catch (URISyntaxException e) {
      throw new InvalidFormatException(e.getMessage());
    }
    return createPartName(partNameURI);
  }
View Full Code Here

    URI newPartNameURI;
    try {
      newPartNameURI = resolvePartUri(
          relativePart.getPartName().getURI(), new URI(partName));
    } catch (URISyntaxException e) {
      throw new InvalidFormatException(e.getMessage());
    }
    return createPartName(newPartNameURI);
  }
View Full Code Here

TOP

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

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.