Package org.docx4j.openpackaging.packages

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


  }

  @Test
  public void testTblStyle_AllSilent() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    wordMLPackage.getMainDocumentPart().setContents(
        (Document)XmlUtils.unmarshalString(mdpXml_tblStyle) );
    wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().setContents(
        (Styles)XmlUtils.unmarshalString(styles_no_font_sz) );
   
    // 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);
   
    setSetting(wordMLPackage, OVERRIDE);

    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    ParagraphStylesInTableFix.process(wordMLPackage);
   
    Style s = getStyle(wordMLPackage, STYLE_NAME);
    Assert.assertTrue(s.getRPr().getSz().getVal().intValue()==EXPECTED_RESULT);
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-TableGrid-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-TableGrid-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);
   
    //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

  @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)// table style should get overridden
   
    wordMLPackage.save(new File(System.getProperty("user.dir") + "/OUT_PStyleInTableTest.docx"));
   
    // 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

    boolean save=true;
   
    String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/unmarshallFromTemplateDirtyExample.docx";
   
    WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    // Before .. note attributes w:rsidRDefault="00D15781" w:rsidR="00D15781"
    System.out.println(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true));
   
    prepare(wmlPackage);
   
    System.out.println(XmlUtils.marshaltoString(wmlPackage.getMainDocumentPart().getJaxbElement(), true, true));

    // Save it
    if (save) {
      SaveToZipFile saver = new SaveToZipFile(wmlPackage);
      saver.save(System.getProperty("user.dir") + "/OUT_VariablePrepare.docx");
View Full Code Here

  @Test
  public void testTblStyle_BasedOnNormal() throws Exception {
   
    // Compat setting says Paragraph style overrides table style   
 
    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)// table style should get overridden
 
    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

   
    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);
   
    assertTrue( alterations.getPartsAdded().size()==0 );
//    assertTrue( alterations.getPartsModified().size()==0 ); // FIXME
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);

    alterations.debug();
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.