Example usage for org.dom4j Branch addElement

List of usage examples for org.dom4j Branch addElement

Introduction

In this page you can find the example usage for org.dom4j Branch addElement.

Prototype

Element addElement(QName qname);

Source Link

Document

Adds a new Element node with the given QName to this branch and returns a reference to the new node.

Usage

From source file:fr.isima.ponge.wsprotocol.xml.StringExtraPropertyHandler.java

License:Open Source License

public void writeExtraProperty(Branch keeperElement, String key, Object value) {
    Element prop = keeperElement.addElement("extra-property").addAttribute("type", getTypeId()); //$NON-NLS-1$ //$NON-NLS-2$
    prop.addElement("name").setText(key); //$NON-NLS-1$
    prop.addElement("value").setText((String) value); //$NON-NLS-1$
}

From source file:itensil.workflow.track.TrackingXML.java

License:Open Source License

public void appendStepCounts(Branch parent) throws StateException {
    Element setElem = parent.addElement("step-counts");
    for (Map.Entry<String, Integer> sc : stateReport.countBySteps().entrySet()) {
        Element elem = setElem.addElement("count");
        elem.addAttribute("id", sc.getKey());
        elem.addText(sc.getValue().toString());
    }//from  w  w w . j a v a  2  s. com
}

From source file:itensil.workflow.track.TrackingXML.java

License:Open Source License

public void appendAllActiveSteps(Branch parent) throws StateException {
    for (StepState<Tk> state : stateReport.getAllActiveSteps()) {
        addStateAttributes(parent.addElement("state"), state);
    }// w w  w.  j av  a  2s  . c o  m
}

From source file:itensil.workflow.track.TrackingXML.java

License:Open Source License

public void appendActiveSteps(Tk token, Branch parent) throws StateException {
    for (StepState<Tk> state : stateStore.getActiveSteps(token)) {
        addStateAttributes(parent.addElement("state"), state);
    }/*from   w  w  w. j a va2 s  . c  om*/
}

From source file:net.sf.eclipsecs.core.config.ConfigurationWriter.java

License:Open Source License

/**
 * Writes a module to the transformer handler.
 *
 * @param module//from   w ww. j a  va 2s  . c  o  m
 *            the module to write
 * @param parent
 *            the parent element
 * @param parentSeverity
 *            the severity of the parent module
 * @param remainingModules
 *            the list of remaining (possibly child) modules
 */
private static void writeModule(Module module, Branch parent, Severity parentSeverity,
        List<Module> remainingModules) {

    Severity severity = parentSeverity;

    // remove this module from the list of modules to write
    remainingModules.remove(module);

    List<Module> childs = getChildModules(module, remainingModules);

    // Start the module
    Element moduleEl = parent.addElement(XMLTags.MODULE_TAG);
    moduleEl.addAttribute(XMLTags.NAME_TAG, module.getMetaData().getInternalName());

    // Write comment
    if (StringUtils.trimToNull(module.getComment()) != null) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, XMLTags.COMMENT_ID);
        metaEl.addAttribute(XMLTags.VALUE_TAG, module.getComment());
    }

    // Write severity only if it differs from the parents severity
    if (module.getSeverity() != null && !Severity.inherit.equals(module.getSeverity())) {

        Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
        propertyEl.addAttribute(XMLTags.NAME_TAG, XMLTags.SEVERITY_TAG);
        propertyEl.addAttribute(XMLTags.VALUE_TAG, module.getSeverity().name());

        // set the parent severity for child modules
        severity = module.getSeverity();
    }

    // write module id
    if (StringUtils.trimToNull(module.getId()) != null) {

        Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
        propertyEl.addAttribute(XMLTags.NAME_TAG, XMLTags.ID_TAG);
        propertyEl.addAttribute(XMLTags.VALUE_TAG, module.getId());
    }

    // write properties of the module
    for (ConfigProperty property : module.getProperties()) {

        // write property only if it differs from the default value
        String value = StringUtils.trimToNull(property.getValue());
        if (value != null && !ObjectUtils.equals(value, property.getMetaData().getDefaultValue())) {

            Element propertyEl = moduleEl.addElement(XMLTags.PROPERTY_TAG);
            propertyEl.addAttribute(XMLTags.NAME_TAG, property.getMetaData().getName());
            propertyEl.addAttribute(XMLTags.VALUE_TAG, property.getValue());
        }
    }

    // write custom messages
    for (Map.Entry<String, String> entry : module.getCustomMessages().entrySet()) {

        Element metaEl = moduleEl.addElement(XMLTags.MESSAGE_TAG);
        metaEl.addAttribute(XMLTags.KEY_TAG, entry.getKey());
        metaEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
    }

    // write custom metadata
    for (Map.Entry<String, String> entry : module.getCustomMetaData().entrySet()) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, entry.getKey());
        metaEl.addAttribute(XMLTags.VALUE_TAG, entry.getValue());
    }

    // Write last enabled severity level
    if (module.getLastEnabledSeverity() != null) {

        Element metaEl = moduleEl.addElement(XMLTags.METADATA_TAG);
        metaEl.addAttribute(XMLTags.NAME_TAG, XMLTags.LAST_ENABLED_SEVERITY_ID);
        metaEl.addAttribute(XMLTags.VALUE_TAG, module.getLastEnabledSeverity().name());
    }

    // write child modules recursivly
    for (Module child : childs) {
        writeModule(child, moduleEl, severity, remainingModules);
    }
}

From source file:org.apache.directory.studio.schemaeditor.model.io.ProjectsExporter.java

License:Apache License

/**
 * Add the XML representation of the given project
 * to the given branch/* w w  w .j  av  a  2s  .c  om*/
 *
 * @param project
 *      the project
 * @param branch
 *      the branch
 */
private static void addProject(Project project, Branch branch) {
    Element element = branch.addElement(PROJECT_TAG);

    if (project != null) {
        // Name 
        String name = project.getName();
        if ((name != null) && (!name.equals(""))) //$NON-NLS-1$
        {
            element.addAttribute(NAME_TAG, name);
        }

        // Type
        ProjectType type = project.getType();
        if (type != null) {
            element.addAttribute(TYPE_TAG, type.toString());
        }

        // If project is an Online Schema Project
        if (type.equals(ProjectType.ONLINE)) {
            // Connection ID
            Connection connection = project.getConnection();

            if (connection != null) {
                element.addAttribute(CONNECTION_TAG, connection.getId());
            }

            // Schema Connection ID
            SchemaConnector schemaConnector = project.getSchemaConnector();

            if (schemaConnector != null) {
                element.addAttribute(SCHEMA_CONNECTOR_TAG, project.getSchemaConnector().getId());
            }

            // Schema Backup
            Element schemaBackupElement = element.addElement(SCHEMA_BACKUP_TAG);
            List<Schema> backupSchemas = project.getInitialSchema();
            if (backupSchemas != null) {
                XMLSchemaFileExporter.addSchemas(backupSchemas.toArray(new Schema[0]), schemaBackupElement);
            }

        }

        // Schemas
        XMLSchemaFileExporter.addSchemas(project.getSchemaHandler().getSchemas().toArray(new Schema[0]),
                element);
    }
}

From source file:org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileExporter.java

License:Apache License

/**
 * Add the XML representation of the given schemas
 * to the given branch.//from w  w w  . j av  a2 s .  c  om
 *
 * @param schemas
 *      the schemas
 * @param branch
 *      the branch
 */
public static void addSchemas(Schema[] schemas, Branch branch) {
    Element element = branch.addElement(SCHEMAS_TAG);

    if (schemas != null) {
        for (Schema schema : schemas) {
            addSchema(schema, element);
        }
    }
}

From source file:org.apache.directory.studio.schemaeditor.model.io.XMLSchemaFileExporter.java

License:Apache License

/**
 * Add the XML representation of the given schema
 * to the given branch.//  w  ww .  j a  v a 2 s .  c  o  m
 *
 * @param schema
 *      the schema
 * @param branch
 *      the branch
 */
public static void addSchema(Schema schema, Branch branch) {
    Element element = branch.addElement(SCHEMA_TAG);
    if (schema != null) {
        // Name
        String name = schema.getSchemaName();
        if ((name != null) && (!name.equals(""))) //$NON-NLS-1$
        {
            element.addAttribute(NAME_TAG, name);
        }

        // Attribute Types
        List<AttributeType> ats = schema.getAttributeTypes();
        if ((ats != null) && (ats.size() >= 1)) {
            Element attributeTypesNode = element.addElement(ATTRIBUTE_TYPES_TAG);
            for (AttributeType at : ats) {
                toXml(at, attributeTypesNode);
            }
        }

        // Object Classes
        List<ObjectClass> ocs = schema.getObjectClasses();
        if ((ocs != null) && (ocs.size() >= 1)) {
            Element objectClassesNode = element.addElement(OBJECT_CLASSES_TAG);
            for (ObjectClass oc : ocs) {
                toXml(oc, objectClassesNode);
            }
        }

        // Matching Rules
        List<MatchingRule> mrs = schema.getMatchingRules();
        if ((mrs != null) && (mrs.size() >= 1)) {
            Element matchingRulesNode = element.addElement(MATCHING_RULES_TAG);
            for (MatchingRule mr : mrs) {
                toXml(mr, matchingRulesNode);
            }
        }

        // Syntaxes
        List<LdapSyntax> syntaxes = schema.getSyntaxes();
        if ((syntaxes != null) && (syntaxes.size() >= 1)) {
            Element syntaxesNode = element.addElement(SYNTAXES_TAG);
            for (LdapSyntax syntax : syntaxes) {
                toXml(syntax, syntaxesNode);
            }
        }
    }
}

From source file:org.danann.cernunnos.xml.NewDocumentPhrase.java

License:Apache License

public Object evaluate(TaskRequest req, TaskResponse res) {

    Branch rslt = new DocumentFactory().createDocument();
    if (name != null) {
        rslt = rslt.addElement((String) name.evaluate(req, res));
    }//from w ww.  j  a  va 2s  .c  o m
    return rslt;

}

From source file:org.dentaku.gentaku.tools.cgen.visitor.JellyTemplateGeneratingVisitor.java

License:Apache License

public void handleChoice(Element choice) throws VisitorException {
    Branch parent = getCurrentParent();
    QName qName = DocumentFactory.getInstance().createQName("forEach", "j", "jelly:core");
    Branch current = parent.addElement(qName).addAttribute("var", "val").addAttribute("items", "${items}");
    pushParent(current);//from  w  ww.  jav  a 2  s.  c  o  m
    for (Iterator it = choice.elementIterator(); it.hasNext();) {
        visit((Element) it.next());
    }
    popParent();
}