List of usage examples for org.dom4j.tree DefaultElement addAttribute
public Element addAttribute(String name, String value)
From source file:com.devoteam.srit.xmlloader.core.operations.protocol.OperationReceiveMessage.java
License:Open Source License
/** * Parses the operation from a root element *//*from w w w .j a v a2 s . com*/ private void addParameterTestTag(Element root, String operation, String path, String value) throws Exception { DefaultElement filter; filter = new DefaultElement("parameter"); filter.addAttribute("name", "[reserved_param]"); filter.addAttribute("operation", "protocol.setFromMessage"); filter.addAttribute("value", path); DefaultElementInterface.addNode((DefaultElement) root, filter, 0); filter = new DefaultElement("test"); filter.addAttribute("parameter", "[reserved_param]"); filter.addAttribute("condition", operation); filter.addAttribute("value", value); DefaultElementInterface.addNode((DefaultElement) root, filter, 1); }
From source file:com.devoteam.srit.xmlloader.http.StackHttp.java
License:Open Source License
/** Creates a specific HTTP Msg */ @Override/*from w ww . ja va2 s . c o m*/ public Msg parseMsgFromXml(Boolean request, Element root, Runner runner) throws Exception { String text = root.getText(); MsgHttp msgHttp = new MsgHttp(text); // // Try to find the channel // String channelName = root.attributeValue("channel"); //part to don't have regression if (channelName == null || channelName.equalsIgnoreCase("")) { channelName = root.attributeValue("connectionName"); } String remoteUrl = root.attributeValue("remoteURL"); //part to don't have regression if (remoteUrl == null || remoteUrl.equalsIgnoreCase("")) { remoteUrl = root.attributeValue("server"); } // // If the message is not a request, it is a response. // The channel to use will be obtained from the // channel of the transaction-associated request. if (msgHttp.isRequest()) { Channel channel = null; // case the channelName is specified if (channelName != null && !channelName.equalsIgnoreCase("")) { channel = getChannel(channelName); } // case the remoteXXX is specified if (remoteUrl != null && !remoteUrl.equalsIgnoreCase("")) { channel = getChannel(remoteUrl); if (channel == null) { //part to don't have regression DefaultElement defaultElement = new DefaultElement("openChannelHTTP"); defaultElement.addAttribute("remoteURL", remoteUrl); defaultElement.addAttribute("name", remoteUrl); channel = this.parseChannelFromXml(defaultElement, StackFactory.PROTOCOL_HTTP); openChannel(channel); channel = getChannel(remoteUrl); } } if (channel == null) { throw new ExecutionException("The channel named " + channelName + " does not exist"); } // call to getTransactionId to generate it NOW (important) // it can be generated now because this is a request from xml msgHttp.getTransactionId(); msgHttp.setChannel(channel); } else { if (channelName != null) { throw new ExecutionException( "You can not specify the \"channel\" attribute while sending a response (provided by the HTTP protocol)."); } if (remoteUrl != null) { throw new ExecutionException( "You can not specify the \"remoteURL\" attribute while sending a response (provided by the HTTP protocol)."); } } return msgHttp; }
From source file:com.heliosapm.aa4h.parser.XMLQueryParser.java
License:Apache License
/** * End Document SAX ContentHandler Method. * Fired at the end of the document parsing event. * At this point the query has been fully parsed and the named or criteria query is complete. * This method executes the query and sets the result field, handling any errors. * @see org.xml.sax.ContentHandler#endDocument() * @throws SAXException//from w w w . j a v a2 s . c o m * TODO Clean up the timeout handling. The current one is Oracle specific. We need the timeout handling to differentiate between standard DB Errors and timeouts as a result of a user requested timeout. */ @SuppressWarnings("unchecked") public void endDocument() throws SAXException { parseTime = System.currentTimeMillis() - parseTime; try { if (isNamedQuery) { result = query.list(); } else { Criteria finalCriteria = (Criteria) criteriaStack.pop(); Projection p = ((CriteriaImpl) finalCriteria).getProjection(); if (p != null) { aliases = p.getAliases(); } result = finalCriteria.list(); } } catch (Exception ex) { try { if (ex.getCause().getMessage().startsWith("ORA-01013")) { toe = new TimeoutException("Query " + queryName + " Timed Out"); QName q = new QName("Error"); DefaultElement de = new DefaultElement(q); de.addAttribute("reason", "Query Time Out"); result = new ArrayList<DefaultElement>(); result.add(de); endTime = System.currentTimeMillis(); } else { throw new SAXException("Unknown Exception At List Time for Query:" + queryName, ex); } } catch (Exception e) { log.error("Unknown Exception At List Time for Query:" + queryName, ex); throw new SAXException("Unknown Exception At List Time for Query:" + queryName, ex); } } endTime = System.currentTimeMillis(); if (log.isDebugEnabled()) { log.info(new StringBuffer("CATSQuery[").append(queryName).append("] Returned ").append(result.size()) .append(" elements in ").append((endTime - startTime)).append(" ms.").toString()); log.info("Elapsed Time For [" + queryName + "]:" + (endTime - startTime) + " ms."); } }
From source file:com.thoughtworks.cruise.ConfigureCruiseUsingApi.java
License:Apache License
@com.thoughtworks.gauge.Step("Create pipeline <pipelineName> using template <templateName>") public void createPipelineUsingTemplate(final String pipelineName, final String templateName) throws Exception { editPipelineGroup(new PipelineGroupEditAction() { public void applyEdit(Document group) { Element pipelines = (Element) group.selectSingleNode("//pipelines"); Element pipeline = new DefaultElement("pipeline"); pipeline.addAttribute("name", pipelineName); pipeline.addAttribute("template", templateName); DefaultElement materials = new DefaultElement("materials"); DefaultElement hg = new DefaultElement("hg"); hg.addAttribute("url", "some-url"); materials.add(hg);//from w w w . ja v a 2s. c o m pipeline.add(materials); pipelines.add(pipeline); scenarioState.pushPipeline(pipelineName, pipelineName); } }); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void setUpSMTP(String hostName, int port, String username, String password, String tls, String from, String adminEmail) {//from w ww. ja v a 2 s .c o m Element serverTag = serverTag(); DefaultElement mailhost = new DefaultElement("mailhost"); mailhost.addAttribute("hostname", hostName); mailhost.addAttribute("port", String.valueOf(port)); mailhost.addAttribute("username", username); mailhost.addAttribute("password", password); mailhost.addAttribute("tls", tls); mailhost.addAttribute("from", from); mailhost.addAttribute("admin", adminEmail); serverTag.add(mailhost); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
private DefaultElement paramElement(String parameterName, String value) { DefaultElement elem = new DefaultElement("param"); elem.addAttribute("name", parameterName); elem.setText(value);/*w w w .j a va 2 s . c om*/ return elem; }
From source file:de.tud.kom.p2psim.impl.network.gnp.topology.CountryLookup.java
License:Open Source License
/** * /* ww w . j a v a 2 s .c o m*/ * @return xml-element containing current lookup data */ public Element exportToXML() { DefaultElement country = new DefaultElement("CountryLookup"); Set<String> codeKeys = countryLookup.keySet(); for (String code : codeKeys) { DefaultElement countryXml = new DefaultElement("CountryKey"); countryXml.addAttribute("code", code); countryXml.addAttribute("countryGeoIP", getGeoIpCountryName(code)); countryXml.addAttribute("countryPingEr", getPingErCountryName(code)); countryXml.addAttribute("regionPingEr", getPingErRegionName(code)); country.add(countryXml); } return country; }
From source file:de.tud.kom.p2psim.impl.network.gnp.topology.HostMap.java
License:Open Source License
/** * /* www.j a v a 2 s.c o m*/ * @return xml Document Object of relevant Class Attributes */ private Document getDocument() { Set<Host> hosts = new HashSet<Host>(); // "GroupLookup" Element log.debug("Generate XML-Element \"GroupLookup\""); DefaultElement groups = new DefaultElement("GroupLookup"); for (String group : this.groups.keySet()) { log.debug(" - Export Group: " + group); hosts.addAll(this.groups.get(group)); DefaultElement peerXml = new DefaultElement("Group"); peerXml.addAttribute("id", group); peerXml.addAttribute("maxsize", String.valueOf(this.groups.get(group).size())); String ip = ""; int x = 0; int blockSize = 1000; // IP Block of 1000, too long blocks leads to hangUp ?? for (Host host : this.groups.get(group)) { x++; ip += "," + host.getIpAddress(); if (x % blockSize == 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); ip = ""; } } if (ip.length() > 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); } groups.add(peerXml); } // "Hosts" Element log.debug("Generate XML-Element \"Hosts\""); DefaultElement peers = new DefaultElement("Hosts"); for (Host host : hosts) { DefaultElement peer = new DefaultElement("Host"); peer.addAttribute("ip", String.valueOf(host.getIpAddress())); String area = (host.getArea() != null) ? host.getArea() : "--"; peer.addAttribute("continentalArea", area); String countryCode = (host.getCountryCode() != null) ? host.getCountryCode() : "--"; peer.addAttribute("countryCode", countryCode); String region = (host.getRegion() != null) ? host.getRegion() : "--"; peer.addAttribute("region", region); String city = (host.getCity() != null) ? host.getCity() : "--"; peer.addAttribute("city", city); String isp = (host.getISP() != null) ? host.getISP() : "--"; peer.addAttribute("isp", isp); peer.addAttribute("longitude", String.valueOf(host.getLongitude())); peer.addAttribute("latitude", String.valueOf(host.getLatitude())); String coordinates = (host.getGnpPositionReference() != null) ? host.getGnpPositionReference().getCoordinateString() : "0"; peer.addAttribute("coordinates", coordinates); peers.add(peer); } // "PingErLookup" Elements log.debug("Generate XML-Element \"PingErLookup\""); Element pingEr = pingErLookup.exportToXML(); // "CountryLookup" Element log.debug("Generate XML-Element \"CountryLookup\""); Element country = countryLookup.exportToXML(); DefaultDocument document = new DefaultDocument(new DefaultElement("gnp")); document.getRootElement().add(groups); document.getRootElement().add(peers); document.getRootElement().add(pingEr); document.getRootElement().add(country); return document; }
From source file:de.tud.kom.p2psim.impl.network.gnp.topology.PingErLookup.java
License:Open Source License
/** * Export the Class Attributes to an XML Element * /*from www. j a v a2 s . c o m*/ * @param element */ public Element exportToXML() { DefaultElement pingEr = new DefaultElement("PingErLookup"); Set<String> fromKeys = data.keySet(); for (String from : fromKeys) { Set<String> toKeys = data.get(from).keySet(); for (String to : toKeys) { DefaultElement pingErXml = new DefaultElement("SummaryReport"); pingErXml.addAttribute("from", from); pingErXml.addAttribute("to", to); pingErXml.addAttribute("minimumRtt", String.valueOf(getMinimumRtt(from, to))); pingErXml.addAttribute("averageRtt", String.valueOf(getAverageRtt(from, to))); pingErXml.addAttribute("delayVariation", String.valueOf(getRttVariation(from, to))); pingErXml.addAttribute("packetLoss", String.valueOf(getPacktLossRate(from, to))); pingEr.add(pingErXml); } } return pingEr; }
From source file:net.sourceforge.sqlexplorer.dbproduct.Alias.java
License:Open Source License
/** * Describes this alias in XML; the result can be passed to the Alias(Element) constructor to refabricate it * /*from w w w . j av a2 s.co m*/ * @return */ public Element describeAsXml() { DefaultElement root = new DefaultElement(ALIAS); root.addAttribute(AUTO_LOGON, Boolean.toString(autoLogon)); root.addAttribute(CONNECT_AT_STARTUP, Boolean.toString(connectAtStartup)); root.addAttribute(DRIVER_ID, driverId); root.addAttribute(HAS_NO_USER_NAME, Boolean.toString(hasNoUserName)); root.addElement(NAME).setText(name); root.addElement(URL).setText(url); root.addElement(FOLDER_FILTER_EXPRESSION).setText(folderFilterExpression); root.addElement(NAME_FILTER_EXPRESSION).setText(nameFilterExpression); root.addElement(SCHEMA_FILTER_EXPRESSION).setText(schemaFilterExpression); Element usersElem = root.addElement(USERS); for (User user : users.values()) { // user.setPassword(ALIAS) usersElem.add(user.describeAsXml()); } if (defaultUser != null) { root.addElement(DEFAULT_USER).setText(defaultUser.getUserName()); } return root; }