List of usage examples for org.dom4j.tree DefaultElement DefaultElement
public DefaultElement(QName qname)
From source file:com.devoteam.srit.xmlloader.core.operations.protocol.OperationReceiveMessage.java
License:Open Source License
/** * Parses the operation from a root element *//*from ww w . java 2 s . c o m*/ 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.core.utils.XMLTree.java
License:Open Source License
/** * Replace nodes previously identified by the method compute() * accordingly to the XMLElementReplacer. * @throws java.lang.Exception//from w ww. java2 s . co m */ public void replace(XMLElementReplacer replacer, ParameterPool parameterPool) throws Exception { if (null == replacer) { throw new ExecutionException("XMLElementReplacer must not be null"); } for (Element e : elementsOrder) { List<Element> newNodesList = replacer.replace(e, parameterPool); if (newNodesList.isEmpty()) { Element element = new DefaultElement("removedElement"); newNodesList.add(element); } elementsMap.put(e, newNodesList); AbstractElement parent = (AbstractElement) e.getParent(); if (null != parent) { for (Element newChild : newNodesList) { DefaultElementInterface.insertNode((DefaultElement) parent, e, newChild); } e.detach(); parent.remove(e); if (1 == newNodesList.size() && e == root) { root = newNodesList.get(0); } } else if (1 == newNodesList.size()) { newNodesList.get(0); root = newNodesList.get(0); e.detach(); } else { // some error } } }
From source file:com.devoteam.srit.xmlloader.gui.frames.JFrameRunProfile.java
License:Open Source License
private void init(RunProfile runProfile) { // special DEV case if (null == runProfile) { try {//from www . ja v a2 s. c o m runProfile = new RunProfile(new DefaultElement("RunProfile")); } catch (Exception e) { e.printStackTrace(); } } this.runProfile = runProfile; refreshGraph(jComboBoxType.getSelectedIndex()); }
From source file:com.devoteam.srit.xmlloader.http.StackHttp.java
License:Open Source License
/** Creates a specific HTTP Msg */ @Override/*from w ww .j a v a2s . 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 ww w . j a va 2s. 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.mor.blogengine.model.BlogCategory.java
License:Open Source License
/** * a-like as {@link #toString() }//from w ww . ja v a2 s . com * * @return an XML representation of element */ @Override public DefaultElement toElement() { // QName lElementDecl = new QName("Category", mNamespace); DefaultElement lReturnElement = new DefaultElement("Category"); // Attribute= a=new Attribute("", mCatName) lReturnElement.add(new DefaultAttribute("ID", getEntityID())); lReturnElement.add(new DefaultAttribute("name", getCatName())); lReturnElement.add(new DefaultAttribute("description", getDescription())); return lReturnElement; }
From source file:com.mor.blogengine.model.BlogComment.java
License:Open Source License
@Override public DefaultElement toElement() { // this is element Declaration in complete form. // QName lCommentTextDecl = new QName("CommentText", mNamespace); // QName lReturnelementdecl = new QName("Comment", mNamespace); DefaultElement lReturnElement = null; DefaultElement lCommentText = new DefaultElement("CommentText"); lCommentText.addText(mCommentText);// w w w . j a va2s .co m lReturnElement = new DefaultElement("Comment"); // lReturnElement.add(mNamespace); lReturnElement.add(new DefaultAttribute("entryID", getEntryID())); lReturnElement.add(new DefaultAttribute("ID", getEntityID())); lReturnElement.add(new DefaultAttribute("date", mDate)); lReturnElement.add(new DefaultAttribute("author", mAuthor)); lReturnElement.add(new DefaultAttribute("webPage", mWebPage)); lReturnElement.add(lCommentText); return lReturnElement; }
From source file:com.mor.blogengine.model.BlogEntry.java
License:Open Source License
/** * * @return XML node representation of entry *//* ww w . jav a 2 s.c om*/ @Override public DefaultElement toElement() { // this is element Declaration in complete form. // QName lElementDecl = new QName("Entry", mNamespace); DefaultElement lReturnElement = new DefaultElement("Entry"); lReturnElement.add(new DefaultAttribute("date", getDate())); lReturnElement.add(new DefaultAttribute("categoryID", getCatID())); lReturnElement.add(new DefaultAttribute("allowComments", getAllowComments())); lReturnElement.add(new DefaultAttribute("ID", getEntityID())); // this is element Declaration in complete form. // QName lEntryTextDecl = new QName("Text", mNamespace); DefaultElement lEntryText = new DefaultElement("Text"); lEntryText.addText(mTexte); lReturnElement.add(lEntryText); // QName lResumeDecl = new QName("Resume", mNamespace); DefaultElement lEntryResume = new DefaultElement("Resume"); lEntryResume.addText(mResume); lReturnElement.add(lEntryResume); return lReturnElement; }
From source file:com.rowtheboat.gui.OptionsSingleton.java
License:Open Source License
/** * This method saves the options to the options.xml file *//*w w w . j a v a2 s . c o m*/ public void saveOptions() throws SAXException, IOException { /* Start the document */ OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(optionsFile), format); writer.startDocument(); /* Add the main options section */ Document document = DocumentHelper.createDocument(); Element root = document.addElement("Options"); /* Standard options */ DefaultElement standardElement = new DefaultElement("Standard"); standardElement.addElement("FullStrokeData").addText(getFullStrokeData() + ""); standardElement.addElement("BoatSmoothing").addText(getBoatSmoothing() + ""); root.add(standardElement); /* Input options */ DefaultElement inputElement = new DefaultElement("Input"); inputElement.addElement("SerialPort").addText(getSerialPort()); root.add(inputElement); /* Race options */ DefaultElement raceElement = new DefaultElement("Race"); raceElement.addElement("Countdown").addText(getDelay() + ""); root.add(raceElement); /* End the document */ writer.write(root); writer.endDocument(); writer.close(); }
From source file:com.safi.workshop.sqlexplorer.dbproduct.AliasManager.java
License:Open Source License
/** * Upgrades a v3 definition (java beans style) to v3.5.0beta2 and onwards * /*from ww w . j a va 2 s.co m*/ * @param beans * @return */ protected Element convertToV350(Element beans) { Element result = new DefaultElement(Alias.ALIASES); for (Object o : beans.elements("Bean")) { Element bean = (Element) o; Element alias = result.addElement(Alias.ALIAS); alias.addAttribute(Alias.AUTO_LOGON, Boolean.toString(getBoolean(bean.elementText("autoLogon"), false))); alias.addAttribute(Alias.CONNECT_AT_STARTUP, Boolean.toString(getBoolean(bean.elementText("connectAtStartup"), false))); alias.addAttribute(Alias.DRIVER_ID, bean.element("driverIdentifier").elementText("string")); alias.addElement(Alias.NAME).setText(bean.elementText("name")); Element userElem = alias.addElement(Alias.USERS).addElement(User.USER); userElem.addElement(User.USER_NAME).setText(bean.elementText("userName")); userElem.addElement(User.PASSWORD).setText(bean.elementText("password")); alias.addElement(Alias.URL).setText(bean.elementText("url")); alias.addElement(Alias.FOLDER_FILTER_EXPRESSION).setText(bean.elementText("folderFilterExpression")); alias.addElement(Alias.NAME_FILTER_EXPRESSION).setText(bean.elementText("nameFilterExpression")); alias.addElement(Alias.SCHEMA_FILTER_EXPRESSION).setText(bean.elementText("schemaFilterExpression")); } return result; }