Exemple #1
0
  protected void fillCell(BandData band, XCell xCell)
      throws NoSuchElementException, WrappedTargetException {
    XText xText = as(XText.class, xCell);
    String cellText = xText.getString();
    cellText = cellText.replace("\r\n", "\n"); // just a workaround for Windows \r\n break symbol
    List<String> parametersToInsert = new ArrayList<String>();
    Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(cellText);
    while (matcher.find()) {
      parametersToInsert.add(unwrapParameterName(matcher.group()));
    }
    for (String parameterName : parametersToInsert) {
      XTextCursor xTextCursor = xText.createTextCursor();

      String paramStr = "${" + parameterName + "}";
      int index = cellText.indexOf(paramStr);
      while (index >= 0) {
        xTextCursor.gotoStart(false);
        xTextCursor.goRight((short) (index + paramStr.length()), false);
        xTextCursor.goLeft((short) paramStr.length(), true);

        insertValue(xText, xTextCursor, band, parameterName);
        cellText = formatCellText(xText.getString());

        index = cellText.indexOf(paramStr);
      }
    }
  }
  /**
   * Retrieves the start range and sets its context to 'Start' string.
   *
   * <p>Has <b>OK</b> status if the whole range string starts with 'Start' substring.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> setString </code>
   * </ul>
   */
  public void _getStart() {

    XText the_text = (XText) tEnv.getObjRelation("XTEXT");

    if (the_text != null) {
      the_text.setString("");
    }

    String exp = "";

    oObj.setString("MiddleEnd");

    oStartRange = oObj.getStart();
    oStartRange.setString("Start");

    if (the_text != null) {
      exp = the_text.getString();
    } else exp = oObj.getText().getString();

    log.println("Start: " + exp);

    tRes.tested("getStart()", oStartRange != null && exp.startsWith("Start"));

    oStartRange.setString("");
  }
  /**
   * Gets the text of the range and retrieves its String content.
   *
   * <p>Has <b>OK</b> status if the string returned equals to 'StartMiddleEnd' value.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> setString </code> to get finally the string expected.
   *   <li><code> getStart </code> to get finally the string expected.
   *   <li><code> getEnd </code> to get finally the string expected.
   * </ul>
   */
  public void _getText() {
    requiredMethod("setString()");
    requiredMethod("getStart()");
    requiredMethod("getEnd()");

    XText txt = oObj.getText();

    tRes.tested("getText()", txt != null && txt.getString().equals("StartMiddle"));
  }
Exemple #4
0
    public BandFinder find() {
      bandName = tableName;
      band = rootBand.findBandRecursively(bandName);
      if (band == null) {
        XText xText = tableManager.findFirstEntryInRow(BAND_NAME_DECLARATION_PATTERN, 0);
        if (xText != null) {
          Matcher matcher = BAND_NAME_DECLARATION_PATTERN.matcher(xText.getString());
          if (matcher.find()) {
            bandName = matcher.group(1);
            band = rootBand.findBandRecursively(bandName);
            XTextCursor xTextCursor = xText.createTextCursor();

            xTextCursor.gotoStart(false);
            xTextCursor.goRight((short) matcher.end(), false);
            xTextCursor.goLeft((short) matcher.group().length(), true);

            xText.insertString(xTextCursor, "", true);
          }
        }
      }
      return this;
    }
Exemple #5
0
  protected void insertValue(
      XText text, XTextRange textRange, BandData band, String parameterName) {
    String fullParameterName = band.getName() + "." + parameterName;
    Object paramValue = band.getParameterValue(parameterName);

    Map<String, ReportFieldFormat> formats = rootBand.getReportFieldFormats();
    try {
      boolean handled = false;

      if (paramValue != null) {
        if ((formats != null) && (formats.containsKey(fullParameterName))) {
          String format = formats.get(fullParameterName).getFormat();
          // Handle doctags
          for (ContentInliner contentInliner : contentInliners) {
            Matcher matcher = contentInliner.getTagPattern().matcher(format);
            if (matcher.find()) {
              contentInliner.inlineToDoc(officeComponent, textRange, text, paramValue, matcher);
              handled = true;
            }
          }
        }
        if (!handled) {
          String valueString = formatValue(paramValue, parameterName, fullParameterName);
          text.insertString(textRange, valueString, true);
        }
      } else {
        text.insertString(textRange, "", true);
      }
    } catch (Exception ex) {
      throw wrapWithReportingException(
          String.format(
              "An error occurred while inserting parameter [%s] into text line [%s]",
              parameterName, text.getString()),
          ex);
    }
  }