Example usage for org.dom4j Element addElement

List of usage examples for org.dom4j Element addElement

Introduction

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

Prototype

Element addElement(String name);

Source Link

Document

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

Usage

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

License:Open Source License

public static void createFeatureElement3(Element rootElement, List<Feature> features) {
    for (Feature feature : features) {
        Element featureElement = rootElement.addElement("feature");
        featureElement.addAttribute("name", feature.getName());
        if (feature.getParams().size() > 0) {
            Element paramElement = featureElement.addElement("param");
            paramElement.addAttribute(feature.getParams().get(0).getValue(),
                    feature.getParams().get(1).getValue());
        }//  w ww .  j  a  v a2  s  .  co m
    }
}

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

License:Open Source License

public static String XMLTOString2(File file) {
    String documentStr = "";
    List<Feature> features = Feature.loadXml3(file);
    Document document = DocumentHelper.createDocument();

    Element rootElement = document.addElement("Features");
    for (Feature feature : features) {
        Element featureElement = rootElement.addElement("feature");
        featureElement.setName(feature.getName());
        if (feature.getParams().size() == 1) {
            Element paramElement = featureElement.addElement("param");
            paramElement.addAttribute(feature.getName(),
                    feature.getParams().get(0).getName() + ":" + feature.getParams().get(0).getValue());
        } else if (feature.getParams().size() == 2) {
            Element paramElement = featureElement.addElement("param");
            paramElement.addAttribute(feature.getParams().get(0).getName(),
                    feature.getParams().get(0).getValue());
            paramElement.addAttribute(feature.getParams().get(1).getName(),
                    feature.getParams().get(1).getValue());
        }/*from ww w.j  a  va 2s.  c om*/
    }
    documentStr = document.asXML();
    return documentStr;
}

From source file:com.arc.intro.CompilerSamplesProvider.java

License:Open Source License

public void init(IIntroContentProviderSite site) {
    if (samplesDoc == null) {
        File samplesXML = computeSampleXML();
        Document doc = null;/*w w  w. j a v  a 2  s . c o  m*/
        if (samplesXML.exists()) {
            SAXReader reader = new SAXReader();
            try {
                doc = reader.read(samplesXML);
            } catch (Exception e) {
                ToolchainPlugin.log("Error in reading " + samplesXML, e);
            }
        }
        if (doc == null) {
            // Create a makeshift version
            DocumentFactory f = DocumentFactory.getInstance();
            Element root = f.createElement(SAMPLES_TAG);
            root.addAttribute(DEMOS_ATTR, DEFAULT_DEMOS_DIR);
            for (int i = 0; i < targetNames.length; i += 2) {
                Element target = root.addElement(TARGET_TAG);
                target.addAttribute(NAME_ATTR, targetNames[i]);
                target.addAttribute(DESC_ATTR, targetNames[i + 1]);
            }
            Element category = root.addElement(CATEGORY_TAG);
            category.addAttribute(TITLE_ATTR, "Compiler Samples");
            category.addAttribute(WORKSPACE_ATTR, ".*mide_workspace");
            category.addAttribute(ID_ATTR, "compiler");
            doc = f.createDocument(root);
        }
        samplesDoc = doc;
    }
}

From source file:com.autoupdater.client.xml.creators.FileCacheXMLCreator.java

License:Apache License

/**
 * Creates node for a file./*from  w ww . j  a  va 2  s  .  c o m*/
 * 
 * @param files
 *            parent node
 * @param path
 *            path to file
 * @param hash
 *            file's hash
 */
private void addFile(Element files, String path, String hash) {
    Element file = files.addElement(FileCacheSchema.Files.file);
    file.addAttribute(FileCacheSchema.Files.File.path, path);
    file.addAttribute(FileCacheSchema.Files.File.hash, hash);
}

From source file:com.beacon.wlsagent.xml.XmlWorker.java

public Document genIniXml(Map pinnedInfoMap) {

    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate());
    if (pinnedInfoMap != null) {

        String agentVer = lic.getIp().equals("ANY") ? "- TRIAL LICENSE" : "- FORMAL LICENSE";
        agentVer = "1.0 " + agentVer;

        root.addElement("INITBUF")
                .addAttribute("AdminServerName", (String) pinnedInfoMap.get("AdminServerName"))
                .addAttribute("DomainVersion", (String) pinnedInfoMap.get("DomainVersion"))
                .addAttribute("Name", (String) pinnedInfoMap.get("Name"))
                .addAttribute("ProductionModeEnabled",
                        ((Boolean) pinnedInfoMap.get("ProductionModeEnabled")).toString())
                .addAttribute("RootDirectory", (String) pinnedInfoMap.get("RootDirectory"))
                .addAttribute("Activationtime",
                        BeaconUtil.longToDateStr((Long) pinnedInfoMap.get("ActivationTime")))
                .addAttribute("JDKVendor", (String) pinnedInfoMap.get("JavaVendor"))
                .addAttribute("JDKVersion", (String) pinnedInfoMap.get("JavaVersion"))
                .addAttribute("OSVersion", (String) pinnedInfoMap.get("OSVersion"))
                .addAttribute("OSName", (String) pinnedInfoMap.get("OSName"))
                .addAttribute("ServerNum", (String) pinnedInfoMap.get("ServerNum"))
                .addAttribute("AgentVersion", "1.0").addAttribute("LICTYPE", lic.getIp());
        ;/* ww  w .  j  av  a  2 s  .co m*/
    }
    return document;
}

From source file:com.beacon.wlsagent.xml.XmlWorker.java

public Document genErrXml(String sysCode) {

    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate());

    root.addElement("SYSTEM").addAttribute("errMsg", sysCode);
    return document;
}

From source file:com.beacon.wlsagent.xml.XmlWorker.java

public Document genMonXml(Document document, BeaconStateCollector fsc) {
    Document resultDoc = null;//from  w  w w .j a  v a2  s.  c o m

    if (fsc.isConnectedToAdmin()) {

        resultDoc = DocumentHelper.createDocument();

        Element root = resultDoc.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate());
        Element osEle = root.addElement("OSResource");

        String cpuStr = BeaconUtil.runShell("sh bin/getCPU.sh");
        String memStr = BeaconUtil.runShell("sh bin/getMEM.sh");
        if ((cpuStr == "") || (memStr == "")) {
            cpuStr = (String) BeaconUtil.runShell().get("CPU");
            memStr = (String) BeaconUtil.runShell().get("MEM");
        }
        osEle.addAttribute("CPU", cpuStr).addAttribute("MEM", memStr);

        List mbeanEleList = document.selectNodes("//MBean");

        ObjectName[] svrRt = fsc.getServerRT();

        int svrRtCount = svrRt.length;

        int f = 0;
        for (Iterator i = mbeanEleList.iterator(); i.hasNext();) {
            Element mbeanEle = (Element) i.next();
            String mbeanName = mbeanEle.attributeValue("name");
            log.debug("Currently dealing with mbean: " + mbeanName);
            Iterator k = mbeanEle.elementIterator("attribute");

            List al = new ArrayList();
            for (; k.hasNext(); f++) {
                al.add(((Element) k.next()).getText());
            }
            String mbeanAttrStrs[] = BeaconUtil.listToStrArray(al);

            for (int m = 0; m < svrRtCount; m++) {
                Map mBeanInfoMap[] = fsc.getMBeanInfoMaps(mbeanAttrStrs, mbeanName, svrRt[m]);
                String svrName = svrRt[m].getKeyProperty("Name");
                log.debug("Currently dealing with server: " + svrRt[m]);
                if (mBeanInfoMap != null) {
                    for (int g = 0; g < mBeanInfoMap.length; g++) {
                        if (mBeanInfoMap[g] != null && mbeanAttrStrs.length > 0) {
                            Element currItem = root.addElement(mbeanName);
                            currItem.addAttribute("serverName", svrName);
                            for (int j = 0; j < mbeanAttrStrs.length; j++) {
                                String curAttr = mbeanAttrStrs[j];
                                Object curAttrVal = mBeanInfoMap[g].get(curAttr);
                                if (curAttrVal != null) {
                                    currItem.addAttribute(curAttr, String.valueOf(curAttrVal));
                                } else {
                                    root.remove(currItem);
                                    j = mbeanAttrStrs.length;
                                }
                                log.debug("Attribute: " + curAttr + " Value: "
                                        + String.valueOf(mBeanInfoMap[g].get(curAttr)));
                            }

                        }
                    }
                }
            }

        }
    } else {
        resultDoc = this.genErrXml("Happened to lose connection to WebLogic Admin. maybe shutdown");
    }

    return resultDoc;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * ElementString/*from  ww w  .j av a2  s. c o  m*/
 *
 * @param parent
 *            
 * @param name
 *            
 *
 *
 *
 * @param value
 *            
 * @return element
 * @throws XMLDocException
 */
public static Element appendChild(Element parent, String name, String value) {
    Element element = parent.addElement(new QName(name, parent.getNamespace()));
    if (value != null) {
        element.addText(value);
    }
    return element;
}

From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java

License:Open Source License

/**
 * Element/* www .ja  va2 s .c om*/
 *
 * @param parent
 *            
 * @param name
 *            
 *
 *
 *
 * @return Element 
 * @throws XMLDocException
 */
public static Element appendChild(Element parent, String name) {
    return parent.addElement(new QName(name, parent.getNamespace()));
}

From source file:com.bluexml.side.Framework.alfresco.dataGenerator.serialization.mapping.XMLForACPMappingHelper.java

License:Open Source License

/**
 * create the xml's element corresponding to type of generated node
 * @param root/*from   w  w w  .  j  a v a2s . c o m*/
 * @param node
 * @return element corresponding to given generated node's type
 */
public Element createType(Element root, INode node) {
    Element type = root.addElement(createType(node));
    type.addNamespace(Constants.NATIVE_SIDE_PREFIX, Constants.NATIVE_SIDE_URI);
    return type;
}