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