Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

In this page you can find the example usage for org.dom4j Element addAttribute.

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java

License:Apache License

private void addSchema(Element container, SchemaImpl s, String elementName) {
    if (_processedSchemas.contains(s))
        return;/*from  ww w.  j a  v  a  2 s  .  com*/

    Element schema = DocumentHelper.createElement(elementName);

    if (s.getId() != null)
        schema.addAttribute("id", qualify(s.getId()));

    if (s.getVisibility() == Visibility.PRIVATE)
        schema.addAttribute("visibility", "private");

    if (s.getAnnotation() != null) {
        schema.addText(s.getAnnotation());
    }

    for (Iterator j = s.getElementModel().iterator(); j.hasNext();) {
        ElementModel em = (ElementModel) j.next();

        Element element = getElementElement(em);

        schema.add(element);
    }

    container.add(schema);

    _processedSchemas.add(s);
}

From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java

License:Apache License

private Element getRulesElement(ElementModel em) {
    Element rules = DocumentHelper.createElement("rules");

    for (Iterator i = em.getRules().iterator(); i.hasNext();) {
        Rule r = (Rule) i.next();//from  w ww.  j a  v a2 s. c o m

        Element rule = null;

        if (r instanceof CreateObjectRule) {
            CreateObjectRule cor = (CreateObjectRule) r;
            rule = DocumentHelper.createElement("create-object");

            rule.addAttribute("class", cor.getClassName());
        } else if (r instanceof InvokeParentRule) {
            InvokeParentRule ipr = (InvokeParentRule) r;
            rule = DocumentHelper.createElement("invoke-parent");

            rule.addAttribute("method", ipr.getMethodName());
            if (ipr.getDepth() != 1)
                rule.addAttribute("depth", Integer.toString(ipr.getDepth()));
        } else if (r instanceof PushAttributeRule) {
            PushAttributeRule par = (PushAttributeRule) r;
            rule = DocumentHelper.createElement("push-attribute");

            rule.addAttribute("attribute", par.getAttributeName());
        } else if (r instanceof PushContentRule) {
            rule = DocumentHelper.createElement("push-content");
        } else if (r instanceof ReadAttributeRule) {
            ReadAttributeRule rar = (ReadAttributeRule) r;
            rule = DocumentHelper.createElement("read-attribute");

            rule.addAttribute("property", rar.getPropertyName());
            rule.addAttribute("attribute", rar.getAttributeName());
            if (!rar.getSkipIfNull())
                rule.addAttribute("skip-if-null", "false");
            if (rar.getTranslator() != null)
                rule.addAttribute("translator", rar.getTranslator());
        } else if (r instanceof ReadContentRule) {
            ReadContentRule rcr = (ReadContentRule) r;
            rule = DocumentHelper.createElement("read-content");

            rule.addAttribute("property", rcr.getPropertyName());
        } else if (r instanceof SetModuleRule) {
            SetModuleRule smr = (SetModuleRule) r;
            rule = DocumentHelper.createElement("set-module");

            rule.addAttribute("property", smr.getPropertyName());
        } else if (r instanceof SetParentRule) {
            SetParentRule spr = (SetParentRule) r;
            rule = DocumentHelper.createElement("set-parent");

            rule.addAttribute("property", spr.getPropertyName());
        } else if (r instanceof SetPropertyRule) {
            SetPropertyRule spr = (SetPropertyRule) r;
            rule = DocumentHelper.createElement("set-property");

            rule.addAttribute("property", spr.getPropertyName());
            rule.addAttribute("value", spr.getValue());
        } else if (r instanceof ConversionDescriptor) {
            ConversionDescriptor cd = (ConversionDescriptor) r;
            rule = DocumentHelper.createElement("conversion");

            rule.addAttribute("class", cd.getClassName());
            if (!cd.getParentMethodName().equals("addElement"))
                rule.addAttribute("parent-method", cd.getParentMethodName());

            for (Iterator j = cd.getAttributeMappings().iterator(); j.hasNext();) {
                AttributeMappingDescriptor amd = (AttributeMappingDescriptor) j.next();

                Element map = DocumentHelper.createElement("map");

                map.addAttribute("attribute", amd.getAttributeName());
                map.addAttribute("property", amd.getPropertyName());

                rule.add(map);
            }
        } else {
            rule = DocumentHelper.createElement("custom");

            rule.addAttribute("class", r.getClass().getName());
        }

        if (rule != null)
            rules.add(rule);
    }
    return rules;
}

From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java

License:Apache License

private Element getElementElement(ElementModel em) {
    Element element = DocumentHelper.createElement("element");
    element.addAttribute("name", em.getElementName());

    if (em.getAnnotation() != null) {
        element.addText(em.getAnnotation());
    }/*from  ww w  .  ja  v  a  2s.  c  om*/

    for (Iterator i = em.getAttributeModels().iterator(); i.hasNext();) {
        AttributeModel am = (AttributeModel) i.next();

        Element attribute = getAttributeElement(am);

        element.add(attribute);
    }

    for (Iterator i = em.getElementModel().iterator(); i.hasNext();) {
        ElementModel nestedEm = (ElementModel) i.next();

        Element nestedElement = getElementElement(nestedEm);

        element.add(nestedElement);
    }

    if (!em.getRules().isEmpty()) {
        Element rules = getRulesElement(em);

        element.add(rules);
    }

    return element;
}

From source file:com.anite.maven.plugin.hivedoc.Dom4JRegistrySerializer.java

License:Apache License

private Element getAttributeElement(AttributeModel am) {
    Element attribute = DocumentHelper.createElement("attribute");

    attribute.addAttribute("name", am.getName());
    if (am.isRequired())
        attribute.addAttribute("required", "true");
    if (am.isUnique())
        attribute.addAttribute("unique", "true");
    if (!am.getTranslator().equals("smart"))
        attribute.addAttribute("translator", am.getTranslator());

    if (am.getAnnotation() != null) {
        attribute.addText(am.getAnnotation());
    }// ww  w.  j a v  a2  s . com

    return attribute;
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

public static Document getDocument(Config config) {
    Document document = XMLUtil.createDocument();
    Element rootElement = document.addElement("widget");
    rootElement.addAttribute("id", config.getId());
    rootElement.addAttribute("version", config.getVersion());
    createGenralElement(rootElement, config);
    createPreferenceElement(rootElement, config);
    createPermissionElement(rootElement, config);
    createAccessElement(rootElement, config);
    createFeatureElement(rootElement, config);
    return document;
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

public static File saveXml(Config config, File file) {
    if (!file.exists()) {
        try {/*from   www.  j av  a  2  s  . c  o m*/
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Document document = XMLUtil.createDocument();
    Element rootElement = document.addElement("widget");
    rootElement.addAttribute("id", config.getId());
    rootElement.addAttribute("version", config.getVersion());
    createGenralElement(rootElement, config);
    createPreferenceElement(rootElement, config);
    createPermissionElement(rootElement, config);
    createAccessElement(rootElement, config);
    createFeatureElement(rootElement, config);
    try {
        XMLUtil.saveXml(file, document);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

private static void createGenralElement(Element rootElement, Config config) {

    Element nameElement = rootElement.addElement("name");
    nameElement.setText(config.getName());

    Element descriptionElement = rootElement.addElement("description");
    descriptionElement.setText(config.getDesc());

    Element authorElement = rootElement.addElement("author");
    authorElement.addAttribute("email", config.getAuthorEmail());
    authorElement.addAttribute("href", config.getAuthorHref());
    authorElement.setText(config.getAuthorName());

    Element contentElement = rootElement.addElement("content");
    contentElement.addAttribute("src", config.getContentSrc());

}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

private static void createPreferenceElement(Element rootElement, Config config) {
    for (Preference preference : config.getPreferences()) {
        Element preferenceElement = rootElement.addElement("preference");
        preferenceElement.addAttribute("name", preference.getName());
        preferenceElement.addAttribute("value", preference.getValue());
    }//  w w w.  j av a 2  s . co  m
}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

private static void createAccessElement(Element rootElement, Config config) {
    for (Access access : config.getAccesses()) {
        Element accessElement = rootElement.addElement("access");
        accessElement.addAttribute("origin", access.getOrigin());
    }/*from  w  w  w. java  2  s.  c  o m*/

}

From source file:com.apicloud.commons.model.Config.java

License:Open Source License

private static void createPermissionElement(Element rootElement, Config config) {
    for (Permission permission : config.getPermissions()) {
        Element permissionElement = rootElement.addElement("permission");
        permissionElement.addAttribute("name", permission.getName());
    }//from   w  w w. ja v a2s.c om
}