Package org.docx4j.finders

Examples of org.docx4j.finders.RangeFinder


    // The inefficient case, where we calculate again
    log.warn("Recalculating starting value for new bookmarks.  For efficiency, you should set this in your code.");
    int highestId = 0;
   
    RangeFinder rt = new RangeFinder("CTBookmark", "CTMarkupRange");
    new TraversalUtil(wordMLPackage.getMainDocumentPart().getContent(), rt);
   
    for (CTBookmark bm : rt.getStarts()) {
     
      BigInteger id = bm.getId();
      if (id!=null && id.intValue()>highestId) {
        highestId = id.intValue();
      }
View Full Code Here


  private int initBookmarkIdStart() {

    int highestId = 0;
   
    RangeFinder rt = new RangeFinder("CTBookmark", "CTMarkupRange");
    new TraversalUtil(wordMLPackage.getMainDocumentPart().getContent(), rt);
   
    for (CTBookmark bm : rt.getStarts()) {
     
      BigInteger id = bm.getId();
      if (id!=null && id.intValue()>highestId) {
        highestId = id.intValue();
      }
View Full Code Here

    wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/OUT_BookmarksTextInserter.docx"));
  }

  private  void replaceBookmarkContents(List<Object> paragraphs,  Map<DataFieldName, String> data) throws Exception {

    RangeFinder rt = new RangeFinder("CTBookmark", "CTMarkupRange");
    new TraversalUtil(paragraphs, rt);
   
    for (CTBookmark bm : rt.getStarts()) {
     
      // do we have data for this one?
      if (bm.getName()==null) continue;
      String value = data.get(new DataFieldName(bm.getName()));
      if (value==null) continue;
View Full Code Here

  }

  private static void fixRange(List<Object> paragraphs, String startElement,
      String endElement) throws Exception {

    RangeFinder rt = new RangeFinder(startElement, endElement);
    new TraversalUtil(paragraphs, rt);
   
    for (CTBookmark bm : rt.getStarts()) {
      try {
        // Can't just remove the object from the parent,
        // since in the parent, it may be wrapped in a JAXBElement
        List<Object> theList = null;
        if (bm.getParent() instanceof List) {
          theList = (List)bm.getParent(); // eg body.getContent()
        } else {
          theList = ((ContentAccessor)(bm.getParent())).getContent();
        }
        Object deleteMe = null;
        for (Object ox : theList) {
          if (XmlUtils.unwrap(ox).equals(bm)) {
            deleteMe = ox;
            break;
          }
        }
        if (deleteMe!=null) {
          theList.remove(deleteMe);           
        }
      } catch (ClassCastException cce) {
        log.error(cce.getMessage(), cce);
      }
    }

    for (CTMarkupRange mr : rt.getEnds()) {
      try {
        // Can't just remove the object from the parent,
        // since in the parent, it may be wrapped in a JAXBElement
        List<Object> theList = null;
        if (mr.getParent() instanceof List) {
View Full Code Here

  }

  private static void fixRange(List<Object> paragraphs, String startElement,
      String endElement) throws Exception {

    RangeFinder rt = new RangeFinder(startElement, endElement);
    new TraversalUtil(paragraphs, rt);
   
    for (CTBookmark bm : rt.getStarts()) {
      try {
        // Can't just remove the object from the parent,
        // since in the parent, it may be wrapped in a JAXBElement
        List<Object> theList = null;
        if (bm.getParent() instanceof List) {
          theList = (List)bm.getParent(); // eg body.getContent()
        } else {
          theList = ((ContentAccessor)(bm.getParent())).getContent();
        }
        Object deleteMe = null;
        for (Object ox : theList) {
          if (XmlUtils.unwrap(ox).equals(bm)) {
            deleteMe = ox;
            break;
          }
        }
        if (deleteMe!=null) {
          theList.remove(deleteMe);           
        }
      } catch (ClassCastException cce) {
        log.error(cce.getMessage(), cce);
      }
    }

    for (CTMarkupRange mr : rt.getEnds()) {
      try {
        // Can't just remove the object from the parent,
        // since in the parent, it may be wrapped in a JAXBElement
        List<Object> theList = null;
        if (mr.getParent() instanceof List) {
View Full Code Here

TOP

Related Classes of org.docx4j.finders.RangeFinder

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.