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


Java Element.addChild方法代码示例

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


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

示例1: 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

示例2: 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

示例3: processAttribute

import org.thymeleaf.dom.Element; //导入方法依赖的package包/类
@Override
protected ProcessorResult processAttribute(Arguments theArguments, Element theElement, String theAttributeName) {
	final String attributeValue = theElement.getAttributeValue(theAttributeName);

	final Configuration configuration = theArguments.getConfiguration();
	final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);

	final IStandardExpression expression = expressionParser.parseExpression(configuration, theArguments, attributeValue);
	final Object value = expression.execute(configuration, theArguments);

	theElement.removeAttribute(theAttributeName);
	theElement.clearChildren();

	if (value == null) {
		return ProcessorResult.ok();
	}

	Context context = new Context();
	context.setVariable("resource", value);

	String name = null;
	if (value != null) {
		Class<? extends Object> nextClass = value.getClass();
		do {
			name = myClassToName.get(nextClass);
			nextClass = nextClass.getSuperclass();
		} while (name == null && nextClass.equals(Object.class) == false);
		
		if (name == null) {
			if (value instanceof IBaseResource) {
				name = myFhirContext.getResourceDefinition((IBaseResource)value).getName();
			} else if (value instanceof IDatatype) {
				name = value.getClass().getSimpleName();
				name = name.substring(0, name.length() - 2);
			} else {
				throw new DataFormatException("Don't know how to determine name for type: " + value.getClass());
			}
			name = name.toLowerCase();
			if (!myNameToNarrativeTemplate.containsKey(name)) {
				name = null;
			}
		}
	}

	if (name == null) {
		if (myIgnoreMissingTemplates) {
			ourLog.debug("No narrative template available for type: {}", value.getClass());
			return ProcessorResult.ok();
		} else {
			throw new DataFormatException("No narrative template for class " + value.getClass());
		}
	}

	String result = myProfileTemplateEngine.process(name, context);
	String trim = result.trim();
	if (!isBlank(trim + "AAA")) {
		Document dom = getXhtmlDOMFor(new StringReader(trim));
		
		Element firstChild = (Element) dom.getFirstChild();
		for (int i = 0; i < firstChild.getChildren().size(); i++) {
			Node next = firstChild.getChildren().get(i);
			if (i == 0 && firstChild.getChildren().size() == 1) {
				if (next instanceof org.thymeleaf.dom.Text) {
					org.thymeleaf.dom.Text nextText = (org.thymeleaf.dom.Text) next;
					nextText.setContent(nextText.getContent().trim());
				}
			}
			theElement.addChild(next);
		}
		
	}
	

	return ProcessorResult.ok();
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:76,代码来源:BaseThymeleafNarrativeGenerator.java


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