Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:com.git.original.common.config.XMLFileConfigDocument.java

/**
 * ??XML/*w  w w .j  a  v a2s. com*/
 * 
 * @param cn
 *            ?
 * @return XML
 */
@SuppressWarnings("unchecked")
static Element convertConfigNode(Document doc, ConfigNode cn) {
    Element elem = doc.createElement(cn.getName());

    Map<String, String> attrMap = cn.attributes();
    if (attrMap != null) {
        for (Entry<String, String> entry : attrMap.entrySet()) {
            elem.setAttribute(entry.getKey(), entry.getValue());
        }
    }

    if (cn.hasChildren()) {
        for (Object child : cn.getAllChildren()) {
            if (child instanceof List) {
                List<ConfigNode> cnList = (List<ConfigNode>) child;
                for (ConfigNode node : cnList) {
                    elem.appendChild(convertConfigNode(doc, node));
                }
            } else {
                elem.appendChild(convertConfigNode(doc, (ConfigNode) child));
            }
        }

    } else if (cn.value != null) {
        elem.setTextContent(cn.value.toString());
    }

    return elem;
}

From source file:it.unibas.spicy.persistence.xml.operators.ExportXMLInstances.java

public void visitLeafNode(LeafNode node) {
    if (node == null || node.getValue() == null) {
        return;// www  .  ja va  2 s.  c  o m
    }
    if (logger.isDebugEnabled()) {
        logger.debug(" -- leaf node: " + node.getValue());
    }
    Element peekElement = stackOfElements.peek();
    peekElement.setTextContent(node.getValue().toString());
}

From source file:com.amalto.core.history.accessor.UnaryFieldAccessor.java

private void internalSet(String value, Element element) {
    element.setTextContent(value);
}

From source file:be.fedict.eid.applet.service.util.KmlLightDocument.java

/**
 * Create a <timespan> element//ww w.  j  ava  2 s .c  o m
 * 
 * @param begin
 * @return
 */
public Element createTimespan(Date begin, Date end) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    Element elTimespan = docKml.createElement("TimeSpan");
    if (null != begin) {
        Element elBegin = docKml.createElement("begin");
        elBegin.setTextContent(dateFormat.format(begin));
        elTimespan.appendChild(elBegin);
    }
    if (end != null) {
        Element elEnd = docKml.createElement("end");
        elEnd.setTextContent(dateFormat.format(end));
        elTimespan.appendChild(elEnd);
    }

    return elTimespan;
}

From source file:fr.aliasource.webmail.server.proxy.client.http.StoreHistoryMethod.java

private Document asXml(History history) throws ParserConfigurationException, FactoryConfigurationError {
    Document doc = DOMUtils.createDoc("http://minig.org/xsd/history.xsd", "history");
    Element root = doc.getDocumentElement();

    for (HistoryItem it : history) {
        Element item = DOMUtils.createElement(root, "item");
        item.setAttribute("ts", "" + it.getTimestamp().getTime());
        item.setAttribute("from", it.getFrom());
        item.setTextContent(it.getText());
    }// www .  j a v a 2  s  .co m

    root.setAttribute("ts", "" + history.getLastChat().getTime());
    return doc;
}

From source file:fr.aliasource.webmail.invitation.GetInvitationInfoAction.java

private Document getXmlDocument(Event event, List<Event> eventsOfDay, String participationState)
        throws Exception {
    Document doc;/*from w  w w. j a  v a2s .c  om*/
    doc = DOMUtils.createDoc("http://minig.org/xsd/invitationInfo", "invitationInfo");

    Element root = doc.getDocumentElement();
    Element att = DOMUtils.createElement(root, "calendarUrl");
    att.setTextContent(getCalendarUrl());
    addEventNode(root, event, participationState);
    addListEvent(root, eventsOfDay);
    return doc;
}

From source file:com.zuora.api.object.Dynamic.java

private void setDynamicProperty(String name, Object value) {
    Element element = getElement(this, name);
    if (element != null) {
        element.setTextContent((String) value);
    } else {// w ww  .  ja va 2  s.  co m
        this.getAny().add(ElementBuilders.newElement(name, (String) value));
    }
}

From source file:fr.aliasource.webmail.invitation.GetInvitationInfoAction.java

private void addEventNode(Element root, Event event, String going) {

    Element eventElem = DOMUtils.createElement(root, "event");

    Element att = DOMUtils.createElement(eventElem, "extId");
    att.setTextContent(event.getExtId());

    att = DOMUtils.createElement(eventElem, "title");
    att.setTextContent(event.getTitle());

    att = DOMUtils.createElement(eventElem, "location");
    att.setTextContent(event.getLocation());

    att = DOMUtils.createElement(eventElem, "owner");
    att.setTextContent(event.getOwner());

    att = DOMUtils.createElement(eventElem, "going");
    att.setTextContent(going);//  w w w.j ava  2s.c  om

    att = DOMUtils.createElement(eventElem, "attendees");
    List<Attendee> whos = event.getAttendees();
    for (Attendee attendee : whos) {
        Element attWho = DOMUtils.createElement(att, "attendee");
        if (StringUtils.isNotEmpty(attendee.getDisplayName())) {
            attWho.setTextContent(attendee.getDisplayName());
        } else {
            attWho.setTextContent(attendee.getEmail());
        }
    }

    att = DOMUtils.createElement(eventElem, "start");
    att.setTextContent(Long.toString(event.getDate().getTime()));

    long lDate = event.getDate().getTime() + (event.getDuration() * 1000);
    att = DOMUtils.createElement(eventElem, "end");
    att.setTextContent(Long.toString(lDate));

}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.AbstractXmlElementConverter.java

protected void updateServletInitParam(Document document, Element servlet, String attributeName,
        Object attributeValue, Properties catalinaProperties) {
    List<Element> initParams = getChildElements(servlet, "init-param");
    boolean paramFound = false;
    for (int i = 0; i < initParams.size(); i++) {
        Element initParam = (Element) initParams.get(i);
        final String paramName = getChildElements(initParam, "param-name").get(0).getTextContent();
        if (paramName.equals(attributeName)) {
            paramFound = true;/*from   w w  w. j a va  2  s.  c o m*/
            if (attributeValue != null && !("".equals(attributeValue))) {
                Element paramValue = getChildElements(initParam, "param-value").get(0);
                paramValue.setTextContent(
                        determineNewValue(paramValue.getTextContent(), attributeValue, catalinaProperties));
            } else {
                servlet.removeChild(initParam);
            }
            break;
        }
    }
    if (!(paramFound) && attributeValue != null && !("".equals(attributeValue))) {
        Element newInitParam = document.createElement("init-param");
        Element paramName = document.createElement("param-name");
        Element paramValue = document.createElement("param-value");
        newInitParam.appendChild(paramName);
        newInitParam.appendChild(paramValue);
        paramName.setTextContent(attributeName);
        paramValue.setTextContent(
                determineNewValue(paramValue.getTextContent(), attributeValue, catalinaProperties));
        // This list contains all the elements that are required by the XSD to occur after init-param node
        List<String> orderedTypes = Arrays.asList("load-on-startup", "enabled", "async-supported", "run-as",
                "security-role-ref", "multipart-config");
        boolean elementInserted = false;
        for (String orderedType : orderedTypes) {
            List<Element> foundElement = getChildElements(servlet, orderedType);
            if (!foundElement.isEmpty()) {
                servlet.insertBefore(newInitParam, foundElement.get(0));
                elementInserted = true;
                break;
            }
        }
        if (!elementInserted) {
            servlet.appendChild(newInitParam);
        }

    }
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

public static synchronized Space getSpace(String key) {
    Space space = spaces.get(key);/*from  ww w.  j av a 2  s  .c om*/
    if (space == null) {
        try {
            doLogin();

            Document doc = DOMUtils.newDocument();
            Element el = doc.createElementNS(SOAPNS, "ns1:getSpace");
            Element el2 = doc.createElement("in0");
            el.appendChild(el2);
            el2.setTextContent(loginToken);
            el2 = doc.createElement("in1");
            el.appendChild(el2);
            el2.setTextContent(key);
            doc.appendChild(el);

            Document out = getDispatch().invoke(doc);
            space = new Space(out);
            spaces.put(key, space);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return space;
}