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.apicloud.commons.model.Config.java

License:Open Source License

private static void createFeatureElement(Element rootElement, Config config) {
    for (Feature feature : config.getFeatures()) {
        Element featureElement = rootElement.addElement("feature");
        featureElement.addAttribute("name", feature.getName());
        createParamElement(featureElement, feature);
    }//from w w  w  . j a v  a  2s .c  o m
}

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

License:Open Source License

private static void createParamElement(Element featureElement, Feature feature) {
    for (Param param : feature.getParams()) {
        Element paramElement = featureElement.addElement("param");
        paramElement.addAttribute("name", param.getName());
        paramElement.addAttribute("value", param.getValue());
    }//from ww w .  j  av a  2  s.c  o  m

}

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

License:Open Source License

private static void createFeatureElement(Element rootElement, List<Feature> features) {
    for (Feature feature : features) {
        Element FeatureElement = rootElement.addElement("feature");
        FeatureElement.addAttribute("name", feature.getName());
        FeatureElement.addAttribute("desc", feature.getDesc());
        FeatureElement.addAttribute("isAndroid", feature.isAndroid() + "");
        FeatureElement.addAttribute("isIOS", feature.isIos() + "");
        FeatureElement.addAttribute("type", feature.getType());
    }/*from  w  ww .  j  av  a  2  s. c  om*/

}

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

License:Open Source License

private static void createFeatureElement2(Element rootElement, List<Feature> features) {
    for (Feature feature : features) {
        Element featureElement = rootElement.addElement("feature");
        featureElement.addAttribute("name", feature.getName());
        featureElement.addAttribute("desc", feature.getDesc());
        featureElement.addAttribute("isAndroid", feature.isAndroid() + "");
        featureElement.addAttribute("isIOS", feature.isIos() + "");
        featureElement.addAttribute("type", feature.getType());
        for (Param param : feature.getParams()) {
            Element paramElement = featureElement.addElement("param");
            paramElement.addAttribute("name", param.getName());
            paramElement.addAttribute("value", param.getValue());
        }//from  ww  w . j  a  va  2s .c  o m
    }

}

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());
        }//from  w  ww .ja v a  2 s .c  o 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());
        }// w w  w  . ja  v a 2s .  c  o  m
    }
    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;//from  ww  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.//  w  w  w.j  a v a  2  s.c om
 * 
 * @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 genMonXml(Document document, BeaconStateCollector fsc) {
    Document resultDoc = null;//  w  w w . j a  v a  2  s.  c om

    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.beetle.framework.resource.container.ContainerConfig.java

License:Apache License

/**
 * // w  ww. j  a  v  a 2  s  . c om
 *
 * @param tagname --??
 * @param key     --??
 * @throws Exception
 */
public static void setContainValue(String tagname, String key, String value) throws Exception {
    Document doc = XMLReader.getXmlDoc(sysconfigFileName);
    Node node = doc.selectSingleNode(XMLReader.convertPath(tagname));
    if (node != null) {
        @SuppressWarnings("rawtypes")
        Iterator it = node.selectNodes("item").iterator();
        while (it.hasNext()) {
            Element e = (Element) it.next();
            String id = e.valueOf("@name");
            if (id != null && id.equals(key)) {
                e.addAttribute("value", value);
                break;
            }
        }
    }
    File f = new File(sysconfigFileName);
    if (f.exists()) {
        OutputFormat format = OutputFormat.createPrettyPrint();
        FileOutputStream fos = new FileOutputStream(f);
        XMLWriter writer = new XMLWriter(fos, format);
        writer.write(doc);
        writer.close();
    } else {
        AppLogger.getInstance(ContainerConfig.class).error("??jarxml");
    }
}