org.modeshape.schematic.document.Document.withVariablesReplacedWithSystemProperties()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.modeshape.schematic.document.Document.withVariablesReplacedWithSystemProperties()方法的一些代码示例,展示了Document.withVariablesReplacedWithSystemProperties()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document.withVariablesReplacedWithSystemProperties()方法的具体详情如下:
包路径:org.modeshape.schematic.document.Document
类名称:Document
方法名:withVariablesReplacedWithSystemProperties

Document.withVariablesReplacedWithSystemProperties介绍

[英]Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the System properties.

Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:

variable := '${' variableNames [ ':' defaultValue ] '}' 
variableNames := variableName [ ',' variableNames ] 
variableName := /* any characters except ',' and ':' and '}' 
defaultValue := /* any characters except

Note that variableName is the name used to look up a System property via System#getProperty(String).

Notice that the syntax supports multiple variables. The logic will process the variables from let to right, until an existing System property is found. And at that point, it will stop and will not attempt to find values for the other variables.

Because only string values can contain variables, the resulting values are left as strings. This may not be valid according to the document's JSON Schema, so see SchemaLibrary#convertValues(Document,String) to convert the string values after variable substitution into the expected non-string types.
[中]获取此文档的克隆,但将字符串字段值中的所有变量替换为系统属性中的引用值。
变量可能出现在字符串值中的任何位置,并且在同一个值中可以使用多个变量。变量的形式如下:

variable := '${' variableNames [ ':' defaultValue ] '}' 
variableNames := variableName [ ',' variableNames ] 
variableName := /* any characters except ',' and ':' and '}' 
defaultValue := /* any characters except

请注意,variableName是用于通过System#getProperty(字符串)查找系统属性的名称。
请注意,该语法支持多个变量。逻辑将从let到right处理变量,直到找到现有的系统属性。在这一点上,它将停止,不会试图找到其他变量的值。
因为只有字符串值可以包含变量,所以结果值保留为字符串。根据文档的JSON模式,这可能无效,因此请参阅SchemaLibrary#convertValues(文档,字符串)将变量替换后的字符串值转换为预期的非字符串类型。

代码示例

代码示例来源:origin: ModeShape/modeshape

/**
 * Returns a DB with reads the given input stream as a configuration document {@code Document}. This document is 
 * expected to contain a {@link Schematic#TYPE_FIELD type field} to indicate the type
 * of DB.
 * 
 * @see #getDb(Document, ClassLoader)
 * @throws ParsingException if the given input stream is not a valid JSON document
 */
public static <T extends SchematicDb> T getDb(InputStream configInputStream) throws ParsingException, RuntimeException {
  Document document = Json.read(configInputStream).withVariablesReplacedWithSystemProperties();
  return getDb(document, Schematic.class.getClassLoader());
}

代码示例来源:origin: org.modeshape/modeshape-schematic

/**
 * Returns a DB with reads the given input stream as a configuration document {@code Document}. This document is 
 * expected to contain a {@link Schematic#TYPE_FIELD type field} to indicate the type
 * of DB.
 * 
 * @see #getDb(Document, ClassLoader)
 * @throws ParsingException if the given input stream is not a valid JSON document
 */
public static <T extends SchematicDb> T getDb(InputStream configInputStream) throws ParsingException, RuntimeException {
  Document document = Json.read(configInputStream).withVariablesReplacedWithSystemProperties();
  return getDb(document, Schematic.class.getClassLoader());
}

代码示例来源:origin: ModeShape/modeshape

/**
 * Utility method to replace all system property variables found within the specified document.
 *
 * @param doc the document; may not be null
 * @return the modified document if system property variables were found, or the <code>doc</code> instance if no such
 *         variables were found
 */
protected static Document replaceSystemPropertyVariables( Document doc ) {
  if (doc.isEmpty()) return doc;
  Document modified = doc.withVariablesReplacedWithSystemProperties();
  if (modified == doc) return doc;
  // Otherwise, we changed some values. Note that the system properties can only be used in
  // string values, whereas the schema may expect non-string values. Therefore, we need to validate
  // the document against the schema and possibly perform some conversions of values ...
  return SCHEMA_LIBRARY.convertValues(modified, JSON_SCHEMA_URI);
}

代码示例来源:origin: org.fcrepo/modeshape-jcr

/**
 * Utility method to replace all system property variables found within the specified document.
 *
 * @param doc the document; may not be null
 * @return the modified document if system property variables were found, or the <code>doc</code> instance if no such
 *         variables were found
 */
protected static Document replaceSystemPropertyVariables( Document doc ) {
  if (doc.isEmpty()) return doc;
  Document modified = doc.withVariablesReplacedWithSystemProperties();
  if (modified == doc) return doc;
  // Otherwise, we changed some values. Note that the system properties can only be used in
  // string values, whereas the schema may expect non-string values. Therefore, we need to validate
  // the document against the schema and possibly perform some conversions of values ...
  return SCHEMA_LIBRARY.convertValues(modified, JSON_SCHEMA_URI);
}

相关文章