Package org.htmlcleaner
Class TagTransformation
- java.lang.Object
-
- org.htmlcleaner.TagTransformation
-
public class TagTransformation extends java.lang.Object
Describes how specified tag is transformed to another one, or is ignored during parsing
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<AttributeTransformation>
attributePatternTransformations
private java.util.Map<java.lang.String,java.lang.String>
attributeTransformations
private java.lang.String
destTag
private boolean
preserveSourceAttributes
private java.lang.String
sourceTag
static java.lang.String
VAR_END
static java.lang.String
VAR_START
-
Constructor Summary
Constructors Constructor Description TagTransformation()
TagTransformation(java.lang.String sourceTag)
Creates new tag transformation in which specified tag will be skipped (ignored) during parsing process.TagTransformation(java.lang.String sourceTag, java.lang.String destTag)
Creates new tag transformation from source tag to target tag preserving all source tag attributes.TagTransformation(java.lang.String sourceTag, java.lang.String destTag, boolean preserveSourceAttributes)
Creates new tag transformation from source tag to target tag specifying whether source tag attributes are preserved.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttributePatternTransformation(java.util.regex.Pattern attNamePattern, java.lang.String transformationDesc)
void
addAttributePatternTransformation(java.util.regex.Pattern attNamePattern, java.util.regex.Pattern attValuePattern, java.lang.String transformationDesc)
void
addAttributePatternTransformation(AttributeTransformation attributeTransformation)
void
addAttributeTransformation(java.lang.String targetAttName)
Adds new attribute transformation in which destination attrbute will not exists (simply removes it from list of attributes).void
addAttributeTransformation(java.lang.String targetAttName, java.lang.String transformationDesc)
Adds new attribute transformation to this tag transformation.java.util.Map<java.lang.String,java.lang.String>
applyTagTransformations(java.util.Map<java.lang.String,java.lang.String> attributes)
java.lang.String
evaluateTemplate(java.lang.String template, java.util.Map<java.lang.String,java.lang.String> variables)
Evaluates string template for specified map of variables.(package private) java.util.Map<java.lang.String,java.lang.String>
getAttributeTransformations()
(package private) java.lang.String
getDestTag()
(package private) java.lang.String
getSourceTag()
(package private) boolean
hasAttributeTransformations()
(package private) boolean
isPreserveSourceAttributes()
-
-
-
Field Detail
-
VAR_START
public static java.lang.String VAR_START
-
VAR_END
public static java.lang.String VAR_END
-
sourceTag
private java.lang.String sourceTag
-
destTag
private java.lang.String destTag
-
preserveSourceAttributes
private boolean preserveSourceAttributes
-
attributeTransformations
private java.util.Map<java.lang.String,java.lang.String> attributeTransformations
-
attributePatternTransformations
private java.util.List<AttributeTransformation> attributePatternTransformations
-
-
Constructor Detail
-
TagTransformation
public TagTransformation()
-
TagTransformation
public TagTransformation(java.lang.String sourceTag, java.lang.String destTag, boolean preserveSourceAttributes)
Creates new tag transformation from source tag to target tag specifying whether source tag attributes are preserved.- Parameters:
sourceTag
- Name of the tag to be transformed.destTag
- Name of tag to which source tag is to be transformed.preserveSourceAttributes
- Tells whether source tag attributes are preserved in transformation.
-
TagTransformation
public TagTransformation(java.lang.String sourceTag, java.lang.String destTag)
Creates new tag transformation from source tag to target tag preserving all source tag attributes.- Parameters:
sourceTag
- Name of the tag to be transformed.destTag
- Name of tag to which source tag is to be transformed.
-
TagTransformation
public TagTransformation(java.lang.String sourceTag)
Creates new tag transformation in which specified tag will be skipped (ignored) during parsing process.- Parameters:
sourceTag
-
-
-
Method Detail
-
addAttributeTransformation
public void addAttributeTransformation(java.lang.String targetAttName, java.lang.String transformationDesc)
Adds new attribute transformation to this tag transformation. It tells how destination attribute will look like. Small templating mechanism is used to describe attribute value: all names between ${ and } inside the template are evaluated against source tag attributes. That way one can make attribute values consist of mix of source tag attributes.- Parameters:
targetAttName
- Name of the destination attributetransformationDesc
- Template describing attribute value.
-
addAttributePatternTransformation
public void addAttributePatternTransformation(java.util.regex.Pattern attNamePattern, java.lang.String transformationDesc)
-
addAttributePatternTransformation
public void addAttributePatternTransformation(java.util.regex.Pattern attNamePattern, java.util.regex.Pattern attValuePattern, java.lang.String transformationDesc)
-
addAttributePatternTransformation
public void addAttributePatternTransformation(AttributeTransformation attributeTransformation)
- Parameters:
attributeTransformation
-
-
addAttributeTransformation
public void addAttributeTransformation(java.lang.String targetAttName)
Adds new attribute transformation in which destination attrbute will not exists (simply removes it from list of attributes).- Parameters:
targetAttName
-
-
hasAttributeTransformations
boolean hasAttributeTransformations()
-
getSourceTag
java.lang.String getSourceTag()
-
getDestTag
java.lang.String getDestTag()
-
isPreserveSourceAttributes
boolean isPreserveSourceAttributes()
-
getAttributeTransformations
java.util.Map<java.lang.String,java.lang.String> getAttributeTransformations()
-
applyTagTransformations
public java.util.Map<java.lang.String,java.lang.String> applyTagTransformations(java.util.Map<java.lang.String,java.lang.String> attributes)
- Parameters:
attributes
-
-
evaluateTemplate
public java.lang.String evaluateTemplate(java.lang.String template, java.util.Map<java.lang.String,java.lang.String> variables)
Evaluates string template for specified map of variables. Template string can contain dynamic parts in the form of ${VARNAME}. Each such part is replaced with value of the variable if such exists in the map, or with empty string otherwise.- Parameters:
template
- Template stringvariables
- Map of variables (can be null)- Returns:
- Evaluated string
-
-