Class XMLConfiguration
prepare(File) or
prepare(Reader). Preparation uses a namespace-aware, secure parser, preprocesses conditional elements,
expands retained element attributes, and records metadata on the resulting DOM nodes. The prepared document is fixed:
later parameter or converter changes do not alter its values.
Parameter keys are replaced literally wherever they occur in attribute values. The standard keys are @user,
@state, and @config; callers may add or replace keys before preparation. Values are expanded with
StringUtil.replace(String, Map) and then passed through registered
StringConverters. Conditions are evaluated before ordinary
attribute expansion. See XMLUtil.preprocessConditions(org.w3c.dom.Document, Map) for condition syntax.
getDocument() returns a defensive DOM copy. Its expanded-state metadata is copied with the nodes so that
downstream processors can distinguish finalized values from values in an unprocessed document. This allows multiple
consumers to inspect the same snapshot without sharing mutable DOM nodes. File-backed configurations retain their
source file; Reader-backed configurations do not have a source file.
Parsing rejects DTD declarations and disables external entities, XInclude, and entity expansion. Namespace-free XML documents remain valid. For example:
<configuration> <service endpoint="@endpoint" enabled="true"/> </configuration>
- Since:
- 3.31
- Author:
- Eike Stepper
-
Constructor Summary
ConstructorsConstructorDescriptionXMLConfiguration(IManagedContainer container) Creates a configuration preparation context. -
Method Summary
Modifier and TypeMethodDescriptionReturns a defensive copy of the prepared document.Returns an immutable copy of parameters used for preparation.Returns the original file, if the configuration was prepared from one.static booleanisExpanded(Node node) Indicates whether a DOM node belongs to a configuration whose attributes were fully expanded during preparation.booleanIndicates whether preparation has completed.Parses and prepares a file-backed configuration.Parses and prepares a reader-backed configuration.voidreplaceParameters(Map<String, String> values) Replaces all preparation parameters with an exact supplied snapshot, including removing any default parameter that is absent from the snapshot.setParameter(String name, String value) Adds or replaces a preparation parameter.voidsetParameters(Map<String, String> values) Adds or replaces preparation parameters.
-
Constructor Details
-
XMLConfiguration
Creates a configuration preparation context.- Parameters:
container- the container used to resolve StringConverter expressions; it may benull
-
-
Method Details
-
setParameter
Adds or replaces a preparation parameter.- Parameters:
name- the parameter namevalue- its value;nullremoves the parameter- Returns:
- the previous value
- Throws:
IllegalStateException- if preparation has completed
-
setParameters
Adds or replaces preparation parameters.- Parameters:
values- the values to copy- Throws:
IllegalStateException- if preparation has completed
-
replaceParameters
Replaces all preparation parameters with an exact supplied snapshot, including removing any default parameter that is absent from the snapshot.- Parameters:
values- the complete parameter snapshot to copy- Throws:
IllegalStateException- if preparation has completed- Since:
- 3.31
-
prepare
public XMLConfiguration prepare(File file) throws ParserConfigurationException, SAXException, IOException Parses and prepares a file-backed configuration.- Parameters:
file- the XML source- Returns:
- this prepared configuration
- Throws:
ParserConfigurationException- if a secure parser cannot be createdSAXException- if XML is malformed or unsafeIOException- if the file cannot be read
-
prepare
public XMLConfiguration prepare(Reader reader) throws ParserConfigurationException, SAXException, IOException Parses and prepares a reader-backed configuration.- Parameters:
reader- the XML source- Returns:
- this prepared configuration
- Throws:
ParserConfigurationException- if a secure parser cannot be createdSAXException- if XML is malformed or unsafeIOException- if the reader cannot be read
-
getDocument
Returns a defensive copy of the prepared document.- Returns:
- an independent DOM copy
- Throws:
IllegalStateException- if preparation has not completed
-
getSourceFile
Returns the original file, if the configuration was prepared from one.- Returns:
- source file or
null
-
isPrepared
public boolean isPrepared()Indicates whether preparation has completed.- Returns:
trueafter successful preparation
-
getParameters
-
isExpanded
Indicates whether a DOM node belongs to a configuration whose attributes were fully expanded during preparation. The marker is attached to the document, elements, and attributes, and is preserved bygetDocument().- Parameters:
node- the DOM node to inspect- Returns:
truewhen the node carries finalized expansion metadata- Since:
- 3.31
-