Example usage for org.dom4j Document addElement

List of usage examples for org.dom4j Document addElement

Introduction

In this page you can find the example usage for org.dom4j Document 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:VersionRelease.java

License:Open Source License

public void run() {
    processDir(jbossHome);/*from  w  w  w .  j  a va  2  s . c  om*/
    try {
        DocumentFactory df = DocumentFactory.getInstance();
        Document doc = df.createDocument();
        Element root = doc.addElement("jar-versions");
        Iterator iter = jars.iterator();
        while (iter.hasNext()) {
            JarInfo info = (JarInfo) iter.next();
            info.writeXML(root);
        }

        File versionsXml = new File(jbossHome, "jar-versions.xml");
        FileWriter versionInfo = new FileWriter(versionsXml);
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(versionInfo, outformat);
        writer.setEscapeText(true);
        writer.write(doc);
        writer.flush();
        versionInfo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:adr.main.AlcorAdrSettings.java

/**
 * ? ?? ?  .xml /*from   w  ww .  j a v  a 2 s  .c  o  m*/
 */
public void SaveSettings() {
    try {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("Settings");

        root.addElement("COM_Port").addText(m_pCOMPortSettings.GetPort());

        root.addElement("COM_Baudrate").addText(Integer.toString(m_pCOMPortSettings.GetBaudRate()));

        if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_5)
            root.addElement("COM_DataBits").addText("5");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_6)
            root.addElement("COM_DataBits").addText("6");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_7)
            root.addElement("COM_DataBits").addText("7");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_8)
            root.addElement("COM_DataBits").addText("8");
        else {
            logger.warn(
                    "Unknown COM_DataBits value '" + m_pCOMPortSettings.GetDataBits() + "'! Saving default!");
            root.addElement("COM_DataBits").addText("8");
        }

        switch (m_pCOMPortSettings.GetParity()) {
        case SerialPort.PARITY_NONE:
            root.addElement("COM_Parity").addText("None");
            break;
        case SerialPort.PARITY_ODD:
            root.addElement("COM_Parity").addText("Odd");
            break;
        case SerialPort.PARITY_EVEN:
            root.addElement("COM_Parity").addText("Even");
            break;
        case SerialPort.PARITY_MARK:
            root.addElement("COM_Parity").addText("Mark");
            break;
        case SerialPort.PARITY_SPACE:
            root.addElement("COM_Parity").addText("Space");
            break;
        default:
            logger.warn("Unknown COM_Parity value '" + m_pCOMPortSettings.GetParity() + "'! Saving default!");
            root.addElement("COM_Parity").addText("None");
            break;
        }

        switch (m_pCOMPortSettings.GetStopBits()) {
        case SerialPort.STOPBITS_1:
            root.addElement("COM_StopBits").addText("1");
            break;
        case SerialPort.STOPBITS_2:
            root.addElement("COM_StopBits").addText("2");
            break;
        default:
            logger.warn(
                    "Unknown COM_StopBits value '" + m_pCOMPortSettings.GetStopBits() + "'! Saving default!");
            root.addElement("COM_StopBits").addText("1");
            break;
        }

        OutputFormat format = OutputFormat.createPrettyPrint();

        //TODO
        String strSettingsXmlFile = "alcor.adr.settings.xml";//System.getenv( "AMS_ROOT") + "/etc/settings.ams.xml";

        XMLWriter writer = new XMLWriter(new FileWriter(strSettingsXmlFile), format);

        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        logger.error("IOException caught while saving settings!", ex);
    }
}

From source file:ams.AMSDevSerialNumbers.java

/**
 * Saves entered numbers to XML file// w w w .  ja  v  a2s .  com
 */
public void SaveDevNumsToXML() {
    try {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("Settings");
        root.addElement("Device1").addText(m_strDev1SerialNumber);
        root.addElement("Device2").addText(m_strDev2SerialNumber);
        root.addElement("Device3").addText(m_strDev3SerialNumber);
        root.addElement("Device4").addText(m_strDev4SerialNumber);
        root.addElement("Device5").addText(m_strDev5SerialNumber);
        root.addElement("Device6").addText(m_strDev6SerialNumber);
        root.addElement("Device7").addText(m_strDev7SerialNumber);
        root.addElement("Device8").addText(m_strDev8SerialNumber);

        OutputFormat format = OutputFormat.createPrettyPrint();
        String strSerialsXmlFile = System.getenv("AMS_ROOT") + "/serials.xml";
        XMLWriter writer = new XMLWriter(new FileWriter(strSerialsXmlFile), format);
        writer.write(document);
        writer.close();

    } catch (IOException ex) {
        logger.error("IOException caught while saving serials!", ex);
    }
}

From source file:ams.AMSSettings.java

/**
 * ? ?? ?  .xml //from  w  w w.  ja v a 2  s .  c  o  m
 */
public void SaveSettings() {
    try {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("Settings");

        root.addElement("COM_Port").addText(m_pCOMPortSettings.GetPort());

        root.addElement("COM_Baudrate").addText(Integer.toString(m_pCOMPortSettings.GetBaudRate()));

        if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_5)
            root.addElement("COM_DataBits").addText("5");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_6)
            root.addElement("COM_DataBits").addText("6");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_7)
            root.addElement("COM_DataBits").addText("7");
        else if (m_pCOMPortSettings.GetDataBits() == SerialPort.DATABITS_8)
            root.addElement("COM_DataBits").addText("8");
        else {
            logger.warn(
                    "Unknown COM_DataBits value '" + m_pCOMPortSettings.GetDataBits() + "'! Saving default!");
            root.addElement("COM_DataBits").addText("8");
        }

        switch (m_pCOMPortSettings.GetParity()) {
        case SerialPort.PARITY_NONE:
            root.addElement("COM_Parity").addText("None");
            break;
        case SerialPort.PARITY_ODD:
            root.addElement("COM_Parity").addText("Odd");
            break;
        case SerialPort.PARITY_EVEN:
            root.addElement("COM_Parity").addText("Even");
            break;
        case SerialPort.PARITY_MARK:
            root.addElement("COM_Parity").addText("Mark");
            break;
        case SerialPort.PARITY_SPACE:
            root.addElement("COM_Parity").addText("Space");
            break;
        default:
            logger.warn("Unknown COM_Parity value '" + m_pCOMPortSettings.GetParity() + "'! Saving default!");
            root.addElement("COM_Parity").addText("None");
            break;
        }

        switch (m_pCOMPortSettings.GetStopBits()) {
        case SerialPort.STOPBITS_1:
            root.addElement("COM_StopBits").addText("1");
            break;
        case SerialPort.STOPBITS_2:
            root.addElement("COM_StopBits").addText("2");
            break;
        default:
            logger.warn(
                    "Unknown COM_StopBits value '" + m_pCOMPortSettings.GetStopBits() + "'! Saving default!");
            root.addElement("COM_StopBits").addText("1");
            break;
        }

        Element adams = root.addElement("Devices");
        adams.addElement("ADC1").addText(m_strADC1Address);
        adams.addElement("ADC2").addText(m_strADC2Address);
        adams.addElement("DAC1").addText(m_strDAC1Address);
        adams.addElement("DAC2").addText(m_strDAC2Address);
        adams.addElement("REL1").addText(m_strREL1Address);
        adams.addElement("ADC3").addText(m_strADC3Address);
        adams.addElement("ADC4").addText(m_strADC4Address);
        adams.addElement("DAC3").addText(m_strDAC3Address);
        adams.addElement("DAC4").addText(m_strDAC4Address);
        adams.addElement("REL2").addText(m_strREL2Address);

        // ***** ***** ***** ***** *****
        //
        //Iterator it = AMSConstants.getInstance().T_DEVICES.iterator();
        //while( it.hasNext()) {            
        for (int nDevice = AMSConstants.T_DEVICE1; nDevice <= AMSConstants.T_DEVICE8; nDevice++) {

            //int nDevice = ( int) it.next();

            Element device = root.addElement("Device" + nDevice + "_channels");
            Element devAn = device.addElement("anode");
            devAn.addElement("ADC_V_DEV")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoAdcVoltDev());
            devAn.addElement("ADC_V_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoAdcVoltChan());

            devAn.addElement("ADC_C_DEV")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoAdcCurrDev());
            devAn.addElement("ADC_C_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoAdcCurrChan());

            devAn.addElement("DAC_DEV").addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoDacDev());
            devAn.addElement("DAC_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoDacChan());

            devAn.addElement("REL_DEV").addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoRelDev());
            devAn.addElement("REL_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetAnoRelChan());

            Element devTu = device.addElement("tubulation");
            devTu.addElement("ADC_V_DEV")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubAdcVoltDev());
            devTu.addElement("ADC_V_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubAdcVoltChan());

            devTu.addElement("ADC_C_DEV")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubAdcCurrDev());
            devTu.addElement("ADC_C_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubAdcCurrChan());

            devTu.addElement("DAC_DEV").addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubDacDev());
            devTu.addElement("DAC_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubDacChan());

            devTu.addElement("REL_DEV").addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubRelDev());
            devTu.addElement("REL_CHAN")
                    .addText("" + ((AMSSettingsTDev) m_mapDevs.get(nDevice)).GetTubRelChan());

        }

        OutputFormat format = OutputFormat.createPrettyPrint();
        String strSettingsXmlFile = System.getenv("AMS_ROOT") + "/settings.xml";
        XMLWriter writer = new XMLWriter(new FileWriter(strSettingsXmlFile), format);

        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        logger.error("IOException caught while saving settings!", ex);
    }
}

From source file:ams.devices.AMSCalibration.java

public void SaveCalibration() {
    try {//  w  w w  .  j a  va2s .c om
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("Calibration");

        AMSCalibrationUnit unit = (AMSCalibrationUnit) m_mapCalibrationUnits.get(AMSConstants.ADC1);
        Element anodes = root.addElement("ADC1");
        anodes.addElement("ADC1_0_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC1_0_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC1_1_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC1_1_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC1_2_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC1_2_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC1_3_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC1_3_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC1_4_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC1_4_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC1_5_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC1_5_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC1_6_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC1_6_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC1_7_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL8)));
        anodes.addElement("ADC1_7_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL8)));

        unit = (AMSCalibrationUnit) m_mapCalibrationUnits.get(AMSConstants.ADC2);
        anodes = root.addElement("ADC2");
        anodes.addElement("ADC2_0_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC2_0_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC2_1_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC2_1_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC2_2_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC2_2_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC2_3_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC2_3_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC2_4_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC2_4_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC2_5_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC2_5_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC2_6_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC2_6_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC2_7_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL8)));
        anodes.addElement("ADC2_7_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL8)));

        unit = (AMSCalibrationUnit) m_mapCalibrationUnits.get(AMSConstants.ADC3);
        anodes = root.addElement("ADC3");
        anodes.addElement("ADC3_0_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC3_0_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC3_1_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC3_1_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC3_2_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC3_2_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC3_3_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC3_3_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC3_4_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC3_4_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC3_5_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC3_5_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC3_6_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC3_6_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC3_7_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL8)));
        anodes.addElement("ADC3_7_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL8)));

        unit = (AMSCalibrationUnit) m_mapCalibrationUnits.get(AMSConstants.ADC4);
        anodes = root.addElement("ADC4");
        anodes.addElement("ADC4_0_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC4_0_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL1)));
        anodes.addElement("ADC4_1_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC4_1_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL2)));
        anodes.addElement("ADC4_2_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC4_2_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL3)));
        anodes.addElement("ADC4_3_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC4_3_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL4)));
        anodes.addElement("ADC4_4_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC4_4_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL5)));
        anodes.addElement("ADC4_5_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC4_5_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL6)));
        anodes.addElement("ADC4_6_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC4_6_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL7)));
        anodes.addElement("ADC4_7_A").addText(String.format("%.3f", unit.GetSlope(AMSConstants.CHANNEL8)));
        anodes.addElement("ADC4_7_B").addText(String.format("%.3f", unit.GetShift(AMSConstants.CHANNEL8)));

        OutputFormat format = OutputFormat.createPrettyPrint();
        String strCalibrationFilePathName = System.getenv("AMS_ROOT") + "/calibration.xml";
        XMLWriter writer = new XMLWriter(new FileWriter(strCalibrationFilePathName), format);

        writer.write(document);
        writer.close();
    } catch (IOException ex) {
        logger.error("IOException caught while saving calibration!", ex);
    }
}

From source file:architecture.common.license.License.java

License:Apache License

public String toXML() {
    DocumentFactory factory = DocumentFactory.getInstance();
    Document document = factory.createDocument();
    Element root = document.addElement("license");

    root.addAttribute("id", String.valueOf(getLicenseId()));
    root.addAttribute("name", getName());
    if (edition != null)
        root.addAttribute("edition", getEdition());
    root.addAttribute("creationDate", formatDate(getCreationDate()));
    root.addAttribute("version", getVersion().getVersionString());
    root.addAttribute("type", getType().name());
    if (getClient() != null) {
        Element client = root.addElement("client");
        if (getClient().getName() != null)
            client.addAttribute("name", getClient().getName());
        if (getClient().getCompany() != null)
            client.addAttribute("company", getClient().getCompany());
    }//from w  w w.  jav a  2  s  . c o m

    for (Module m : getModules()) {
        Element me = root.addElement("module");
        me.addAttribute("name", m.getName());
    }

    for (java.util.Map.Entry<String, String> entry : getProperties().entrySet()) {
        Element prop = root.addElement("property");
        prop.addAttribute("name", (String) entry.getKey());
        prop.setText((String) entry.getValue());
    }
    return document.asXML();
}

From source file:architecture.ee.component.core.lifecycle.RepositoryImpl.java

License:Apache License

public ApplicationProperties getSetupApplicationProperties() {
    if (setupProperties == null) {
        try {//ww w.j  av  a 2s  .com
            File file = getFile(ApplicationConstants.DEFAULT_STARTUP_FILENAME);
            if (!file.exists()) {
                boolean error = false;
                // create default file...
                log.debug("No startup file now create !!!");
                Writer writer = null;
                try {

                    writer = new OutputStreamWriter(new FileOutputStream(file),
                            ApplicationConstants.DEFAULT_CHAR_ENCODING);
                    XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
                    StringBuilder sb = new StringBuilder();
                    org.dom4j.Document document = org.dom4j.DocumentHelper.createDocument();
                    org.dom4j.Element root = document.addElement("startup-config");
                    // setup start
                    // ------------------------------------------------------------
                    org.dom4j.Element setupNode = root.addElement("setup");
                    setupNode.addElement("complete").setText("false");
                    // setup end
                    // --------------------------------------------------------------
                    // license start
                    org.dom4j.Element licenseNode = root.addElement("license");
                    // license end
                    // view start
                    org.dom4j.Element viewNode = root.addElement("view");
                    org.dom4j.Element renderNode = viewNode.addElement("render");
                    org.dom4j.Element freemarkerNode = renderNode.addElement("freemarker");
                    freemarkerNode.addElement("enabled").setText("true");
                    freemarkerNode.addElement("source").addElement("location");
                    org.dom4j.Element velocityNode = renderNode.addElement("velocity");
                    velocityNode.addElement("enabled").setText("false");
                    // view end
                    // security start
                    org.dom4j.Element securityNode = root.addElement("security");
                    securityNode.addElement("authentication").addElement("encoding").addElement("algorithm")
                            .setText("SHA-256");
                    // security end

                    // scripting start
                    org.dom4j.Element scriptingNode = root.addElement("scripting");
                    org.dom4j.Element groovyNode = scriptingNode.addElement("groovy");
                    groovyNode.addElement("debug").setText("false");
                    org.dom4j.Element sourceGroovyNode = groovyNode.addElement("source");
                    sourceGroovyNode.addElement("location");
                    sourceGroovyNode.addElement("encoding").setText(ApplicationConstants.DEFAULT_CHAR_ENCODING);
                    sourceGroovyNode.addElement("recompile").setText("true");
                    // scripting end
                    // database start
                    org.dom4j.Element databaseNode = root.addElement("database");
                    // database end
                    xmlWriter.write(document);
                } catch (Exception e) {
                    log.error(L10NUtils.format("003007", file.getName(), e.getMessage()));
                    error = true;
                } finally {
                    try {
                        writer.flush();
                        writer.close();
                    } catch (Exception e) {
                        log.error(e);
                        error = true;
                    }
                }
            }
            this.setupProperties = new XmlApplicationProperties(file);
        } catch (Exception e) {
            log.warn("I warning you!");
            log.debug(e.getMessage(), e);
            return EmptyApplicationProperties.getInstance();
        }
    }
    return setupProperties;
}

From source file:architecture.ee.component.RepositoryImpl.java

License:Apache License

public ApplicationProperties getSetupApplicationProperties() {
    if (setupProperties == null) {
        if (initailized.get()) {

            File file = getFile(ApplicationConstants.DEFAULT_STARTUP_FILENAME);

            if (!file.exists()) {
                boolean error = false;
                // create default file...
                log.debug(CommonLogLocalizer.format("003012", file.getAbsolutePath()));
                Writer writer = null;
                try {

                    lock.lock();//from w ww.  j av  a2 s  .  c om

                    writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
                    XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint());
                    StringBuilder sb = new StringBuilder();

                    org.dom4j.Document document = org.dom4j.DocumentHelper.createDocument();
                    org.dom4j.Element root = document.addElement("startup-config");
                    // setup start
                    // ------------------------------------------------------------
                    org.dom4j.Element setupNode = root.addElement("setup");
                    setupNode.addElement("complete").setText("false");
                    // setup end

                    // license start
                    root.addComment("LICENSE SETTING");
                    org.dom4j.Element licenseNode = root.addElement("license");
                    // license end

                    // view start
                    /*
                    org.dom4j.Element viewNode = root.addElement("view");
                    org.dom4j.Element renderNode = viewNode.addElement("render");
                    org.dom4j.Element freemarkerNode = renderNode.addElement("freemarker");
                    freemarkerNode.addElement("enabled").setText("true");
                    freemarkerNode.addElement("source").addElement("location");
                    org.dom4j.Element velocityNode = renderNode.addElement("velocity");
                    velocityNode.addElement("enabled").setText("false");
                    */
                    // view end

                    // security start         
                    root.addComment("SECURITY SETTING");
                    org.dom4j.Element securityNode = root.addElement("security");
                    org.dom4j.Element encrpptNode = securityNode.addElement("encrypt");
                    encrpptNode.addElement("algorithm").setText("Blowfish");
                    encrpptNode.addElement("key").addElement("current");
                    org.dom4j.Element encrpptPropertyNode = encrpptNode.addElement("property");
                    encrpptPropertyNode.addElement("name").setText("username");
                    encrpptPropertyNode.addElement("name").setText("password");
                    securityNode.addElement("authentication").addElement("encoding").addElement("algorithm")
                            .setText("SHA-256");
                    // security end
                    // services start
                    root.addComment("SERVICES SETTING");
                    org.dom4j.Element servicesNode = root.addElement("services");
                    servicesNode.addElement("sql").addElement("location").addText("sql");
                    // services end

                    // database start
                    root.addComment("DATABASE SETTING");
                    org.dom4j.Element databaseNode = root.addElement("database");
                    org.dom4j.Element databaseDefaultNode = databaseNode.addElement("default");
                    databaseDefaultNode.addComment(" 1. jndi datasource ");
                    databaseDefaultNode.addComment((new StringBuilder()).append("\n").append("      ")
                            .append("<jndiDataSourceProvider>").append("\n").append("      ")
                            .append("   <jndiName></jndiName>").append("\n").append("      ")
                            .append("</jndiDataSourceProvider>").append("\n").toString());
                    databaseDefaultNode.addComment(" 2. connection pool datasource using dbcp ");
                    databaseDefaultNode.addComment((new StringBuilder()).append("\n").append("      ")
                            .append("<pooledDataSourceProvider> ").append("\n").append("      ")
                            .append("    <driverClassName></driverClassName> ").append("\n").append("      ")
                            .append("    <url></url>").append("\n").append("      ")
                            .append("    <username></username>").append("\n").append("      ")
                            .append("    <password></password>").append("\n").append("      ")
                            .append("    <connectionProperties>").append("\n").append("      ")
                            .append("        <initialSize>1</initialSize>").append("\n").append("      ")
                            .append("        <maxActive>8</maxActive>").append("\n").append("      ")
                            .append("        <maxIdle>8</maxIdle>").append("\n").append("      ")
                            .append("        <maxWait>-1</maxWait>").append("\n").append("      ")
                            .append("        <minIdle>0</minIdle>").append("\n").append("      ")
                            .append("        <testOnBorrow>true</testOnBorrow>").append("\n").append("      ")
                            .append("        <testOnReturn>false</testOnReturn>").append("\n").append("      ")
                            .append("        <testWhileIdle>false</testWhileIdle>").append("\n")
                            .append("      ")
                            .append("        <validationQuery>select 1 from dual</validationQuery>")
                            .append("\n").append("      ").append("    </connectionProperties>").append("\n")
                            .append("      ").append("</pooledDataSourceProvider>").toString());
                    // database end
                    xmlWriter.write(document);
                } catch (Exception e) {
                    log.error("fail to making {} - {}", file.getName(), e.getMessage());
                    error = true;
                } finally {

                    try {
                        writer.flush();
                        writer.close();
                    } catch (Exception e) {
                        log.error("error", e);
                        error = true;
                    }
                    lock.unlock();
                }
            } else {
                try {
                    log.debug(CommonLogLocalizer.format("003011", file.getPath()));
                    this.setupProperties = new LocalApplicationProperties(file);
                } catch (IOException e) {
                    log.error(CommonLogLocalizer.getMessage("003013"), e);
                }
            }
        } else {
            return LocalApplicationProperties.EMPTY_APPLICATION_PROPERTIES;
        }
    }
    return setupProperties;
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param searchResults//from   www .j a va  2  s .co  m
 * 
 * @return {@link Document} containing the {@link SearchResults} in XML form.
 */
public static Document genoogleOutputToXML(List<SearchResults> searchResults) {
    assert searchResults != null;
    DocumentFactory factory = DocumentFactory.getInstance();

    Document doc = factory.createDocument();
    doc.setName("genoogle");

    Element output = doc.addElement(Genoogle.SOFTWARE_NAME);
    output.addAttribute("version", Genoogle.VERSION.toString());
    output.addAttribute("copyright", Genoogle.COPYRIGHT);

    Element iterationsElement = output.addElement("iterations");
    for (int i = 0; i < searchResults.size(); i++) {
        SearchResults searchResult = searchResults.get(i);

        Element iterationElement = iterationsElement.addElement("iteration");
        iterationElement.addAttribute("number", String.valueOf(i));

        SymbolList query = searchResult.getParams().getQuery();
        if (query instanceof RichSequence) {
            iterationElement.addAttribute("query", ((RichSequence) query).getHeader());
        }

        iterationElement.add(searchResultToXML(searchResult));
    }

    return doc;
}

From source file:bio.pih.genoogle.io.Output.java

public static Element genoogleXmlHeader() {
    DocumentFactory factory = DocumentFactory.getInstance();

    Document doc = factory.createDocument();
    doc.setName("genoogle");

    Map<String, String> xslProcessing = Maps.newHashMap();
    xslProcessing.put("type", "text/xsl");
    xslProcessing.put("href", "results.xsl");
    ProcessingInstruction xsltInstruction = DocumentHelper.createProcessingInstruction("xml-stylesheet",
            xslProcessing);//from  w w  w . ja va2s .  c om
    doc.add(xsltInstruction);

    Element output = doc.addElement("genoogle");
    output.addElement("references").addAttribute("program", Genoogle.SOFTWARE_NAME)
            .addAttribute("version", Double.toString(Genoogle.VERSION))
            .addAttribute("copyright", Genoogle.COPYRIGHT);
    return output;
}