use of org.thymeleaf.model.IStandaloneElementTag in project thymeleaf-tests by thymeleaf.
the class ReplaceWithProcessableProcessingInstructionProcessor method doProcess.
@Override
protected void doProcess(final ITemplateContext context, final IProcessingInstruction processingInstruction, final IProcessingInstructionStructureHandler structureHandler) {
final IModelFactory modelFactory = context.getModelFactory();
final IStandaloneElementTag tag = modelFactory.createStandaloneElementTag("replaced", "th:text", "one", false, true);
final IModel model = modelFactory.createModel(tag);
structureHandler.replaceWith(model, true);
}
use of org.thymeleaf.model.IStandaloneElementTag in project thymeleaf-tests by thymeleaf.
the class ReplaceWithProcessableTextProcessor method doProcess.
@Override
protected void doProcess(final ITemplateContext context, final IText text, final ITextStructureHandler structureHandler) {
if (EngineEventUtils.isWhitespace(text) || text.getText().equals("one")) {
return;
}
final IModelFactory modelFactory = context.getModelFactory();
final IStandaloneElementTag tag = modelFactory.createStandaloneElementTag("replaced", "th:text", "one", false, true);
final IModel model = modelFactory.createModel(tag);
structureHandler.replaceWith(model, true);
}
use of org.thymeleaf.model.IStandaloneElementTag in project thymeleaf by thymeleaf.
the class StandaloneElementTag method asEngineStandaloneElementTag.
// Meant to be called only from within the engine
static StandaloneElementTag asEngineStandaloneElementTag(final IStandaloneElementTag standaloneElementTag) {
if (standaloneElementTag instanceof StandaloneElementTag) {
return (StandaloneElementTag) standaloneElementTag;
}
final IAttribute[] originalAttributeArray = standaloneElementTag.getAllAttributes();
final Attributes attributes;
if (originalAttributeArray == null || originalAttributeArray.length == 0) {
attributes = null;
} else {
// We will perform a deep cloning of the attributes into objects of the Attribute class, so that
// we make sure absolutely all Attributes in the new event are under the engine's control
final Attribute[] newAttributeArray = new Attribute[originalAttributeArray.length];
for (int i = 0; i < originalAttributeArray.length; i++) {
final IAttribute originalAttribute = originalAttributeArray[i];
newAttributeArray[i] = new Attribute(originalAttribute.getAttributeDefinition(), originalAttribute.getAttributeCompleteName(), originalAttribute.getOperator(), originalAttribute.getValue(), originalAttribute.getValueQuotes(), originalAttribute.getTemplateName(), originalAttribute.getLine(), originalAttribute.getCol());
}
final String[] newInnerWhiteSpaces;
if (newAttributeArray.length == 1) {
newInnerWhiteSpaces = Attributes.DEFAULT_WHITE_SPACE_ARRAY;
} else {
newInnerWhiteSpaces = new String[newAttributeArray.length];
Arrays.fill(newInnerWhiteSpaces, Attributes.DEFAULT_WHITE_SPACE);
}
attributes = new Attributes(newAttributeArray, newInnerWhiteSpaces);
}
return new StandaloneElementTag(standaloneElementTag.getTemplateMode(), standaloneElementTag.getElementDefinition(), standaloneElementTag.getElementCompleteName(), attributes, standaloneElementTag.isSynthetic(), standaloneElementTag.isMinimized(), standaloneElementTag.getTemplateName(), standaloneElementTag.getLine(), standaloneElementTag.getCol());
}
use of org.thymeleaf.model.IStandaloneElementTag in project thymeleaf-tests by thymeleaf.
the class StandaloneElementTagTest method testHtmlStandaloneElementAttrManagement.
@Test
public void testHtmlStandaloneElementAttrManagement() {
IStandaloneElementTag tag;
tag = computeHtmlTag("<input>");
Assert.assertEquals("<input>", tag.toString());
tag = computeHtmlTag("<input type=\"text\">");
Assert.assertEquals("<input type=\"text\">", tag.toString());
tag = computeHtmlTag("<input type=\"text\" value='hello!!!'>");
Assert.assertEquals("<input type=\"text\" value='hello!!!'>", tag.toString());
tag.getAttributes().removeAttribute("type");
Assert.assertEquals("<input value='hello!!!'>", tag.toString());
tag.getAttributes().removeAttribute("value");
Assert.assertEquals("<input>", tag.toString());
tag = computeHtmlTag("<input type=\"text\" value='hello!!!' >");
Assert.assertEquals("<input type=\"text\" value='hello!!!' >", tag.toString());
tag.getAttributes().removeAttribute(null, "type");
Assert.assertEquals("<input value='hello!!!' >", tag.toString());
tag.getAttributes().removeAttribute(null, "value");
Assert.assertEquals("<input >", tag.toString());
tag = computeHtmlTag("<input type=\"text\" value='hello!!!' ba >");
Assert.assertEquals("<input type=\"text\" value='hello!!!' ba >", tag.toString());
tag.getAttributes().setAttribute("value", "bye! :(");
Assert.assertEquals("<input type=\"text\" value='bye! :(' ba >", tag.toString());
tag.getAttributes().setAttribute("type", "one");
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba >", tag.toString());
tag.getAttributes().setAttribute("ba", "two");
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba=\"two\" >", tag.toString());
tag.getAttributes().setAttribute("ba", "three", ElementAttributes.ValueQuotes.SINGLE);
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba='three' >", tag.toString());
tag.getAttributes().setAttribute("ba", "four", ElementAttributes.ValueQuotes.NONE);
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba=four >", tag.toString());
tag.getAttributes().setAttribute("ba", "five");
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba=five >", tag.toString());
tag.getAttributes().setAttribute("ba", null);
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba >", tag.toString());
tag.getAttributes().setAttribute("ba", "six");
Assert.assertEquals("<input type=\"one\" value='bye! :(' ba=six >", tag.toString());
tag = computeHtmlTag("<input type=\"text\" value='hello!!!' ba=twenty >");
tag.getAttributes().setAttribute("ba", "thirty");
Assert.assertEquals("<input type=\"text\" value='hello!!!' ba=thirty >", tag.toString());
tag = computeHtmlTag("<input type=\"text\" value='hello!!!' ba=twenty ><p id='one'/>");
Assert.assertEquals("<p id='one'/>", tag.toString());
}
Aggregations