/** * Creates the search descriptor which searches for 'xTextDoc' string. * * <p>Has <b> OK </b> status if the method returns not <code>null</code> value. */ public void _createSearchDescriptor() { log.println("testing createSearchDescriptor() ... "); Sdesc = oObj.createSearchDescriptor(); Sdesc.setSearchString(mSearchString); tRes.tested("createSearchDescriptor()", Sdesc != null); }
/** * Replaces all aliases ${bandname.paramname} in document text. * * @throws com.haulmont.yarg.exception.ReportingException If there is not appropriate band or * alias is bad */ protected void replaceAllAliasesInDocument() { XTextDocument xTextDocument = as(XTextDocument.class, xComponent); XReplaceable xReplaceable = as(XReplaceable.class, xTextDocument); XSearchDescriptor searchDescriptor = xReplaceable.createSearchDescriptor(); searchDescriptor.setSearchString(ALIAS_WITH_BAND_NAME_REGEXP); try { searchDescriptor.setPropertyValue(SEARCH_REGULAR_EXPRESSION, true); } catch (Exception e) { throw new OpenOfficeException( "An error occurred while setting search properties in Open office", e); } XIndexAccess indexAccess = xReplaceable.findAll(searchDescriptor); for (int i = 0; i < indexAccess.getCount(); i++) { try { XTextRange textRange = as(XTextRange.class, indexAccess.getByIndex(i)); String alias = unwrapParameterName(textRange.getString()); BandPathAndParameterName bandAndParameter = separateBandNameAndParameterName(alias); BandData band = findBandByPath(bandAndParameter.getBandPath()); if (band != null) { insertValue(textRange.getText(), textRange, band, bandAndParameter.getParameterName()); } else { throw wrapWithReportingException(String.format("No band for alias [%s] found", alias)); } } catch (ReportingException e) { throw e; } catch (Exception e) { throw wrapWithReportingException( String.format( "An error occurred while replacing aliases in document. Regexp [%s]. Replacement number [%d]", ALIAS_WITH_BAND_NAME_REGEXP, i), e); } } }