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:adr.main.AlcorAdrSettings.java

/**
 * ? ?? ?  .xml /* w  w w.jav a2 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//  ww  w .  j  a  v a 2s.c o  m
 */
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 /* www .j  a v  a 2  s  .  co 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 {/*from w  w w  .  j  av  a  2  s  .c  o  m*/
        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:BlastResultXMLsplit.BlastXMLsplit.java

public BlastXMLsplit(String filepath, int seqnumber)
        throws FileNotFoundException, IOException, ParserConfigurationException {
    SAXReader reader = new SAXReader();
    reader.setValidation(false);//from w ww.j  a v  a  2 s  .co m
    try {
        System.out.println("Xlmfile reading");
        Document document = reader.read(new FileInputStream(filepath));//XMLdocument?
        System.out.println("Xlmfile read done!");
        org.dom4j.DocumentFactory DocumentFactory = new org.dom4j.DocumentFactory();

        ArrayList str = new ArrayList();//??? 

        String fileoutpath;

        org.dom4j.Element rootElm = document.getRootElement();//
        File f = new File(filepath);
        int count = 1;
        List<org.dom4j.Element> blastOutput_iterations = rootElm.element("BlastOutput_iterations").elements();//?
        org.dom4j.Element BlastOutput_program = rootElm.element("BlastOutput_program");
        org.dom4j.Element BlastOutput_version = rootElm.element("BlastOutput_version");
        org.dom4j.Element BlastOutput_reference = rootElm.element("BlastOutput_reference");
        org.dom4j.Element BlastOutput_db = rootElm.element("BlastOutput_db");
        //?
        BlastOutput_program.getParent().remove(BlastOutput_program);
        BlastOutput_version.getParent().remove(BlastOutput_version);
        BlastOutput_reference.getParent().remove(BlastOutput_reference);
        BlastOutput_db.getParent().remove(BlastOutput_db);
        // org.dom4j.Element BlastOutput_query_def=rootElm.element("BlastOutput_query-def");
        //org.dom4j.Element BBlastOutput_query_len=rootElm.element("BlastOutput_query-len");

        org.dom4j.Element BlastOutput_param = rootElm.element("BlastOutput_param");
        rootElm.remove(BlastOutput_param);

        String Iteration_queryIDstr, Iteration_queryDefstr, Iteration_query_len;
        List<org.dom4j.Element> Iterationlist = null;
        int size = blastOutput_iterations.size();
        System.out.println("Your query seqcount is " + size + "\r\n Start dividing your file");
        for (int i = 0; i < size; i = i + seqnumber) {
            //??
            fileoutpath = f.getParent() + System.getProperty("file.separator") + count + ".xml";
            count++;
            System.out.println("The " + count + " is located in " + fileoutpath);
            FileOutputStream fos = new FileOutputStream(fileoutpath);
            OutputFormat format = OutputFormat.createPrettyPrint();
            XMLWriter writer = new XMLWriter(fos, format);
            // XMLWriter writer = new XMLWriter(new FileOutputStream(fileoutpath));
            //w??
            org.dom4j.Element firstelement = blastOutput_iterations.get(i);
            Iteration_queryIDstr = firstelement.element("Iteration_query-ID").getText();
            Iteration_queryDefstr = firstelement.element("Iteration_query-def").getText();
            Iteration_query_len = firstelement.element("Iteration_query-len").getText();

            //org.dom4j.DocumentFactory DocumentFactory = new org.dom4j.DocumentFactory();

            Document document2 = DocumentHelper.createDocument();
            ;
            org.dom4j.Element BlastOutputElement = document2.addElement("BlastOutput");
            //doc.setRootElement(BlastOutputElement);
            //;
            BlastOutputElement.add(BlastOutput_program);
            BlastOutputElement.add(BlastOutput_version);
            BlastOutputElement.add(BlastOutput_reference);
            BlastOutputElement.add(BlastOutput_db);
            BlastOutputElement.addElement("BlastOutput_query-ID");
            BlastOutputElement.element("BlastOutput_query-ID").setText(Iteration_queryIDstr);
            BlastOutputElement.addElement("BlastOutput_query-def");
            BlastOutputElement.element("BlastOutput_query-def").setText(Iteration_queryDefstr);
            BlastOutputElement.addElement("BlastOutput_query-len");
            BlastOutputElement.element("BlastOutput_query-len").setText(Iteration_query_len);
            //                Element BlastOutput_param_new=DocumentFactory.createElement("BlastOutput_param");
            //                for (Iterator it = BlastOutput_param.elementIterator(); it.hasNext();) {
            //                    Element tempele=(Element) it.next();
            //                    tempele.getParent().remove(tempele);
            //                    BlastOutput_param_new.add(tempele);
            //                }
            BlastOutputElement.add(BlastOutput_param);
            //BlastOutputElement.add(BlastOutput_param);
            if (i + seqnumber < blastOutput_iterations.size()) {
                Iterationlist = blastOutput_iterations.subList(i, i + seqnumber);
            } else {
                Iterationlist = blastOutput_iterations.subList(i, blastOutput_iterations.size() - 1);
            }
            //System.out.println(Iterationlist.size());
            //?query
            resetIterationlist(Iterationlist);
            //?BlastOutput_iterations

            Element BlastOutput_iterations = DocumentFactory.createElement("BlastOutput_iterations");
            //BlastOutputElement.addAttribute("BlastOutput_iterations");
            //org.dom4j.Element BlastOutput_iterations = new org.dom4j.Element("BlastOutput_iterations");
            for (int j = 0; j < Iterationlist.size(); j++) {
                Iterationlist.get(j).getParent().remove(Iterationlist.get(j));
                //System.out.println(j);
                BlastOutput_iterations.add(Iterationlist.get(j));
            }
            BlastOutputElement.add(BlastOutput_iterations);

            //
            writer.write(document2);
            writer.close();
            BlastOutput_program.getParent().remove(BlastOutput_program);
            BlastOutput_version.getParent().remove(BlastOutput_version);
            BlastOutput_reference.getParent().remove(BlastOutput_reference);
            BlastOutput_db.getParent().remove(BlastOutput_db);
            BlastOutput_param.getParent().remove(BlastOutput_param);
        }
    } catch (DocumentException ex) {
        Logger.getLogger(BlastXMLsplit.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:bookmarks.BookmarkXML.java

License:Open Source License

/**
 * 
 * 
 */
public BookmarkXML() {
    xmlDoc = DocumentHelper.createDocument();
}

From source file:bookmarks.buddylist.BuddyList.java

License:Open Source License

/**
 * //from  www  .j ava 2s  . co m
 * @return
 * @throws SQLException 
 */
public Document toXml() throws SQLException {
    Buddy curBuddy = null;
    Document buddyList = DocumentHelper.createDocument();
    Element root = buddyList.addElement("buddylist");

    for (int i = 0; i < this.buddies.size(); i++) {
        Element buddy = root.addElement("buddy");
        Element username = buddy.addElement("username");
        Element nickname = buddy.addElement("nickname");

        curBuddy = (Buddy) this.buddies.get(i);
        username.addText(curBuddy.username);
        if (curBuddy.nickname != null)
            nickname.addText(curBuddy.nickname);
    }

    return buddyList;

}

From source file:bookmarks.buddylist.BuddyListServlet.java

License:Open Source License

private Document constructSuccess() {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("xml");
    Element status = root.addElement("result");

    status.addElement("status").addText("SUCCESS");
    status.addElement("message");
    return document;
}

From source file:bookmarks.buddylist.BuddyListServlet.java

License:Open Source License

private Document constructFailure(String errMessage) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("xml");
    Element status = root.addElement("result");

    status.addElement("status").addText("FAILURE");
    status.addElement("message").addText(errMessage);
    return document;
}

From source file:cc.warlock.core.configuration.WarlockConfiguration.java

License:Open Source License

public void save() {
    Document document = DocumentHelper.createDocument();
    Element warlockConfig = DocumentHelper.createElement("warlock-config");

    document.setRootElement(warlockConfig);

    for (IConfigurationProvider provider : providers) {
        List<Element> elements = provider.getTopLevelElements();

        for (Element element : elements) {
            warlockConfig.add(element);/* ww  w  .  j  a  va 2 s  . c o  m*/
        }
    }

    for (Element unhandled : unhandledElements) {
        // Make sure to resave unhandled elements, just in case the corresponding handler wasn't instantiated
        warlockConfig.add(unhandled.createCopy());
    }

    try {
        if (configFile.exists()) {
            File backupFile = new File(configFile.getPath() + ".bak");
            if (backupFile.exists())
                backupFile.renameTo(new File(backupFile.getPath() + ".1"));
            configFile.renameTo(backupFile);
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        FileOutputStream stream = new FileOutputStream(configFile);
        XMLWriter writer = new XMLWriter(stream, format);
        writer.write(document);
        stream.close();

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}