Examples of HeaderPart


Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
   
    int relsCountBefore = wordMLPackage.getMainDocumentPart().getRelationshipsPart().size();
    int partsCountBefore = wordMLPackage.getParts().getParts().size();
   
    HeaderPart part = new HeaderPart();   
    wordMLPackage.getMainDocumentPart().addTargetPart(part, mode);
   
    // Just added a part
    Assert.assertTrue("hmm", wordMLPackage.getMainDocumentPart().getRelationshipsPart().size()==relsCountBefore+1);
    Assert.assertTrue("hmm", wordMLPackage.getParts().getParts().size()==partsCountBefore+1);   
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

  private void inPkg(AddPartBehaviour mode, int partsAdded, int relsAdded, boolean expectReplace) throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();

    HeaderPart part = new HeaderPart();   
    wordMLPackage.getMainDocumentPart().addTargetPart(part, mode);
   
//    int mdpRelsCountBefore = wordMLPackage.getMainDocumentPart().getRelationshipsPart().size();
    int rootRelsCountBefore = wordMLPackage.getRelationshipsPart().size();
    int partsCountBefore = wordMLPackage.getParts().getParts().size();

    // Add it again
    // Note that we're adding this ELSEWHERE in the pkg for the purposes of this test only
    HeaderPart part2 = new HeaderPart()
    Relationship rel = wordMLPackage.addTargetPart(part2, mode);
    if (mode==AddPartBehaviour.REUSE_EXISTING) {
      // In the REUSE_EXISTING case, we won't be adding this part, so
      // we can't add content to it (since its pkg isn't set)
      part2 = (HeaderPart)wordMLPackage.getRelationshipsPart().getPart(rel);
    }
    part2.getContent().add(Context.getWmlObjectFactory().createP() );
   
    // Just added a part
    //Assert.assertTrue("hmm", wordMLPackage.getMainDocumentPart().getRelationshipsPart().size()==mdpRelsCountBefore+expectedIncrement);
    Assert.assertTrue("hmm", wordMLPackage.getRelationshipsPart().size()==rootRelsCountBefore+relsAdded);
    Assert.assertTrue("hmm", wordMLPackage.getParts().getParts().size()==partsCountBefore+partsAdded);   
   
    // Check this part is the one we added - differentiated by its content
    HeaderPart result = (HeaderPart)wordMLPackage.getRelationshipsPart().getPart(rel);
    if (expectReplace) {
      Assert.assertTrue("hmm", result.getContent().size()==1);
    } else {
      Assert.assertTrue("hmm", result.getContent().size()==0);     
    }
   
  } 
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

 

  private void inRels(AddPartBehaviour mode, int partsAdded, int relsAdded, boolean expectReplace) throws Exception {

    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    HeaderPart part = new HeaderPart();   
    wordMLPackage.getMainDocumentPart().addTargetPart(part,  mode);

    int relsCountBefore = wordMLPackage.getMainDocumentPart().getRelationshipsPart().size();
    int partsCountBefore = wordMLPackage.getParts().getParts().size();
   
    // Add it again
    HeaderPart part2 = new HeaderPart();   
    part2.getContent().add(Context.getWmlObjectFactory().createP() );
    Relationship rel = wordMLPackage.getMainDocumentPart().addTargetPart(part2, mode);
   
    // Just added a part
    Assert.assertTrue("hmm", wordMLPackage.getMainDocumentPart().getRelationshipsPart().size()==relsCountBefore+relsAdded);
    Assert.assertTrue("hmm", wordMLPackage.getParts().getParts().size()==partsCountBefore+partsAdded);
   
    // Check this part is the one we added - differentiated by its content
    HeaderPart result = (HeaderPart)wordMLPackage.getMainDocumentPart().getRelationshipsPart().getPart(rel);
    if (expectReplace) {
      Assert.assertTrue("hmm", result.getContent().size()==1);
    } else {
      Assert.assertTrue("hmm", result.getContent().size()==0);     
    }
   
  }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

  private void createDummyHeaderFooter() {
    synchronized (dummyHeaderFooterMutex) {
      if (dummyHeader == null) {
        ObjectFactory factory = new ObjectFactory();
        try {
          dummyHeader = new HeaderPart(new PartName("/word/dummyheader.xml"));
          dummyFooter = new FooterPart(new PartName("/word/dummyfooter.xml"));
        } catch (InvalidFormatException e) {
          //should not happen
        }
        dummyHeader.setJaxbElement(factory.createHdr());
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

         
          // Create a suitable part
          JaxbXmlPart part = hfTemplates.get(ctRel);
          JaxbXmlPart clonedPart = null;
          if (part instanceof HeaderPart) {
            clonedPart = new HeaderPart();
            clonedPart.setJaxbElement(Context.getWmlObjectFactory().createHdr());
          } else if (part instanceof FooterPart) {
            clonedPart = new FooterPart();
            clonedPart.setJaxbElement(Context.getWmlObjectFactory().createFtr());
          }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

   
  public static Relationship createHeaderPart(
      WordprocessingMLPackage wordprocessingMLPackage)
      throws Exception {
   
    HeaderPart headerPart = new HeaderPart();
    Relationship rel =  wordprocessingMLPackage.getMainDocumentPart()
        .addTargetPart(headerPart);
   
    headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, headerPart));

    return rel;
  }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

   
    // Open a document from the file system
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
       
    if (ADD_TO_HEADER) {
      HeaderPart hp = wordMLPackage.getDocumentModel().getSections().get(0).getHeaderFooterPolicy().getDefaultHeader();
      hp.addAltChunk(AltChunkType.WordprocessingML, new FileInputStream(chunkPath) );
    } else {
      MainDocumentPart main = wordMLPackage.getMainDocumentPart();
      main.addAltChunk(AltChunkType.WordprocessingML, new FileInputStream(chunkPath) );
    }
   
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

    return new GlossaryDocumentPart(new PartName(partName));
  }

  public Part CreateHeaderPartObject(String partName)
      throws InvalidFormatException {
    return new HeaderPart(new PartName(partName));
  }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

 
  public static Relationship createHeaderPart(
      WordprocessingMLPackage wordprocessingMLPackage)
      throws Exception {
   
    HeaderPart headerPart = new HeaderPart();
    Relationship rel =  wordprocessingMLPackage.getMainDocumentPart()
        .addTargetPart(headerPart);
   
    // After addTargetPart, so image can be added properly
    headerPart.setJaxbElement(getHdr(wordprocessingMLPackage, headerPart));

    return rel;
  }
View Full Code Here

Examples of org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart

 
  }

  private Relationship createHeaderPart(String nameSuffix) throws Exception {
   
    HeaderPart headerPart = new HeaderPart(new PartName("/word/header-" + nameSuffix + ".xml"));
    Relationship rel =  wordMLPackage.getMainDocumentPart().addTargetPart(headerPart);
   
    setHdr( headerPart);

    return rel;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.