List of usage examples for org.w3c.dom Node appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:org.ojbc.intermediaries.sn.FbiSubscriptionProcessor.java
public Document appendFbiSubscriptionIdToUnsubscribeDoc(Document unsubscribeDoc, String fbiSubId) throws Exception { logger.info("\n\n\n appendFbiDataToFbiUnSubscribeDoc... \n\n\n"); Element relatedFBISubscriptionElement = unsubscribeDoc.createElementNS(OjbcNamespaceContext.NS_SUB_MSG_EXT, "RelatedFBISubscription"); relatedFBISubscriptionElement.setPrefix(OjbcNamespaceContext.NS_PREFIX_SUB_MSG_EXT); Node unsubMsgNode = XmlUtils.xPathNodeSearch(unsubscribeDoc, "//unsubmsg-exch:UnsubscriptionMessage"); unsubMsgNode.appendChild(relatedFBISubscriptionElement); if (StringUtils.isNotEmpty(fbiSubId)) { Element subFbiIdElement = XmlUtils.appendElement(relatedFBISubscriptionElement, OjbcNamespaceContext.NS_SUB_MSG_EXT, "SubscriptionFBIIdentification"); Element fbiIdValElement = XmlUtils.appendElement(subFbiIdElement, OjbcNamespaceContext.NS_NC, "IdentificationID"); fbiIdValElement.setTextContent(fbiSubId); }// w ww. ja v a 2 s . c om OjbcNamespaceContext ojbNsCtxt = new OjbcNamespaceContext(); ojbNsCtxt.populateRootNamespaceDeclarations(unsubscribeDoc.getDocumentElement()); return unsubscribeDoc; }
From source file:org.ojbc.intermediaries.sn.FbiSubscriptionProcessor.java
public Document appendFbiDataToSubscriptionDoc(Document subscriptionDoc, FbiRapbackSubscription fbiRapbackSubscription) throws Exception { logger.info("appendFbiDataToSubscriptionDoc..."); Element relatedFBISubscriptionElement = subscriptionDoc.createElementNS(OjbcNamespaceContext.NS_SUB_MSG_EXT, "RelatedFBISubscription"); relatedFBISubscriptionElement.setPrefix(OjbcNamespaceContext.NS_PREFIX_SUB_MSG_EXT); Node subMsgNode = XmlUtils.xPathNodeSearch(subscriptionDoc, "//submsg-exch:SubscriptionMessage"); subMsgNode.appendChild(relatedFBISubscriptionElement); Element dateRangeElement = XmlUtils.appendElement(relatedFBISubscriptionElement, OjbcNamespaceContext.NS_NC, "DateRange"); DateTime jtStartDate = fbiRapbackSubscription.getRapbackStartDate(); if (jtStartDate != null) { Element startDateElement = XmlUtils.appendElement(dateRangeElement, OjbcNamespaceContext.NS_NC, "StartDate"); Element startDateValElement = XmlUtils.appendElement(startDateElement, OjbcNamespaceContext.NS_NC, "Date"); String sStartDate = sdf.format(jtStartDate.toDate()); startDateValElement.setTextContent(sStartDate); }/*from ww w .jav a2s. c o m*/ DateTime jtEndDate = fbiRapbackSubscription.getRapbackExpirationDate(); if (jtEndDate != null) { Element endDateElement = XmlUtils.appendElement(dateRangeElement, OjbcNamespaceContext.NS_NC, "EndDate"); Element endDateValElement = XmlUtils.appendElement(endDateElement, OjbcNamespaceContext.NS_NC, "Date"); String sEndDate = sdf.format(jtEndDate.toDate()); endDateValElement.setTextContent(sEndDate); } String fbiId = fbiRapbackSubscription.getFbiSubscriptionId(); if (StringUtils.isNotEmpty(fbiId)) { Element subFbiIdElement = XmlUtils.appendElement(relatedFBISubscriptionElement, OjbcNamespaceContext.NS_SUB_MSG_EXT, "SubscriptionFBIIdentification"); Element fbiIdValElement = XmlUtils.appendElement(subFbiIdElement, OjbcNamespaceContext.NS_NC, "IdentificationID"); fbiIdValElement.setTextContent(fbiId); } String reasonCode = fbiRapbackSubscription.getRapbackCategory(); if (StringUtils.isNotEmpty(reasonCode)) { Element reasonCodeElement = XmlUtils.appendElement(relatedFBISubscriptionElement, OjbcNamespaceContext.NS_SUB_MSG_EXT, "CriminalSubscriptionReasonCode"); reasonCodeElement.setTextContent(reasonCode); } String subTerm = fbiRapbackSubscription.getSubscriptionTerm(); if (StringUtils.isNotEmpty(subTerm)) { Element subscriptionTermElement = XmlUtils.appendElement(relatedFBISubscriptionElement, OjbcNamespaceContext.NS_SUB_MSG_EXT, "SubscriptionTerm"); Element termDurationElement = XmlUtils.appendElement(subscriptionTermElement, OjbcNamespaceContext.NS_JXDM_41, "TermDuration"); termDurationElement.setTextContent(subTerm); } OjbcNamespaceContext ojbNsCtxt = new OjbcNamespaceContext(); ojbNsCtxt.populateRootNamespaceDeclarations(subscriptionDoc.getDocumentElement()); return subscriptionDoc; }
From source file:org.ojbc.web.model.incident.search.IncidentSearchRequestDomUtils.java
public static Element createLocationElement(Document doc, IncidentSearchRequest isr, String cityTownCodelistNamespace, String cityTownCodelistElementName) { //UI only provide for 'city/town' searches so that is the only mapping provided Element locationElement = NIEMXMLUtils.createLocationElement(doc, "L001"); if (StringUtils.isNotBlank(isr.getIncidentCityTown())) { Element locationStructuredAddress = NIEMXMLUtils.createLocationStructuredAddressElement(doc, OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_EXT); Element locationCityTownCode = doc.createElementNS(cityTownCodelistNamespace, cityTownCodelistElementName); locationCityTownCode.setTextContent(isr.getIncidentCityTown()); Node structuredAddress = locationStructuredAddress.getFirstChild(); if (!structuredAddress.getLocalName().equals("StructuredAddress")) { throw new RuntimeException("LocationAddress contains unexpected child element"); }//from ww w . j a v a 2s . c om structuredAddress.appendChild(locationCityTownCode); locationElement.appendChild(locationStructuredAddress); } return locationElement; }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
private void appendHeading(String text, Heading style, String additionalText) { if (!StringHelper.containsNonWhitespace(text)) return;/*from www . j a v a2 s . com*/ Element textEl = createTextEl(text); List<Element> runsEl = new ArrayList<Element>(2); Element runEl = createRunEl(Collections.singletonList(textEl)); runsEl.add(runEl); Element styleEl = createParagraphStyle(style.styleId()); if (StringHelper.containsNonWhitespace(additionalText)) { //add an "insecable" blank between the title and the additional text Element blankRunEl = document.createElement("w:r"); blankRunEl.appendChild(createPreserveSpaceEl()); runsEl.add(blankRunEl); //add additional text Element addRunEl = document.createElement("w:r"); Node addRunPrefsEl = addRunEl.appendChild(document.createElement("w:rPr")); Element bEl = (Element) addRunPrefsEl.appendChild(document.createElement("w:b")); bEl.setAttribute("w:val", "0"); Element colorEl = (Element) addRunPrefsEl.appendChild(document.createElement("w:color")); colorEl.setAttribute("w:val", "auto"); Element szEl = (Element) addRunPrefsEl.appendChild(document.createElement("w:sz")); szEl.setAttribute("w:val", "24"); Element szCsEl = (Element) addRunPrefsEl.appendChild(document.createElement("w:szCs")); szCsEl.setAttribute("w:val", "24"); addRunEl.appendChild(createTextEl(additionalText)); runsEl.add(addRunEl); } Element paragraphEl = createParagraphEl(styleEl, runsEl); getCursor().appendChild(paragraphEl); }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
/** * Must be done at the end of the document *///from www .java 2 s .co m public void appendPageSettings() { Node lastChild = bodyElement.getLastChild(); if (lastChild != null && "w:sectPr".equals(lastChild.getLocalName())) { return;//nothing to do, already set } Node sectionPrefs = bodyElement.appendChild(document.createElement("w:sectPr")); //A4 Element pageSize = (Element) sectionPrefs.appendChild(document.createElement("w:pgSz")); pageSize.setAttribute("w:w", "11900"); pageSize.setAttribute("w:h", "16840"); Element margins = (Element) sectionPrefs.appendChild(document.createElement("w:pgMar")); margins.setAttribute("w:top", "1440"); margins.setAttribute("w:right", "1440"); margins.setAttribute("w:bottom", "1440"); margins.setAttribute("w:left", "1440"); margins.setAttribute("w:header", "708"); margins.setAttribute("w:footer", "708"); margins.setAttribute("w:gutter", "0"); if (StringHelper.containsNonWhitespace(documentHeader)) { try (InputStream headerIn = OpenXMLDocument.class.getResourceAsStream("_resources/header.xml")) { String headerTemplate = IOUtils.toString(headerIn); String header = headerTemplate.replace("[oodocumentitlte]", documentHeader); String headerId = generateId(); Element headerRefEl = (Element) sectionPrefs .appendChild(document.createElement("w:headerReference")); headerRefEl.setAttribute("w:type", "default"); headerRefEl.setAttribute("r:id", headerId); HeaderReference headerRef = new HeaderReference(headerId, header); headers.add(headerRef); } catch (DOMException e) { log.error("", e); } catch (IOException e) { log.error("", e); } } }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
public void appendFillInBlanck(int length, boolean newParagraph) { Element paragraphEl = getParagraphToAppendTo(newParagraph); Node runEl = paragraphEl.appendChild(createRunEl(null)); runEl.appendChild(createRunPrefsEl(Style.underline)); int tabLength = length / 5; for (int i = tabLength; i-- > 0;) { runEl.appendChild(document.createElement("w:tab")); }// www .j a va 2 s. c o m getCursor().appendChild(paragraphEl); }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
public void appendFillInBlanckWholeLine(int rows) { for (int i = rows + 1; i-- > 0;) { Element paragraphEl = createParagraphEl(); Node pargraphPrefs = paragraphEl.appendChild(document.createElement("w:pPr")); Node pargraphBottomPrefs = pargraphPrefs.appendChild(document.createElement("w:pBdr")); Element bottomEl = (Element) pargraphBottomPrefs.appendChild(document.createElement("w:between")); bottomEl.setAttribute("w:val", "single"); bottomEl.setAttribute("w:sz", "4"); bottomEl.setAttribute("w:space", "1"); bottomEl.setAttribute("w:color", "auto"); getCursor().appendChild(paragraphEl); }/*from www . j a va2 s .c om*/ }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
public Node createRunPrefsEl(Node runPrefsEl, Style... styles) { if (styles != null && styles.length > 0) { for (Style style : styles) { if (style != null) { switch (style) { case underline: { Element underlinePrefs = (Element) runPrefsEl.appendChild(document.createElement("w:u")); underlinePrefs.setAttribute("w:val", "single"); break; }//from ww w. j av a 2 s . c o m case italic: runPrefsEl.appendChild(document.createElement("w:i")); break; case bold: runPrefsEl.appendChild(document.createElement("w:b")); break; case strike: runPrefsEl.appendChild(document.createElement("w:strike")); break; } } } } return runPrefsEl; }
From source file:org.olat.core.util.openxml.OpenXMLDocument.java
public Node createRunReversePrefsEl(Node runPrefsEl, Style... styles) { if (styles != null && styles.length > 0) { for (Style style : styles) { if (style != null) { switch (style) { case underline: Element underlinePrefs = (Element) runPrefsEl.appendChild(document.createElement("w:u")); underlinePrefs.setAttribute("w:val", "none"); break; case italic: Element italicPrefs = (Element) runPrefsEl.appendChild(document.createElement("w:i")); italicPrefs.setAttribute("w:val", "0"); break; case bold: Element boldPrefs = (Element) runPrefsEl.appendChild(document.createElement("w:b")); boldPrefs.setAttribute("w:val", "0"); break; case strike: Element strikePrefs = (Element) runPrefsEl.appendChild(document.createElement("w:strike")); strikePrefs.setAttribute("w:val", "0"); break; }//from w ww. j a va 2 s .co m } } } return runPrefsEl; }
From source file:org.pentaho.osgi.i18n.webservice.ResourceBundleMessageBodyWriter.java
@Override public void writeTo(ResourceBundle resourceBundle, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) { JSONObject resourceBundleJsonObject = new JSONObject(); for (String key : Collections.list(resourceBundle.getKeys())) { resourceBundleJsonObject.put(key, resourceBundle.getString(key)); }//from www . j a v a 2s . c om OutputStreamWriter outputStreamWriter = null; try { outputStreamWriter = new OutputStreamWriter(entityStream); resourceBundleJsonObject.writeJSONString(outputStreamWriter); } finally { if (outputStreamWriter != null) { outputStreamWriter.flush(); } } } else if (MediaType.APPLICATION_XML_TYPE.equals(mediaType)) { try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Node propertiesNode = document.createElement("properties"); document.appendChild(propertiesNode); for (String key : Collections.list(resourceBundle.getKeys())) { Node propertyNode = document.createElement("property"); propertiesNode.appendChild(propertyNode); Node keyNode = document.createElement("key"); keyNode.setTextContent(key); propertyNode.appendChild(keyNode); Node valueNode = document.createElement("value"); valueNode.setTextContent(resourceBundle.getString(key)); propertyNode.appendChild(valueNode); } Result output = new StreamResult(entityStream); Source input = new DOMSource(document); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(input, output); } catch (TransformerException e) { throw new IOException(e); } } catch (ParserConfigurationException e) { throw new WebApplicationException(e); } } }