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


        String contentType = element.attribute(
            CONTENT_TYPE_ATTRIBUTE_NAME).getValue();
        addOverrideContentType(partName, contentType);
      }
    } catch (URISyntaxException urie) {
      throw new InvalidFormatException(urie.getMessage());
    } catch (DocumentException e) {
      throw new InvalidFormatException(e.getMessage());
    }
  }
View Full Code Here

    while (itNS.hasNext()) {
      Namespace ns = itNS.next();

      // Rule M4.2
      if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY))
        throw new InvalidFormatException(
            "OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
    }

    // Rule M4.3
    if (el.getNamespace().getURI().equals(
        PackageProperties.NAMESPACE_DCTERMS)
        && !(el.getName().equals(KEYWORD_CREATED) || el.getName()
            .equals(KEYWORD_MODIFIED)))
      throw new InvalidFormatException(
          "OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");

    // Rule M4.4
    if (el.attribute(new QName("lang", namespaceXML)) != null)
      throw new InvalidFormatException(
          "OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");

    // Rule M4.5
    if (el.getNamespace().getURI().equals(
        PackageProperties.NAMESPACE_DCTERMS)) {
      // DCTerms namespace only use with 'created' and 'modified' elements
      String elName = el.getName();
      if (!(elName.equals(KEYWORD_CREATED) || elName
          .equals(KEYWORD_MODIFIED)))
        throw new InvalidFormatException("Namespace error : " + elName
            + " shouldn't have the following naemspace -> "
            + PackageProperties.NAMESPACE_DCTERMS);

      // Check for the 'xsi:type' attribute
      Attribute typeAtt = el.attribute(new QName("type", namespaceXSI));
      if (typeAtt == null)
        throw new InvalidFormatException("The element '" + elName
            + "' must have the '" + namespaceXSI.getPrefix()
            + ":type' attribute present !");

      // Check for the attribute value => 'dcterms:W3CDTF'
      if (!typeAtt.getValue().equals("dcterms:W3CDTF"))
        throw new InvalidFormatException("The element '" + elName
            + "' must have the '" + namespaceXSI.getPrefix()
            + ":type' attribute with the value 'dcterms:W3CDTF' !");
    }

    // Check its children
View Full Code Here

       if(target.getFragment() != null) {
          String t = target.toString();
          try {
             target = new URI( t.substring(0, t.indexOf('#')) );
          } catch(URISyntaxException e) {
             throw new InvalidFormatException("Invalid target URI: " + target);
          }
       }
  
       // Turn that into a name, and fetch
       PackagePartName relName = PackagingURIHelper.createPartName(target);
View Full Code Here

   *             If the specified content type is not valid with RFC 2616.
   */
  public ContentType(String contentType) throws InvalidFormatException {
    Matcher mMediaType = patternMediaType.matcher(contentType);
    if (!mMediaType.matches())
      throw new InvalidFormatException(
          "The specified content type '"
              + contentType
              + "' is not compliant with RFC 2616: malformed content type.");

    // Type/subtype
View Full Code Here

    SimpleDateFormat df = new SimpleDateFormat(
        "yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date d = df.parse(s, new ParsePosition(0));
    if (d == null) {
      throw new InvalidFormatException("Date not well formated");
    }
    return new Nullable<Date>(d);
  }
View Full Code Here

                // Check Rule M4.1
                if (type.equals(PackageRelationshipTypes.CORE_PROPERTIES))
                    if (!fCorePropertiesRelationship)
                        fCorePropertiesRelationship = true;
                    else
                        throw new InvalidFormatException(
                                "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");

                /* End OPC Compliance */

                // TargetMode (default value "Internal")
                Attr targetModeAttr = element.getAttributeNode(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME);
                TargetMode targetMode = TargetMode.INTERNAL;
                if (targetModeAttr != null) {
                    targetMode = targetModeAttr.getValue().toLowerCase()
                            .equals("internal") ? TargetMode.INTERNAL
                            : TargetMode.EXTERNAL;
                }

                // Target converted in URI
                URI target = PackagingURIHelper.toURI("http://invalid.uri"); // dummy url
                String value = element.getAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME);
                try {
                    // when parsing of the given uri fails, we can either
                    // ignore this relationship, which leads to IllegalStateException
                    // later on, or use a dummy value and thus enable processing of the
                    // package
                    target = PackagingURIHelper.toURI(value);
                } catch (URISyntaxException e) {
                    logger.log(POILogger.ERROR, "Cannot convert " + value
                            + " in a valid relationship URI-> dummy-URI used", e);
                }
                addRelationship(target, targetMode, type, id);
            }
        } catch (Exception e) {
            logger.log(POILogger.ERROR, e);
            throw new InvalidFormatException(e.getMessage());
        }
    }
View Full Code Here

    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

      PackagePart[] parts = this.getPartsImpl();
      this.partList = new PackagePartCollection();
      for (PackagePart part : parts) {
        if (partList.containsKey(part._partName))
          throw new InvalidFormatException(
              "A part with the name '"
                  + part._partName
                  + "' already exist : 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
        if (part.getContentType().equals(
            ContentTypes.CORE_PROPERTIES_PART)) {
          if (!hasCorePropertiesPart)
            hasCorePropertiesPart = true;
          else
            throw new InvalidFormatException(
                "OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !");
        }

        PartUnmarshaller partUnmarshaller = partUnmarshallers
            .get(part._contentType);

        if (partUnmarshaller != null) {
          UnmarshallContext context = new UnmarshallContext(this,
              part._partName);
          try {
            PackagePart unmarshallPart = partUnmarshaller
                .unmarshall(context, part.getInputStream());
            partList.put(unmarshallPart._partName, unmarshallPart);

            // Core properties case
            if (unmarshallPart instanceof PackagePropertiesPart)
              this.packageProperties = (PackagePropertiesPart) unmarshallPart;
          } catch (IOException ioe) {
            logger.log(POILogger.WARN, "Unmarshall operation : IOException for "
                + part._partName);
            continue;
          } catch (InvalidOperationException invoe) {
            throw new InvalidFormatException(invoe.getMessage());
          }
        } else {
          try {
            partList.put(part._partName, part);
          } catch (InvalidOperationException e) {
            throw new InvalidFormatException(e.getMessage());
          }
        }
      }
    }
    return new ArrayList<PackagePart>(partList.values());
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.