Package org.docx4j.openpackaging.packages

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


  public void testComment2() throws Exception {
    // document.xml + comments part should be different

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

    alterations.debug();
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-TableNormal-BR is irrelevant)
     *
          <w:tc>
            <w:p>
              <w:pPr>
                <w:pStyle w:val="Normal-TableNormal-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()==EXPECTED_RESULT);
 
   
  }
View Full Code Here

    // TODO - test that OpenDoPE parts aren't already present
    // or if they are, that this docx is using our answer format
    // (since only that format is supported here)
   
    // Clone it
    WordprocessingMLPackage pkgOut = (WordprocessingMLPackage)pkgIn.clone();
   
    // Run the cleaner first
    VariablePrepare.prepare(pkgOut);   
   
    // Create the CustomXML parts
    createParts(pkgOut);
   
    // Operate at the p level
    PFinder pFinder = new PFinder();
        new TraversalUtil(pkgOut.getMainDocumentPart().getContent(), pFinder);

        for ( P p : pFinder.pList) {
         
          List<Object> replacementContent = new ArrayList<Object>();
         
View Full Code Here

    String inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/unmarshallFromTemplateExample.docx";

    String outputfilepath = System.getProperty("user.dir")
        + "/OUT_VariableReplace.docx";

    WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    FromVariableReplacement migrator = new FromVariableReplacement();
    WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn);
   
    SaveToZipFile saver = new SaveToZipFile(pkgOut);
    saver.save(outputfilepath);
   
  }
View Full Code Here

    // TODO - test that OpenDoPE parts aren't already present
    // or if they are, that this docx is using our answer format
    // (since only that format is supported here)
   
    // Clone it
    WordprocessingMLPackage pkgOut = (WordprocessingMLPackage)pkgIn.clone();
       
    // Create the CustomXML parts
    createParts(pkgOut);
   
    FieldsPreprocessor.complexifyFields(pkgOut.getMainDocumentPart() );
    log.debug("complexified: "
        + XmlUtils.marshaltoString(pkgOut.getMainDocumentPart().getJaxbElement(), true));
   
    // find fields
    ComplexFieldLocator fl = new ComplexFieldLocator();
    new TraversalUtil(pkgOut.getMainDocumentPart().getContent(), fl);
    log.info("Found " + fl.getStarts().size() + " fields ");
   
   
    // canonicalise and setup fieldRefs
    List<FieldRef> fieldRefs = new ArrayList<FieldRef>();
View Full Code Here

                  + "/TEST1.docx";

    String outputfilepath = System.getProperty("user.dir")
        + "/OUT_TEST1.docx";

    WordprocessingMLPackage pkgIn = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
   
    FromMergeFields migrator = new FromMergeFields();
    WordprocessingMLPackage pkgOut = migrator.migrate(pkgIn);
   
    SaveToZipFile saver = new SaveToZipFile(pkgOut);
    saver.save(outputfilepath);
   
  }
View Full Code Here

  }

  @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)// table style should get overridden
 
    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()==40);
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-TableGrid-BR".equals(s.getStyleId())) {
        ours = s;
        break;
      }
    }
View Full Code Here

  @Test
  public void testTblStyle_BasedOn_Normal12() 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_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
  //@Ignore
  public void testTblStyle_P12() throws Exception {
   
    WordprocessingMLPackage wordMLPackage = test(mdpXml_direct_12pt, styles_no_font_sz, 40);
   
    //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

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.