Search in sources :

Example 86 with Attribute

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();
    }
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 87 with Attribute

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;
}
Also used : HashMap(java.util.HashMap) Attribute(org.dom4j.Attribute)

Example 88 with Attribute

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;
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) HashSet(java.util.HashSet)

Example 89 with Attribute

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);
    }
}
Also used : BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) DeclarativeAction(com.haulmont.cuba.gui.xml.DeclarativeAction) DeclarativeTrackingAction(com.haulmont.cuba.gui.xml.DeclarativeTrackingAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) Attribute(org.dom4j.Attribute) ConstraintOperationType(com.haulmont.cuba.security.entity.ConstraintOperationType)

Example 90 with Attribute

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);
    }
}
Also used : HashMap(java.util.HashMap) Attribute(org.dom4j.Attribute) QName(org.dom4j.QName) Node(org.dom4j.Node) Element(org.dom4j.Element) Namespace(org.dom4j.Namespace) Dom4jXPath(org.jaxen.dom4j.Dom4jXPath) JaxenException(org.jaxen.JaxenException) SimpleNamespaceContext(org.jaxen.SimpleNamespaceContext)

Aggregations

Attribute (org.dom4j.Attribute)114 Element (org.dom4j.Element)88 Document (org.dom4j.Document)30 ArrayList (java.util.ArrayList)28 List (java.util.List)26 Iterator (java.util.Iterator)23 Node (org.dom4j.Node)14 HashMap (java.util.HashMap)12 File (java.io.File)11 SAXReader (org.dom4j.io.SAXReader)11 IOException (java.io.IOException)10 Map (java.util.Map)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)6 Namespace (org.dom4j.Namespace)5 QName (org.dom4j.QName)5 PropertyString (org.pentaho.commons.util.repository.type.PropertyString)5 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3