Example usage for org.dom4j DocumentHelper createDocument

List of usage examples for org.dom4j DocumentHelper createDocument

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createDocument.

Prototype

public static Document createDocument() 

Source Link

Usage

From source file:com.ah.ui.actions.config.USBModemAction.java

private Document generateExportDoc() {
    List<USBModem> usbModemLst = QueryUtil.executeQuery(USBModem.class, null, null, null, this);
    if (usbModemLst.isEmpty()) {
        return null;
    }/*from  w w w .  jav a 2 s  .c  om*/
    Document document = DocumentHelper.createDocument();
    Element modems = document.addElement("hiveos-modem-support-list").addElement("modems");
    for (USBModem usbModem : usbModemLst) {
        Element modem = modems.addElement("modem").addAttribute("id", usbModem.getModemName());
        modem.addElement("display").addAttribute("name", usbModem.getDisplayName()).addAttribute("type",
                usbModem.getDisplayType());
        modem.addElement("usb-info").addAttribute("vendor-id", usbModem.getUsbVendorId())
                .addAttribute("product-id", usbModem.getUsbProductId())
                .addAttribute("module", usbModem.getUsbModule());
        modem.addElement("hiveos-version").addAttribute("min", usbModem.getHiveOSVersionMin());
        //Element strengthCheck = modem.addElement("signal-strength-check");
        //if (usbModem.getUsbSignalStrengthCheckList() != null && usbModem.getUsbSignalStrengthCheckList().size()> 0) {
        //   strengthCheck.addAttribute("type", usbModem.getUsbSignalStrengthCheckList().get(0).getType());
        //   strengthCheck.addElement("serial-port").addAttribute("value", usbModem.getUsbSignalStrengthCheckList().get(0).getSerialPort());
        //   strengthCheck.addElement("check-cmd").addAttribute("value", usbModem.getUsbSignalStrengthCheckList().get(0).getCheckCmd());
        //}
        Element connect = modem.addElement("connect").addAttribute("type", usbModem.getConnectType());
        connect.addElement("serial-port").addAttribute("value", usbModem.getSerialPort());
        connect.addElement("dialstring").addAttribute("value", usbModem.getDailupNumber());
        connect.addElement("apn").addAttribute("value", usbModem.getApn());
        Element userAuth = connect.addElement("user-auth").addAttribute("type", usbModem.getAuthType());
        if ("password".equals(usbModem.getAuthType())) {
            userAuth.addElement("username").addAttribute("value", usbModem.getUserId());
            userAuth.addElement("password").addAttribute("value", usbModem.getPassword());
        }
        //modem.addElement("usepeerdns").addAttribute("value", usbModem.isUsePeerDns()?"true":"false");
    }

    return document;
}

From source file:com.alkacon.opencms.feeder.CmsFeedXmlContentHandler.java

License:Open Source License

/**
 * @see org.opencms.xml.content.CmsDefaultXmlContentHandler#validateAppinfoElement(org.dom4j.Element)
 *///w ww  .j a va  2s .  c  om
protected void validateAppinfoElement(Element appinfoElement) throws CmsXmlException {

    // create a document to validate
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement(APPINFO_APPINFO);
    // attach the default appinfo schema
    root.add(I_CmsXmlSchemaType.XSI_NAMESPACE);
    root.addAttribute(I_CmsXmlSchemaType.XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION,
            FEED_APPINFO_SCHEMA_SYSTEM_ID);
    // append the content from the appinfo node in the content definition 
    root.appendContent(appinfoElement);
    // now validate the document with the default appinfo schema
    CmsXmlUtils.validateXmlStructure(doc, CmsEncoder.ENCODING_UTF_8, new CmsXmlEntityResolver(null));
}

From source file:com.amalto.workbench.utils.MDMServerHelper.java

License:Open Source License

private static Element getRootElement() {
    Document logininfoDocument;/* w ww.j a v  a2 s .c  o  m*/
    Element rootElement;
    if (new File(workbenchConfigFile).exists()) {
        try {
            SAXReader reader = new SAXReader();
            logininfoDocument = reader.read(new File(workbenchConfigFile));
        } catch (DocumentException e) {
            log.error(e.getMessage(), e);
            return null;
        }
        rootElement = logininfoDocument.getRootElement();
    } else {
        logininfoDocument = DocumentHelper.createDocument();
        rootElement = logininfoDocument.addElement(ROOT);
    }
    return rootElement;
}

From source file:com.amalto.workbench.utils.XmlUtil.java

License:Open Source License

public static Document createDocument(DocumentCreate documentCreate) {

    Document document = DocumentHelper.createDocument();

    documentCreate.create(document);//from   ww w . j a va2  s .  c  om

    logger.info(Messages.XmlUtil_Loginfo);

    return document;
}

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

License:Apache License

public Document createRegistryDocument() {

    _document = DocumentHelper.createDocument();

    Element registry = DocumentHelper.createElement("registry");
    _document.add(registry);/*from w w w  . j  a va 2 s  .c o  m*/

    for (Iterator i = _providers.iterator(); i.hasNext();) {
        ModuleDescriptorProvider provider = (ModuleDescriptorProvider) i.next();

        processModuleDescriptorProvider(registry, provider);
    }

    return _document;
}

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  .j  a  va  2  s.  c o  m*/
    }
    documentStr = document.asXML();
    return documentStr;
}

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

License:Apache License

/**
 * Creates XML document with file cache data and stores it info file.
 * //from   w w  w .j  a  v a2  s .c  om
 * @param destination
 *            destination file
 * @param fileCache
 *            file cache which needs to be saved
 * @throws IOException
 *             thrown when error occurs during storing data to file
 */
public void createXML(File destination, Map<String, String> fileCache) throws IOException {
    logger.debug("Save file cache data at: " + destination.getCanonicalPath());
    Document fileCacheXML = DocumentHelper.createDocument();
    fileCacheXML.addComment(XMLCreationConfiguration.DO_NOT_EDIT_FILE_MANUALLY_WARNING);
    Element files = fileCacheXML.addElement(FileCacheSchema.files);
    addFiles(files, fileCache);
    Files.write(fileCacheXML.asXML(), destination, XMLCreationConfiguration.XML_ENCODING);
    logger.trace("Saved file cache data at: " + destination.getCanonicalPath());
}

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());
        ;/*w  ww  . j a  v a 2  s  . c  o 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;// w  ww. j  ava 2  s  .  co  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;
}