List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java
/** * Creates the section component of a chapter.xml for a specific Level. * * @param buildData Information and data structures for the build. * @param container The level object to get content from. * @param doc The document object that this container is to be added to. * @param parentNode The parent XML node of this section. * @param parentFileLocation The parent file location, so any files can be saved in a subdirectory of the parents location. * @param flattenStructure Whether or not the build should be flattened. * @throws BuildProcessingException Thrown if an unexpected error occurs during building. *//* www.j av a2 s. com*/ protected void createContainerXML(final BuildData buildData, final Level container, final Document doc, final Element parentNode, final String parentFileLocation, final Boolean flattenStructure) throws BuildProcessingException { final List<org.jboss.pressgang.ccms.contentspec.Node> levelData = container.getChildNodes(); // Get the name of the element based on the type final String elementName = container.getLevelType() == LevelType.PROCESS ? "chapter" : container.getLevelType().getTitle().toLowerCase(Locale.ENGLISH); final Element intro = doc.createElement(elementName + "intro"); // Storage container to hold the levels so they can be added in proper order with the intro final LinkedList<Node> childNodes = new LinkedList<Node>(); // Add the section and topics for this level to the chapter.xml for (final org.jboss.pressgang.ccms.contentspec.Node node : levelData) { // Check if the app should be shutdown if (isShuttingDown.get()) { return; } if (node instanceof Level && node.getParent() != null && (((Level) node).getParent().getLevelType() == LevelType.BASE || ((Level) node).getParent().getLevelType() == LevelType.PART) && ((Level) node).getLevelType() != LevelType.INITIAL_CONTENT) { final Level childContainer = (Level) node; // Create a new file for the Chapter/Appendix final Element xiInclude = createSubRootContainerXML(buildData, doc, childContainer, parentFileLocation, flattenStructure); if (xiInclude != null) { childNodes.add(xiInclude); } } else if (node instanceof Level && ((Level) node).getLevelType() == LevelType.INITIAL_CONTENT) { if (container.getLevelType() == LevelType.PART) { addLevelsInitialContent(buildData, (InitialContent) node, doc, intro, false); } else { addLevelsInitialContent(buildData, (InitialContent) node, doc, parentNode, false); } } else if (node instanceof Level) { final Level childLevel = (Level) node; // Create the section and its title final Element sectionNode = doc.createElement("section"); setUpRootElement(buildData, childLevel, doc, sectionNode); // Ignore sections that have no spec topics if (!childLevel.hasSpecTopics() && !childLevel.hasCommonContents()) { if (buildData.getBuildOptions().isAllowEmptySections()) { Element warning = doc.createElement("warning"); warning.setTextContent("No Content"); sectionNode.appendChild(warning); } else { continue; } } else { // Add this sections child sections/topics createContainerXML(buildData, childLevel, doc, sectionNode, parentFileLocation, flattenStructure); } childNodes.add(sectionNode); } else if (node instanceof CommonContent) { final CommonContent commonContent = (CommonContent) node; final Node xiInclude = XMLUtilities.createXIInclude(doc, "Common_Content/" + commonContent.getFixedTitle()); if (commonContent.getParent() != null && commonContent.getParent().getLevelType() == LevelType.PART) { intro.appendChild(xiInclude); } else { childNodes.add(xiInclude); } } else if (node instanceof SpecTopic) { final SpecTopic specTopic = (SpecTopic) node; final Node topicNode = createTopicDOMNode(specTopic, doc, flattenStructure, parentFileLocation); // Add the node to the chapter if (topicNode != null) { if (specTopic.getParent() != null && ((Level) specTopic.getParent()).getLevelType() == LevelType.PART) { intro.appendChild(topicNode); } else { childNodes.add(topicNode); } } } } // Add the child nodes and intro to the parent if (intro.hasChildNodes()) { parentNode.appendChild(intro); } for (final Node node : childNodes) { parentNode.appendChild(node); } }
From source file:org.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java
/** * Builds the Author_Group.xml using the assigned writers for topics inside of the content specification. * * @param buildData Information and data structures for the build. * @param specTopic The topic to build the Author Group in place of. * @throws BuildProcessingException/* w w w .j a v a 2s . c o m*/ */ private void buildAuthorGroup(final BuildData buildData, final SpecTopic specTopic) throws BuildProcessingException { log.info("\tBuilding " + AUTHOR_GROUP_FILE_NAME); // Setup Author_Group.xml Document authorDoc = null; try { authorDoc = XMLUtilities.convertStringToDocument("<authorgroup></authorgroup>"); } catch (Exception ex) { // Exit since we shouldn't fail at converting the basic author group log.debug("", ex); throw new BuildProcessingException( String.format(getMessages().getString("FAILED_CONVERTING_TEMPLATE"), AUTHOR_GROUP_FILE_NAME)); } final LinkedHashMap<Integer, AuthorInformation> authorIDtoAuthor = new LinkedHashMap<Integer, AuthorInformation>(); // Check if the app should be shutdown if (isShuttingDown.get()) { return; } // Set the id if (specTopic != null) { DocBookBuildUtilities.processTopicID(buildData, specTopic, authorDoc); } else { DocBookBuildUtilities.setDOMElementId(buildData.getDocBookVersion(), authorDoc.getDocumentElement(), "Author_Group"); } // Get the mapping of authors using the topics inside the content spec for (final Integer topicId : buildData.getBuildDatabase().getTopicIds()) { final BaseTopicWrapper<?> topic = buildData.getBuildDatabase().getTopicNodesForTopicID(topicId).get(0) .getTopic(); final List<TagWrapper> authorTags = topic.getTagsInCategories( CollectionUtilities.toArrayList(buildData.getServerEntities().getWriterCategoryId())); if (authorTags.size() > 0) { for (final TagWrapper author : authorTags) { if (!authorIDtoAuthor.containsKey(author.getId())) { final AuthorInformation authorInfo = EntityUtilities.getAuthorInformation(providerFactory, buildData.getServerEntities(), author.getId(), author.getRevision()); if (authorInfo != null) { authorIDtoAuthor.put(author.getId(), authorInfo); } } } } } // Sort and make sure duplicate authors don't exist final Set<AuthorInformation> authors = new TreeSet<AuthorInformation>(new AuthorInformationComparator()); for (final Entry<Integer, AuthorInformation> authorEntry : authorIDtoAuthor.entrySet()) { final AuthorInformation authorInfo = authorEntry.getValue(); if (authorInfo != null) { authors.add(authorInfo); } } // Check if the app should be shutdown if (isShuttingDown.get()) { return; } boolean insertedAuthor = false; // If one or more authors were found then remove the default and attempt to add them if (!authors.isEmpty()) { // For each author attempt to find the author information records and populate Author_Group.xml. for (final AuthorInformation authorInfo : authors) { // Check if the app should be shutdown if (isShuttingDown.get()) { shutdown.set(true); return; } final Element authorEle = authorDoc.createElement("author"); final Element firstNameEle = authorDoc.createElement("firstname"); firstNameEle.setTextContent(authorInfo.getFirstName()); final Element lastNameEle = authorDoc.createElement("surname"); lastNameEle.setTextContent(authorInfo.getLastName()); // Docbook 5 needs <firstname>/<surname> wrapped in <personname> if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) { final Element personnameEle = authorDoc.createElement("personname"); authorEle.appendChild(personnameEle); personnameEle.appendChild(firstNameEle); personnameEle.appendChild(lastNameEle); } else { authorEle.appendChild(firstNameEle); authorEle.appendChild(lastNameEle); } // Add the affiliation information if (authorInfo.getOrganization() != null) { final Element affiliationEle = authorDoc.createElement("affiliation"); final Element orgEle = authorDoc.createElement("orgname"); orgEle.setTextContent(authorInfo.getOrganization()); affiliationEle.appendChild(orgEle); if (authorInfo.getOrgDivision() != null) { final Element orgDivisionEle = authorDoc.createElement("orgdiv"); orgDivisionEle.setTextContent(authorInfo.getOrgDivision()); affiliationEle.appendChild(orgDivisionEle); } authorEle.appendChild(affiliationEle); } // Add an email if one exists if (authorInfo.getEmail() != null) { Element emailEle = authorDoc.createElement("email"); emailEle.setTextContent(authorInfo.getEmail()); authorEle.appendChild(emailEle); } authorDoc.getDocumentElement().appendChild(authorEle); insertedAuthor = true; } } // If no authors were inserted then use a default value if (!insertedAuthor) { // Use the author "PressGang CCMS Build System" final Element authorEle = authorDoc.createElement("author"); authorDoc.getDocumentElement().appendChild(authorEle); // Use the author "PressGang Alpha Build System" final Element firstNameEle = authorDoc.createElement("firstname"); firstNameEle.setTextContent(""); final Element lastNameEle = authorDoc.createElement("surname"); lastNameEle.setTextContent("PressGang CCMS Build System"); // Docbook 5 needs <firstname>/<surname> wrapped in <personname> if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) { final Element personnameEle = authorDoc.createElement("personname"); authorEle.appendChild(personnameEle); personnameEle.appendChild(firstNameEle); personnameEle.appendChild(lastNameEle); } else { authorEle.appendChild(firstNameEle); authorEle.appendChild(lastNameEle); } // Add the affiliation final Element affiliationEle = authorDoc.createElement("affiliation"); final Element orgEle = authorDoc.createElement("orgname"); orgEle.setTextContent("Red Hat"); affiliationEle.appendChild(orgEle); final Element orgDivisionEle = authorDoc.createElement("orgdiv"); orgDivisionEle.setTextContent("Engineering Content Services"); affiliationEle.appendChild(orgDivisionEle); authorEle.appendChild(affiliationEle); } // Add the Author_Group.xml to the book final String authorGroupXml = DocBookBuildUtilities.convertDocumentToDocBookFormattedString( buildData.getDocBookVersion(), authorDoc, "authorgroup", buildData.getEntityFileName(), getXMLFormatProperties()); addToZip(buildData.getBookLocaleFolder() + AUTHOR_GROUP_FILE_NAME, authorGroupXml, buildData); }
From source file:org.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java
/** * Fills in the information required inside of a revision tag, for the Revision_History.xml file. * * @param buildData Information and data structures for the build. * @param xmlDoc An XML DOM document that contains key regex expressions. * @param authorInfo An AuthorInformation entity object containing the details for who requested the build. * @return Returns an XML element that represents a {@code <revision>} element initialised with the authors information. * @throws BuildProcessingException Thrown if an unexpected error occurs during building. *//*from w ww . ja v a 2 s . c o m*/ protected Element generateRevision(final BuildData buildData, final Document xmlDoc, final AuthorInformation authorInfo) throws BuildProcessingException { if (authorInfo == null) { return null; } // Build up the revision final Element revision = xmlDoc.createElement("revision"); final Element revnumberEle = xmlDoc.createElement("revnumber"); revision.appendChild(revnumberEle); final Element revDateEle = xmlDoc.createElement("date"); final DateFormat dateFormatter = new SimpleDateFormat(BuilderConstants.REV_DATE_STRING_FORMAT, Locale.ENGLISH); revDateEle.setTextContent(dateFormatter.format(buildData.getBuildDate())); revision.appendChild(revDateEle); /* * Determine the revnumber to use. If we have an override specified then use that directly. If not then build up the * revision number using the Book Edition and Publication Number. The format to build it in is: <EDITION>-<PUBSNUMBER>. * If Edition only specifies a x or x.y version (eg 5 or 5.1) then postfix the version so it matches the x.y.z format * (eg 5.0.0). */ final String overrideRevnumber = buildData.getBuildOptions().getOverrides() .get(CSConstants.REVNUMBER_OVERRIDE); final String revnumber; if (overrideRevnumber == null) { revnumber = DocBookBuildUtilities.generateRevisionNumber(buildData.getContentSpec()); } else { revnumber = overrideRevnumber; } // Set the revision number in Revision_History.xml revnumberEle.setTextContent(revnumber); // Create the Author node final Element author = xmlDoc.createElement("author"); revision.appendChild(author); final Element firstName = xmlDoc.createElement("firstname"); firstName.setTextContent(authorInfo.getFirstName()); final Element lastName = xmlDoc.createElement("surname"); lastName.setTextContent(authorInfo.getLastName()); // Docbook 5 needs <firstname>/<surname> wrapped in <personname> if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) { final Element personname = xmlDoc.createElement("personname"); author.appendChild(personname); personname.appendChild(firstName); personname.appendChild(lastName); } else { author.appendChild(firstName); author.appendChild(lastName); } final Element email = xmlDoc.createElement("email"); email.setTextContent( authorInfo.getEmail() == null ? BuilderConstants.DEFAULT_EMAIL : authorInfo.getEmail()); author.appendChild(email); // Create the Revision Messages final Element revDescription = xmlDoc.createElement("revdescription"); revision.appendChild(revDescription); final Element simplelist = xmlDoc.createElement("simplelist"); revDescription.appendChild(simplelist); // Add the custom revision messages if one or more exists. if (buildData.getBuildOptions().getRevisionMessages() != null && !buildData.getBuildOptions().getRevisionMessages().isEmpty()) { for (final String revMessage : buildData.getBuildOptions().getRevisionMessages()) { final Element revMemberEle = xmlDoc.createElement("member"); revMemberEle.setTextContent(revMessage); simplelist.appendChild(revMemberEle); } } // Add the revision information final Element listMemberEle = xmlDoc.createElement("member"); final ContentSpec contentSpec = buildData.getContentSpec(); if (contentSpec.getId() != null && contentSpec.getId() > 0) { if (contentSpec.getRevision() == null) { listMemberEle.setTextContent(String.format(BuilderConstants.BUILT_MSG, contentSpec.getId(), contentSpecProvider.getContentSpec(contentSpec.getId()).getRevision()) + (authorInfo.getAuthorId() > 0 ? (" by " + buildData.getRequester()) : "")); } else { listMemberEle.setTextContent( String.format(BuilderConstants.BUILT_MSG, contentSpec.getId(), contentSpec.getRevision()) + (authorInfo.getAuthorId() > 0 ? (" by " + buildData.getRequester()) : "")); } } else { listMemberEle.setTextContent(BuilderConstants.BUILT_FILE_MSG + (authorInfo.getAuthorId() > 0 ? (" by " + buildData.getRequester()) : "")); } simplelist.appendChild(listMemberEle); return revision; }
From source file:org.jboss.pressgang.ccms.contentspec.builder.DocBookBuilder.java
/** * Process a topic and add the section info information. This information consists of the keywordset information. The * keywords are populated using the tags assigned to the topic. * * @param buildData Information and data structures for the build. * @param topic The Topic to create the sectioninfo for. * @param doc The XML Document DOM object for the topics XML. *//* w w w . j a v a 2 s . c o m*/ protected void processTopicSectionInfo(final BuildData buildData, final BaseTopicWrapper<?> topic, final Document doc) { if (doc == null || topic == null) return; final String infoName; if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) { infoName = "info"; } else { infoName = DocBookUtilities.TOPIC_ROOT_SECTIONINFO_NODE_NAME; } final CollectionWrapper<TagWrapper> tags = topic.getTags(); final List<Integer> seoCategoryIds = buildData.getServerSettings().getSEOCategoryIds(); if (seoCategoryIds != null && !seoCategoryIds.isEmpty() && tags != null && tags.getItems() != null && tags.getItems().size() > 0) { // Find the sectioninfo node in the document, or create one if it doesn't exist final Element sectionInfo; final List<Node> sectionInfoNodes = XMLUtilities.getDirectChildNodes(doc.getDocumentElement(), infoName); if (sectionInfoNodes.size() == 1) { sectionInfo = (Element) sectionInfoNodes.get(0); } else { sectionInfo = doc.createElement(infoName); } // Build up the keywordset final Element keywordSet = doc.createElement("keywordset"); final List<TagWrapper> tagItems = tags.getItems(); for (final TagWrapper tag : tagItems) { if (tag.getName() == null || tag.getName().isEmpty()) continue; if (tag.containedInCategories(seoCategoryIds)) { final Element keyword = doc.createElement("keyword"); keyword.setTextContent(tag.getName()); keywordSet.appendChild(keyword); } } // Only update the section info if we've added data if (keywordSet.hasChildNodes()) { sectionInfo.appendChild(keywordSet); DocBookUtilities.setInfo(buildData.getDocBookVersion(), sectionInfo, doc.getDocumentElement()); } } }
From source file:org.jboss.qa.phaser.util.XmlUtils.java
private static Element createTestCaseElement(PhaseDefinition phaseDefinition, Throwable ex) { final Element elem = doc.createElement("testcase"); elem.setAttribute("name", phaseDefinition.getMethod().getName()); elem.setAttribute("classname", phaseDefinition.getJob().getClass().getCanonicalName()); // TODO(jkasztur): implement time elem.setAttribute("time", "0"); if (ex != null) { final Element failElem = doc.createElement("failure"); failElem.setAttribute("type", ex.getCause().getClass().getName()); failElem.setTextContent(ExceptionUtils.getStackTrace(ex.getCause())); elem.appendChild(failElem);// ww w . java 2s . c o m } return elem; }
From source file:org.jenkinsmvn.jenkins.api.model.ConfigDocument.java
public void setElementTextContent(String expression, String value, boolean ignoreNotFound) throws TransformerException { Element el = getElement(expression); if (ignoreNotFound && el == null) { return;// w w w. ja va 2 s .c o m } Validate.notNull(el, String.format("Element with expression '%s' not found.", expression)); modified = true; el.setTextContent(value); }
From source file:org.jenkinsmvn.jenkins.api.model.ConfigDocument.java
public void setSVNPath(String path) throws TransformerException { Element el = getSVNPathElement(); Validate.notNull(el, "SVN path not found"); modified = true;/*from w w w. j a v a 2 s .co m*/ el.setTextContent(path); }
From source file:org.kuali.kra.irb.actions.notification.ProtocolActionsNotificationServiceImpl.java
/** * // w w w. j a va 2 s. c o m * @see org.kuali.kra.irb.actions.notification.ProtocolActionsNotificationService#sendActionsNotification(org.kuali.kra.irb.Protocol, * org.kuali.kra.irb.actions.notification.NotificationEventBase) */ public void sendActionsNotification(Protocol protocol, NotificationEventBase notificationEvent) throws Exception { String actionNotificationTemplate = notificationTemplates.get(0); InputStream inputStream = this.getClass().getResourceAsStream(actionNotificationTemplate); Document notificationRequestDocument; try { // transForm(); notificationRequestDocument = Util.parse(new InputSource(inputStream), false, false, null); Element recipients = (Element) notificationRequestDocument.getElementsByTagName("recipients").item(0); notificationEvent.getRecipients(recipients); Element sender = (Element) notificationRequestDocument.getElementsByTagName("sender").item(0); sender.setTextContent(GlobalVariables.getUserSession().getPrincipalName()); Element message = (Element) notificationRequestDocument.getElementsByTagName("message").item(0); // message.setTextContent(getTransFormData(protocol, notificationEvent.getTemplatePath())); String messageBody = getTransFormData(protocol, notificationEvent.getTemplate()); if (ProtocolActionType.NOTIFY_IRB.equals(notificationEvent.getActionTypeCode())) { // this url is needed for embedded mode String applicationUrl = kualiConfigurationService .getPropertyString(KNSConstants.APPLICATION_URL_KEY); messageBody = messageBody.replace("submissionId=", "submissionId=" + protocol.getProtocolSubmission().getSubmissionId()); messageBody = messageBody.replace("../", applicationUrl + "/"); } if (ReviewCompleteEvent.REVIEW_COMPLETE.equals(notificationEvent.getActionTypeCode())) { // this url is needed for embedded mode messageBody = messageBody.replace("reviewerNameHolder", GlobalVariables.getUserSession().getPerson().getName()); } messageBody = messageBody.replace("$amp;", "&"); message.setTextContent(messageBody); Element title = (Element) notificationRequestDocument.getElementsByTagName("title").item(0); title.setTextContent(notificationEvent.getTitle()); Element sendDateTime = (Element) notificationRequestDocument.getElementsByTagName("sendDateTime") .item(0); sendDateTime.setTextContent(Util.toXSDDateTimeString(Calendar.getInstance().getTime())); } finally { if (inputStream != null) { inputStream.close(); } } String XML = Util.writeNode(notificationRequestDocument, true); // Waiting for rice KEN bootstrap to be corrected notificationService.sendNotification(XML); }
From source file:org.kuali.rice.edl.impl.components.NetworkIdWorkflowEDLConfigComponent.java
@Override public Element getReplacementConfigElement(Element element) { Element replacementEl = (Element) element.cloneNode(true); Element type = (Element) ((NodeList) replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0); type.setTextContent("text"); //find the validation element if required is true set a boolean and determin if blanks //are allowed based on that Element validation = (Element) ((NodeList) replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)) .item(0);/*from w ww . jav a2s . co m*/ if (validation != null && validation.getAttribute("required").equals("true")) { required = true; } return replacementEl; }
From source file:org.linguafranca.pwdb.kdbx.dom.DomHelper.java
@NotNull static String ensureElementContent(String elementPath, Element parentElement, @NotNull String value) { Element result = getElement(elementPath, parentElement, false); if (result == null) { result = createHierarchically(elementPath, parentElement); result.setTextContent(value); }/*from ww w. j a v a 2s . com*/ return result.getTextContent(); }