当前位置: 首页>>代码示例>>Java>>正文


Java Element.setAttribute方法代码示例

本文整理汇总了Java中org.thymeleaf.dom.Element.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Element.setAttribute方法的具体用法?Java Element.setAttribute怎么用?Java Element.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.thymeleaf.dom.Element的用法示例。


在下文中一共展示了Element.setAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processAttribute

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
@Override
protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
    String[] value = element.getAttributeValue(attributeName).split(":");
    String webjarName = value[0];
    String filePath = value[1];

    element.removeAttribute(attributeName);

    element.setAttribute("th:" + attribute, String.format("@{/{path}/%s(path=${#webjars['%s'].path})}", filePath, webjarName));
    // reevaluate th:src
    element.setRecomputeProcessorsImmediately(true);

    return ProcessorResult.OK;
}
 
开发者ID:Catalysts,项目名称:cat-boot,代码行数:15,代码来源:WebjarsLinkProcessor.java

示例2: getScriptElement

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
protected Element getScriptElement(String src, boolean async, boolean defer) {
    Element e = new Element("script");
    e.setAttribute("type", "text/javascript");
    e.setAttribute("src", src);
    if (async) {
        e.setAttribute("async", true, null);
    }
    if (defer) {
        e.setAttribute("defer", true, null);
    }
    return e;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:13,代码来源:ResourceBundleProcessor.java

示例3: processElement

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
@Override
protected ProcessorResult processElement(Arguments arguments, Element element) {
    // If the form will be not be submitted with a GET, we must add the CSRF token
    // We do this instead of checking for a POST because post is default if nothing is specified
    if (!"GET".equalsIgnoreCase(element.getAttributeValueFromNormalizedName("method"))) {
        try {
            String csrfToken = eps.getCSRFToken();

            //detect multipart form
            if ("multipart/form-data".equalsIgnoreCase(element.getAttributeValueFromNormalizedName("enctype"))) {
                Expression expression = (Expression) StandardExpressions.getExpressionParser(arguments.getConfiguration())
                        .parseExpression(arguments.getConfiguration(), arguments, element.getAttributeValueFromNormalizedName("th:action"));
                String action = (String) expression.execute(arguments.getConfiguration(), arguments);
                String csrfQueryParameter = "?" + eps.getCsrfTokenParameter() + "=" + csrfToken;
                element.removeAttribute("th:action");
                element.setAttribute("action", action + csrfQueryParameter);
            } else {
                Element csrfNode = new Element("input");
                csrfNode.setAttribute("type", "hidden");
                csrfNode.setAttribute("name", eps.getCsrfTokenParameter());
                csrfNode.setAttribute("value", csrfToken);
                element.addChild(csrfNode);
            }

        } catch (ServiceException e) {
            throw new RuntimeException("Could not get a CSRF token for this session", e);
        }
    }
    
    // Convert the <blc:form> node to a normal <form> node
    Element newElement = element.cloneElementNodeWithNewName(element.getParent(), "form", false);
    newElement.setRecomputeProcessorsImmediately(true);
    element.getParent().insertAfter(element, newElement);
    element.getParent().removeChild(element);
    
    return ProcessorResult.OK;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:38,代码来源:FormProcessor.java

示例4: processAttribute

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
@Override
protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
    
    Expression expression = (Expression) StandardExpressions.getExpressionParser(arguments.getConfiguration())
            .parseExpression(arguments.getConfiguration(), arguments, element.getAttributeValue(attributeName));
    ProductOptionValue productOptionValue = (ProductOptionValue) expression.execute(arguments.getConfiguration(), arguments);

    ProductOptionValueDTO dto = new ProductOptionValueDTO();
    dto.setOptionId(productOptionValue.getProductOption().getId());
    dto.setValueId(productOptionValue.getId());
    dto.setValueName(productOptionValue.getAttributeValue());
    if (productOptionValue.getPriceAdjustment() != null) {
        dto.setPriceAdjustment(productOptionValue.getPriceAdjustment().getAmount());
    }
    try {
        ObjectMapper mapper = new ObjectMapper();
        Writer strWriter = new StringWriter();
        mapper.writeValue(strWriter, dto);
        element.setAttribute("data-product-option-value", strWriter.toString());
        element.removeAttribute(attributeName);
        return ProcessorResult.OK;
    } catch (Exception ex) {
        LOG.error("There was a problem writing the product option value to JSON", ex);
    }
    
    return null;
    
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:29,代码来源:ProductOptionValueProcessor.java

示例5: fixElement

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
public void fixElement(Element element, Arguments arguments) {
    boolean elementAdded = false;
    boolean removeElement = false;
    Set<String> attributeNames = element.getAttributeMap().keySet();

    for (String a : attributeNames) {
        String attrName = a.toLowerCase();
        if (attrName.startsWith("th")) {
            if (attrName.equals("th:substituteby") || (attrName.equals("th:replace") || attrName.equals("th:include"))) {
                if (!elementAdded) {
                    Element extraDiv = new Element("div");
                    String attrValue = element.getAttributeValue(attrName);
                    element.removeAttribute(attrName);
                    extraDiv.setAttribute(attrName, attrValue);
                    element.addChild(extraDiv);
                    elementAdded = true;
                    element.setNodeProperty("templateName", attrValue);

                    // This will ensure that the substituteby and replace processors only run for the child element
                    element.setRecomputeProcessorsImmediately(true);
                }
            } else if (attrName.equals("th:remove")) {
                Attribute attr = element.getAttributeMap().get(attrName);
                if ("tag".equals(attr.getValue())) {
                    removeElement = true;

                    // The cache functionality will remove the element. 
                    element.setAttribute(attrName, "none");
                }
            }
        }
    }

    if (!elementAdded || removeElement) {
        element.setNodeProperty("blcOutputParentNode", Boolean.TRUE);
    }
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:38,代码来源:BroadleafCacheProcessor.java

示例6: getLinkElement

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
protected Element getLinkElement(String src) {
    Element e = new Element("link");
    e.setAttribute("rel", "stylesheet");
    e.setAttribute("href", src);
    return e;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:7,代码来源:ResourceBundleProcessor.java


注:本文中的org.thymeleaf.dom.Element.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。