Package org.docx4j.wml

Examples of org.docx4j.wml.Tag


      SdtPr sdtPr = sdt.getSdtPr();
     
      if (sdtPr.getDataBinding()==null ) {
       
        // Identify xpathId
        Tag tag = sdtPr.getTag();
        HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(), true);
        String xpathId= map.get(OpenDoPEHandler.BINDING_ROLE_XPATH);
       
        // Look up - throws InputIntegrityException if not found
        Xpath xp = xPathsPart.getXPathById(xpathId);
         
View Full Code Here


       
        SdtPr sdtPr = OpenDoPEHandler.getSdtPr(o);
        if (sdtPr!=null) {
         
          log.debug("Processing " + OpenDoPEHandler.getSdtPr(o).getId().getVal());
          Tag tag = sdtPr.getTag();

          log.debug(tag.getVal());

          HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(), true);

          String conditionId = map.get(OpenDoPEHandler.BINDING_ROLE_CONDITIONAL);
          String repeatId = map.get(OpenDoPEHandler.BINDING_ROLE_REPEAT);

          if (conditionId != null) {
View Full Code Here

       
        SdtPr sdtPr = OpenDoPEHandler.getSdtPr(o);
        if (sdtPr!=null) {
         
          log.debug("Processing " + OpenDoPEHandler.getSdtPr(o).getId().getVal());
          Tag tag = sdtPr.getTag();

          if (tag!=null) {
           
            log.debug(tag.getVal());
 
            HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(), true);
           
            String conditionId = map.get(OpenDoPEHandler.BINDING_ROLE_CONDITIONAL);
            String resultConditionId = map.get(OpenDoPEHandler.BINDING_RESULT_CONDITION_FALSE);
            String resultRepeatId = map.get(OpenDoPEHandler.BINDING_RESULT_RPTD);
            String resultRptdZeroId = map.get(OpenDoPEHandler.BINDING_RESULT_RPTD_ZERO);
 
            String xpathId= map.get(OpenDoPEHandler.BINDING_ROLE_XPATH);
           
            if (conditionId != null ) {
 
              sdtsByConditionIDtoReplace.add(o);
              previousRepeatID = null;
             
            } else if (resultConditionId != null) {
 
              sdtsByConditionIDtoReplace.add(o);
              previousRepeatID = null;
             
            } else if (resultRptdZeroId != null) {
 
              repeatSdtToReplace.add( o);
              previousRepeatID = null;
             
            } else if (resultRepeatId != null) {
 
              if (previousRepeatID!=null && previousRepeatID.equals(resultRepeatId)) {
                // it is second or subsequent
                repeatSdtToDelete.add( o);
              } else {
                repeatSdtToReplace.add( o);             
              }
              previousRepeatID = resultRepeatId;
             
            } else if (xpathId != null) {
             
              boundSdtPotentialRepair.add(o);
             
            } else if (tag.getVal().contains("od:")){
              log.info("Ignoring (!) tag: " + tag.getVal());
            } else {
              log.debug("Ignoring tag: " + tag.getVal());
            }
          }
        }
      } else {
        previousRepeatID = null;
View Full Code Here

      </w:sdtPr>
      */
   
    Alias alias = Context.getWmlObjectFactory().createSdtPrAlias();
    alias.setVal(key);
    Tag tag = Context.getWmlObjectFactory().createTag();
    tag.setVal("od:xpath=" + key);
    sdtPr.setTag(tag);
    sdtPr.setId();
    CTDataBinding ctDataBinding = Context.getWmlObjectFactory().createCTDataBinding();
    JAXBElement<CTDataBinding> jaxbDB =
        Context.getWmlObjectFactory().createSdtPrDataBinding(ctDataBinding);
View Full Code Here

      // Object ublock = XmlUtils.unwrap(block);
      if (block instanceof org.docx4j.wml.SdtBlock) {

        org.docx4j.wml.SdtBlock sdt = (org.docx4j.wml.SdtBlock) block;

        Tag tag = getSdtPr(sdt).getTag();

        if (tag == null) {
          List<Object> newContent = new ArrayList<Object>();
          newContent.add(sdt);
          continue;
        }

        log.info(tag.getVal());

        HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(),
            true);

        String componentId = map.get(BINDING_ROLE_COMPONENT);
        if (componentId == null)
          continue;
View Full Code Here

   * @throws Exception
   */
  private List<Object> processBindingRoleIfAny(
      WordprocessingMLPackage wordMLPackage, Object sdt) {
    log.debug("Processing " + getSdtPr(sdt).getId().getVal());
    Tag tag = getSdtPr(sdt).getTag();

    if (tag == null) {
      List<Object> newContent = new ArrayList<Object>();
      newContent.add(sdt);
      return newContent;
    }

    log.info(tag.getVal());

    HashMap<String, String> map = QueryString.parseQueryString(tag.getVal(), true);

    String conditionId = map.get(BINDING_ROLE_CONDITIONAL);
    String repeatId = map.get(BINDING_ROLE_REPEAT);
    String xp = map.get(BINDING_ROLE_XPATH);
    if (conditionId == null && repeatId == null && xp == null) {
      List<Object> newContent = new ArrayList<Object>();
      newContent.add(sdt);
      return newContent;
    }

    Map<String, CustomXmlPart> customXmlDataStorageParts = wordMLPackage
        .getCustomXmlDataStorageParts();

    if (conditionId != null) {

      log.info("Processing Conditional: " + tag.getVal());

      // At present, this only handles simple conditions
      Condition c = ConditionsPart.getConditionById(conditions,
          conditionId);
      if (c == null) {
        log.error("Missing condition " + conditionId);
      }

      if ( c.evaluate(wordMLPackage, customXmlDataStorageParts, conditions, xPaths) ) {
        log.debug("so keeping");

        List<Object> newContent = new ArrayList<Object>();
        newContent.add(sdt);
        return newContent;

      } else {
        return conditionFalse(sdt);
      }

    } else if (repeatId != null) {

      log.info("Processing Repeat: " + tag.getVal());

      return processRepeat(sdt,
          customXmlDataStorageParts, wordMLPackage
              .getMainDocumentPart().getXPathsPart());

View Full Code Here

    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 stripConditionArgPattern = Pattern
        .compile("(.*od:condition=)([^&]*)(.*)");
    final Matcher stripPatternMatcher = stripConditionArgPattern
        .matcher(tagVal);
    if (!stripPatternMatcher.matches()) {
      log.error("Cannot find condition tag in sdtPr/tag while setting conditionFalse; something is wrong with " + tagVal);
      return newContent;
    }
    final String emptyConditionValue = BINDING_RESULT_CONDITION_FALSE + "=" + stripPatternMatcher.group(2) + stripPatternMatcher.group(3);
    tag.setVal(emptyConditionValue)
   
    // 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);
View Full Code Here

  private List<Object> processRepeat(Object sdt,
      Map<String, CustomXmlPart> customXmlDataStorageParts,
      XPathsPart xPathsPart) {

    Tag tag = getSdtPr(sdt).getTag();

    HashMap<String, String> map = QueryString.parseQueryString(
        tag.getVal(), true);

    String repeatId = map.get(BINDING_ROLE_REPEAT);

    // Check, whether we are in an old repeat case. These can be removed.
    if (StringUtils.isEmpty(repeatId))
View Full Code Here

    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);
View Full Code Here

    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);

    if (binding == null) {

      conditionId = map.get(BINDING_ROLE_CONDITIONAL);
      repeatId = map.get(BINDING_ROLE_REPEAT);

      if (conditionId != null) {

//        c = ConditionsPart.getConditionById(conditions, conditionId);
//        if (c == null) {
//          log.error("Missing condition " + conditionId);
//          throw new InputIntegrityException("Required condition '" + conditionId + "' is missing");
//        }
//
//        // TODO: this code assumes the condition contains
//        // a simple xpath
//        log.debug("Using condition"
//            + XmlUtils.marshaltoString(c, true, true));
//        xpathObj = getXPathFromCondition(c);
//        thisXPath = xpathObj.getDataBinding().getXpath();

        processDescendantCondition( sdt,  xpathBase,
             index,  tag );
        return;

      } else if (repeatId != null) {

        xpathObj = XPathsPart.getXPathById(xPaths, repeatId);
        thisXPath = xpathObj.getDataBinding().getXpath();

      } else if (map.containsKey(BINDING_CONTENTTYPE)
          || map.containsKey(BINDING_HANDLER)
          || map.containsKey(BINDING_PROGID)) {

        xpathObj = XPathsPart.getXPathById(xPaths,
            map.get(BINDING_ROLE_XPATH) );
        thisXPath = xpathObj.getDataBinding().getXpath();
       
      } else {

        log.warn("couldn't find binding or bindingrole!");
        // not all sdt's need have a binding;
        // they could be present in the docx for other purposes
        return;

        // NB an OpenDoPE xpath tag (with no w:binding element)
        // eg as created by authoring tool for a "count(" XPath
        // ends up here.
      }

    } else {
      thisXPath = binding.getXpath();

      // Set this stuff up now
      bindingId = map.get(BINDING_ROLE_XPATH);
      xpathObj = XPathsPart.getXPathById(xPaths, bindingId);

      // Sanity test
      if (!thisXPath.equals(xpathObj.getDataBinding().getXpath())) {
        log.error("XPaths didn't match for id " + bindingId + ": \n\r    " + thisXPath + "\n\rcf. "
            + xpathObj.getDataBinding().getXpath());
      }

      // 2012 09 20 - when did this break?
      //thisXPath = xpathObj.getDataBinding().getXpath();
    }

//    System.out.println("xpathBase: " + xpathBase);
//    System.out.println("index: " + index);
//    System.out.println("thisXPath: " + thisXPath);


    final String newPath = enhanceXPath(xpathBase, index + 1, thisXPath);

//    System.out.println("newPath: " + newPath);

    if (log.isDebugEnabled() && !thisXPath.equals(newPath)) {
      log.debug("xpath prefix enhanced " + thisXPath + " to " + newPath);
    }

    if (binding == null) {

      if (repeatId != null) {

        // Create the new xpath object
        org.opendope.xpaths.Xpaths.Xpath newXPathObj = createNewXPathObject(
            newPath, xpathObj, index);

        // set sdt to use it
        map.put(BINDING_ROLE_REPEAT, newXPathObj.getId());
        tag.setVal(QueryString.create(map));

      } else if (map.containsKey(BINDING_CONTENTTYPE)
          || map.containsKey(BINDING_HANDLER)
          || map.containsKey(BINDING_PROGID)) {

        // Also need to create new xpath id, and add that
        org.opendope.xpaths.Xpaths.Xpath newXPathObj = createNewXPathObject(
            newPath, xpathObj, index);

        // set sdt to use it
        map.put(BINDING_ROLE_XPATH, newXPathObj.getId());
        tag.setVal(QueryString.create(map));

      }

    } else {
      binding.setXpath(newPath);

      // Also need to create new xpath id, and add that
      org.opendope.xpaths.Xpaths.Xpath newXPathObj = createNewXPathObject(
          newPath, xpathObj, index);

      // set sdt to use it
      map.put(BINDING_ROLE_XPATH, newXPathObj.getId());
      tag.setVal(QueryString.create(map));
    }

  }
View Full Code Here

TOP

Related Classes of org.docx4j.wml.Tag

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.