List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:batch.performance.PerformanceTestDescriptor.java
License:Open Source License
/** * @param metaFile//from ww w . j a va2s .c om * @throws Exception */ public PerformanceTestDescriptor(File metaFile) throws Exception { super(metaFile); Element testSpec = Util.loadXML(metaFile).getRootElement(); List configs = new ArrayList(); for (Iterator itr = testSpec.elementIterator("performance"); itr.hasNext();) { Element performance = (Element) itr.next(); // load scenario Scenario scenario = createScenario(metaFile, performance); // load profiler Profiler profiler; if (performance.attributeValue("profiler").equals("memory")) profiler = Profiler.MEMORY; else profiler = Profiler.SPEED; // associated with instance? if (performance.attributeValue("run", "---").equals("once")) { // no configs.add(new Config(scenario, profiler, null)); } else { // yes for (int i = 0; i < instances.length; i++) configs.add(new Config(scenario, profiler, instances[i])); } } this.configs = (Config[]) configs.toArray(new Config[configs.size()]); }
From source file:batch.performance.PerformanceTestDescriptor.java
License:Open Source License
/** * Creates the {@link Scenario} object from the descriptor. * // w ww .j a v a2s .co m * Derived classes may override this method. */ protected Scenario createScenario(File baseLocation, Element performance) throws Exception { String className = performance.attributeValue("scenario"); if (className == null) { // this is a bean-shell based script. return new ScriptScenario(performance.element("scenario")); } Class clazz = Class.forName("batch.performance.scenarios." + className); try { // try the constructor with Element return (Scenario) clazz.getConstructor(new Class[] { Element.class }) .newInstance(new Object[] { performance }); } catch (NoSuchMethodException e) { // then the default constructor return (Scenario) clazz.newInstance(); } }
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);/* 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);//from w ww. jav a 2 s .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//w ww . jav a 2s . c om 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 www.j a v a 2s.com*/ } 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 Vector parsePredefinedWeekSchedulesFromXMLConfigValue() { Vector schedules = new Vector(); // read xml containing predefined weekSchedules try {//from w w w .j a va2 s . c o 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; }
From source file:bio.pih.genoogle.io.XMLConfigurationReader.java
/** * @return how many simultaneous searchs a searchManager can handle. */// w w w. ja v a 2 s .c om private static int getMaxSimultaneousSearchs(Element searchManager) { Element maxSimultaneousSearchs = searchManager.element("max-simultaneous-searchs"); String value = maxSimultaneousSearchs.attributeValue("value"); return Integer.parseInt(value); }
From source file:bio.pih.genoogle.io.XMLConfigurationReader.java
public static int getMatchScore() { if (match == null) { Element rootElement = doc.getRootElement(); Element scoreElement = rootElement.element("score"); Element matchElement = scoreElement.element("match"); String value = matchElement.attributeValue("value"); match = Integer.parseInt(value); }//ww w .j a v a 2 s . com return match.intValue(); }
From source file:bio.pih.genoogle.io.XMLConfigurationReader.java
public static int getMismatchScore() { if (mismatch == null) { Element rootElement = doc.getRootElement(); Element scoreElement = rootElement.element("score"); Element mismatchElement = scoreElement.element("mismatch"); String value = mismatchElement.attributeValue("value"); mismatch = Integer.parseInt(value); }/*from w ww. j a va2s . c om*/ return mismatch.intValue(); }