List of usage examples for org.dom4j.dom DOMElement setAttribute
public void setAttribute(String name, String value) throws DOMException
From source file:com.bullx.cacconfig.CACConfig.java
License:Open Source License
@SuppressWarnings("unchecked") private DOMElement getConfigs() { final int config_count = 5; final int attr_count = 2; DOMElement configsNode = new DOMElement("configs"); for (int i = 0; i < config_count; i++) { DOMElement config = new DOMElement("config"); config.setAttribute("objid", "liubida"); config.setAttribute("dataacquiretime", "30"); config.setAttribute("heartbeattime", "20"); config.setAttribute("version", "1.01"); for (int j = 0; j < attr_count; j++) { DOMElement attr = new DOMElement("attr"); attr.setAttribute("desc", "?"); attr.setAttribute("name", "SENSORNUM"); attr.setAttribute("type", "INT"); attr.setAttribute("length", "2"); attr.setAttribute("uint", ""); attr.setAttribute("range", ">=0"); attr.setAttribute("note", "nimabi"); attr.setAttribute("value", "2"); config.add(attr);//from w w w.j a va2 s . c o m } configsNode.add(config); } return configsNode; }
From source file:com.bullx.cacdata.CACData.java
License:Open Source License
@SuppressWarnings("unchecked") private DOMElement getMonitorData() { DOMElement monitorNode = new DOMElement("monitordata"); // sensor?/*from ww w . j av a 2s. c om*/ int dataNumber = 0; ConfigIedDAO iedDAO = new ConfigIedDAO(); List<ConfigIed> list = iedDAO.findAll(); monitorNode.setAttribute("cacid", list.get(0).getConfigCac().getCacId()); HashMap<String, String> objectMapper = new HashMap<String, String>(); //add mappers the first is the ied class, the second is the query string objectMapper.put("SIML", "DataSiml"); objectMapper.put("SPDC", "DataSpdc"); objectMapper.put("MMXN", "DataMmxn"); objectMapper.put("ZSAR", "DataZsar"); objectMapper.put("SIMG", "DataSimg"); objectMapper.put("SENV", "DataSenv"); for (int i = 0; i < list.size(); i++) { ConfigIed ied = list.get(i); String objectString = objectMapper.get(ied.getLnClass()); String queryString = "from " + objectString + " as inst where inst.lnInst=? order by inst.dataTime desc"; Query query = iedDAO.getSession().createQuery(queryString); query.setInteger(0, ied.getLnInst()); query.setFirstResult(0); query.setMaxResults(1); List<Node> thizNodes = getDataNodes(ied.getLnClass(), query, ied); for (int j = 0; j < thizNodes.size(); j++, dataNumber++) { monitorNode.add(thizNodes.get(j)); } } monitorNode.setAttribute("datanodenum", Integer.toString(dataNumber)); return monitorNode; }
From source file:esa.mo.tools.stubgen.GeneratorXsd.java
License:Open Source License
private Object updateMessageField(Object any) { if (null != any) { if (any instanceof JAXBElement) { JAXBElement re = (JAXBElement) any; if (re.getValue() instanceof TypeReference) { throw new IllegalArgumentException("Direct type not supported in message body of : " + re.getValue().getClass().getSimpleName()); } else if (re.getValue() instanceof NamedElementReferenceWithCommentType) { NamedElementReferenceWithCommentType ne = (NamedElementReferenceWithCommentType) re.getValue(); String partType = createCompositeElementsDetails(null, false, null, ne.getType(), true, true, null).getTypeName(); if (ne.getType().isList()) { // the message part is a list, XML schema does not support this at this level so we need to warn getLog().warn(// ww w. j av a 2 s.co m "XML Schema does not support top level elements with multiple occurrences of type " + partType); } DOMElement e = new DOMElement( new org.dom4j.QName("element", Namespace.get("http://www.w3.org/2001/XMLSchema")), 2); e.setAttribute("name", ne.getName()); e.setAttribute("type", partType); return e; } else { throw new IllegalArgumentException( "Unexpected type in message body of : " + re.getValue().getClass().getSimpleName()); } } else if (!(any instanceof Element)) { throw new IllegalArgumentException( "Unexpected type in message body of : " + any.getClass().getSimpleName()); } } return any; }
From source file:org.eclipse.birt.build.GenCaseResult.java
License:Open Source License
private void wrtTestReport(String reportType) { try {//from ww w . j av a2 s .c o m if (reportType.equalsIgnoreCase("autotest")) { DOMElement testElement = new DOMElement("TestPlugin"); String testSuitePlugin; testSuitePlugin = PluginName.replace(".AllTests", ""); testElement.setAttribute("id", testSuitePlugin); testElement.setAttribute("total", TotalCase); /*Add Fail Node Leaf*/ DOMElement detailElement = new DOMElement("fail"); detailElement.setText(FailCase); if ((FailCase != "N/A") && (Integer.valueOf(FailCase.trim()).intValue() > 0)) { detailElement.setAttribute("color", CONSTANT_RED); detailElement.setAttribute("boldStyle", CONSTANT_BOLD); } else { detailElement.setAttribute("color", CONSTANT_BLACK); detailElement.setAttribute("boldStyle", CONSTANT_NORMAL); } testElement.add(detailElement); /*Add Error Node Leaf */ detailElement = new DOMElement("error"); detailElement.setText(ErrorCase); if ((FailCase != "N/A") && (Integer.valueOf(ErrorCase.trim()).intValue() > 0)) { detailElement.setAttribute("color", CONSTANT_RED); detailElement.setAttribute("boldStyle", CONSTANT_BOLD); } else { detailElement.setAttribute("color", CONSTANT_BLACK); detailElement.setAttribute("boldStyle", CONSTANT_NORMAL); } testElement.add(detailElement); /* Add compile status */ detailElement = new DOMElement("compileStatus"); if (compileError) { detailElement.setText("Fail"); detailElement.setAttribute("color", CONSTANT_RED); detailElement.setAttribute("boldStyle", CONSTANT_BOLD); } else { detailElement.setText("Pass"); detailElement.setAttribute("color", CONSTANT_BLACK); detailElement.setAttribute("boldStyle", CONSTANT_NORMAL); } testElement.add(detailElement); this.rootElement.add(testElement); } else if (reportType.equalsIgnoreCase("performance")) { DOMElement testElement = new DOMElement("Performance"); testElement.setAttribute("id", "org.eclipse.birt.tests.performance"); testElement.setAttribute("URL", getPerformanceFilePath(performancePath)); /* * Add compile status */ DOMElement detailElement = new DOMElement("compileStatus"); if (compileError) { detailElement.setText("Fail"); detailElement.setAttribute("color", CONSTANT_RED); detailElement.setAttribute("boldStyle", CONSTANT_BOLD); } else { detailElement.setText("Pass"); detailElement.setAttribute("color", CONSTANT_BLACK); detailElement.setAttribute("boldStyle", CONSTANT_NORMAL); } testElement.add(detailElement); this.rootElement.add(testElement); } else { DOMElement testElement = new DOMElement("smoketest"); int index; index = reportType.indexOf("DTE"); if (index == -1) { index = reportType.indexOf("Engine"); if (index == -1) return; else testElement.setAttribute("id", "Engine Smoke"); } else { testElement.setAttribute("id", "DTE Smoke"); } testElement.setAttribute("total", this.TotalRpt.trim()); testElement.setAttribute("same", this.SameRpt.trim()); /* testElement.setAttribute("diff",this.DiffRpt); */ DOMElement detailElement = new DOMElement("diff"); detailElement.setText(this.DiffRpt); if (Integer.valueOf(this.DiffRpt.trim()).intValue() > 0) { detailElement.setAttribute("color", CONSTANT_RED); detailElement.setAttribute("boldStyle", CONSTANT_BOLD); } else { detailElement.setAttribute("color", CONSTANT_BLACK); detailElement.setAttribute("boldStyle", CONSTANT_NORMAL); } testElement.add(detailElement); this.rootElement.add(testElement); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.eclipse.birt.build.VersionUpdater.java
License:Open Source License
/** * @author /* w ww . ja va2 s . co m*/ * @param folderPath * @param plug_id * @param lastDate * @param dayInpast */ private void genVersionLog(File folderPath, String plug_id, String lastDate, int dayInpast) { // gen the dest file path String parentPath = folderPath.getAbsolutePath(); String fileName = plug_id + "_DayInPast" + ".xml"; String fullName = parentPath + "/" + fileName; File dest = new File(fullName); System.out.println("dest file full path:\t" + fullName); try { //genarate document factory DocumentFactory factory = new DocumentFactory(); //create root element DOMElement rootElement = new DOMElement("plugin"); rootElement.setAttribute("id", plug_id); //add child:lastdate DOMElement dateElement = new DOMElement("LastDate"); dateElement.setText(lastDate); rootElement.add(dateElement); //add child:dayinpast DOMElement dayElement = new DOMElement("DayInPast"); dayElement.setText(Integer.toString(dayInpast)); rootElement.add(dayElement); //gen the doc Document doc = factory.createDocument(rootElement); //PrettyFormat OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(dest), format); writer.write(doc); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.rivetlogic.export.components.data.QueryReporter.java
License:Open Source License
private DOMElement generateErrorElem(Throwable cte, String errorMsg) { DOMElement errorReportElem = new DOMElement("error"); if (cte != null) { if (cte instanceof ContentTransformationException) { errorReportElem.setAttribute("source", ((ContentTransformationException) cte).getId()); } else if (cte instanceof UrlTransformationException) { errorReportElem.setAttribute("source", ((UrlTransformationException) cte).getId()); } else if (cte instanceof DeployerException) { errorReportElem.setAttribute("source", ((DeployerException) cte).getId()); } else {//w w w . j ava2s . c om errorReportElem.setAttribute("source", "unknown"); } ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream(); PrintStream errorPrintStream = new PrintStream(errorOutputStream, true); cte.printStackTrace(errorPrintStream); errorReportElem.setText(errorOutputStream.toString()); } else if (errorMsg != null) { errorReportElem.setText(errorMsg); } else { // no msg } return errorReportElem; }