- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.apache.commons.configuration2.XMLConfiguration
类的一些代码示例,展示了XMLConfiguration
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLConfiguration
类的具体详情如下:
包路径:org.apache.commons.configuration2.XMLConfiguration
类名称:XMLConfiguration
[英]A specialized hierarchical configuration class that is able to parse XML documents.
The parsed document will be stored keeping its structure. The class also tries to preserve as much information from the loaded XML document as possible, including comments and processing instructions. These will be contained in documents created by the save() methods, too.
Like other file based configuration classes this class maintains the name and path to the loaded configuration file. These properties can be altered using several setter methods, but they are not modified by save() and load() methods. If XML documents contain relative paths to other documents (e.g. to a DTD), these references are resolved based on the path set for this configuration.
By inheriting from AbstractConfiguration this class provides some extended functionality, e.g. interpolation of property values. Like in PropertiesConfiguration property values can contain delimiter characters (the comma ',' per default) and are then split into multiple values. This works for XML attributes and text content of elements as well. The delimiter can be escaped by a backslash. As an example consider the following XML fragment:
<config>
<array>10,20,30,40</array>
<scalar>3\,1415</scalar>
<cite text="To be or not to be\, this is the question!"/>
</config>
Here the content of the array element will be split at the commas, so the array key will be assigned 4 values. In the scalarproperty and the text attribute of the cite element the comma is escaped, so that no splitting is performed.
The configuration API allows setting multiple values for a single attribute, e.g. something like the following is legal (assuming that the default expression engine is used):
XMLConfiguration config = new XMLConfiguration();
config.addProperty("test.dir[@name]", "C:\\Temp\\");
config.addProperty("test.dir[@name]", "D:\\Data\\");
However, in XML such a constellation is not supported; an attribute can appear only once for a single element. Therefore, an attempt to save a configuration which violates this condition will throw an exception.
Like other Configuration implementations, XMLConfigurationuses a ListDelimiterHandler object for controlling list split operations. Per default, a list delimiter handler object is set which disables this feature. XML has a built-in support for complex structures including list properties; therefore, list splitting is not that relevant for this configuration type. Nevertheless, by setting an alternative ListDelimiterHandler implementation, this feature can be enabled. It works as for any other concrete Configuration implementation.
Whitespace in the content of XML documents is trimmed per default. In most cases this is desired. However, sometimes whitespace is indeed important and should be treated as part of the value of a property as in the following example:
<indent> </indent>
Per default the spaces in the indent element will be trimmed resulting in an empty element. To tell XMLConfiguration that spaces are relevant the xml:space attribute can be used, which is defined in the XML specification. This will look as follows:
<indent xml:space="preserve"> </indent>
The value of the indent property will now contain the spaces.
XMLConfiguration implements the FileBasedConfigurationinterface and thus can be used together with a file-based builder to load XML configuration files from various sources like files, URLs, or streams.
Like other Configuration implementations, this class uses a Synchronizer object to control concurrent access. By choosing a suitable implementation of the Synchronizer interface, an instance can be made thread-safe or not. Note that access to most of the properties typically set through a builder is not protected by the Synchronizer. The intended usage is that these properties are set once at construction time through the builder and after that remain constant. If you wish to change such properties during life time of an instance, you have to use the lock() and unlock() methods manually to ensure that other threads see your changes.
More information about the basic functionality supported by XMLConfiguration can be found at the user's guide at Basic features and AbstractConfiguration. There is also a separate chapter dealing with XML Configurations in special.
[中]一个专门的层次结构配置类,能够解析XML文档。
解析后的文档将保持其结构。该类还试图从加载的XML文档中保留尽可能多的信息,包括注释和处理指令。它们也将包含在save()方法创建的文档中。
与其他基于文件的配置类一样,该类维护加载的配置文件的名称和路径。可以使用几个setter方法更改这些属性,但save()和load()方法不会修改它们。如果XML文档包含到其他文档(例如到DTD)的相对路径,这些引用将基于为此配置设置的路径进行解析。
通过继承AbstractConfiguration,该类提供了一些扩展功能,例如属性值的插值。与PropertiesConfiguration中一样,属性值可以包含分隔符(逗号“,”每个默认值),然后拆分为多个值。这也适用于XML属性和元素的文本内容。分隔符可以用反斜杠转义。作为一个例子,考虑下面的XML片段:
<config>
<array>10,20,30,40</array>
<scalar>3\,1415</scalar>
<cite text="To be or not to be\, this is the question!"/>
</config>
在这里,数组元素的内容将在逗号处拆分,因此数组键将被分配4个值。在cite元素的scalarproperty和text属性中,逗号被转义,因此不执行拆分。
配置API允许为单个属性设置多个值,例如,以下内容是合法的(假设使用默认表达式引擎):
XMLConfiguration config = new XMLConfiguration();
config.addProperty("test.dir[@name]", "C:\\Temp\\");
config.addProperty("test.dir[@name]", "D:\\Data\\");
然而,在XML中,这样的星座是不受支持的;对于单个元素,属性只能出现一次。因此,试图保存违反此条件的配置将引发异常。
与其他配置实现一样,XMLConfiguration使用ListDelimiterHandler对象来控制列表拆分操作。默认情况下,会设置一个列表分隔符处理程序对象来禁用此功能。XML内置了对复杂结构的支持,包括列表属性;因此,列表拆分与此配置类型无关。不过,通过设置一个替代的ListDelimiterHandler实现,可以启用此功能。它与任何其他具体的配置实现一样有效。
默认情况下,XML文档内容中的空白会被删除。在大多数情况下,这是需要的。然而,有时空格的确很重要,应该被视为财产价值的一部分,如下例所示:
<indent> </indent>
默认情况下,缩进元素中的空格将被修剪,从而生成一个空元素。为了告诉XMLConfiguration空间是相关的,可以使用XML specification中定义的xml:space属性。这将如下所示:
<indent xml:space="preserve"> </indent>
缩进属性的值现在将包含空格。
XMLConfiguration实现了FileBasedConfiguration接口,因此可以与基于文件的生成器一起使用,从各种源(如文件、URL或流)加载XML配置文件。
与其他配置实现一样,此类使用同步器对象来控制并发访问。通过选择同步器接口的合适实现,实例可以是线程安全的,也可以不是线程安全的。请注意,对通常通过生成器设置的大多数属性的访问不受同步器的保护。预期用途是,这些属性在构建时通过构建器设置一次,之后保持不变。如果希望在实例的生命周期内更改此类属性,则必须手动使用lock()和unlock()方法,以确保其他线程看到您的更改。
有关XMLConfiguration支持的基本功能的更多信息,可以在Basic features and AbstractConfiguration的《用户指南》中找到。另外还有一章专门讨论{{2$}。
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Sets the name of the root element. This name is used when this
* configuration object is stored in an XML file. Note that setting the name
* of the root element works only if this configuration has been newly
* created. If the configuration was loaded from an XML file, the name
* cannot be changed and an {@code UnsupportedOperationException}
* exception is thrown. Whether this configuration has been loaded from an
* XML document or not can be found out using the {@code getDocument()}
* method.
*
* @param name the name of the root element
*/
public void setRootElementName(final String name)
{
beginRead(true);
try
{
if (getDocument() != null)
{
throw new UnsupportedOperationException(
"The name of the root element "
+ "cannot be changed when loaded from an XML document!");
}
rootElementName = name;
}
finally
{
endRead();
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Sets the public ID of the DOCTYPE declaration. When this configuration is
* saved, a DOCTYPE declaration will be constructed that contains this
* public ID.
*
* @param publicID the public ID
* @since 1.3
*/
public void setPublicID(final String publicID)
{
beginWrite(false);
try
{
this.publicID = publicID;
}
finally
{
endWrite();
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Checks whether an element defines a complete list. If this is the case,
* extended list handling can be applied.
*
* @param element the element to be checked
* @return a flag whether this is the only element defining the list
*/
private static boolean isSingleElementList(final Element element)
{
final Node parentNode = element.getParentNode();
return countChildElements(parentNode, element.getTagName()) == 1;
}
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Returns the public ID of the DOCTYPE declaration from the loaded XML
* document. This is <b>null</b> if no document has been loaded yet or if
* the document does not contain a DOCTYPE declaration with a public ID.
*
* @return the public ID
* @since 1.3
*/
public String getPublicID()
{
beginRead(false);
try
{
return publicID;
}
finally
{
endRead();
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
beginWrite(false);
try
final Transformer transformer = createTransformer();
final Source source = new DOMSource(createDocument());
final StringWriter writer = new StringWriter();
final Result result = new StreamResult(writer);
XMLDocumentHelper.transform(transformer, source, result);
final Reader reader = new StringReader(writer.getBuffer().toString());
final DocumentBuilder builder = createDocumentBuilder();
builder.parse(new InputSource(reader));
endWrite();
代码示例来源:origin: org.apache.commons/commons-configuration2
final Map<ImmutableNode, Object> elemRefs, final boolean trim, final int level)
final boolean trimFlag = shouldTrim(element, trim);
final Map<String, String> attributes = processAttributes(element);
attributes.put(ATTR_SPACE_INTERNAL, String.valueOf(trimFlag));
final StringBuilder buffer = new StringBuilder();
new MutableObject<>();
final Map<String, String> attrmap =
constructHierarchy(childNode, refChildValue, child,
elemRefs, trimFlag, level + 1);
final Boolean childTrim = Boolean.valueOf(attrmap.remove(ATTR_SPACE_INTERNAL));
childNode.addAttributes(attrmap);
final ImmutableNode newChild =
createChildNodeWithValue(node, childNode, child,
refChildValue.getValue(),
childTrim.booleanValue(), attrmap, elemRefs);
final String text = determineValue(buffer.toString(), childrenFlag, trimFlag);
if (text.length() > 0 || (!childrenFlag && level != 0))
代码示例来源:origin: com.goldmansachs.obevo/obevo-core
if (sysCfg.containsKey(ignorableAttribute)) {
sysCfg.clearProperty(ignorableAttribute);
if (!sysCfg.configurationsAt(ignorableSysNode).isEmpty()) {
sysCfg.clearTree(ignorableSysNode);
sysCfg.clearProperty("environments.environment[@" + ignorableAttribute + "]");
sysCfg.clearProperty("environments.dbEnvironment[@" + ignorableAttribute + "]");
sysCfg.clearTree("environments.environment." + ignorableSysNode);
sysCfg.clearTree("environments.dbEnvironment." + ignorableSysNode);
ImmutableList<HierarchicalConfiguration<ImmutableNode>> envConfigs = ListAdapter.adapt(sysCfg.configurationsAt("environments.dbEnvironment")).toImmutable();
if (envConfigs.isEmpty()) {
envConfigs = ListAdapter.adapt(sysCfg.configurationsAt("environments.environment")).toImmutable();
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Initializes this configuration from an XML document.
*
* @param docHelper the helper object with the document to be parsed
* @param elemRefs a flag whether references to the XML elements should be set
*/
private void initProperties(final XMLDocumentHelper docHelper, final boolean elemRefs)
{
final Document document = docHelper.getDocument();
setPublicID(docHelper.getSourcePublicID());
setSystemID(docHelper.getSourceSystemID());
final ImmutableNode.Builder rootBuilder = new ImmutableNode.Builder();
final MutableObject<String> rootValue = new MutableObject<>();
final Map<ImmutableNode, Object> elemRefMap =
elemRefs ? new HashMap<>() : null;
final Map<String, String> attributes =
constructHierarchy(rootBuilder, rootValue,
document.getDocumentElement(), elemRefMap, true, 0);
attributes.remove(ATTR_SPACE_INTERNAL);
final ImmutableNode top =
rootBuilder.value(rootValue.getValue())
.addAttributes(attributes).create();
getSubConfigurationParentModel().mergeRoot(top,
document.getDocumentElement().getTagName(), elemRefMap,
elemRefs ? docHelper : null, this);
}
代码示例来源:origin: com.airlenet/play-config
subConfig = new XMLConfiguration();
代码示例来源:origin: goldmansachs/obevo
if (sysCfg.containsKey(ignorableAttribute)) {
sysCfg.clearProperty(ignorableAttribute);
if (!sysCfg.configurationsAt(ignorableSysNode).isEmpty()) {
sysCfg.clearTree(ignorableSysNode);
sysCfg.clearProperty("environments.environment[@" + ignorableAttribute + "]");
sysCfg.clearProperty("environments.dbEnvironment[@" + ignorableAttribute + "]");
sysCfg.clearTree("environments.environment." + ignorableSysNode);
sysCfg.clearTree("environments.dbEnvironment." + ignorableSysNode);
ImmutableList<HierarchicalConfiguration<ImmutableNode>> envConfigs = ListAdapter.adapt(sysCfg.configurationsAt("environments.dbEnvironment")).toImmutable();
if (envConfigs.isEmpty()) {
envConfigs = ListAdapter.adapt(sysCfg.configurationsAt("environments.environment")).toImmutable();
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Returns the system ID of the DOCTYPE declaration from the loaded XML
* document. This is <b>null</b> if no document has been loaded yet or if
* the document does not contain a DOCTYPE declaration with a system ID.
*
* @return the system ID
* @since 1.3
*/
public String getSystemID()
{
beginRead(false);
try
{
return systemID;
}
finally
{
endRead();
}
}
代码示例来源:origin: org.apache.commons/commons-configuration2
/**
* Sets the system ID of the DOCTYPE declaration. When this configuration is
* saved, a DOCTYPE declaration will be constructed that contains this
* system ID.
*
* @param systemID the system ID
* @since 1.3
*/
public void setSystemID(final String systemID)
{
beginWrite(false);
try
{
this.systemID = systemID;
}
finally
{
endWrite();
}
}
在流处理方面,Apache Beam和Apache Kafka之间有什么区别? 我也试图掌握技术和程序上的差异。 请通过您的经验报告来帮助我理解。 最佳答案 Beam是一种API,它以一种统一的方式使
有点n00b的问题。 如果我使用 Apache Ignite 进行消息传递和事件处理,是否还需要使用 Kafka? 与 Ignite 相比,Kafka 基本上会给我哪些(如果有的话)额外功能? 提前致
Apache MetaModel 是一个数据访问框架,它为发现、探索和查询不同类型的数据源提供了一个通用接口(interface)。 Apache Drill 是一种无架构的 SQL 查询引擎,它通过
Tomcat是一个广泛使用的java web服务器,而Apache也是一个web服务器,它们在实际项目使用中有什么不同? 经过一些研究,我有了一个简单的想法,比如, Apache Tomcat Ja
既然简单地使用 Apache 就足以运行许多 Web 应用程序,那么人们何时以及为什么除了 Apache 之外还使用 Tomcat? 最佳答案 Apache Tomcat是一个网络服务器和 Java
我在某个 VPS( friend 的带 cPanel 的 apache 服务器)上有一个帐户,我在那里有一个 public_html 目录。我们有大约 5-6 个网站: /home/myusernam
我目前正在尝试将模块加载到 Apache,使用 cmake 构建。该模块称为 mod_mapcache。它已成功构建并正确安装在/usr/lib/apache2/modules directroy 中
我对 url 中的问号有疑问。 例如:我有 url test.com/controller/action/part_1%3Fpart_2 (其中 %3F 是 url 编码的问号),并使用此重写规则:R
在同一台机器上,Apache 在端口 80 上运行,Tomcat 在端口 8080 上运行。 Apache 包括 html;css;js;文件并调用 tomcat 服务。 基本上 exampledom
Apache 1 和 Apache 2 的分支有什么区别? 使用一种或另一种的优点和缺点? 似乎 Apache 2 的缺点之一是使用大量内存,但也许它处理请求的速度更快? 最有趣的是 Apache 作
实际上,我们正在使用 Apache 网络服务器来托管我们的 REST-API。 脚本是用 Lua 编写的,并使用 mod-lua 映射。 例如来自 httpd.conf 的实际片段: [...] Lu
我在 apache 上的 ubuntu 中有一个虚拟主机,这不是我的主要配置,我有另一个网页作为我的主要网页,所以我想使用虚拟主机在同一个 IP 上设置这个。 urologyexpert.mx 是我的
我使用 Apache camel 已经很长时间了,发现它是满足各种系统集成相关业务需求的绝佳解决方案。但是几年前我遇到了 Apache Nifi 解决方案。经过一番谷歌搜索后,我发现虽然 Nifi 可
由于两者都是一次处理事件的流框架,这两种技术/流框架之间的核心架构差异是什么? 此外,在哪些特定用例中,一个比另一个更合适? 最佳答案 正如您所提到的,两者都是实时内存计算的流式平台。但是当您仔细观察
apache 文件(如 httpd.conf 和虚拟主机)中使用的语言名称是什么,例如 # Ensure that Apache listens on port 80 Listen 80 D
作为我学习过程的一部分,我认为如果我扩展更多关于 apache 的知识会很好。我有几个问题,虽然我知道有些内容可能需要相当冗长的解释,但我希望您能提供一个概述,以便我知道去哪里寻找。 (最好引用 mo
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4 个月前关闭。 Improve
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
这个问题在这里已经有了答案: Difference Between Apache Kafka and Camel (Broker vs Integration) (4 个回答) 3年前关闭。 据我所知
我有 2 个使用相同规则的子域,如下所示: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond
我是一名优秀的程序员,十分优秀!