Package org.docx4j.wml

Examples of org.docx4j.wml.P


    if (content.size()==0) {
      return null;
    }
   
    P p = null;
    for (Object o : content ) {
      if (o instanceof P ) {
        p = (P)o;
        break;
      }
    }
   
    if (p==null) {
      // No top level paragraph, so
      // do the work of traversing the document
     
      log.debug("traversing for w14, w15");
     
      IgnorablePrefixFinder finder = new IgnorablePrefixFinder();
      if (body.getSectPr()!=null
        && body.getSectPr().getFootnoteColumns()!=null) {
          finder.needW15 = true;                         
      }
      new TraversalUtil(content, finder);
     
      String mceIgnorableVal = "";
      if (finder.needW14) {
        mceIgnorableVal = "w14";
      }
     
      if (finder.needW15) {
        mceIgnorableVal += " w15";
      }
     
      return mceIgnorableVal;
     
     
    } else {
      // The quick hack
     
      // For W14, we'll check/set paraId, textId
      if (p.getParaId()==null) {
        // Values MUST be greater than 0 and less than 0x80000000
        // So let's
       
        String uuid = java.util.UUID.randomUUID().toString();
        // That's 32 digits, but 8'll do nicely
        /*
        * 8 can create a number too large - using 7
        * Bob Fleischman - July 24, 2014
        */
        uuid = uuid.replace("-", "").substring(0, 7);
       
        p.setParaId(uuid);
        p.setTextId(uuid);
      }
     
      // For W15, collapse
      PPr ppr = p.getPPr();
      if (ppr==null) {
        ppr = Context.getWmlObjectFactory().createPPr();
        p.setPPr(ppr);
      }
      if (ppr.getCollapsed()==null) {
        BooleanDefaultTrue notCollapsed = new BooleanDefaultTrue();
        notCollapsed.setVal(Boolean.FALSE);
        ppr.setCollapsed(notCollapsed);
View Full Code Here


        // NB: the tests in this method have to be comprehensive,
        // so if support for glow etc is introduced, tests for those
        // will need to be added
     
      if (o instanceof org.docx4j.wml.P) {
        P p = (P)o;
       
        // W14?
        if (p.getParaId()!=null) {
          needW14 = true;
        }
        // W15?
        if (!needW15) {
          PPr ppr = p.getPPr();
          if (ppr!=null) {
            if (ppr.getCollapsed()!=null) {
              needW15 = true;           
            }
           
View Full Code Here

    int assertionCount=0;
    for (Object o : wordMLPackage.getMainDocumentPart().getContent() ) {

      if (o instanceof P) {

        P p = (P)o;

        if (p.getPPr()!=null) {

            PPr pPr = propertyResolver.getEffectivePPr(p.getPPr());

            if (pPr.getInd()!=null) {

              String actual = removeNamespaces(XmlUtils.marshaltoString(pPr.getInd(), true));

              Text text = (Text)XmlUtils.unwrap(
                  ((R)p.getContent().get(0)).getContent().get(0));
              String content = text.getValue();

              // If contains [expect] [/expect], then test for this
              // Since attributes can be in any order, work on an
              // attribute by attribute basis.
View Full Code Here

   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();

    P p = createNumberedP("ChapterLevel1", 12, 0);
    mdp.getContent().add(p);
    Assert.assertEquals("1", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
    //System.out.println(Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
    p = createNumberedP("ChapterLevel2", 6, 1);
    mdp.getContent().add(p);
    Assert.assertEquals("1.1", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
    p = createNumberedP("ChapterLevel2", 6, 1);
    mdp.getContent().add(p);
    Assert.assertEquals("1.2", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());

    p = createNumberedP("ChapterLevel3", 6, 2);
    mdp.getContent().add(p);
    Assert.assertEquals("1.2.1", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
    p = createNumberedP("ChapterLevel1", -1, -1); // no numPr
    mdp.getContent().add(p);
    Assert.assertEquals("2", Emulator.getNumber(wordMLPackage, p.getPPr()).getNumString());
   
  }
View Full Code Here

   
  }

  protected P createNumberedP(String style, int numId, int ilvl) {
   
    P p = wmlObjectFactory.createP();
        // Create object for pPr
        PPr ppr = wmlObjectFactory.createPPr();
        p.setPPr(ppr);
       
        if (numId>-1) {
            // Create object for numPr
            PPrBase.NumPr pprbasenumpr = wmlObjectFactory.createPPrBaseNumPr();
            ppr.setNumPr(pprbasenumpr);
                // Create object for ilvl
                PPrBase.NumPr.Ilvl pprbasenumprilvl = wmlObjectFactory.createPPrBaseNumPrIlvl();
                pprbasenumpr.setIlvl(pprbasenumprilvl);
                    pprbasenumprilvl.setVal( BigInteger.valueOf( ilvl) );
                // Create object for numId
                PPrBase.NumPr.NumId pprbasenumprnumid = wmlObjectFactory.createPPrBaseNumPrNumId();
                pprbasenumpr.setNumId(pprbasenumprnumid);
                    pprbasenumprnumid.setVal( BigInteger.valueOf( numId) );
        }
            // Create object for pStyle
            PPrBase.PStyle pprbasepstyle = wmlObjectFactory.createPPrBasePStyle();
            ppr.setPStyle(pprbasepstyle);
                pprbasepstyle.setVal( style);
        // Create object for r
        R r = wmlObjectFactory.createR();
        p.getContent().add( r);
            // Create object for t (wrapped in JAXBElement)
            Text text = wmlObjectFactory.createText();
            JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
            r.getContent().add( textWrapped);
                text.setValue( style + "; list " + numId + ", ilvl " + ilvl);
View Full Code Here

    return p;
    }
 
  protected P createUnnumberedP() {
   
    P p = wmlObjectFactory.createP();
        R r = wmlObjectFactory.createR();
        p.getContent().add( r);
            // Create object for t (wrapped in JAXBElement)
            Text text = wmlObjectFactory.createText();
            JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
            r.getContent().add( textWrapped);
                text.setValue( "UnnumberedP");
View Full Code Here

    int assertionCount=0;
    for (Object o : wordMLPackage.getMainDocumentPart().getContent() ) {
   
      if (o instanceof P) {
       
        P p = (P)o;
       
        if (p.getPPr()!=null) {
         
          // Set up values required for call to Emulator's getNumber
          String pStyleVal = null;
          if (p.getPPr().getPStyle()!=null) {
            pStyleVal = p.getPPr().getPStyle().getVal();
          }
         
          String numId = null;
          String levelId = null;
          if (p.getPPr().getNumPr()!=null) {
            if (p.getPPr().getNumPr().getNumId()!=null) {
              numId = p.getPPr().getNumPr().getNumId().getVal().toString();
            }
            if (p.getPPr().getNumPr().getIlvl()!=null) {
              levelId = p.getPPr().getNumPr().getIlvl().getVal().toString();
            }
          }
         
          ResultTriple rt = Emulator.getNumber(wordMLPackage, pStyleVal, numId, levelId);
         
          Text text = (Text)XmlUtils.unwrap(
              ((R)p.getContent().get(0)).getContent().get(0));
          String content = text.getValue();
         
          // If contains [expect] [/expect], then test for this
          if (content.contains(EXPECT_START)) {
            int start = content.indexOf(EXPECT_START) + EXPECT_START.length();
View Full Code Here

      // is a better alternative if you are using a new style, since it
      // will ensure that the style is activated 

    // Example 3b: bold text
      // Well, actually you can use addParagraphOfText:
    P p3b = mdp.addParagraphOfText("Example 3b (bold)");
    R r3b = (R)p3b.getContent().get(0);
      // .. now set rPr (I'll just reuse the above object)
    r3b.setRPr(rpr);

     
      // Example 4: Here is an easier way:
View Full Code Here

   
    // canonicalise and setup fieldRefs
    List<FieldRef> fieldRefs = new ArrayList<FieldRef>();
    for( P p : fl.getStarts() ) {
      int index = ((ContentAccessor)p.getParent()).getContent().indexOf(p);
      P newP = FieldsPreprocessor.canonicalise(p, fieldRefs);
      ((ContentAccessor)p.getParent()).getContent().set(index, newP);
     
      /*
       *   <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:ns23="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
            <w:r>
View Full Code Here

     
        System.out.println("<h1>TESTING " + testparagraphs[i]
                + ", " + testparagraphs[j] + "</h1>");
       
        // Test setup
        P pl = Differencer.loadParagraph(BASE_DIR + testparagraphs[i]);
        P pr = Differencer.loadParagraph(BASE_DIR + testparagraphs[j]);
       
        // Result format
        StreamResult result = new StreamResult(System.out);
   
        // Run the diff
View Full Code Here

TOP

Related Classes of org.docx4j.wml.P

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.