/** * Returns a string with variables replaced by system property values if they exist * * @return */ public static String resolveProperties(String str) { return StrSubstitutor.replaceSystemProperties(str); }
/** * Returns a List with variables replaced by system property values if they exist * * @return */ public static List<String> resolveProperties(List<String> list) { for (final ListIterator<String> i = list.listIterator(); i.hasNext(); ) { final String item = StrSubstitutor.replaceSystemProperties(i.next()); i.set(item); } return list; }
/** * Replace any ${prop} with system properties. * * @param props current state of properties that contain placeholders of the form ${property}. * @return the given property object with system property placeholders switched to their actual * values. */ @VisibleForTesting static Properties substituteSystemPropertyPlaceholders(Properties props) { Properties filtered = new Properties(); for (Map.Entry<?, ?> entry : props.entrySet()) { filtered.put( StrSubstitutor.replaceSystemProperties(entry.getKey()), StrSubstitutor.replaceSystemProperties(entry.getValue())); StrSubstitutor.replaceSystemProperties(new Object()); } return filtered; } }
/** * Parses a string and retruns a JSON tree */ public static JsonNode json(String s) throws IOException { // do system property expansion String jsonString = StrSubstitutor.replaceSystemProperties(s); return getObjectMapper().readTree(jsonString); }
/** * Reads the {@link InputStream} and substitutes system properties. * * @return {@link Reader} */ private static Reader loadInputStream(InputStream propertiesStream) throws IOException { StringBuilder buff = new StringBuilder(); try (InputStreamReader isr = new InputStreamReader(propertiesStream, Charset.defaultCharset()); BufferedReader reader = new BufferedReader(isr)) { String line; while ((line = reader.readLine()) != null) { buff.append(line).append("\n"); } } return new StringReader(StrSubstitutor.replaceSystemProperties(buff.toString())); }
/** * Gets values of the specified node as a list. Use this method for JSON * arrays. * * @param path XPath to node * @return value list, possibly empty */ public List<Object> getList(String path) { List<Object> valueList = new ArrayList<Object>(); Iterator<?> valueIterator = getJXPath().iterate(path); while (valueIterator.hasNext()) { Object value = valueIterator.next(); valueList.add(value instanceof String ? StrSubstitutor .replaceSystemProperties(value) : value); } return valueList; }
/** * Gets a map of the child nodes of the specified node * * @param path XPath to node * @return node map, possibly empty */ public Map<String, Object> getMap(String path) { Map<String, Object> valueMap = new LinkedHashMap<String, Object>(); Object valueNode = getJXPath().getValue(path); if (valueNode instanceof Map) { Map<String, Object> map = (Map<String, Object>) valueNode; for (String key : map.keySet()) { Object value = map.get(key); if (value instanceof String) { valueMap.put(key, StrSubstitutor.replaceSystemProperties(value)); } else { valueMap.put(key, value); } } } return valueMap; }
/** * Gets the value of the specified node, with a specified default if the not * was not found * * @param path XPath to node * @param defaultValue value to return if the node was not found * @return node value or defaultValue if not found */ public String get(String path, String defaultValue) { Object valueNode = null; try { valueNode = getJXPath().getValue(path); } catch (Exception e) { } String value = valueNode == null ? defaultValue : valueNode.toString(); return StrSubstitutor.replaceSystemProperties(value); }
List<String> temp = JsonSimple.getStringList((JSONArray) target); for (String string : temp) { response.add(StrSubstitutor.replaceSystemProperties(string)); response.add(StrSubstitutor.replaceSystemProperties((String) target)); } else { response.add((String) target);
InputStream input = null; final String mappings = StrSubstitutor.replaceSystemProperties(yamlConfig); final String trimmedMappings = StringUtils.trim(mappings);
response = StrSubstitutor.replaceSystemProperties(response);
/** * Gets a Drools audit logger given an audit model and a session. * @param audit the audit model * @param ksession the session * @return the logger */ public static KnowledgeRuntimeLogger getLogger(AuditModel audit, KnowledgeRuntimeEventManager ksession) { if (audit != null) { AuditType type = audit.getType(); if (type == null) { type = AuditType.THREADED_FILE; } String log = Strings.trimToNull(audit.getLog()); String fileName = log != null ? StrSubstitutor.replaceSystemProperties(log) : "event"; Integer interval = audit.getInterval(); if (interval == null) { interval = Integer.valueOf(1000); } switch (type) { case CONSOLE: return KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); case FILE: return KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, fileName); case THREADED_FILE: return KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, fileName, interval.intValue()); } } return null; }