Class StandardModelFactory
- Object
-
- org.thymeleaf.engine.StandardModelFactory
-
- All Implemented Interfaces:
IModelFactory
public class StandardModelFactory extends Object implements IModelFactory
- Since:
- 3.0.0
- Author:
- Daniel Fernández
-
-
Constructor Summary
Constructors Constructor Description StandardModelFactory(IEngineConfiguration configuration, TemplateMode templateMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ICDATASectioncreateCDATASection(CharSequence content)Create a new CDATA Section event, containing the specified contents.ICloseElementTagcreateCloseElementTag(String elementName)Create a new close tag, non-synthetic and non-unmatched.ICloseElementTagcreateCloseElementTag(String elementName, boolean synthetic, boolean unmatched)Create a new close tag.ICommentcreateComment(CharSequence content)Create a new Comment event, containing the specified contents.IDocTypecreateDocType(String publicId, String systemId)Create a DOCTYPE clause event with the specified public ID and system ID.IDocTypecreateDocType(String keyword, String elementName, String publicId, String systemId, String internalSubset)Create a DOCTYPE clause event, specifying all its components.IDocTypecreateHTML5DocType()Create a DOCTYPE clause event for HTML5 (no type, no public or system id).IModelcreateModel()Creates a new, empty model.IModelcreateModel(ITemplateEvent event)Creates a new model containing only one event (initially).IOpenElementTagcreateOpenElementTag(String elementName)Create a new open element tag, non-synthetic.IOpenElementTagcreateOpenElementTag(String elementName, boolean synthetic)Create a new open element tag.IOpenElementTagcreateOpenElementTag(String elementName, String attributeName, String attributeValue)Create a new open element tag, non-synthetic, specifying one attribute.IOpenElementTagcreateOpenElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic)Create a new open element tag, specifying one attribute.IOpenElementTagcreateOpenElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic)Create a new open element tag, specifying several attributes.IProcessingInstructioncreateProcessingInstruction(String target, String content)Create a new Processing Instruction event, specifying its target and content.IStandaloneElementTagcreateStandaloneElementTag(String elementName)Create a new standalone element tag, non synthetic and minimized.IStandaloneElementTagcreateStandaloneElementTag(String elementName, boolean synthetic, boolean minimized)Create a new standalone element tag.IStandaloneElementTagcreateStandaloneElementTag(String elementName, String attributeName, String attributeValue)Create a new standalone element tag, non synthetic and minimized, specifying one attribute.IStandaloneElementTagcreateStandaloneElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic, boolean minimized)Create a new standalone element tag, specifying one attribute.IStandaloneElementTagcreateStandaloneElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic, boolean minimized)Create a new standalone element tag, specifying several attributes.ITextcreateText(CharSequence text)Create a new Text event, specifying its contents.IXMLDeclarationcreateXMLDeclaration(String version, String encoding, String standalone)Create a new XML Declaration event, specifying values for all its attributes.IModelparse(TemplateData ownerTemplate, String template)Parse the template specified as String and return the result as a model.<T extends IProcessableElementTag>
TremoveAttribute(T tag, String attributeName)Create a new tag removing an existing attribute.<T extends IProcessableElementTag>
TremoveAttribute(T tag, String prefix, String name)Create a new tag removing an existing attribute.<T extends IProcessableElementTag>
TremoveAttribute(T tag, AttributeName attributeName)Create a new tag removing an existing attribute.<T extends IProcessableElementTag>
TreplaceAttribute(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>
TreplaceAttribute(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>
TsetAttribute(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>
TsetAttribute(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.
-
-
-
Constructor Detail
-
StandardModelFactory
public StandardModelFactory(IEngineConfiguration configuration, TemplateMode templateMode)
-
-
Method Detail
-
createModel
public IModel createModel()
Description copied from interface:IModelFactoryCreates a new, empty model.
- Specified by:
createModelin interfaceIModelFactory- Returns:
- the new model.
-
createModel
public IModel createModel(ITemplateEvent event)
Description copied from interface:IModelFactoryCreates a new model containing only one event (initially).
- Specified by:
createModelin interfaceIModelFactory- Parameters:
event- the event to be put into the newly created model.- Returns:
- the new model.
-
parse
public IModel parse(TemplateData ownerTemplate, String template)
Description copied from interface:IModelFactoryParse the template specified as String and return the result as a model.
Note the
templateargument specified here is the template content itself, not a name to be resolved by a template resolver. TheownerTemplateargument is mandatory, and specifies the template that is being processed and as a part of which process the String template is being parsed.- Specified by:
parsein interfaceIModelFactory- Parameters:
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.- Returns:
- the
IModelrepresenting the parsed template.
-
createCDATASection
public ICDATASection createCDATASection(CharSequence content)
Description copied from interface:IModelFactoryCreate a new CDATA Section event, containing the specified contents.
- Specified by:
createCDATASectionin interfaceIModelFactory- Parameters:
content- the content (i.e. without prefix or suffix) of the new CDATA Section.- Returns:
- the new CDATA Section.
-
createComment
public IComment createComment(CharSequence content)
Description copied from interface:IModelFactoryCreate a new Comment event, containing the specified contents.
- Specified by:
createCommentin interfaceIModelFactory- Parameters:
content- the content (i.e. without prefix or suffix) of the new Comment.- Returns:
- the new Comment.
-
createHTML5DocType
public IDocType createHTML5DocType()
Description copied from interface:IModelFactoryCreate a DOCTYPE clause event for HTML5 (no type, no public or system id).
- Specified by:
createHTML5DocTypein interfaceIModelFactory- Returns:
- the new DOCTYPE, corresponding with an HTML5 DOCTYPE clause.
-
createDocType
public IDocType createDocType(String publicId, String systemId)
Description copied from interface:IModelFactoryCreate a DOCTYPE clause event with the specified public ID and system ID.
- Specified by:
createDocTypein interfaceIModelFactory- Parameters:
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).- Returns:
- the new DOCTPYE.
-
createDocType
public IDocType createDocType(String keyword, String elementName, String publicId, String systemId, String internalSubset)
Description copied from interface:IModelFactoryCreate a DOCTYPE clause event, specifying all its components.
- Specified by:
createDocTypein interfaceIModelFactory- Parameters:
keyword- the keyword value (should beDOCTYPE, 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).- Returns:
- the new DOCTYPE.
-
createProcessingInstruction
public IProcessingInstruction createProcessingInstruction(String target, String content)
Description copied from interface:IModelFactoryCreate a new Processing Instruction event, specifying its target and content.
- Specified by:
createProcessingInstructionin interfaceIModelFactory- Parameters:
target- the target value.content- the content value.- Returns:
- the new Processing Instruction.
-
createText
public IText createText(CharSequence text)
Description copied from interface:IModelFactoryCreate a new Text event, specifying its contents.
- Specified by:
createTextin interfaceIModelFactory- Parameters:
text- the text contents.- Returns:
- the new Text.
-
createXMLDeclaration
public IXMLDeclaration createXMLDeclaration(String version, String encoding, String standalone)
Description copied from interface:IModelFactoryCreate a new XML Declaration event, specifying values for all its attributes.
- Specified by:
createXMLDeclarationin interfaceIModelFactory- Parameters:
version- the version value (might be null).encoding- the encoding value (might be null).standalone- the standalone value (might be null).- Returns:
- the new XML Declaration.
-
createStandaloneElementTag
public IStandaloneElementTag createStandaloneElementTag(String elementName)
Description copied from interface:IModelFactoryCreate a new standalone element tag, non synthetic and minimized.
This is equivalent to calling
IModelFactory.createStandaloneElementTag(String, boolean, boolean)withfalseas a value forsyntheticandtrueas a value forminimized.- Specified by:
createStandaloneElementTagin interfaceIModelFactory- Parameters:
elementName- the element name.- Returns:
- the standalone tag.
-
createStandaloneElementTag
public IStandaloneElementTag createStandaloneElementTag(String elementName, String attributeName, String attributeValue)
Description copied from interface:IModelFactoryCreate a new standalone element tag, non synthetic and minimized, specifying one attribute.
This is equivalent to calling
IModelFactory.createStandaloneElementTag(String, String, String, boolean, boolean)withfalseas a value forsyntheticandtrueas a value forminimized.- Specified by:
createStandaloneElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the standalone tag.
-
createStandaloneElementTag
public IStandaloneElementTag createStandaloneElementTag(String elementName, boolean synthetic, boolean minimized)
Description copied from interface:IModelFactoryCreate a new standalone element tag.
- Specified by:
createStandaloneElementTagin interfaceIModelFactory- Parameters:
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>.- Returns:
- the standalone tag.
-
createStandaloneElementTag
public IStandaloneElementTag createStandaloneElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic, boolean minimized)
Description copied from interface:IModelFactoryCreate a new standalone element tag, specifying one attribute.
- Specified by:
createStandaloneElementTagin interfaceIModelFactory- Parameters:
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>.- Returns:
- the standalone tag.
-
createStandaloneElementTag
public IStandaloneElementTag createStandaloneElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic, boolean minimized)
Description copied from interface:IModelFactoryCreate a new standalone element tag, specifying several attributes.
- Specified by:
createStandaloneElementTagin interfaceIModelFactory- Parameters:
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>.- Returns:
- the standalone tag.
-
createOpenElementTag
public IOpenElementTag createOpenElementTag(String elementName)
Description copied from interface:IModelFactoryCreate a new open element tag, non-synthetic.
This is equivalent to calling
IModelFactory.createOpenElementTag(String, boolean)withfalseas a value forsynthetic.- Specified by:
createOpenElementTagin interfaceIModelFactory- Parameters:
elementName- the element name.- Returns:
- the open tag.
-
createOpenElementTag
public IOpenElementTag createOpenElementTag(String elementName, String attributeName, String attributeValue)
Description copied from interface:IModelFactoryCreate a new open element tag, non-synthetic, specifying one attribute.
This is equivalent to calling
IModelFactory.createOpenElementTag(String, String, String, boolean)withfalseas a value forsynthetic.- Specified by:
createOpenElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the open tag.
-
createOpenElementTag
public IOpenElementTag createOpenElementTag(String elementName, boolean synthetic)
Description copied from interface:IModelFactoryCreate a new open element tag.
- Specified by:
createOpenElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the open tag.
-
createOpenElementTag
public IOpenElementTag createOpenElementTag(String elementName, String attributeName, String attributeValue, boolean synthetic)
Description copied from interface:IModelFactoryCreate a new open element tag, specifying one attribute.
- Specified by:
createOpenElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the open tag.
-
createOpenElementTag
public IOpenElementTag createOpenElementTag(String elementName, Map<String,String> attributes, AttributeValueQuotes attributeValueQuotes, boolean synthetic)
Description copied from interface:IModelFactoryCreate a new open element tag, specifying several attributes.
- Specified by:
createOpenElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the open tag.
-
setAttribute
public <T extends IProcessableElementTag> T setAttribute(T tag, String attributeName, String attributeValue)
Description copied from interface:IModelFactoryCreate 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
ITemplateEventimplementations are immutable. Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.- Specified by:
setAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
tag- the original tag.attributeName- the name of the attribute to be added.attributeValue- the value of the attribute to be added.- Returns:
- the new tag.
-
setAttribute
public <T extends IProcessableElementTag> T setAttribute(T tag, String attributeName, String attributeValue, AttributeValueQuotes attributeValueQuotes)
Description copied from interface:IModelFactoryCreate 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
ITemplateEventimplementations are immutable. Also, the created tag will be of the same type (i.e. standalone or open) as the specified as argument.- Specified by:
setAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
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.- Returns:
- the new tag.
-
replaceAttribute
public <T extends IProcessableElementTag> T replaceAttribute(T tag, AttributeName oldAttributeName, String attributeName, String attributeValue)
Description copied from interface:IModelFactoryCreate a new tag object replacing an attribute in the original tag with another one.
Note that this method should create a new object because
ITemplateEventimplementations 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.- Specified by:
replaceAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
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.- Returns:
- the new tag.
-
replaceAttribute
public <T extends IProcessableElementTag> T replaceAttribute(T tag, AttributeName oldAttributeName, String attributeName, String attributeValue, AttributeValueQuotes attributeValueQuotes)
Description copied from interface:IModelFactoryCreate 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
ITemplateEventimplementations 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.- Specified by:
replaceAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
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.- Returns:
- the new tag.
-
removeAttribute
public <T extends IProcessableElementTag> T removeAttribute(T tag, String attributeName)
Description copied from interface:IModelFactoryCreate a new tag removing an existing attribute.
Note that this method should create a new object because
ITemplateEventimplementations 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.
- Specified by:
removeAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
tag- the original tag.attributeName- the name of the attribute to be removed.- Returns:
- the new tag.
-
removeAttribute
public <T extends IProcessableElementTag> T removeAttribute(T tag, String prefix, String name)
Description copied from interface:IModelFactoryCreate a new tag removing an existing attribute.
Note that this method should create a new object because
ITemplateEventimplementations 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.
- Specified by:
removeAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
tag- the original tag.prefix- the prefix of the attribute (might be null).name- the name of the attribute.- Returns:
- the new tag.
-
removeAttribute
public <T extends IProcessableElementTag> T removeAttribute(T tag, AttributeName attributeName)
Description copied from interface:IModelFactoryCreate a new tag removing an existing attribute.
Note that this method should create a new object because
ITemplateEventimplementations 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.
- Specified by:
removeAttributein interfaceIModelFactory- Type Parameters:
T- the type of the original and new tags.- Parameters:
tag- the original tag.attributeName- the attribute name.- Returns:
- the new tag.
-
createCloseElementTag
public ICloseElementTag createCloseElementTag(String elementName)
Description copied from interface:IModelFactoryCreate a new close tag, non-synthetic and non-unmatched.
This is equivalent to calling
IModelFactory.createCloseElementTag(String, boolean, boolean)withfalseas a value forsyntheticand alsofalseas a value forunmatched.- Specified by:
createCloseElementTagin interfaceIModelFactory- Parameters:
elementName- the element name.- Returns:
- the close tag.
-
createCloseElementTag
public ICloseElementTag createCloseElementTag(String elementName, boolean synthetic, boolean unmatched)
Description copied from interface:IModelFactoryCreate a new close tag.
- Specified by:
createCloseElementTagin interfaceIModelFactory- Parameters:
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.- Returns:
- the close tag.
-
-