List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.buddycloud.pusher.handler.GetPusherMetadataQueryHandler.java
License:Apache License
/** * @param iq/*from w ww .j a va 2 s. c om*/ * @param userJid * @param metadata * @return */ private IQ createResponse(IQ iq, String userJid, Map<String, String> metadata) { IQ result = IQ.createResultIQ(iq); Element queryElement = result.getElement().addElement("query", getNamespace()); for (Entry<String, String> entry : metadata.entrySet()) { queryElement.addElement(entry.getKey()).setText(entry.getValue()); } return result; }
From source file:com.buddycloud.pusher.utils.NotificationUtils.java
License:Apache License
/** * @param queryElement /*ww w . j ava 2 s.c o m*/ * @param notificationSettings * @return */ public static void appendXML(Element queryElement, NotificationSettings notificationSettings) { Element settingsEl = queryElement.addElement("notificationSettings"); if (notificationSettings == null) { return; } setText(settingsEl, "target", notificationSettings.getTarget()); setText(settingsEl, "type", notificationSettings.getType()); setText(settingsEl, "postAfterMe", notificationSettings.getPostAfterMe()); setText(settingsEl, "postMentionedMe", notificationSettings.getPostMentionedMe()); setText(settingsEl, "postOnMyChannel", notificationSettings.getPostOnMyChannel()); setText(settingsEl, "postOnSubscribedChannel", notificationSettings.getPostOnSubscribedChannel()); setText(settingsEl, "followMyChannel", notificationSettings.getFollowedMyChannel()); setText(settingsEl, "followRequest", notificationSettings.getFollowRequest()); }
From source file:com.buddycloud.pusher.utils.NotificationUtils.java
License:Apache License
private static void setText(Element rootEl, String property, Object text) { if (text == null) { return;//from w w w. ja v a 2 s . co m } rootEl.addElement(property).setText(text.toString()); }
From source file:com.buddycloud.pusher.utils.XMPPUtils.java
License:Apache License
public static void addInfo(String message, Element queryElement) { Element messageEl = queryElement.addElement("info"); messageEl.setText(message);//w ww .j a va 2 s . c om }
From source file:com.bullx.demo.xml.XMLParser.java
License:Open Source License
public static void bookListToXML(List<Book> books) { Document document = DocumentHelper.createDocument(); // XMLbooks//from w w w . j av a2 s . c om Element booksElement = document.addElement("books"); // booksElement.addComment("This is a test for dom4j, liubida, 2012.8.11"); for (Book book : books) { // Element bookElement = booksElement.addElement("book"); // : show bookElement.addAttribute("show", book.getShow() ? "yes" : "no"); // title bookElement.addElement("title").setText(book.getTitle()); // express bookElement.addElement("express").setText(book.getExpress()); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); StringWriter out = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(out, format); try { xmlWriter.write(document); xmlWriter.flush(); String s = out.toString(); System.out.println(s); Log.info("xml done!"); } catch (Exception e) { Log.error("xml error!"); } finally { try { if (null != xmlWriter) { xmlWriter.close(); } if (null != out) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.collabnet.ccf.core.AbstractReader.java
License:Open Source License
private void modifySyncInfo(Document syncInfo, boolean isForced) { Element rootElement = syncInfo.getRootElement(); Element forcedArtifactElement = rootElement.addElement(FORCED_ARTIFACT_ELEMENT); forcedArtifactElement.setText(Boolean.toString(isForced)); }
From source file:com.collabnet.ccf.core.AbstractReader.java
License:Open Source License
private void modifySyncInfo(Document syncInfo, String lastArtifactModifiedTime, String lastArtifactModifiedVersion) { if (lastArtifactModifiedTime == null && lastArtifactModifiedVersion == null) { return;// ww w. jav a 2 s. c om } //Cloned syncInfo is used to create two new element - ARTIFACT_LAST_MODIFIED_DATE and ARTIFACT_LAST_MODIFIED_VERSION Element rootElement = syncInfo.getRootElement(); Element artifactLastModifiedTimeElement = rootElement.addElement(ARTIFACT_LAST_MODIFIED_DATE_ELEMENT); artifactLastModifiedTimeElement.setText(lastArtifactModifiedTime); Element artifactLastModifiedVersionElement = rootElement.addElement(ARTIFACT_LAST_MODIFIED_VERSION_ELEMENT); artifactLastModifiedVersionElement.setText(lastArtifactModifiedVersion); }
From source file:com.collabnet.ccf.core.hospital.Ambulance.java
License:Open Source License
public Object[] process(Object data) { log.warn("Artifact reached ambulance"); if (data instanceof MessageException) { MessageException exception = (MessageException) data; Object dataObj = exception.getData(); String source = exception.getOriginatingModule(); Exception rootCause = exception.getException(); Document doc = createXMLDocument("UTF-8"); Element failure = doc.addElement("Failure"); Element failureSource = failure.addElement("Source"); if (source != null) failureSource.setText(source); Element exceptionDetail = failure.addElement("Exception"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream st = new PrintStream(bos); rootCause.printStackTrace(st);//w w w .j a va2 s. co m exceptionDetail.setText(new String(bos.toByteArray())); Element dataElement = failure.addElement("Data"); if (dataObj instanceof Document) { Document dataDoc = (Document) dataObj; String artifactFileName = null; try { artifactFileName = CCFUtils.getTempFileName(dataDoc); } catch (GenericArtifactParsingException e) { log.warn("The data that reached the hospital is not a Generic Artifact"); } if (artifactFileName == null) { artifactFileName = "sync-info"; } String tempFilePath = null; FileOutputStream fos = null; try { File tempFile = File.createTempFile(artifactFileName, ".xml", artifactsDirectoryFile); fos = new FileOutputStream(tempFile); String dataXML = dataDoc.asXML(); fos.write(dataXML.getBytes()); fos.flush(); fos.close(); tempFilePath = tempFile.getAbsolutePath(); } catch (IOException e) { log.error("Could not create temporary File", e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { log.warn("Could not close temp file stream", e); } } } dataElement.setText(tempFilePath); } String writeData = failure.asXML(); try { fos.write(writeData.getBytes()); fos.write(System.getProperty("line.separator").getBytes()); fos.flush(); } catch (IOException e) { log.error("An IO-Exception occured in the hospital: " + e.getMessage()); return null; } } return new Object[0]; }
From source file:com.cosmosource.common.service.UserMgrManager.java
/** * @??: ?xml?// w w w. j a v a 2s.c o m * @param nodeId * @param orgid * @return */ public String getOrgTreeData(String orgid, String ctx, String type) { if ("init".equals(type)) { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("tree"); root.addAttribute("id", "0"); TAcOrg org = (TAcOrg) dao.findById(TAcOrg.class, new Long(orgid)); Element el = root.addElement("item"); el.addAttribute("text", org.getOrgname()); el.addAttribute("id", org.getOrgid() + ""); // el.addAttribute("open", "1"); el.addAttribute("child", "1"); Element elx = el.addElement("userdata"); elx.addAttribute("name", "url"); elx.addText(ctx + "/common/userMgr/list.act?nodeId=" + org.getOrgid() + "&orgtype=" + org.getOrgtype()); // getOrgTreeDoc(new Long(orgid), el, ctx, org.getOrgtype()); return doc.asXML(); } else { Element root = DocumentHelper.createElement("tree"); root.addAttribute("id", orgid); List<TAcOrg> list = dao .findByHQL("select t from TAcOrg t where t.parentid=" + orgid + " order by orgcode "); if (list.size() <= 500) { for (TAcOrg org : list) { Element el = root.addElement("item"); el.addAttribute("text", org.getOrgname()); el.addAttribute("id", org.getOrgid() + ""); if ("1".equals(org.getIsbottom())) { el.addAttribute("child", "1"); } else { el.addAttribute("child", "0"); } // if(org.getParentid()==0){ // el.addAttribute("open", "1"); // } Element elx = el.addElement("userdata"); elx.addAttribute("name", "url"); if (!org.getOrgtype().equals("3")) { elx.addText(ctx + "/common/userMgr/list.act?nodeId=" + org.getOrgid() + "&orgtype=" + org.getOrgtype()); } else { elx.addText(ctx + "/common/userMgr/orgFrame.act?nodeId=" + org.getOrgid()); } } } return root.asXML(); } }
From source file:com.cosmosource.common.service.UserMgrManager.java
/** * @??: DOC//from w w w . ja va2s .c o m * @param orgId * @param root */ public void getOrgTreeDoc(Long orgId, Element root, String ctx, String orgtype) { List<TAcOrg> list = dao.findByHQL("select t from TAcOrg t where t.parentid=" + orgId); if (!orgtype.equals("3")) { for (TAcOrg org : list) { Element el = root.addElement("item"); el.addAttribute("text", org.getOrgname()); el.addAttribute("id", org.getOrgid() + ""); if (org.getParentid() == 0) { el.addAttribute("open", "1"); } Element elx = el.addElement("userdata"); elx.addAttribute("name", "url"); if (!org.getOrgtype().equals("3")) { elx.addText(ctx + "/common/userMgr/list.act?nodeId=" + org.getOrgid() + "&orgtype=" + org.getOrgtype()); } else { elx.addText(ctx + "/common/userMgr/orgFrame.act?nodeId=" + org.getOrgid()); } if ("1".equals(org.getIsbottom())) { getOrgTreeDoc(org.getOrgid(), el, ctx, org.getOrgtype()); } } } }