Package org.docx4j.openpackaging.parts

Examples of org.docx4j.openpackaging.parts.Part


   
    for (CTRel rel : hdrFtrRefs) {
      String relId = rel.getId();
      log.debug("for h|f relId: " + relId);
     
      Part part = rels.getPart(relId);
      if (rel instanceof HeaderReference  ) {
       
        HeaderReference headerReference = (HeaderReference)rel;
       
        if (headerReference.getType() == HdrFtrRef.FIRST) {
View Full Code Here


   
    for (CTRel rel : hdrFtrRefs) {
      String relId = rel.getId();
      log.debug("for h|f relId: " + relId);
     
      Part part = rels.getPart(relId);
      if (rel instanceof FooterReference  ) {
       
        FooterReference footerReference = (FooterReference)rel;
       
        if (footerReference.getType() == HdrFtrRef.FIRST) {
View Full Code Here

        // TODO - if this is already in our hashmap, skip
        // to the next       
        if (!false) {
          log.info("Getting part /" + resolvedPartUri );
         
          Part part = packageIn.getParts().get(new PartName("/" + resolvedPartUri));
         
          if (part==null) {
            log.error("Part " + resolvedPartUri + " not found!");
          } else {
            log.info(part.getClass().getName() );
          }
         
          savePart(part);
         
        }
View Full Code Here

    Relationships targetRelationships = null;
   
    Relationship sourceRelationship = null;
    Relationship targetRelationship = null;
   
    Part sourceChild = null;
    Part targetChild = null;
   
    if ((sourceRelationshipList != null) &&
      (!sourceRelationshipList.isEmpty())) {
     
      targetRelationshipsPart = targetPart.getRelationshipsPart(); //create if needed
View Full Code Here

  }

  protected static Part deepCopyPart(OpcPackage opcPackage, Base targetParent, Part sourcePart, Set<String> relationshipTypes) throws Docx4JException {

    //check if already handled
    Part ret = opcPackage.getParts().get(sourcePart.getPartName());
    if (ret == null) {
      //
      ret = copyPart(sourcePart,
               opcPackage, ((relationshipTypes == null) ||
                        relationshipTypes.contains(sourcePart.getRelationshipType()))
               );
      opcPackage.getParts().put(ret);
      targetParent.setPartShortcut(ret, ret.getRelationshipType());
    }
    return ret;
  }
View Full Code Here

    return ret;
  }


  protected static Part copyPart(Part part, OpcPackage targetPackage, boolean deepCopy) throws Docx4JException {
  Part ret = null;
    try {
      ret = part.getClass().getConstructor(PartName.class).newInstance(part.getPartName());
    } catch (Exception e) {
      throw new Docx4JException("Error cloning part of class " + part.getClass().getName(), e);
    }
    ret.setRelationshipType(part.getRelationshipType());
    ret.setContentType(new ContentType(part.getContentType()));
    if (targetPackage != null) {
      ret.setPackage(targetPackage);
    }
    if (deepCopy) {
      deepCopyContent(part, ret);
    }
    else {
View Full Code Here

      Base attachmentPoint,
      ContentTypeManager foreignCtm,
      String resolvedPartUri, InputStream is) throws Exception{
   
   
    Part foreignPart = Load.getRawPart(is, foreignCtm,  resolvedPartUri, null);
      // the null means this won't work for an AlternativeFormatInputPart
    attachmentPoint.addTargetPart(foreignPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // Add content type
    ContentTypeManager packageCtm = wordMLPackage.getContentTypeManager();
    packageCtm.addOverrideContentType(foreignPart.getPartName().getURI(), foreignPart.getContentType());
   
    System.out.println("Attached foreign part: " + resolvedPartUri);
   
  }
View Full Code Here

     
      try {
        String resolvedPartUri = URIHelper.resolvePartUri(rp.getSourceURI(), new URI(r.getTarget() ) ).toString();   
        resolvedPartUri = resolvedPartUri.substring(1)
       
        Part part = rp.getPart(r);
       
        // Or could  have done:
        // Part part = wordMLPackage.getParts().get(new PartName("/" + resolvedPartUri));
       
        if (part!=null) {
          printInfo(part, sb, indent);         
        }
       
        if (part==null) {
          sb.append("Part " + resolvedPartUri + " not found! \n");
        } else if ( part instanceof org.docx4j.openpackaging.parts.ThemePart
              || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart
              || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.FontTablePart) {       
          deletions.add(r );           
          sb.append(".. DELETED" );           
        } else if (part instanceof org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) {
         
          if (!keepStyles) {
            deletions.add(r );           
            sb.append(".. DELETED" );           
          } else {
            sb.append(".. KEEPING" );           
          }
         
        } else {         
          if (stripPropertiesParts
              && ( part instanceof org.docx4j.openpackaging.parts.DocPropsExtendedPart
                  || part instanceof org.docx4j.openpackaging.parts.DocPropsCorePart
                  || part instanceof org.docx4j.openpackaging.parts.DocPropsCustomPart
                  || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.WebSettingsPart
                  || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.DocumentSettingsPart)) {
           
            deletions.add(r );
            sb.append(".. DELETED" );           
           
          } else if ( part instanceof org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
              || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart
              || part instanceof org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart) {
            sb.append(".. KEEPING" );
            if (part.getRelationshipsPart()==null) {
              sb.append(".. no rels" );           
            } else {
              traverseRelationships(wordMLPackage, part.getRelationshipsPart(), sb, indent + "    ");
            }
          }
          else if (defaultToDelete) {
            // Delete it
            deletions.add(r );
View Full Code Here

       
        if (!false) {
          log.debug("Getting part /" + resolvedPartUri );
         
          //Part part = p.getParts().get(new PartName("/" + resolvedPartUri));
          Part part = rp.getPart(r);
            // 2012 09 26: If the part is actually attached to
            // a different package, using this you can still get it.
            // Use this 'feature' at your own risk!
         
          if (part==null) {
            log.error("Part " + resolvedPartUri + " not found!");
          } else {
            log.debug(part.getClass().getName() );
          }

          if (part.getPackage()==null) {
            log.warn("Packae is not set on Part " + resolvedPartUri);
          } else if (!part.getPackage().equals(p)) {
            log.warn("Part " + resolvedPartUri + " is attached to some other package");
          }
         
          savePart(out, part);
         
View Full Code Here

    // though part.getPackage() will only return the dest package.
    // So, be careful, you should throw away source package after doing this! 
    // TODO: This example probably should be re-worked.
    RelationshipsPart rp = wmlSourcePkg.getMainDocumentPart().getRelationshipsPart();
    Relationship rel = rp.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);   
    Part p = rp.getPart(rel);
   
    System.out.println(p.getPartName().getName() );
   
    //p.setPartName( new PartName(p.getPartName().getName()) ); // same name
      // WARNING: that has the effect of removing the part of old name
      // from wmlSourcePkg, and adding it again - with same name.
      // So there is not much point in doing that.
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.Part

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.