当前位置: 首页>>代码示例>>Java>>正文


Java StrSubstitutor类代码示例

本文整理汇总了Java中org.apache.commons.lang.text.StrSubstitutor的典型用法代码示例。如果您正苦于以下问题:Java StrSubstitutor类的具体用法?Java StrSubstitutor怎么用?Java StrSubstitutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StrSubstitutor类属于org.apache.commons.lang.text包,在下文中一共展示了StrSubstitutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMessage

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private String getMessage(ApprovalStatusUpdateEvent event, IOrderApprovalMapping orderApproval,
                          IUserAccount requester, IKiosk kiosk, IUserAccount updatedBy) {

  String message = getMessage(event.getStatus(), requester);
  Map<String, String> values = new HashMap<>();
  values.put("approvalType", ApprovalUtils.getApprovalType(orderApproval.getApprovalType()));
  values.put("requestorName", requester.getFullName());
  values.put("requestorPhone", requester.getMobilePhoneNumber());
  values.put("eName", kiosk.getName());
  values.put("eCity", kiosk.getCity());
  values.put("orderId", event.getTypeId());
  values.put("statusChangedTime", LocalDateUtil.format(event.getUpdatedAt(),
      requester.getLocale(), requester.getTimezone()));
  values.put("updatedBy", updatedBy.getFullName());
  values.put("updatedByPhone", updatedBy.getMobilePhoneNumber());

  StrSubstitutor sub = new StrSubstitutor(values);

  return sub.replace(message);
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:ApprovalStatusUpdateEventProcessor.java

示例2: interpolate

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
public static void interpolate(File file)  {
	String content;
	try {
		content = new String(Files.readAllBytes(file.toPath()));
		String replace = StrSubstitutor.replace(content, new ConfigurationMap( configuration()));
		Files.write(file.toPath(), replace.getBytes());

	} catch (IOException e) {
		LOGGER.error( file  +  " interpolation error ", e);
		
	}
	
}
 
开发者ID:rockitconsulting,项目名称:test.rockitizer,代码行数:14,代码来源:PayloadReplacer.java

示例3: notifyStockEditors

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
 * Notify user with "Edit stock inventories" right for the facility/program that
 * facility has stocked out of a product.
 *
 * @param stockCard StockCard for a product
 */
public void notifyStockEditors(StockCard stockCard) {
  Collection<UserDto> recipients = getEditors(stockCard);

  String subject = getMessage(EMAIL_ACTION_REQUIRED_SUBJECT);
  String content = getMessage(EMAIL_ACTION_REQUIRED_CONTENT);

  Map<String, String> valuesMap = getValuesMap(stockCard);
  StrSubstitutor sub = new StrSubstitutor(valuesMap);
  for (UserDto recipient : recipients) {
    if (recipient.getHomeFacilityId().equals(stockCard.getFacilityId())
        && canBeNotified(recipient)) {
      valuesMap.put("username", recipient.getUsername());
      notificationService.notify(recipient, sub.replace(subject), sub.replace(content));
    }
  }
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:23,代码来源:StockoutNotifier.java

示例4: resolveJsonPaths

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
@Override
public String resolveJsonPaths(String jsonString, String scenarioState) {
    List<String> jsonPaths = getAllJsonPathTokens(jsonString);
    Map<String, String> paramMap = new HashMap<>();

    jsonPaths.forEach(thisPath -> {
        try {
            paramMap.put(thisPath, JsonPath.read(scenarioState, thisPath));
        } catch (Exception e) {
            throw new RuntimeException("\nJSON:" + jsonString + "\nPossibly comments in the JSON found or bad JSON path found: " + thisPath + ", Details: " + e);
        }
    });

    StrSubstitutor sub = new StrSubstitutor(paramMap);

    return sub.replace(jsonString);
}
 
开发者ID:authorjapps,项目名称:zerocode,代码行数:18,代码来源:ZeroCodeJsonTestProcesorImpl.java

示例5: createStepWith

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
protected String createStepWith(String stepName) {
    Map<String, String> parammap = new HashMap<>();

    parammap.put("STEP.NAME", stepName);
    parammap.put("STEP.REQUEST", "{\n" +
            "    \"customer\": {\n" +
            "        \"firstName\": \"FIRST_NAME\"\n" +
            "    }\n" +
            "}");
    parammap.put("STEP.RESPONSE", "{\n" +
            "    \"id\" : 10101\n" +
            "}");

    StrSubstitutor sub = new StrSubstitutor(parammap);

    return sub.replace((new StepExecutionState()).getRequestResponseState());
}
 
开发者ID:authorjapps,项目名称:zerocode,代码行数:18,代码来源:ScenarioExecutionStateTest.java

示例6: initHomeDir

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
protected void initHomeDir() {
    String homeDir = System.getProperty(DesktopAppContextLoader.HOME_DIR_SYS_PROP);
    if (StringUtils.isBlank(homeDir)) {
        homeDir = getDefaultHomeDir();
    }
    homeDir = StrSubstitutor.replaceSystemProperties(homeDir);
    System.setProperty(DesktopAppContextLoader.HOME_DIR_SYS_PROP, homeDir);

    File file = new File(homeDir);
    if (!file.exists()) {
        boolean success = file.mkdirs();
        if (!success) {
            System.out.println("Unable to create home dir: " + homeDir);
            System.exit(-1);
        }
    }
    if (!file.isDirectory()) {
        System.out.println("Invalid home dir: " + homeDir);
        System.exit(-1);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:22,代码来源:App.java

示例7: getFileName

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
 * Get the final filename of the generated .ass subtitle
 * 
 * @return the name of the first subtitle
 */
private String getFileName() {

	String filename = this.userConfig.getFilename();
	if (StringUtils.isEmpty(filename)) {
		filename = this.userConfig.getFirstSubtitle().getFileName();
		filename = FilenameUtils.getBaseName(filename);
	} else {
		Map<String, String> substitutes = new HashMap<>();

		String oneN = FilenameUtils.getBaseName(this.userConfig.getFirstSubtitle().getFileName());
		String twoN = FilenameUtils.getBaseName(this.userConfig.getSecondSubtitle().getFileName());

		substitutes.put("one", oneN);
		substitutes.put("two", twoN);
		substitutes.put("baseOne", StringUtils.substringBeforeLast(oneN, "."));
		substitutes.put("baseTwo", StringUtils.substringBeforeLast(twoN, "."));

		StrSubstitutor substitutor = new StrSubstitutor(substitutes);
		filename = substitutor.replace(filename);
	}
	return filename;
}
 
开发者ID:dnbn,项目名称:submerge,代码行数:28,代码来源:IndexBean.java

示例8: serialize

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
@Override
public Iterable<Record> serialize(Event event) {
  RecordKey key = new RecordKey();
  Text value = new Text();
  try {
    value.set(new String(event.getBody(), Charsets.UTF_8.name()));
    key.setHash(event.getHeaders().get(HEADER_TIMESTAMP).hashCode());
    key.setType(event.getHeaders().get(HEADER_BATCH_TYPE));
    key.setCodec(DFS_CODEC);
    key.setContainer(DFS_CONTAINER);
    key.setBatch(new StrSubstitutor(event.getHeaders(), "%{", "}").replace(DFS_BATCH_PATTERN));
    key.setTimestamp(Long.parseLong(event.getHeaders().get(HEADER_TIMESTAMP)));
    key.setValid(true);
  } catch (Exception exception) {
    key.setValid(false);
  }
  return Collections.singletonList(new Record(key, value));
}
 
开发者ID:ggear,项目名称:cloudera-framework,代码行数:19,代码来源:Stream.java

示例9: replaceProperties

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private void replaceProperties(Properties props) {
    StrSubstitutor substitutor = new StrSubstitutor(sqlProperties);

    // we must delete slash(it is added to the ${sql.url}) from connection string -> ${sql.url}/database
    if (props.getProperty(CONNECTION_URL_KEY) != null) {
        String connectionUrl = parseConnectionString(props.getProperty(CONNECTION_URL_KEY));
        props.put(CONNECTION_URL_KEY, connectionUrl);
    }

    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        if (entry.getValue() instanceof String) {
            String substituted = substitutor.replace(entry.getValue());
            entry.setValue(substituted);
        }
    }
}
 
开发者ID:motech,项目名称:motech,代码行数:17,代码来源:SqlDBManagerImpl.java

示例10: goArtifact

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private Function<File, GoArtifact> goArtifact(final UriConfig config, final Map<String, String> properties, final TaskExecutionContext context) {
    return new Function<File, GoArtifact>() {
        @Override
        public GoArtifact apply(File file) {
            GoArtifact artifact = new GoArtifact(file.getAbsolutePath(), artifactUri(file.getName()));
            artifact.properties(properties);
            return artifact;
        }

        private String artifactUri(String artifactName) {
            String uri = config.isFolder() ? config.uri() + "/" + artifactName : config.uri();
            StrSubstitutor sub = new StrSubstitutor(context.environment().asMap());
            return sub.replace(uri);
        }
        
    };
}
 
开发者ID:tusharm,项目名称:go-artifactory-plugin,代码行数:18,代码来源:GoArtifactFactory.java

示例11: impliesURI

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
public static boolean impliesURI(String privilege, String request) {
  try {
    URI privilegeURI = new URI(new StrSubstitutor(System.getProperties()).replace(privilege));
    URI requestURI = new URI(request);
    if (privilegeURI.getScheme() == null || privilegeURI.getPath() == null) {
      LOGGER.warn("Privilege URI " + request + " is not valid. Either no scheme or no path.");
      return false;
    }
    if (requestURI.getScheme() == null || requestURI.getPath() == null) {
      LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path.");
      return false;
    }
    return PathUtils.impliesURI(privilegeURI, requestURI);
  } catch (URISyntaxException e) {
    LOGGER.warn("Request URI " + request + " is not a URI", e);
    return false;
  }
}
 
开发者ID:apache,项目名称:incubator-sentry,代码行数:19,代码来源:PathUtils.java

示例12: renderBlock

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
/**
 * Loads the template with the specified name from the classloader and uses
 * it to templatize the properties using Apache Commons Lang's
 * StrSubstitutor and writes it to the response.
 * 
 * @param res
 *            the response to write to
 * @param template
 *            the template file to load from the classpath
 * @param properties
 *            the properties to templatize
 * @throws IOException
 */
private void renderBlock(HttpServletResponse res, String templateName,
		Map<String, String> properties) throws IOException {
	InputStream is = null;
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	String template = null;
	try {
		is = getClass().getClassLoader().getResourceAsStream(templateName);
		if (is != null) {
			IOUtils.copy(is, baos);
			template = baos.toString();
		} else {
			throw new IOException("Unable to load template " + templateName);
		}
	} finally {
		IOUtils.closeQuietly(is);
		IOUtils.closeQuietly(baos);
	}
	StrSubstitutor sub = new StrSubstitutor(properties);
	res.getWriter().write(sub.replace(template));
}
 
开发者ID:SixDimensions,项目名称:Component-Bindings-Provider,代码行数:34,代码来源:ComponentBindingsProviderWebConsole.java

示例13: testProperty

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private void testProperty( String propertyName, boolean containsSubstitution ) {
    String propertyValue = setup.get( propertyName );
    assertTrue( propertyName + " was not found", isNotBlank( propertyValue ) );
    logger.info( propertyName + "=" + propertyValue );

    if ( containsSubstitution ) {
        Map<String, String> valuesMap = new HashMap<String, String>();
        valuesMap.put( "reset_url", "test-url" );
        valuesMap.put( "organization_name", "test-org" );
        valuesMap.put( "activation_url", "test-url" );
        valuesMap.put( "confirmation_url", "test-url" );
        valuesMap.put( "user_email", "test-email" );
        valuesMap.put( "pin", "test-pin" );
        StrSubstitutor sub = new StrSubstitutor( valuesMap );
        String resolvedString = sub.replace( propertyValue );
        assertNotSame( propertyValue, resolvedString );
    }
}
 
开发者ID:apache,项目名称:usergrid,代码行数:19,代码来源:EmailFlowIT.java

示例14: getCommitMessage

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
private String getCommitMessage(final Project project) {
    String templateString = TemplateFileHandler.loadFile(project);

    Map<String, String> valuesMap = new HashMap<>();
    String branchName = CommitMessage.extractBranchName(project);
    String[] branchParts = CommitMessage.splitBranchName(branchName);
    if (branchParts.length > 1) {
        valuesMap.put(Consts.TICKET, branchParts[1]);
    }
    valuesMap.put(Consts.SHORT_DESCRIPTION, "");
    valuesMap.put(Consts.LONG_DESCRIPTION, "");
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(templateString);
}
 
开发者ID:JanGatting,项目名称:GitCommitMessage,代码行数:15,代码来源:GetCommitMessageAction.java

示例15: getCommitMessage

import org.apache.commons.lang.text.StrSubstitutor; //导入依赖的package包/类
String getCommitMessage(Project project) {
    String templateString = TemplateFileHandler.loadFile(project);

    Map<String, String> valuesMap = new HashMap<>();
    valuesMap.put(Consts.TICKET, getBranch());
    valuesMap.put(Consts.SHORT_DESCRIPTION, panel.getShortDescription());
    valuesMap.put(Consts.LONG_DESCRIPTION, getLongDescription(templateString));
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(templateString);
}
 
开发者ID:JanGatting,项目名称:GitCommitMessage,代码行数:11,代码来源:PanelDialog.java


注:本文中的org.apache.commons.lang.text.StrSubstitutor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。