use of org.dom4j.Attribute in project core by craftercms.
the class Dom4jDocumentJsonSerializer method elementToJson.
@SuppressWarnings("unchecked")
private void elementToJson(Element element, JsonGenerator jsonGenerator) throws IOException {
boolean objectStarted = false;
if (element.attributeCount() > 0) {
List<Attribute> attributes = element.attributes();
jsonGenerator.writeStartObject();
objectStarted = true;
for (Attribute attribute : attributes) {
jsonGenerator.writeStringField(attribute.getName(), attribute.getValue());
}
}
if (!element.hasContent()) {
if (!objectStarted) {
jsonGenerator.writeNull();
}
} else if (element.isTextOnly()) {
if (!objectStarted) {
jsonGenerator.writeString(element.getText());
} else {
jsonGenerator.writeStringField(TEXT_JSON_KEY, element.getText());
}
} else {
if (!objectStarted) {
jsonGenerator.writeStartObject();
objectStarted = true;
}
if (element.hasMixedContent()) {
List<String> textContent = getTextContentFromMixedContent(element);
if (textContent.size() > 1) {
jsonGenerator.writeArrayFieldStart(TEXT_JSON_KEY);
for (String text : textContent) {
jsonGenerator.writeString(text);
}
jsonGenerator.writeEndArray();
} else if (textContent.size() == 1) {
jsonGenerator.writeStringField(TEXT_JSON_KEY, textContent.get(0));
}
}
Map<String, List<Element>> children = getChildren(element);
for (Map.Entry<String, List<Element>> entry : children.entrySet()) {
if (entry.getValue().size() > 1) {
jsonGenerator.writeArrayFieldStart(entry.getKey());
for (Element child : entry.getValue()) {
elementToJson(child, jsonGenerator);
}
jsonGenerator.writeEndArray();
} else {
jsonGenerator.writeFieldName(entry.getKey());
elementToJson(entry.getValue().get(0), jsonGenerator);
}
}
}
if (objectStarted) {
jsonGenerator.writeEndObject();
}
}
use of org.dom4j.Attribute in project core by craftercms.
the class MergeCueResolverImpl method getMergeCueParams.
@SuppressWarnings("unchecked")
protected Map<String, String> getMergeCueParams(Element element, Attribute mergeCueAttribute) {
Map<String, String> params = new HashMap<String, String>();
String paramsPrefix = mergeCueAttribute.getQualifiedName() + "-";
List<Attribute> attributes = element.attributes();
for (Iterator<Attribute> i = attributes.iterator(); i.hasNext(); ) {
Attribute attribute = i.next();
String attributeQualifiedName = attribute.getQualifiedName();
if (attributeQualifiedName.startsWith(paramsPrefix)) {
i.remove();
String paramName = attributeQualifiedName.substring(paramsPrefix.length());
String paramValue = attribute.getValue();
params.put(paramName, paramValue);
}
}
return params;
}
use of org.dom4j.Attribute in project cuba by cuba-platform.
the class FilterParser method createCondition.
protected Condition createCondition(Element conditionElement) {
Condition condition;
String conditionName;
if (conditionElement.attributeValue("locCaption") == null) {
conditionName = conditionElement.attributeValue("name");
} else {
conditionName = conditionElement.attributeValue("locCaption");
}
if ("c".equals(conditionElement.getName())) {
condition = new Clause(conditionName, conditionElement.getText(), getJoinValue(conditionElement), conditionElement.attributeValue("operatorType"), conditionElement.attributeValue("type"));
Set<ParameterInfo> params = new HashSet<>();
for (Element paramElem : conditionElement.elements("param")) {
Set<ParameterInfo> singleParam = ParametersHelper.parseQuery(":" + paramElem.attributeValue("name"));
Attribute javaClass = paramElem.attribute("javaClass");
if (javaClass != null) {
for (ParameterInfo param : singleParam) {
// noinspection CatchMayIgnoreException
try {
param.setJavaClass(ReflectionHelper.loadClass(javaClass.getValue()));
param.setConditionName(conditionName);
param.setValue(paramElem.getText());
} catch (ClassNotFoundException e) {
}
}
}
params.addAll(singleParam);
}
((Clause) condition).setInputParameters(params);
} else {
condition = new LogicalCondition(conditionName, LogicalOp.fromString(conditionElement.getName()));
}
return condition;
}
use of org.dom4j.Attribute in project cuba by cuba-platform.
the class AbstractComponentLoader method loadActionConstraint.
protected void loadActionConstraint(Action action, Element element) {
if (action instanceof Action.HasSecurityConstraint) {
Action.HasSecurityConstraint itemTrackingAction = (Action.HasSecurityConstraint) action;
Attribute operationTypeAttribute = element.attribute("constraintOperationType");
if (operationTypeAttribute != null) {
ConstraintOperationType operationType = ConstraintOperationType.fromId(operationTypeAttribute.getValue());
itemTrackingAction.setConstraintOperationType(operationType);
}
String constraintCode = element.attributeValue("constraintCode");
itemTrackingAction.setConstraintCode(constraintCode);
}
}
use of org.dom4j.Attribute in project application by collectionspace.
the class XTmplTmpl method compileTemplate.
@SuppressWarnings("unchecked")
private void compileTemplate(Document template) throws InvalidXTmplException {
try {
Map<String, String> map = new HashMap<String, String>();
map.put("xtmpl", XTMPL_URI);
Dom4jXPath xpath = new Dom4jXPath("//.[@xtmpl:point]");
xpath.setNamespaceContext(new SimpleNamespaceContext(map));
List<Node> paths = xpath.selectNodes(template);
QName attr_qname = new QName("point", new Namespace("xtmpl", XTMPL_URI));
for (Node n : paths) {
if (!(n instanceof Element))
continue;
Element e = (Element) n;
Attribute attr = e.attribute(attr_qname);
String key = attr.getText();
String path = e.getPath();
e.remove(attr);
attach.put(key, path);
}
removeNamespaces(template.getDocument().getRootElement());
document = template;
} catch (JaxenException e) {
throw new InvalidXTmplException("Cannot parse template file", e);
}
}
Aggregations