List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.b5chat.crossfire.xmpp.handler.IQTimeHandler.java
License:Open Source License
public IQTimeHandler() { super("XMPP Server Time Handler"); info = new IQHandlerInfo("query", "jabber:iq:time"); responseElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:time")); responseElement.addElement("utc"); responseElement.addElement("tz").setText(TIME_FORMAT.getTimeZone().getDisplayName()); responseElement.addElement("display"); }
From source file:org.b5chat.crossfire.xmpp.handler.IQVersionHandler.java
License:Open Source License
public IQVersionHandler() { super("XMPP Server Version Handler"); info = new IQHandlerInfo("query", "jabber:iq:version"); if (bodyElement == null) { bodyElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:version")); bodyElement.addElement("name").setText(AdminConsole.getAppName()); bodyElement.addElement("version").setText(AdminConsole.getVersionString()); }// w w w . j a va 2 s . c o m }
From source file:org.codehaus.cargo.container.jboss.JBoss75xStandaloneLocalConfiguration.java
License:Apache License
/** * Add resources to JBoss domain/* ww w.j ava 2 s .co m*/ */ protected void addResources() { String configurationXmlFile = "configuration/" + getPropertyValue(JBossPropertySet.CONFIGURATION) + ".xml"; // Create resources - so far just Email resource Map<String, String> ns = new HashMap<String, String>(); ns.put("domain", "urn:jboss:domain:1.7"); ns.put("mail", "urn:jboss:domain:mail:1.2"); String configurationXmlFilePath = getFileHandler().append(getHome(), configurationXmlFile); for (Resource resource : getResources()) { if (ConfigurationEntryType.MAIL_SESSION.equals(resource.getType())) { String host = resource.getParameter("mail.smtp.host") != null ? resource.getParameter("mail.smtp.host") : "localhost"; String port = resource.getParameter("mail.smtp.port") != null ? resource.getParameter("mail.smtp.port") : "25"; XmlFileBuilder manager = new Dom4JXmlFileBuilder(getFileHandler()); manager.setFile(configurationXmlFilePath); manager.loadFile(); manager.setNamespaces(ns); String jndiName = resource.getName(); if (!jndiName.startsWith("java:/")) { jndiName = "java:/" + jndiName; getLogger().warn( "JBoss 7 requires resource JNDI names to start with " + "java:/, hence changing the given JNDI name to: " + jndiName, this.getClass().getName()); } Element mailSession = DocumentHelper.createElement("mail-session"); mailSession.addAttribute("jndi-name", jndiName); mailSession.addAttribute("name", resource.getId()); if (resource.getParameter("mail.smtp.from") != null) { mailSession.addAttribute("from", resource.getParameter("mail.smtp.from")); } Element smtpServer = mailSession.addElement("smtp-server"); smtpServer.addAttribute("outbound-socket-binding-ref", resource.getId()); manager.insertElementUnderXPath(mailSession, "//domain:profile/mail:subsystem"); Element socketBinding = DocumentHelper.createElement("outbound-socket-binding"); socketBinding.addAttribute("name", resource.getId()); Element remoteDestination = socketBinding.addElement("remote-destination"); remoteDestination.addAttribute("host", host); remoteDestination.addAttribute("port", port); manager.insertElementUnderXPath(socketBinding, "//domain:socket-binding-group"); manager.writeFile(); } else { throw new CargoException("Resource type " + resource.getType() + " isn't supported."); } } }
From source file:org.collectionspace.services.common.XmlSaxFragmenter.java
License:Educational Community License
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { String attsString = attsToStr(atts); append("<" + name(qName, localName) + attsString + ">"); if (inFragment) { inFragmentDepth++;/*from w w w . j av a 2s . c om*/ return; } if (currentElement == null) { currentElement = document.addElement(qName); } else { Element element = DocumentHelper.createElement(qName); currentElement.add(element); previousElement = currentElement; currentElement = element; } addAttributes(currentElement, atts); String currentPath = currentElement.getPath(); if (currentPath.equals(chopPath)) { buffer = new StringBuffer(); inFragment = true; if (includeParent) { append("<" + name(qName, localName) + attsString + ">"); } } }
From source file:org.craftercms.core.xml.mergers.impl.cues.impl.MergeParentAndChildMergeCue.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Element merge(Element parent, Element child, Map<String, String> params) throws XmlMergeException { Element merged = DocumentHelper.createElement(child.getQName()); org.craftercms.core.util.CollectionUtils.move(child.attributes(), merged.attributes()); if (parent.isTextOnly() && child.isTextOnly()) { String parentText = parent.getText(); String childText = child.getText(); if (getMergeOrder(params).equalsIgnoreCase("after")) { merged.setText(parentText + childText); } else {//from w w w .ja v a 2s . c o m merged.setText(childText + parentText); } } else { List<Element> parentElements = parent.elements(); List<Element> childElements = child.elements(); List<Element> mergedElements = merged.elements(); if (CollectionUtils.isNotEmpty(parentElements) && CollectionUtils.isNotEmpty(childElements)) { for (Iterator<Element> i = parentElements.iterator(); i.hasNext();) { Element parentElement = i.next(); boolean elementsMerged = false; for (Iterator<Element> j = childElements.iterator(); !elementsMerged && j.hasNext();) { Element childElement = j.next(); if (elementMergeMatcher.matchForMerge(parentElement, childElement)) { MergeCueContext context = mergeCueResolver.getMergeCue(parentElement, childElement); if (context != null) { i.remove(); j.remove(); Element mergedElement = context.doMerge(); mergedElements.add(mergedElement); elementsMerged = true; } else { throw new XmlMergeException("No merge cue was resolved for matching elements " + parentElement + " (parent) and " + childElement + " (child)"); } } } } } if (getMergeOrder(params).equalsIgnoreCase("after")) { org.craftercms.core.util.CollectionUtils.move(parentElements, mergedElements); org.craftercms.core.util.CollectionUtils.move(childElements, mergedElements); } else { org.craftercms.core.util.CollectionUtils.move(childElements, mergedElements); org.craftercms.core.util.CollectionUtils.move(parentElements, mergedElements); } } return merged; }
From source file:org.dentaku.gentaku.tools.cgen.visitor.PluginOutputVisitor.java
License:Apache License
/** * Standard visitor pattern entry point. * * @param mappingNode Node that we are currently visiting in the mapping document * @param parentOutput Output node for document we are building. Recursive calls gradually expand this * @param modelElement ModelElement from UML that we are currently working on * @param location/*from w w w . ja va2 s . c o m*/ * @return true if we did something worth keeping */ public boolean visit(LocalDefaultElement mappingXSD, Branch parentOutput, ModelElement modelElement, String location) throws GenerationException { boolean result = false; if (!mappingXSD.getName().equals("element")) { result = iterateElements(mappingXSD, parentOutput, modelElement, location); } else { String ref = mappingXSD.attributeValue("ref"); if (ref != null) { mappingXSD = (LocalDefaultElement) Util.selectSingleNode(xsdDoc, "/xs:schema/xs:element[@name='" + ref + "']"); } location = updateLocation(mappingXSD, location); if (location.equals("root")) { // root element is a special case because we always iterate it. But is this the only occurence not caught // in the following loop? Smells fishy. todo This is also broken because the root element cannot have attributes Element newLocalNode = DocumentHelper.createElement(mappingXSD.attributeValue("name")); if (iterateElements(mappingXSD, newLocalNode, modelElement, location)) { parentOutput.add(newLocalNode); result = true; } } else { // iterate candidate ModelElements that match these criteria // the tag prefix we are looking for in tags named "prefix.tag" String prefix = mappingXSD.attributeValue("name"); Collection c = findElementsForLocationAndPrefix(location, prefix, modelElement); for (Iterator elementIterator = c.iterator(); elementIterator.hasNext();) { ModelElementImpl element = (ModelElementImpl) elementIterator.next(); if (element instanceof Namespace || element instanceof Feature) { modelElement = element; } else { throw new AssertionError("Please report this to Brian"); } preGenerate(mappingXSD, parentOutput, modelElement); if (generate(mappingXSD, parentOutput, modelElement)) { Element newLocalNode = DocumentHelper.createElement(mappingXSD.attributeValue("name")); // @todo note that in older versions of this code, we used to keep elements that properly rendered, even if a node did not have // any attributes that rendered. This was removed organically in the process of tracking down problems, but it may be that with // that problem solved that the old behavior is the correct behavior. If it is, the special case noise when a root element is // being rendered can probably be removed as well if (iterateAttributes(mappingXSD, element, newLocalNode)) { iterateElements(mappingXSD, newLocalNode, modelElement, location); postGenerate(mappingXSD, parentOutput, modelElement, newLocalNode); parentOutput.add(newLocalNode); result = true; } } else { result = true; } } } } return result; }
From source file:org.dom4j.samples.rule.SongFilter.java
License:Open Source License
/** Creates a new instance of SongFilter */ public SongFilter() { this.songElement = DocumentHelper.createElement("song"); }
From source file:org.dom4j.samples.rule.SongFilter.java
License:Open Source License
public Document filtering(org.dom4j.Document doc) throws Exception { Element resultRoot = DocumentHelper.createElement("result"); this.resultDoc = DocumentHelper.createDocument(resultRoot); Rule songElementRule = new Rule(); songElementRule.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3")); songElementRule.setAction(new SongElementBuilder()); Rule titleTextNodeFilter = new Rule(); titleTextNodeFilter.setPattern(DocumentHelper.createPattern("/Songs/song/mp3/id3/title")); titleTextNodeFilter.setAction(new NodeTextFilter()); this.style = new Stylesheet(); this.style.addRule(songElementRule); this.style.addRule(titleTextNodeFilter); style.run(doc);// w ww. jav a2 s. c o m return this.resultDoc; }
From source file:org.ednovo.gooru.application.util.ResourceInstanceFormatter.java
License:Open Source License
private Element getQuestionResource(Question question) { StringBuilder questionXML = new StringBuilder(getQuestionSet(question)); Element resourceElm = DocumentHelper.createElement(RESOURCE); if (question.getGooruOid() != null) { resourceElm.addAttribute(ID, question.getGooruOid()); } else {//from w ww .j ava 2 s .c o m String resourceId = UUID.randomUUID().toString(); resourceElm.addAttribute(ID, resourceId); question.setGooruOid(resourceId); } resourceElm.addAttribute(TYPE, ResourceType.Type.QUIZ.getType()); Element nativeurl = resourceElm.addElement(NATIVE_URL); if (question.getUrl() != null) { nativeurl.addText(question.getUrl()); } else { nativeurl.addText(""); } Element folder = resourceElm.addElement(RESOURCE_FOLDER); if (question.getFolder() != null) { folder.addText(question.getFolder()); } else { folder.addText(""); } Element questionSet = null; try { questionSet = (Element) DocumentHelper.parseText(questionXML.toString()).getRootElement(); } catch (Exception e) { throw new MethodFailureException("Error while converting to a document"); } resourceElm.add(questionSet); return resourceElm; }
From source file:org.ednovo.gooru.application.util.ResourceInstanceFormatter.java
License:Open Source License
private Element getResourceInstance(ResourceInstance resourceInstance) { Element resourceElement = null; try {// w ww . j a v a 2 s . c om Resource resource = resourceInstance.getResource(); if (resource.getResourceType().getName().equals(ResourceType.Type.QUIZ.getType()) && !(resource instanceof Question)) { resource = getResourceService().findResourceByContentGooruId(resource.getGooruOid()); } else if (resource.getResourceType().getName().equals(ResourceType.Type.TEXTBOOK.getType()) && !(resource instanceof Textbook)) { resource = getResourceService().findTextbookByContentGooruId(resource.getGooruOid()); } if (resource.getResourceType().getName().equals(ResourceType.Type.QUIZ.getType())) { resourceElement = getQuestionResource((Question) resource); } else { resourceElement = DocumentHelper.createElement(RESOURCE); resourceElement.addAttribute(TYPE, resource.getResourceType().getName()); resourceElement.addAttribute(TYPE_DESC, resource.getResourceType().getDescription()); resourceElement.addAttribute(SHARING, resource.getSharing()); resourceElement.addAttribute(CATEGORY, resource.getCategory()); resourceElement.addAttribute(SHORTENED_URL_STATUS, resourceInstance.getShortenedUrlStatus() != null ? resourceInstance.getShortenedUrlStatus().toString() : FALSE); if (resource.getGooruOid() == null) { String resourceId = UUID.randomUUID().toString(); resourceElement.addAttribute(ID, resourceId); resource.setGooruOid(resourceId); } resourceElement.addAttribute(ID, resource.getGooruOid()); if (resourceInstance.getTitle() != null) { setElementText(resourceElement, LABEL, resourceInstance.getTitle(), true); } else { setElementText(resourceElement, LABEL, resource.getTitle(), true); } setElementText(resourceElement, NATIVE_URL, resource.getUrl(), true); setElementText(resourceElement, RESOURCE_FOLDER, resource.getFolder(), true); if (resourceInstance.getDescription() != null) { setElementText(resourceElement, DESCRIPTION, resourceInstance.getDescription(), true); } else { setElementText(resourceElement, DESCRIPTION, resource.getDescription(), true); } if (resource instanceof Textbook) { setElementText(resourceElement, DOCUMENT_ID, ((Textbook) resource).getDocumentId(), true); setElementText(resourceElement, DOCUMENT_KEY, ((Textbook) resource).getDocumentKey(), true); } } Element instructorNotes = resourceElement.addElement(INSTRUCTOR_NOTES); setElementText(instructorNotes, INSTRUCTION, resourceInstance.getNarrative(), true); setElementText(instructorNotes, START, resourceInstance.getStart(), true); setElementText(instructorNotes, STOP, resourceInstance.getStop(), true); // Element tagSet = resourceElement.addElement("tagSet"); Element resourceSource = resourceElement.addElement(RESOURCE_SOURCE); if (resourceInstance.getResource().getResourceSource() != null) { setElementText(resourceSource, RESOURCE_SOURCE_ID, StringUtils.defaultString( resourceInstance.getResource().getResourceSource().getResourceSourceId().toString()), true); setElementText(resourceSource, ATTRIBUTION, StringUtils .defaultString(resourceInstance.getResource().getResourceSource().getAttribution()), true); setElementText(resourceSource, RESOURCE_DOMAIN_NAME, StringUtils .defaultString(resourceInstance.getResource().getResourceSource().getDomainName()), true); } Element resourceInfo = resourceElement.addElement(RESOURCE_INFO); if (resourceInstance.getResource().getResourceInfo() != null) { Integer numOfPages = resourceInstance.getResource().getResourceInfo().getNumOfPages(); setElementText(resourceInfo, NUM_OF_PAGES, StringUtils.defaultString(numOfPages != null ? numOfPages + "" : ""), true); } String brokenResource = "0"; if (resourceInstance.getResource().getBrokenStatus() != null && resourceInstance.getResource().getBrokenStatus() != 0) { brokenResource = "1"; } String hasFrameBreaker = "0"; if (resourceInstance.getResource().getHasFrameBreaker() != null && resourceInstance.getResource().getHasFrameBreaker().booleanValue()) { hasFrameBreaker = "1"; } Element resourceStatus = resourceElement.addElement(RESOURCE_STATUS); setElementText(resourceStatus, STATUS_IS_BROKEN, brokenResource, true); setElementText(resourceStatus, STATUS_IS_FRAMEBREAKER, hasFrameBreaker, true); if (resourceInstance.getResourceInstanceId() != null) { resourceElement.addAttribute(RESOURCE_INSTANCE_ID, resourceInstance.getResourceInstanceId()); } setElementText(resourceElement, THUMBNAIL, resourceInstance.getResource().getThumbnail(), true); setElementText(resourceElement, ASSET_URI, resourceInstance.getResource().getAssetURI(), true); Element thumbnails = resourceElement.addElement(THUMBNAILS); String isDefaultThumbnail = FALSE; setElementText(thumbnails, DEFAULT_IMAGE, isDefaultThumbnail, true); setElementText(resourceElement, TAXONOMY_DATA_SET, TAXONOMY_DATA_SET != null ? TAXONOMY_DATA_SET.toString() : "", true); return resourceElement; } catch (Exception e) { return null; } }