Package org.docx4j.wml

Examples of org.docx4j.wml.SdtBlock


   
    WordprocessingMLPackage wordMLPackage = createPkg();
   
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
   
    SdtBlock sdtBlock = new SdtBlock();
    SdtContentBlock sdtContentBlock = new SdtContentBlock();
   
    sdtBlock.setSdtContent(sdtContentBlock);
   
    mdp.getContent().add(sdtBlock);
   
    sdtBlock.getSdtContent().getContent().add(createUnnumberedP());
   
    sdtBlock.getSdtContent().getContent().add(createNumberedP(1,0));
    sdtBlock.getSdtContent().getContent().add(createNumberedP(1,0));

    sdtBlock.getSdtContent().getContent().add(createUnnumberedP());

    ListsToContentControls.process(wordMLPackage);
   
    System.out.println(mdp.getXML());
   
View Full Code Here


          }
         
          // add appropriate levels
          for (int i=0; i<=ilvl.intValue(); i++) {
            listSpec = new ListSpec(numId, BigInteger.valueOf(i));
            listSpec.sdtList = new SdtBlock();
            setTag(listSpec.sdtList, numId, ilvl);     

            listSpec.sdtList.setSdtContent(new SdtContentBlock());
           
            if (listStack.peek()==null) {
              resultElts.add(listSpec.sdtList);
            } else {
              listStack.peek().sdtList.getSdtContent().getContent().add(listSpec.sdtList);
            }
            listStack.push(listSpec);
          }
         
          listSpec.sdtList.getSdtContent().getContent().add(paragraph);
        } else if (numId==null) {
          log.error("TODO: encountered null numId!");
          closeAllLists();
          resultElts.add(o);
          continue
        } else // (numId.equals(listSpec.numId))
        {
          // same list
         
          if (ilvl.equals(listSpec.ilvl)) {
            // just add to it
          } else if (ilvl.compareTo(listSpec.ilvl)>0) {

            // deeper, so add levels
            for (int i=listSpec.ilvl.intValue(); i<ilvl.intValue(); i++) {
              listSpec = new ListSpec(numId, BigInteger.valueOf(i));
              listSpec.sdtList = new SdtBlock();
              setTag(listSpec.sdtList, numId, ilvl);     
             
              listSpec.sdtList.setSdtContent(new SdtContentBlock());
             
              if (listStack.peek()==null) {
View Full Code Here

  private static List<Object> groupBodyContent(List<Object> bodyElts) {
   
    List<Object> resultElts = new ArrayList<Object>();
    List<Object> paragraphElts = null;
    SdtBlock sdtBorders = null;
    SdtBlock sdtShading = null;
    PBdr lastBorders = null;
    PBdr currentBorders = null;
    CTShd lastShading = null;
    CTShd currentShading = null;
    P paragraph = null;
   
    for (Object o : bodyElts) {
      if (o instanceof JAXBElement) {
        o = ((JAXBElement)o).getValue();
      }
      if (o instanceof P) {
        paragraph = (P)o;
        paragraphElts = groupRuns(paragraph.getContent());
        paragraph.getContent().clear();
        if (paragraphElts != null) {
          paragraph.getContent().addAll(paragraphElts);
        }

        currentBorders = null;
        currentShading = null;
        if (paragraph.getPPr() != null ) {
          // TODO: use effective ppr properties!
          // ie take styles into account       
          currentBorders = paragraph.getPPr().getPBdr();
          currentShading = paragraph.getPPr().getShd();
        }

        if ( bordersChanged(currentBorders, lastBorders )) {
          // could mean null to borders; borders to null; or bordersA to bordersB
          if (currentBorders == null) {
            sdtBorders = null;
          } else {
            sdtBorders = createSdt(TAG_BORDERS);
            resultElts.add(sdtBorders);
          }
        }
       
        if (shadingChanged(currentShading, lastShading )) {
          // handle change to shading before addElement
          if (currentShading == null) {
            sdtShading = null;
          } else {
            sdtShading = createSdt(TAG_SHADING);
           
            // need to set margins, so there isn't a white strip
            // between paragraphs.  hmm, model.properties.paragraph
            // won't translate this.  so do it at the fo level
            if (sdtBorders!=null) {
              sdtBorders.getSdtContent().getContent().add(sdtShading);
            }
            else {
              resultElts.add(sdtShading);
            }
          }
        }
      }
      else if (o instanceof Tbl) {
        groupTable((Tbl)o);
      }
      if (sdtShading!=null) {
        sdtShading.getSdtContent().getContent().add(o);
      }
      else if (sdtBorders!=null) {
        sdtBorders.getSdtContent().getContent().add(o);
      }
      else {
View Full Code Here

  }
 
  private static List<Object> groupRuns(List<Object> paragraphElts) {
   
    List<Object> resultElts = new ArrayList<Object>();
    SdtBlock currentBlock = null;
    CTBorder lastBorder = null;
    CTBorder currentBorder = null;
    R run = null;
   
//      java.util.Stack stack = new java.util.Stack();
//      stack.push(newList);
   
    for (Object o : paragraphElts) {
      if (o instanceof R) {
        run = (R)o;
        currentBorder = null;
        if (run.getRPr() != null ) {
          currentBorder = run.getRPr().getBdr();
        }
       
        if ( borderChanged(currentBorder, lastBorder )) {
          appendRun(currentBlock, resultElts);
          currentBlock = null;
          // could mean null to borders; borders to null; or bordersA to bordersB
          if (currentBorder != null) {
            currentBlock = createSdt(TAG_RPR, run.getRPr());
          }
        }
      }
      if (currentBlock!=null) {
        currentBlock.getSdtContent().getContent().add(o);
      }
      else {
        resultElts.add(o);
      }
     
View Full Code Here

  }

  private static SdtBlock createSdt(String tagVal, RPr rPr) {
   
    // .. so create content control!
    SdtBlock sdtBlock = Context.getWmlObjectFactory().createSdtBlock();

    SdtPr sdtPr = Context.getWmlObjectFactory().createSdtPr();
    sdtBlock.setSdtPr(sdtPr);

    SdtContentBlock sdtContent = Context.getWmlObjectFactory().createSdtContentBlock();
    sdtBlock.setSdtContent(sdtContent);

    // For borders/shading, we'll use the values in this first paragraph.
    // We'll use a tag, so the XSLT can detect that its supposed to do something special.
    Tag tag = Context.getWmlObjectFactory().createTag();
    tag.setVal(tagVal);
View Full Code Here

    new TraversalUtil(document.getContent(), sbr);
    for( int i=sbr.sdtBlocks.size()-1 ; i>=0; i--) {
      // Have to process in reverse order
      // so that parentList is correct for nested sdt
     
      SdtBlock sdtBlock = sbr.sdtBlocks.get(i);
      List<Object> parentList = null;
      if (sdtBlock.getParent() instanceof ArrayList) {
        parentList = (ArrayList)sdtBlock.getParent();
      } else {
        log.error("Handle " + sdtBlock.getParent().getClass().getName());
      }
      int index = parentList.indexOf(sdtBlock);
      parentList.remove(index);
      parentList.addAll(index, sdtBlock.getSdtContent().getContent());       
    }
   
//    if (log.isDebugEnabled()) {
//      log.debug(XmlUtils.marshaltoString(document, true, true));
//    }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.SdtBlock

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.