當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。