Package org.docx4j.openpackaging.packages

Examples of org.docx4j.openpackaging.packages.WordprocessingMLPackage$FilterSettings


    noPart(AddPartBehaviour.RENAME_IF_NAME_EXISTS);   
 

  private void noPart(AddPartBehaviour mode) throws Exception {
   
    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


   
 

  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

    inRels( AddPartBehaviour.RENAME_IF_NAME_EXISTS, 1, 1, true);
 

  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

  @Test
  public void testTblStyle_AllSilent() throws Exception {
   
    // Result is to use the implicit 10pt
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_no_font_sz) );

    setSetting(wordMLPackage, OVERRIDE);
    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
    // TODO make this change in other AllSilent tests

   
    // NB createVirtualStylesForDocDefaults() puts 10pt there, if nothing is specified!
    // So we need to delete that!
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().createVirtualStylesForDocDefaults();
    Style dd = wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getStyleById("DocDefaults");
    dd.getRPr().setSz(null);
    dd.getRPr().setSzCs(null);
   
   
    ParagraphStylesInTableFix.process(wordMLPackage);
View Full Code Here

  @Test
  public void testTblStyle_BasedOnNormal() throws Exception {
   
    // A style basedOn Normal is honoured, provided it (not Normal) contributes the font size
 
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_in_basedOn_Normal) );
   
    // Use our style!
    List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
    PPr ppr = Context.getWmlObjectFactory().createPPr();
    ((P)xpathResults.get(0)).setPPr(ppr);
    PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
    ps.setVal("testStyle");
    ppr.setPStyle(ps);
   
    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
View Full Code Here

  @Test
  public void testTblStyle_BasedOn_Normal12() throws Exception {
   
    // A style basedOn Normal is ignored where the font size comes from Normal
 
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_basedOn_Normal) );
   
    // Use our style!
    List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", true);
    PPr ppr = Context.getWmlObjectFactory().createPPr();
    ((P)xpathResults.get(0)).setPPr(ppr);
    PStyle ps = Context.getWmlObjectFactory().createPPrBasePStyle();
    ps.setVal("testStyle");
    ppr.setPStyle(ps);
   
    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
//    // Revert style and save:
//    ppr.setPStyle(ps); // doesn't work - wrong ref!
//    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    Style ours = null;
    for (Style s : wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getContents().getStyle()) {
      if ("testStyle-TableNormal-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
View Full Code Here

  }

  @Test
  public void testTblStyle_P12() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = test(mdpXml_direct_12pt, styles_no_font_sz, 20); // uses implicit DocDefault, but irrelevant
   
    //wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    /* In this case, our result correctly preserves the direct rPr formatting
     * (so the contents of Normal-TableGrid-BR is irrelevant)
     *
          <w:tc>
            <w:p>
              <w:pPr>
                <w:pStyle w:val="Normal-TableGrid-BR"/>
              </w:pPr>
              <w:r>
                <w:rPr>
                  <w:sz w:val="24"/>
                  <w:szCs w:val="24"/>
                </w:rPr>
                <w:t xml:space="preserve">some latin text here </w:t>
              </w:r>
            </w:p>
          </w:tc>
         */
   
    List<Object> xpathResults = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:rPr", true);
    RPr rPr = ((RPr)xpathResults.get(0));
    Assert.assertTrue(rPr.getSz().getVal().intValue()==24);
 
   
  }
View Full Code Here

   
    log.warn("\ntestSimpleDocx\n");
   
    String inputfilepath = resourceDir + "paragraph-single.docx";
   
    WordprocessingMLPackage thisPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
    WordprocessingMLPackage otherPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    Alterations alterations = AlteredParts.start(thisPackage, otherPackage);
   
    Patcher.apply(otherPackage, alterations);
   
View Full Code Here

  public void testExtraParagraph() throws Exception {
    // Only document.xml should be different

    log.warn("\ntestExtraParagraph\n");
   
    WordprocessingMLPackage thisPackage = WordprocessingMLPackage.load(
        new java.io.File(resourceDir + "paragraph-single.docx"));
    WordprocessingMLPackage otherPackage = WordprocessingMLPackage.load(
        new java.io.File(resourceDir + "paragraph-two.docx"));
   
    Alterations alterations = AlteredParts.start(thisPackage, otherPackage);

    Patcher.apply(otherPackage, alterations);
View Full Code Here

    // document.xml and rels should be different,
    // and styles, since hyperlink style is now in use

    log.warn("\ntestHyperlink\n");
   
    WordprocessingMLPackage thisPackage = WordprocessingMLPackage.load(
        new java.io.File(resourceDir + "hyperlink.docx"));
    WordprocessingMLPackage otherPackage = WordprocessingMLPackage.load(
        new java.io.File(resourceDir + "paragraph-single.docx"));
   
    Alterations alterations = AlteredParts.start(thisPackage, otherPackage);
    alterations.debug();
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.packages.WordprocessingMLPackage$FilterSettings

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.