Package org.docx4j.openpackaging.exceptions

Examples of org.docx4j.openpackaging.exceptions.InvalidFormatException


   */
  public Relationship addTargetPart(Part targetpart, AddPartBehaviour mode, String proposedRelId
      ) throws InvalidFormatException {
   
    if ( this.getPackage()==null ) {           
      throw new InvalidFormatException("Package not set; if you are adding part2 to part1, make sure part1 is added first.");
    }
    if ( this instanceof RelationshipsPart ) {     
      throw new InvalidFormatException("You should add your part to the target part, not the target part's relationships part.");
    }
   
    // Now add the targetpart to the relationships
    Relationship rel = this.getRelationshipsPart().addPart(targetpart, mode,
        getPackage().getContentTypeManager(), proposedRelId);
View Full Code Here


    }
   
    String uriPath = partURI.getPath();
    if (uriPath.length() == 0
        || ((uriPath.length() == 1) && (uriPath.charAt(0) == URIHelper.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("")) {
      log.error( "" );
      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)) {
        log.error( "" );
        throw new InvalidFormatException(
            "A part name shall not have empty segments [M1.3]: "
                + partUri.getPath());
      }

      if (seg.endsWith(".")) {
        log.error( "" );
        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]
        log.error( "" );
        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)) {
          log.error( "" );
          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 == '\\') {
          log.error( "" );
          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) {
          log.error( "" );
          throw new InvalidFormatException(
              "A segment shall not contain percent-encoded unreserved characters. [M1.8]");
          }
      }

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

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

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

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

        }
      }
     
    } catch (Exception e ) {
      log.error(e.getMessage(), e);
      throw new InvalidFormatException("Bad [Content_Types].xml", e);
    }
   
   
  }
View Full Code Here

      p = new GloxPackage(this);
      return p;           
    }
       
    // Nothing in overrides or defaults
    throw new InvalidFormatException("Couldn't identify package from " + pkgContentType);
  }
View Full Code Here

    }
   
    // sanity check
    if (existsAlready!=null && mode.equals(AddPartBehaviour.RENAME_IF_NAME_EXISTS)) {
      // Shouldn't happen
      throw new InvalidFormatException("Found existing rel, and yet constructed part name should be globally unique!");
    }
   
    if (this.getPackage().getParts().get( newPartName )!=null
        && mode.equals(AddPartBehaviour.OVERWRITE_IF_NAME_EXISTS)) {
     
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.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.