List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:ImageEncode.java
/******************************************************************************************************************** * $Id: Base64.java,v 1.4 2002/12/24 15:17:17 russgold Exp $ * //from ww w .j a v a 2 s.c om * Copyright (c) 2000-2002 by Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ public void encode(String filePath, Element node) throws IOException { // ByteArrayOutputStream baos = null; try { final File imageFile = new File(filePath); final byte[] array = getBytesFromFile(imageFile); final String encodedImage = Base64.encodeBase64String(array); node.setTextContent(encodedImage); // store it inside node } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:imageencode.ImageEncode.java
/******************************************************************************************************************** * $Id: Base64.java,v 1.4 2002/12/24 15:17:17 russgold Exp $ * //from w ww . j a va 2 s .co m * Copyright (c) 2000-2002 by Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ public void encode(final String filePath, final Element node) throws IOException { // ByteArrayOutputStream baos = null; try { final File imageFile = new File(filePath); final byte[] array = getBytesFromFile(imageFile); final String encodedImage = Base64.encodeBase64String(array); node.setTextContent(encodedImage); // store it inside node } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.AbstractXmlSignatureService.java
@Override public byte[] postSign(final byte[] signedXML, final List<X509Certificate> signingCertificateChain, final String signatureId, final byte[] signatureValue) throws ParserConfigurationException, SAXException, IOException, TransformerException { // Load the signature DOM document. final Document document = loadDocument(new ByteArrayInputStream(signedXML)); // Locate the correct ds:Signature node. final Element nsElement = document.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:ds", Constants.SignatureSpecNS); //$NON-NLS-1$ final Element signatureElement = (Element) XPathAPI.selectSingleNode(document, "//ds:Signature[@Id='" + signatureId + "']", nsElement); //$NON-NLS-1$ //$NON-NLS-2$ if (null == signatureElement) { throw new IllegalArgumentException("ds:Signature not found for @Id: " + signatureId); //$NON-NLS-1$ }//from w w w. java 2 s. c o m // Insert signature value into the ds:SignatureValue element final NodeList signatureValueNodeList = signatureElement .getElementsByTagNameNS(javax.xml.crypto.dsig.XMLSignature.XMLNS, "SignatureValue"); //$NON-NLS-1$ final Element signatureValueElement = (Element) signatureValueNodeList.item(0); signatureValueElement.setTextContent(Base64.encode(signatureValue)); // TODO: Cambiar a OOXMLSignedDocumentOutputStream final ByteArrayOutputStream signedDocumentOutputStream = new ByteArrayOutputStream(); writeDocument(document, signedDocumentOutputStream); return signedDocumentOutputStream.toByteArray(); }
From source file:org.openmrs.module.xforms.aop.XformsConceptAdvisor.java
private boolean refreshConceptName(Concept concept, String newName, String oldName, Element parentElement) { NodeList elements = parentElement.getElementsByTagName(XformBuilder.PREFIX_XFORMS + ":" + "label"); if (elements.getLength() > 0) { Element labelElement = (Element) elements.item(0); //We deal with only the first label node. //Assuming label element for the select1 node comes first. if (oldName.equals(labelElement.getTextContent())) { labelElement.setTextContent(newName); setItemValueText(parentElement, StringEscapeUtils.escapeXml(FormUtil.conceptToString(concept, Context.getLocale()))); return true; }//from w ww.j a v a2 s.c o m } return false; }
From source file:edu.duke.cabig.c3pr.web.security.SecureWebServiceHandler.java
/** * @param msg/* w w w . j a v a 2s . co m*/ * @param reason */ private void generateSecurityFault(Throwable ex) { Fault fault = new Fault(ex); fault.setMessage(ex.getMessage()); Element detail = fault.getOrCreateDetail(); final Element detailEntry = detail.getOwnerDocument().createElementNS(NS_COMMON, SecurityExceptionFault.class.getSimpleName()); detail.appendChild(detailEntry); final Element detailMsg = detail.getOwnerDocument().createElementNS(NS_COMMON, "message"); detailMsg.setTextContent(ex.getMessage()); detailEntry.appendChild(detailMsg); throw fault; }
From source file:be.fedict.eid.applet.service.signer.odf.OpenOfficeSignatureFacet.java
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("pre sign"); Element dateElement = document.createElementNS("", "dc:date"); dateElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:dc", "http://purl.org/dc/elements/1.1/"); DateTime dateTime = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String now = fmt.print(dateTime); now = now.substring(0, now.indexOf("Z")); LOG.debug("now: " + now); dateElement.setTextContent(now); String signaturePropertyId = "sign-prop-" + UUID.randomUUID().toString(); List<XMLStructure> signaturePropertyContent = new LinkedList<XMLStructure>(); signaturePropertyContent.add(new DOMStructure(dateElement)); SignatureProperty signatureProperty = signatureFactory.newSignatureProperty(signaturePropertyContent, "#" + signatureId, signaturePropertyId); List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); List<SignatureProperty> signaturePropertiesContent = new LinkedList<SignatureProperty>(); signaturePropertiesContent.add(signatureProperty); SignatureProperties signatureProperties = signatureFactory .newSignatureProperties(signaturePropertiesContent, null); objectContent.add(signatureProperties); objects.add(signatureFactory.newXMLObject(objectContent, null, null, null)); DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); Reference reference = signatureFactory.newReference("#" + signaturePropertyId, digestMethod); references.add(reference);/*from w w w . j ava2 s . c o m*/ }
From source file:fr.aliasource.webmail.proxy.impl.ResponderImpl.java
/** * @param m/* www . j a v a 2 s . c om*/ * @param me */ private void messageDetail(MailMessage m, Element me) { me.setAttribute("date", "" + (m.getDate() != null ? m.getDate().getTime() : 0)); me.setAttribute("read", "" + m.isRead()); me.setAttribute("starred", "" + m.isStarred()); me.setAttribute("answered", "" + m.isAnswered()); me.setAttribute("hp", "" + m.isHighPriority()); me.setAttribute("uid", "" + m.getUid()); String sub = m.getSubject(); if (sub == null) { sub = "[Empty Subject]"; } DOMUtils.createElementAndText(me, "subject", sub); Address sender = m.getSender(); Element from = DOMUtils.createElement(me, "from"); if (sender != null) { String ma = sender.getMail().replace("<", "").replace(">", ""); from.setAttribute("addr", ma); from.setAttribute("displayName", "" + sender.getDisplayName()); } else { from.setAttribute("addr", "from@is.not.set"); from.setAttribute("displayName", "From not set"); } addRecipients(DOMUtils.createElement(me, "to"), m.getTo()); addRecipients(DOMUtils.createElement(me, "cc"), m.getCc()); addRecipients(DOMUtils.createElement(me, "bcc"), m.getBcc()); Element attachements = DOMUtils.createElement(me, "attachements"); for (String attach : m.getAttachements().keySet()) { Element ae = DOMUtils.createElement(attachements, "a"); ae.setAttribute("id", attach); } Element invitation = DOMUtils.createElement(me, "invitation"); if (m.getInvitation() != null) { invitation.setTextContent("true"); } else { invitation.setTextContent("false"); } if (!m.getDispositionNotificationTo().isEmpty()) { Element dispositionNotification = DOMUtils.createElement(me, "disposition-notification"); addRecipients(dispositionNotification, m.getDispositionNotificationTo()); } if (m.getBody() != null) { formatBody(m, me); } }
From source file:com.bluexml.xforms.controller.mapping.MappingToolSearch.java
/** * Creates and initializes the DOM section for a field. * /*from w ww . ja va 2 s . c o m*/ * @param doc * @param fieldType * @return */ private Element getSearchFieldNode(Document doc, SearchFieldType fieldType) { String fieldName = fieldType.getName(); Element fieldElt = doc.createElement(fieldName); Element opElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_OPCODE.getText()); fieldElt.appendChild(opElt); opElt.setTextContent(fieldType.getPick()); // set the default operator String dataType = fieldType.getType(); boolean isTyped = (StringUtils.trimToNull(dataType) != null); if (isTyped && dataType.equalsIgnoreCase("datetime")) { dataType = "Date"; } if (hasSingleInput(fieldType) == true) { Element valueElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE.getText()); if (isTyped) { valueElt.setTextContent(createXFormsInitialValue(dataType, null, null, null)); } fieldElt.appendChild(valueElt); } else { // when more than two inputs become supported, test for the number of inputs Element valueLoElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE_LO.getText()); if (isTyped) { valueLoElt.setTextContent(createXFormsInitialValue(dataType, null, null, null)); } fieldElt.appendChild(valueLoElt); Element valueHiElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE_HI.getText()); if (isTyped) { valueHiElt.setTextContent(createXFormsInitialValue(dataType, null, null, null)); } fieldElt.appendChild(valueHiElt); } return fieldElt; }
From source file:de.elatePortal.autotool.SubTasklet_AutotoolImpl.java
private void setText(Element memento, String nodeName, String text) { Element element = getElement(memento, nodeName); if (element == null) { element = memento.getOwnerDocument().createElement(nodeName); memento.appendChild(element);/*from w ww.j a v a2s .c om*/ } element.setTextContent(text);//setTextContent() laesst sich mit maven nicht kompilieren??? dom3 nicht im classpath? }