Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:au.gov.ansto.bragg.process.parse.Parse.java

License:Open Source License

public static List<ConfigurationItem> parseConfiguration(File filename) throws DocumentException {
    List<ConfigurationItem> propertyList = new LinkedList<ConfigurationItem>();
    Document document = readFile(filename);
    Element rootElement = document.getRootElement();
    //      List<?> list = rootElement.selectNodes("//extension");
    //      System.out.println(list.toString());
    for (Iterator<?> iter = rootElement.elementIterator("extension"); iter.hasNext();) {
        Element item = (Element) iter.next();
        if (item.getName().equals("extension")
                && item.attributeValue("point").matches("au.gov.ansto.bragg.cicada.configuration")) {
            ConfigurationItem configuration = new ConfigurationItem(Integer.valueOf(getAttribute(item, "id")),
                    getAttribute(item, "name"), getAttribute(item, "version"), getAttribute(item, "class"),
                    getAttribute(item, "default"));
            propertyList.add(configuration);
        }/*from ww  w .j a va 2 s.  c  o  m*/
    }
    return propertyList;
}

From source file:batch.core.VersionProcessor.java

License:Open Source License

public VersionProcessor(Document testSpecMeta) {
    this(testSpecMeta.getRootElement().attributeValue("since", null),
            testSpecMeta.getRootElement().attributeValue("until", null),
            testSpecMeta.getRootElement().attributeValue("excludeFrom", null));
}

From source file:batch.performance.visualizer.om.Result.java

License:Open Source License

public void parse(Document dom) throws IOException {
    List runs = dom.getRootElement().elements("run");
    for (Iterator itr = runs.iterator(); itr.hasNext();) {
        Element run = (Element) itr.next();
        final String date = run.attributeValue("date");

        List groups = run.elements("group");
        for (Iterator jtr = groups.iterator(); jtr.hasNext();) {
            Element group = (Element) jtr.next();
            final URL testSpec = new URL(group.attributeValue("name"));

            List results = group.elements("result");
            for (Iterator ktr = results.iterator(); ktr.hasNext();) {
                Element result = (Element) ktr.next();

                URL instance = null;
                if (result.attribute("instance") != null)
                    instance = new URL(result.attributeValue("instance"));

                DataSeries ds = createDataSeries(testSpec, result.attributeValue("scenario"),
                        result.attributeValue("mode").equals("speed") ? Profiler.SPEED : Profiler.MEMORY,
                        instance);//from   w  w w. j  a  v a2  s .  c  o  m
                try {
                    ds.addDataPoint(date, new BigInteger(result.getTextTrim()));
                } catch (NumberFormatException e) {
                    ; // throw away this data point
                }
            }
        }
    }
}

From source file:batch.qa.QATestDescriptor.java

License:Open Source License

public QATestDescriptor(File metaFile) throws Exception {
    super(metaFile);

    Document doc = Util.loadXML(metaFile);
    Element testSpec = doc.getRootElement();

    List runOnce = new ArrayList();
    List normal = new ArrayList();

    {// run sciprts with "run='once'" attribute.
        Iterator jtr = testSpec.elementIterator("script");
        while (jtr.hasNext()) {
            Element script = (Element) jtr.next();
            URL url = new URL(testSpecUrl, script.attributeValue("href"));
            Script s = new Script(url);

            if ("once".equals(script.attributeValue("run"))) {
                runOnce.add(s);/*w  w  w  .j  a  v a 2s  .co m*/
            } else {
                normal.add(s);
            }
        }
    }

    this.runOnceScripts = (Script[]) runOnce.toArray(new Script[runOnce.size()]);
    this.perInstanceScripts = (Script[]) normal.toArray(new Script[normal.size()]);

    if (perInstanceScripts.length != 0 && instances.length == 0)
        throw new IllegalArgumentException(metaFile + " has per-instance scripts but no instance");

    // this might simply mean that the test is written for something other than QA.
    //        if( perInstanceScripts.length==0 && instances.length!=0 )
    //            throw new IllegalArgumentException(metaFile+" has instances but no per-instance script");
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

protected void printHRWorkSchedules(SessionContainerWO sessionContainerWO, AdminPerson activePatient)
        throws Exception {
    table = new PdfPTable(10);
    table.setWidthPercentage(pageWidth);

    // title//from w  w w . ja v  a2s.  c  o  m
    table.addCell(createTitleCell(getTran("web", "workSchedule"), 10));

    // compose object to pass search criteria with
    Workschedule findObject = new Workschedule();
    findObject.personId = Integer.parseInt(activePatient.personid); // required

    List workschedules = Workschedule.getList(findObject);
    String sReturn = "";

    if (workschedules.size() > 0) {
        // header
        table.addCell(createHeaderCell(getTran("web.hr", "begin"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "end"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "fte.short"), 1));
        table.addCell(createHeaderCell(getTran("web.hr", "type"), 2));
        table.addCell(createHeaderCell(getTran("web.hr", "details"), 4));
        table.addCell(createHeaderCell(getTran("web.hr", "duration"), 1));

        Hashtable hSort = new Hashtable();
        Workschedule workschedule;

        // sort on workschedule.getUid
        for (int i = 0; i < workschedules.size(); i++) {
            workschedule = (Workschedule) workschedules.get(i);
            hSort.put(workschedule.getUid() + "=" + workschedule.getUid(), workschedule);
        }

        Vector keys = new Vector(hSort.keySet());
        Collections.sort(keys);
        Collections.reverse(keys);

        Iterator iter = keys.iterator();
        while (iter.hasNext()) {
            workschedule = (Workschedule) hSort.get(iter.next());

            // parse xml
            String sXML = checkString(workschedule.scheduleXml);
            String sScheduleType = "", sScheduleHours = "";

            if (sXML.length() > 0) {
                SAXReader reader = new SAXReader(false);
                org.dom4j.Document xmlDoc = reader.read(new StringReader(sXML));

                // fetch type and hours
                org.dom4j.Element workScheduleElem = xmlDoc.getRootElement();
                if (workScheduleElem != null) {
                    org.dom4j.Element scheduleElem = workScheduleElem.element("Schedule");
                    if (scheduleElem != null) {
                        sScheduleType = checkString(scheduleElem.attributeValue("type"));

                        if (sScheduleType.equalsIgnoreCase("day")) {
                            sScheduleHours = checkString(scheduleElem.elementText("HoursPerDay"));
                        } else if (sScheduleType.equalsIgnoreCase("week")) {
                            org.dom4j.Element weekSchedule = scheduleElem.element("WeekSchedule");
                            if (weekSchedule != null) {
                                sScheduleHours = checkString(weekSchedule.elementText("HoursPerWeek"));
                            }
                        } else if (sScheduleType.equalsIgnoreCase("month")) {
                            sScheduleHours = checkString(scheduleElem.elementText("HoursPerMonth")) + " "
                                    + getTran("web.hr", "hours").toLowerCase();
                        }
                    }
                }
                workschedule.type = sScheduleType;
            }

            // one record
            table.addCell(createValueCell(ScreenHelper.getSQLDate(workschedule.begin), 1));
            table.addCell(createValueCell(ScreenHelper.getSQLDate(workschedule.end), 1));
            table.addCell(createValueCell(workschedule.fte + "%", 1));
            table.addCell(createValueCell(getTran("web.hr", sScheduleType + "Schedule")
                    + (sScheduleType.equals("week") ? " (" + getPredefinedWeekScheduleName(workschedule) + ")"
                            : ""),
                    2));
            table.addCell(createValueCell(getWorkscheduleDetails(workschedule), 4));
            table.addCell(createValueCell(sScheduleHours, 1));

            //addWorkscheduleDetails(table,workschedule);
        }
    } else {
        // no records found
        table.addCell(createValueCell(getTran("web", "noRecordsFound"), 10));
    }

    // add transaction to doc
    if (table.size() > 0) {
        doc.add(new Paragraph(" "));
        doc.add(table);
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private String getPredefinedWeekScheduleName(Workschedule workschedule) throws Exception {
    String sName = "";

    if (workschedule.type.equalsIgnoreCase("week")) {
        String sScheduleXml = checkString(workschedule.scheduleXml);
        if (sScheduleXml.length() > 0) {
            // parse weekSchedule from xml            
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(sScheduleXml));
            org.dom4j.Element workScheduleElem = document.getRootElement();

            org.dom4j.Element scheduleElem = workScheduleElem.element("Schedule");
            if (scheduleElem != null) {
                workschedule.scheduleXml = scheduleElem.asXML();
            }/*from  w  ww . j a  va2 s  .  c  om*/
        }

        String sWeekSchedule = workschedule.getScheduleElementValue(workschedule.type, "WeekSchedule")
                .replaceAll("\"", "'");

        // parse weekSchedule from xml           
        SAXReader reader = new SAXReader(false);
        org.dom4j.Document document = reader.read(new StringReader(sWeekSchedule));
        org.dom4j.Element weekSchedule = document.getRootElement();

        Vector weekSchedules = parsePredefinedWeekSchedulesFromXMLConfigValue();
        PredefinedWeekSchedule schedule;
        for (int i = 0; i < weekSchedules.size(); i++) {
            schedule = (PredefinedWeekSchedule) weekSchedules.get(i);

            if (weekSchedule.attributeValue("scheduleType").toLowerCase().equals(schedule.id.toLowerCase())) {
                sName = schedule.type;
            }
        }
    }

    return sName;
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void addSalaryDetails(PdfPTable table, Salary salary) {
    PdfPTable detailsTable = new PdfPTable(10);
    detailsTable.setWidthPercentage(100);

    //*** XML 1 - benefits (multi-add) **************************
    if (salary.benefits.length() > 0) {
        detailsTable.addCell(createSubtitleCell(getTran("web.hr", "benefits"), 10));

        // header          
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {/*  ww w  .  jav  a 2 s. c om*/
            // parse benefits from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.benefits));
            org.dom4j.Element benefitsElem = document.getRootElement();

            if (benefitsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element benefitElem;

                Iterator benefitsIter = benefitsElem.elementIterator("Benefit");
                while (benefitsIter.hasNext()) {
                    benefitElem = (org.dom4j.Element) benefitsIter.next();

                    sTmpBegin = checkString(benefitElem.elementText("Begin"));
                    sTmpEnd = checkString(benefitElem.elementText("End"));
                    sTmpPeriod = checkString(benefitElem.elementText("Period"));
                    sTmpType = checkString(benefitElem.elementText("Type"));
                    sTmpAmount = checkString(benefitElem.elementText("Amount"));

                    // one benefit
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(getTran("hr.salary.period", sTmpPeriod), 2));
                    detailsTable.addCell(createValueCell(getTran("hr.salary.benefit.type", sTmpType), 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 2 - bonuses (multi-add) **************************        
    if (salary.bonuses.length() > 0) {
        table.addCell(createSubtitleCell(getTran("web.hr", "bonuses"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web", "percentage"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 2));

        try {
            // parse bonuses from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.bonuses));
            org.dom4j.Element bonusesElem = document.getRootElement();

            if (bonusesElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpPercentage, sTmpAmount;
                org.dom4j.Element bonusElem;

                Iterator bonusesIter = bonusesElem.elementIterator("Bonus");
                while (bonusesIter.hasNext()) {
                    bonusElem = (org.dom4j.Element) bonusesIter.next();

                    sTmpBegin = checkString(bonusElem.elementText("Begin"));
                    sTmpEnd = checkString(bonusElem.elementText("End"));
                    sTmpPeriod = checkString(bonusElem.elementText("Period"));
                    sTmpType = checkString(bonusElem.elementText("Type"));
                    sTmpPercentage = checkString(bonusElem.elementText("Percentage"));
                    sTmpAmount = checkString(bonusElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 2));
                    detailsTable.addCell(createValueCell(sTmpPercentage + "%", 2));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 2);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 3 - otherIncome (multi-add) ***********************
    if (salary.otherIncome.length() > 0) {
        table.addCell(createSubtitleCell(getTran("web.hr", "otherIncome"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {
            // parse otherIncome from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.otherIncome));
            org.dom4j.Element benefitsElem = document.getRootElement();

            if (benefitsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element otherIncomeElem;

                Iterator otherIncomesIter = benefitsElem.elementIterator("OtherIncome");
                while (otherIncomesIter.hasNext()) {
                    otherIncomeElem = (org.dom4j.Element) otherIncomesIter.next();

                    sTmpBegin = checkString(otherIncomeElem.elementText("Begin"));
                    sTmpEnd = checkString(otherIncomeElem.elementText("End"));
                    sTmpPeriod = checkString(otherIncomeElem.elementText("Period"));
                    sTmpType = checkString(otherIncomeElem.elementText("Type"));
                    sTmpAmount = checkString(otherIncomeElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    //*** XML 4 - deductions (multi-add) ************************
    if (salary.deductions.length() > 0) {
        detailsTable.addCell(createSubtitleCell(getTran("web.hr", "deductions"), 10));

        // header
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3));
        detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3));

        try {
            // parse deductions from xml           
            SAXReader reader = new SAXReader(false);
            org.dom4j.Document document = reader.read(new StringReader(salary.deductions));
            org.dom4j.Element deductionsElem = document.getRootElement();

            if (deductionsElem != null) {
                String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount;
                org.dom4j.Element deductionElem;

                Iterator deductionsIter = deductionsElem.elementIterator("Deduction");
                while (deductionsIter.hasNext()) {
                    deductionElem = (org.dom4j.Element) deductionsIter.next();

                    sTmpBegin = checkString(deductionElem.elementText("Begin"));
                    sTmpEnd = checkString(deductionElem.elementText("End"));
                    sTmpPeriod = checkString(deductionElem.elementText("Period"));
                    sTmpType = checkString(deductionElem.elementText("Type"));
                    sTmpAmount = checkString(deductionElem.elementText("Amount"));

                    // one record
                    detailsTable.addCell(createValueCell(sTmpBegin, 1));
                    detailsTable.addCell(createValueCell(sTmpEnd, 1));
                    detailsTable.addCell(createValueCell(sTmpPeriod, 2));
                    detailsTable.addCell(createValueCell(sTmpType, 3));

                    cell = createValueCell(
                            sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3);
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                    detailsTable.addCell(cell);
                }
            }
        } catch (Exception e) {
            Debug.printStackTrace(e);
        }
    }

    if (detailsTable.size() > 0) {
        table.addCell(emptyCell(3));
        cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 3, PdfPCell.ALIGN_CENTER,
                PdfPCell.BOX);
        cell.setPadding(2);
        table.addCell(cell);
    }
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private void displayWeekSchedule(PdfPTable table, Workschedule schedule) throws Exception {
    String sScheduleXml = checkString(schedule.scheduleXml);
    if (sScheduleXml.length() > 0) {
        // parse weekSchedule from xml            
        SAXReader reader = new SAXReader(false);
        org.dom4j.Document document = reader.read(new StringReader(sScheduleXml));
        org.dom4j.Element workScheduleElem = document.getRootElement();

        // attribute : type
        org.dom4j.Element scheduleElem = workScheduleElem.element("Schedule");
        if (scheduleElem != null) {
            schedule.scheduleXml = scheduleElem.asXML();
        }/*from   www .j av  a 2s. c  om*/
    }

    String sWeekSchedule = schedule.getScheduleElementValue(schedule.type, "WeekSchedule").replaceAll("\"",
            "'");

    // parse weekSchedule from xml           
    SAXReader reader = new SAXReader(false);
    org.dom4j.Document document = reader.read(new StringReader(sWeekSchedule));
    org.dom4j.Element weekSchedule = document.getRootElement();

    displayTimeblocks(table, parseWeekschedule(weekSchedule));
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private String getWeekScheduleDetails(Workschedule schedule) throws Exception {
    String sDetails = "";

    String sScheduleXml = checkString(schedule.scheduleXml);
    if (sScheduleXml.length() > 0) {
        // parse weekSchedule from xml            
        SAXReader reader = new SAXReader(false);
        org.dom4j.Document document = reader.read(new StringReader(sScheduleXml));
        org.dom4j.Element workScheduleElem = document.getRootElement();

        // attribute : type
        org.dom4j.Element scheduleElem = workScheduleElem.element("Schedule");
        if (scheduleElem != null) {
            schedule.scheduleXml = scheduleElem.asXML();
        }//from  ww w  .  j a  v  a2  s  .c  o m
    }

    String sWeekSchedule = schedule.getScheduleElementValue(schedule.type, "WeekSchedule").replaceAll("\"",
            "'");

    // parse weekSchedule from xml           
    SAXReader reader = new SAXReader(false);
    org.dom4j.Document document = reader.read(new StringReader(sWeekSchedule));
    org.dom4j.Element weekSchedule = document.getRootElement();

    sDetails = getTimeblocksDetails(parseWeekschedule(weekSchedule));

    return sDetails;
}

From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java

private Vector parsePredefinedWeekSchedulesFromXMLConfigValue() {
    Vector schedules = new Vector();

    // read xml containing predefined weekSchedules
    try {/*from   ww w . java 2s. co  m*/
        SAXReader xmlReader = new SAXReader();
        String sXMLValue = MedwanQuery.getInstance().getConfigString("defaultWeekschedules");
        org.dom4j.Document document = xmlReader.read(new StringReader(sXMLValue));

        if (document != null) {
            org.dom4j.Element root = document.getRootElement();
            Iterator scheduleElems = root.elementIterator("WeekSchedule");

            PredefinedWeekSchedule schedule;
            org.dom4j.Element scheduleElem, timeBlockElem;
            while (scheduleElems.hasNext()) {
                schedule = new PredefinedWeekSchedule();

                scheduleElem = (org.dom4j.Element) scheduleElems.next();
                schedule.id = scheduleElem.attributeValue("id");
                schedule.type = scheduleElem.attributeValue("scheduleType");
                schedule.xml = scheduleElem.asXML();

                // timeblocks
                Iterator timeBlockElems = scheduleElem.element("TimeBlocks").elementIterator("TimeBlock");
                while (timeBlockElems.hasNext()) {
                    timeBlockElem = (org.dom4j.Element) timeBlockElems.next();

                    TimeBlock timeBlock = new TimeBlock();
                    timeBlock.id = checkString(timeBlockElem.attributeValue("id"));
                    timeBlock.dayIdx = checkString(timeBlockElem.elementText("DayIdx"));
                    timeBlock.beginHour = checkString(timeBlockElem.elementText("BeginHour"));
                    timeBlock.endHour = checkString(timeBlockElem.elementText("EndHour"));

                    schedule.timeBlocks.add(timeBlock);
                }

                Collections.sort(schedule.timeBlocks); // on day     
                schedules.add(schedule);
            }
        }
    } catch (Exception e) {
        if (Debug.enabled)
            e.printStackTrace();
        Debug.printProjectErr(e, Thread.currentThread().getStackTrace());
    }

    return schedules;
}