public static void setAttribute( final IElementTagStructureHandler structureHandler, final AttributeDefinition attributeDefinition, final String attributeName, final String attributeValue) { if (structureHandler instanceof ElementTagStructureHandler) { ((ElementTagStructureHandler) structureHandler).setAttribute(attributeDefinition, attributeName, attributeValue, null); } else { structureHandler.setAttribute(attributeName, attributeValue); } }
structureHandler.setAttribute(newAttributeName, newAttributeName); } else { structureHandler.removeAttribute(newAttributeName); tag.getAttributeValue(newAttributeName).length() == 0) { structureHandler.setAttribute(newAttributeName, newAttributeValue); } else { String currentValue = tag.getAttributeValue(newAttributeName); if (this.modificationType == ModificationType.APPEND) { structureHandler.setAttribute(newAttributeName, currentValue + newAttributeValue); } else if (this.modificationType == ModificationType.APPEND_WITH_SPACE) { structureHandler.setAttribute(newAttributeName, currentValue + ' ' + newAttributeValue); } else if (this.modificationType == ModificationType.PREPEND) { structureHandler.setAttribute(newAttributeName, newAttributeValue + currentValue); } else { // modification type is PREPEND_WITH_SPACE structureHandler.setAttribute(newAttributeName, newAttributeValue + ' ' + currentValue);
/** * This method replaces the attribute device:replace="XXX" with th:replace"DEVICE_PREFIX/XXX" * This is useful for including device specific fragments */ @Override protected void doProcess( ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler ) { ApplicationContext applicationContext = (ApplicationContext) context.getConfiguration() .getExecutionAttributes() .get( DeviceDialect.APPLICATION_CONTEXT_ATTRIBUTE ); DeviceBasedViewNameResolver deviceBasedViewNameResolver = applicationContext.getBean( DeviceBasedViewNameResolver.class ); structureHandler.setAttribute( StandardDialect.PREFIX + ":" + StandardReplaceTagProcessor.ATTR_NAME, deviceBasedViewNameResolver.resolveDeviceSpecificView( attributeValue ) ); } }
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim(); Page<?> page = PageUtils.findPage(context); String url = PageUtils.createSortUrl(context, attrValue); // Append class to the element if sorted by this field Sort sort = page.getSort(); boolean isSorted = sort != null && sort.getOrderFor(attributeValue) != null; String clas = isSorted ? SORTED_PREFIX.concat(sort.getOrderFor(attributeValue).getDirection().toString().toLowerCase()) : EMPTY; structureHandler.setAttribute(HREF, url); String currentClass = tag.getAttributeValue(CLASS); structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas)); }
@Override protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler) { String attrValue = String.valueOf(Expressions.evaluate(context, attributeValue)).trim(); Page<?> page = PageUtils.findPage(context); String url = PageUtils.createSortUrl(context, attrValue, getForcedDirection()); // Append class to the element if sorted by this field Sort sort = page.getSort(); boolean isSorted = sort != null && sort.getOrderFor(attrValue) != null; String clas = isSorted ? SORTED_PREFIX.concat(sort.getOrderFor(attrValue).getDirection().toString().toLowerCase()) : EMPTY; structureHandler.setAttribute(HREF, url); String currentClass = tag.getAttributeValue(CLASS); structureHandler.setAttribute(CLASS, Strings.concat(currentClass, BLANK, clas)); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }
@Override protected void doProcess( final ITemplateContext context, final IProcessableElementTag tag, final IElementTagStructureHandler structureHandler) { final AttributeName selectAttrNameToAdd = (AttributeName) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_NAME); if (selectAttrNameToAdd == null) { // Nothing to do return; } // It seems this <option> is inside a <select th:field="...">, and the processor for that "th:field" has left // as a local variable the name and value of the attribute to be added final String selectAttrValueToAdd = (String) context.getVariable(SpringSelectFieldTagProcessor.OPTION_IN_SELECT_ATTR_VALUE); if (tag.hasAttribute(selectAttrNameToAdd)) { if (!selectAttrValueToAdd.equals(tag.getAttributeValue(selectAttrNameToAdd))) { throw new TemplateProcessingException( "If specified (which is not required), attribute \"" + selectAttrNameToAdd + "\" in " + "\"option\" tag must have exactly the same value as in its containing \"select\" tag"); } } // This attribute value does not need to be escaped, because we are just "transporting" the th:field in the // container <select> to its <option>'s, without any modifications. It will be executed (and its results // escaped) later... structureHandler.setAttribute(selectAttrNameToAdd.getCompleteAttributeNames()[0], selectAttrValueToAdd); }