public class StandardModelFactory extends Object implements IModelFactory
Constructor and Description |
---|
StandardModelFactory(IEngineConfiguration configuration,
TemplateMode templateMode) |
Modifier and Type | Method and Description |
---|---|
ICDATASection |
createCDATASection(CharSequence content)
Create a new CDATA Section event, containing the specified contents.
|
ICloseElementTag |
createCloseElementTag(String elementName)
Create a new close tag, non-synthetic and non-unmatched.
|
ICloseElementTag |
createCloseElementTag(String elementName,
boolean synthetic,
boolean unmatched)
Create a new close tag.
|
IComment |
createComment(CharSequence content)
Create a new Comment event, containing the specified contents.
|
IDocType |
createDocType(String publicId,
String systemId)
Create a DOCTYPE clause event with the specified public ID and system ID.
|
IDocType |
createDocType(String keyword,
String elementName,
String publicId,
String systemId,
String internalSubset)
Create a DOCTYPE clause event, specifying all its components.
|
IDocType |
createHTML5DocType()
Create a DOCTYPE clause event for HTML5 (no type, no public or system id).
|
IModel |
createModel()
Creates a new, empty model.
|
IModel |
createModel(ITemplateEvent event)
Creates a new model containing only one event (initially).
|
IOpenElementTag |
createOpenElementTag(String elementName)
Create a new open element tag, non-synthetic.
|
IOpenElementTag |
createOpenElementTag(String elementName,
boolean synthetic)
Create a new open element tag.
|
IOpenElementTag |
createOpenElementTag(String elementName,
Map<String,String> attributes,
AttributeValueQuotes attributeValueQuotes,
boolean synthetic)
Create a new open element tag, specifying several attributes.
|
IOpenElementTag |
createOpenElementTag(String elementName,
String attributeName,
String attributeValue)
Create a new open element tag, non-synthetic, specifying one attribute.
|
IOpenElementTag |
createOpenElementTag(String elementName,
String attributeName,
String attributeValue,
boolean synthetic)
Create a new open element tag, specifying one attribute.
|
IProcessingInstruction |
createProcessingInstruction(String target,
String content)
Create a new Processing Instruction event, specifying its target and content.
|
IStandaloneElementTag |
createStandaloneElementTag(String elementName)
Create a new standalone element tag, non synthetic and minimized.
|
IStandaloneElementTag |
createStandaloneElementTag(String elementName,
boolean synthetic,
boolean minimized)
Create a new standalone element tag.
|
IStandaloneElementTag |
createStandaloneElementTag(String elementName,
Map<String,String> attributes,
AttributeValueQuotes attributeValueQuotes,
boolean synthetic,
boolean minimized)
Create a new standalone element tag, specifying several attributes.
|
IStandaloneElementTag |
createStandaloneElementTag(String elementName,
String attributeName,
String attributeValue)
Create a new standalone element tag, non synthetic and minimized, specifying one attribute.
|
IStandaloneElementTag |
createStandaloneElementTag(String elementName,
String attributeName,
String attributeValue,
boolean synthetic,
boolean minimized)
Create a new standalone element tag, specifying one attribute.
|
IText |
createText(CharSequence text)
Create a new Text event, specifying its contents.
|
IXMLDeclaration |
createXMLDeclaration(String version,
String encoding,
String standalone)
Create a new XML Declaration event, specifying values for all its attributes.
|
IModel |
parse(TemplateData ownerTemplate,
String template)
Parse the template specified as String and return the result as a model.
|
<T extends IProcessableElementTag> |
removeAttribute(T tag,
AttributeName attributeName)
Create a new tag removing an existing attribute.
|
<T extends IProcessableElementTag> |
removeAttribute(T tag,
String attributeName)
Create a new tag removing an existing attribute.
|
<T extends IProcessableElementTag> |
removeAttribute(T tag,
String prefix,
String name)
Create a new tag removing an existing attribute.
|
<T extends IProcessableElementTag> |
replaceAttribute(T tag,
AttributeName oldAttributeName,
String attributeName,
String attributeValue)
Create a new tag object replacing an attribute in the original tag with another one.
|
<T extends IProcessableElementTag> |
replaceAttribute(T tag,
AttributeName oldAttributeName,
String attributeName,
String attributeValue,
AttributeValueQuotes attributeValueQuotes)
Create a new tag object replacing an attribute in the original tag with another one, also specifying the
type of quotes to be used for representing the attribute value.
|
<T extends IProcessableElementTag> |
setAttribute(T tag,
String attributeName,
String attributeValue)
Create a new tag object that adds a new attribute to the existing ones in a specified tag.
|
<T extends IProcessableElementTag> |
setAttribute(T tag,
String attributeName,
String attributeValue,
AttributeValueQuotes attributeValueQuotes)
Create a new tag object that adds a new attribute to the existing ones in a specified tag, also specifying the
type of quotes to be used for representing the attribute value.
|
public StandardModelFactory(IEngineConfiguration configuration, TemplateMode templateMode)
public IModel createModel()
IModelFactory
Creates a new, empty model.
createModel
in interface IModelFactory
public IModel createModel(ITemplateEvent event)
IModelFactory
Creates a new model containing only one event (initially).
createModel
in interface IModelFactory
event
- the event to be put into the newly created model.public IModel parse(TemplateData ownerTemplate, String template)
IModelFactory
Parse the template specified as String and return the result as a model.
Note the template argument specified here is the template content itself, not a name to be resolved by a template resolver. The ownerTemplate argument is mandatory, and specifies the template that is being processed and as a part of which process the String template is being parsed.
parse
in interface IModelFactory
ownerTemplate
- the template being processed, for which the String template is being parsed
into a model object.template
- the String containing the contents of the template to be parsed.IModel
representing the parsed template.public ICDATASection createCDATASection(CharSequence content)
IModelFactory
Create a new CDATA Section event, containing the specified contents.
createCDATASection
in interface IModelFactory
content
- the content (i.e. without prefix or suffix) of the new CDATA Section.public IComment createComment(CharSequence content)
IModelFactory
Create a new Comment event, containing the specified contents.
createComment
in interface IModelFactory
content
- the content (i.e. without prefix or suffix) of the new Comment.public IDocType createHTML5DocType()
IModelFactory
Create a DOCTYPE clause event for HTML5 (no type, no public or system id).
createHTML5DocType
in interface IModelFactory
public IDocType createDocType(String publicId, String systemId)
IModelFactory
Create a DOCTYPE clause event with the specified public ID and system ID.
createDocType
in interface IModelFactory
publicId
- the public ID to be applied (might be null).systemId
- the system ID to be applied (might be null if public ID is also null).public IDocType createDocType(String keyword, String elementName, String publicId, String systemId, String internalSubset)
IModelFactory
Create a DOCTYPE clause event, specifying all its components.
createDocType
in interface IModelFactory
keyword
- the keyword value (should be DOCTYPE, but case might vary).elementName
- the root element name.publicId
- the public ID (might be null).systemId
- the system ID (might be null).internalSubset
- the internal subset (might be null).public IProcessingInstruction createProcessingInstruction(String target, String content)
IModelFactory
Create a new Processing Instruction event, specifying its target and content.
createProcessingInstruction
in interface IModelFactory
target
- the target value.content
- the content value.public IText createText(CharSequence text)
IModelFactory
Create a new Text event, specifying its contents.
createText
in interface IModelFactory
text
- the text contents.public IXMLDeclaration createXMLDeclaration(String version, String encoding, String standalone)
IModelFactory
Create a new XML Declaration event, specifying values for all its attributes.
createXMLDeclaration
in interface IModelFactory
version
- the version value (might be null).encoding
- the encoding value (might be null).standalone
- the standalone value (might be null).public IStandaloneElementTag createStandaloneElementTag(String elementName)
IModelFactory
Create a new standalone element tag, non synthetic and minimized.
This is equivalent to calling IModelFactory.createStandaloneElementTag(String, boolean, boolean)
with
false as a value for synthetic and true as a value for minimized.
createStandaloneElementTag
in interface IModelFactory
elementName
- the element name.public IStandaloneElementTag createStandaloneElementTag(String elementName, String attributeName, String attributeValue)
IModelFactory
Create a new standalone element tag, non synthetic and minimized, specifying one attribute.
This is equivalent to calling IModelFactory.createStandaloneElementTag(String, String, String, boolean, boolean)
with
false as a value for synthetic and true as a value for minimized.
createStandaloneElementTag
in interface IModelFactory
elementName
- the element name.attributeName
- the name of the attribute to be added to the tag.attributeValue
- the value of the attribute to be added to the tag.public IStandaloneElementTag createStandaloneElementTag(String elementName, boolean synthetic, boolean minimized)
IModelFactory
Create a new standalone element tag.
createStandaloneElementTag
in interface IModelFactory
elementName
- the element name.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.minimized
- whether the tag is minimized or not, i.e. whether it ends in /> or simply
>.public IStandaloneElementTag createStandaloneElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic, boolean minimized)
IModelFactory
Create a new standalone element tag, specifying one attribute.
createStandaloneElementTag
in interface IModelFactory
elementName
- the element name.attributeName
- the name of the attribute to be added to the tag.attributeValue
- the value of the attribute to be added to the tag.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.minimized
- whether the tag is minimized or not, i.e. whether it ends in /> or simply
>.public IStandaloneElementTag createStandaloneElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic, boolean minimized)
IModelFactory
Create a new standalone element tag, specifying several attributes.
createStandaloneElementTag
in interface IModelFactory
elementName
- the element name.attributes
- the map of attribute names and values.attributeValueQuotes
- the type of quotes to be used for representing the attribute values.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.minimized
- whether the tag is minimized or not, i.e. whether it ends in /> or simply
>.public IOpenElementTag createOpenElementTag(String elementName)
IModelFactory
Create a new open element tag, non-synthetic.
This is equivalent to calling IModelFactory.createOpenElementTag(String, boolean)
with
false as a value for synthetic.
createOpenElementTag
in interface IModelFactory
elementName
- the element name.public IOpenElementTag createOpenElementTag(String elementName, String attributeName, String attributeValue)
IModelFactory
Create a new open element tag, non-synthetic, specifying one attribute.
This is equivalent to calling IModelFactory.createOpenElementTag(String, String, String, boolean)
with
false as a value for synthetic.
createOpenElementTag
in interface IModelFactory
elementName
- the element name.attributeName
- the name of the attribute to be added to the tag.attributeValue
- the value of the attribute to be added to the tag.public IOpenElementTag createOpenElementTag(String elementName, boolean synthetic)
IModelFactory
Create a new open element tag.
createOpenElementTag
in interface IModelFactory
elementName
- the element name.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.public IOpenElementTag createOpenElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic)
IModelFactory
Create a new open element tag, specifying one attribute.
createOpenElementTag
in interface IModelFactory
elementName
- the element name.attributeName
- the name of the attribute to be added to the tag.attributeValue
- the value of the attribute to be added to the tag.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.public IOpenElementTag createOpenElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic)
IModelFactory
Create a new open element tag, specifying several attributes.
createOpenElementTag
in interface IModelFactory
elementName
- the element name.attributes
- the map of attribute names and values.attributeValueQuotes
- the type of quotes to be used for representing the attribute values.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.public <T extends IProcessableElementTag> T setAttribute(T tag, String attributeName, String attributeValue)
IModelFactory
Create a new tag object that adds a new attribute to the existing ones in a specified tag.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
setAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.attributeName
- the name of the attribute to be added.attributeValue
- the value of the attribute to be added.public <T extends IProcessableElementTag> T setAttribute(T tag, String attributeName, String attributeValue, AttributeValueQuotes attributeValueQuotes)
IModelFactory
Create a new tag object that adds a new attribute to the existing ones in a specified tag, also specifying the type of quotes to be used for representing the attribute value.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
setAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.attributeName
- the name of the attribute to be added.attributeValue
- the value of the attribute to be added.attributeValueQuotes
- the type of quotes to be used for representing the attribute value.public <T extends IProcessableElementTag> T replaceAttribute(T tag, AttributeName oldAttributeName, String attributeName, String attributeValue)
IModelFactory
Create a new tag object replacing an attribute in the original tag with another one.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
If the attribute being replaced does not exist, the new one will be created as if
IModelFactory.setAttribute(IProcessableElementTag, String, String)
was called instead. If the old attribute does
exist, its position in the tag as well as its quote type will be used.
replaceAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.oldAttributeName
- the name of the attribute to be replaced.attributeName
- the name of the attribute to be added.attributeValue
- the value of the attribute to be added.public <T extends IProcessableElementTag> T replaceAttribute(T tag, AttributeName oldAttributeName, String attributeName, String attributeValue, AttributeValueQuotes attributeValueQuotes)
IModelFactory
Create a new tag object replacing an attribute in the original tag with another one, also specifying the type of quotes to be used for representing the attribute value.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
If the attribute being replaced does not exist, the new one will be created as if
IModelFactory.setAttribute(IProcessableElementTag, String, String)
was called instead. If the old attribute does
exist, its position in the tag will be used.
replaceAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.oldAttributeName
- the name of the attribute to be replaced.attributeName
- the name of the attribute to be added.attributeValue
- the value of the attribute to be added.attributeValueQuotes
- the type of quotes to be used for representing the attribute value.public <T extends IProcessableElementTag> T removeAttribute(T tag, String attributeName)
IModelFactory
Create a new tag removing an existing attribute.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
If the attribute being removed does not exist, nothing will be done and the same tag object will be returned.
removeAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.attributeName
- the name of the attribute to be removed.public <T extends IProcessableElementTag> T removeAttribute(T tag, String prefix, String name)
IModelFactory
Create a new tag removing an existing attribute.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
If the attribute being removed does not exist, nothing will be done and the same tag object will be returned.
removeAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.prefix
- the prefix of the attribute (might be null).name
- the name of the attribute.public <T extends IProcessableElementTag> T removeAttribute(T tag, AttributeName attributeName)
IModelFactory
Create a new tag removing an existing attribute.
Note that this method should create a new object because ITemplateEvent
implementations are immutable.
Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.
If the attribute being removed does not exist, nothing will be done and the same tag object will be returned.
removeAttribute
in interface IModelFactory
T
- the type of the original and new tags.tag
- the original tag.attributeName
- the attribute name.public ICloseElementTag createCloseElementTag(String elementName)
IModelFactory
Create a new close tag, non-synthetic and non-unmatched.
This is equivalent to calling IModelFactory.createCloseElementTag(String, boolean, boolean)
with
false as a value for synthetic and also false as a value for unmatched.
createCloseElementTag
in interface IModelFactory
elementName
- the element name.public ICloseElementTag createCloseElementTag(String elementName, boolean synthetic, boolean unmatched)
IModelFactory
Create a new close tag.
createCloseElementTag
in interface IModelFactory
elementName
- the element name.synthetic
- whether the tag is synthetic or not. Synthetic tags are used for balancing of markup and
will not appear on output.unmatched
- whether this tag should be considered unmatched, i.e. there is no corresponding
previous open tag for it.Copyright © 2017 The THYMELEAF team. All rights reserved.