Package org.docx4j.wml

Examples of org.docx4j.wml.SdtPr


//    }
   
    newContent.add(sdt);

    // Change the tag to od:resultRepeatZero
    SdtPr sdtPr = getSdtPr(sdt);

    CTDataBinding binding = sdtPr.getDataBinding();
    if (binding != null) {  // Shouldn't be a binding anyway
      sdtPr.getRPrOrAliasOrLock().remove(binding);
    }

    Tag tag = sdtPr.getTag();

    final String tagVal = tag.getVal();
    final Pattern stripRepeatArgPattern = Pattern
        .compile("(.*od:repeat=)([^&]*)(.*)");
    final Matcher stripPatternMatcher = stripRepeatArgPattern
        .matcher(tagVal);
    if (!stripPatternMatcher.matches()) {
      log.error("Cannot find repeat tag in sdtPr/tag while processing repeat; something is wrong with " + tagVal);
      return newContent;
    }
    final String emptyRepeatValue = BINDING_RESULT_RPTD_ZERO + "=" + stripPatternMatcher.group(2) + stripPatternMatcher.group(3);
    tag.setVal(emptyRepeatValue)
   
    // Lock it
        CTLock lock = Context.getWmlObjectFactory().createCTLock();
        lock.setVal(org.docx4j.wml.STLock.SDT_CONTENT_LOCKED);   
        JAXBElement<org.docx4j.wml.CTLock> lockWrapped = Context.getWmlObjectFactory().createSdtPrLock(lock);
        sdtPr.getRPrOrAliasOrLock().add( lockWrapped); // assumes no lock is there already

    // Empty the content
        // .. OpenDoPEIntegrity fixes this where it is not OK, but
        // where it needs to insert a tc, it has no way of adding original tcPr, so
        // we handle this here
View Full Code Here


  private List<Object> cloneRepeatSdt(Object sdt, String xpathBase,
      int numRepeats) {

    List<Object> newContent = new ArrayList<Object>();

    SdtPr sdtPr = getSdtPr(sdt);

    log.debug(XmlUtils.marshaltoString(sdtPr, true, true));

    // CTDataBinding binding =
    // (CTDataBinding)XmlUtils.unwrap(sdtPr.getDataBinding());
    CTDataBinding binding = sdtPr.getDataBinding();
    if (binding != null) {  // Shouldn't be a binding anyway
      sdtPr.getRPrOrAliasOrLock().remove(binding);
    }

    emptyRepeatTagValue(sdtPr.getTag()); // 2012 07 15: do it to the first one

    for (int i = 0; i < numRepeats; i++) {

      // 2012 07 13: for "od:RptPosCon" processing to
      // work (conditional inclusion dependant on position
      // in repeat), we need each entry (ie including the
      // original) to have the same tag (which I've changed
      // to od:rptd).

      if (i > 0) {
        // Change ID
        sdtPr.setId();
      } // preserve ID on index 0, important for OpenDoPEReverter!
     
      // Clone
      newContent.add(XmlUtils.deepCopy(sdt));
    }
View Full Code Here

  }

  private void processDescendantBindings(Object sdt, String xpathBase,
      int index) {

    SdtPr sdtPr = getSdtPr(sdt);

    // log.debug(XmlUtils.marshaltoString(sdtPr, true, true));

    // Give it a unique ID (supersedes above?)
    sdtPr.setId();

    // log.debug(XmlUtils.marshaltoString(sdtPr, true, true));
    CTDataBinding binding = (CTDataBinding) XmlUtils.unwrap(sdtPr
        .getDataBinding());

    String thisXPath = null;

    // It'll have one of these three...
    String conditionId = null;
    String repeatId = null;
    String bindingId = null;

    org.opendope.xpaths.Xpaths.Xpath xpathObj = null;

    Tag tag = sdtPr.getTag();
    if (tag == null)
      return;
    HashMap<String, String> map = QueryString.parseQueryString(
        tag.getVal(), true);
View Full Code Here

    listStack.clear();
  }
 
  private void setTag(SdtBlock sdtList, BigInteger numId, BigInteger ilvl) {
   
    SdtPr sdtPr = new SdtPr();
    Tag tag = new Tag();
    sdtPr.setTag(tag);
   
    sdtList.setSdtPr(sdtPr);
   
    // Bullets = UL.  Work it out.
    ListNumberingDefinition lnd = ndp.getInstanceListDefinitions().get(numId.toString());
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);
   
    sdtPr.setTag(tag);
    if (rPr != null) {
      sdtPr.getRPrOrAliasOrLock().add((RPr)XmlUtils.deepCopy(rPr));
      /*
       * ECMA-376 says "specifies the set of run properties which shall be applied to
       *  the text entered into the parent structured document tag in replacement of
       *  placeholder text. When placeholder text is present in a structured document
       *  tag, its formatting is often different than the desired underlying formatting,
View Full Code Here

    }
   
    private void handleSdt(Object o) {
     
      SdtElement sdt = (SdtElement)o;
      SdtPr sdtPr = sdt.getSdtPr();
     
      Tag tag = sdtPr.getTag();     
      HashMap<String, String> map = null;
      if (tag!=null) {
        map = QueryString.parseQueryString(
          tag.getVal(), true);
      }     
     
      SdtPr.Picture pic = getPicture(sdtPr);
      if (sdtPr.getDataBinding()!=null && pic!=null) {
       
        Object sdtParent = ((Child)o).getParent();
               
        sdt.getSdtContent().getContent().clear();       
        sdt.getSdtContent().getContent().add(
            this.xpathInjectImage(
                (WordprocessingMLPackage)pkg, part,
                sdtPr.getDataBinding(), sdt,
                sdtParent));
       
        // TODO v3 XSLT approach
        // .. if the sdt contains a template picture,
        // find its a:blip, and just replace that.
       
      } else if (map!=null && map.containsKey(OpenDoPEHandler.BINDING_CONTENTTYPE)
            && map.get(OpenDoPEHandler.BINDING_CONTENTTYPE).equals("application/xhtml+xml")) {
          // Convert XHTML.
        log.error("TODO: add HTML import support");
       
      } else if (map!=null && map.containsKey(OpenDoPEHandler.BINDING_ROLE_CONDITIONAL) ) {
        // Do nothing
      } else if (map!=null && map.containsKey(OpenDoPEHandler.BINDING_RESULT_RPTD) ) {
        // Do nothing
       
      } else if (map!=null && map.containsKey(OpenDoPEHandler.BINDING_ROLE_RPT_POS_CON) ) {
        // This may be tricky to do here ..
       
      } else if (map!=null && map.containsKey(OpenDoPEHandler.BINDING_ROLE_XPATH) ) {
       
        boolean isMultiline = isMultiline(sdtPr);
       
        sdt.getSdtContent().getContent().clear();
       
        sdt.getSdtContent().getContent().addAll(
            this.xpathGenerateRuns(
              (WordprocessingMLPackage)pkg, part,
              sdtPr,
              sdtPr.getDataBinding(),
              //sdtParent, contentChild,
              null, isMultiline));
       
      } else if (sdtPr.getDataBinding()!=null && !isRichText(sdtPr) ) {
        // TODO and not(w:sdtPr/w:docPartGallery)
        // .. but which is that?
            //@XmlElementRef(name = "docPartList", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class),
            //@XmlElementRef(name = "docPartObj", namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", type = JAXBElement.class),
       
        sdt.getSdtContent().getContent().clear();
       
        sdt.getSdtContent().getContent().addAll(
            this.xpathGenerateRuns(
              (WordprocessingMLPackage)pkg, part,
              sdtPr,
              sdtPr.getDataBinding(),
              //sdtParent, contentChild,
              null, false));
       
      } else {
       
View Full Code Here

    @Override
    public void apply(SdtElement element, Object parent, List<Object> siblings) {

      System.out.println();
     
      SdtPr sdtPr = element.getSdtPr();
      if (sdtPr==null) {
        System.out.println(callback.indent + element.getClass().getSimpleName() + "  [no sdtPr!]" + " (having parent " + parent.getClass().getSimpleName() + ")");
      } else {       
        System.out.println(callback.indent + element.getClass().getSimpleName()  + " (having parent " + parent.getClass().getSimpleName() + ")");
       
        CTDataBinding binding = (CTDataBinding) XmlUtils.unwrap(sdtPr
            .getDataBinding());
        if (binding!=null) {
          System.out.println(callback.indent + "  binding: " + binding.getXpath() );         
        }
       
        Tag tag = sdtPr.getTag();
        if (tag == null)
          return;

        System.out.println(callback.indent + "  " + tag.getVal() );         
       
View Full Code Here

      this.definedStoreItemIds = definedStoreItemIds;
    }
   
    @Override
    public void apply(SdtElement element) {
    SdtPr sdtPr = element.getSdtPr();
     
      if ((sdtPr.getDataBinding() != null) &&
        (sdtPr.getDataBinding().getStoreItemID() != null)) {
        String tmp = sdtPr.getDataBinding().getStoreItemID().toLowerCase();
        if (definedStoreItemIds.contains(tmp)) {
          storeItemId = tmp;
          throw new BreakException();
        }
      }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.SdtPr

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.