Example usage for org.w3c.dom CharacterData getData

List of usage examples for org.w3c.dom CharacterData getData

Introduction

In this page you can find the example usage for org.w3c.dom CharacterData getData.

Prototype

public String getData() throws DOMException;

Source Link

Document

The character data of the node that implements this interface.

Usage

From source file:org.osaf.cosmo.xml.DomWriter.java

private static void writeCharacters(CharacterData cd, XMLStreamWriter writer) throws XMLStreamException {
    //if (log.isDebugEnabled())
    //log.debug("Writing characters: '" + cd.getData() + "'");
    writer.writeCharacters(cd.getData());
}

From source file:org.sakaiproject.tool.assessment.qti.asi.ASIBaseClass.java

protected void wrappingMattext() {
    log.debug("wrappingMattext()");

    try {/*w  ww.  j  av  a 2 s  .co m*/
        NodeList list = this.getDocument().getElementsByTagName(QTIConstantStrings.MATTEXT);
        int size = list.getLength();
        for (int i = 0; i < size; i++) {
            Node node = list.item(i);
            Node childNode = node.getFirstChild();
            if ((childNode != null) && childNode instanceof CharacterData) {
                CharacterData cdi = (CharacterData) childNode;
                String data = cdi.getData();

                //modify this string;
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document doc = db.newDocument();
                Comment comment = doc.createComment(data);
                node.appendChild(node.getOwnerDocument().importNode(comment, true));
                cdi.setData("");
            }
        }
    } catch (ParserConfigurationException e) {
        log.error(e.getMessage(), e);
    } catch (SAXException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:org.sakaiproject.tool.assessment.qti.helper.item.ItemHelperBase.java

/**
 * Concatenate nodes for xpath/* w ww  .ja  v  a 2  s. c o  m*/
 * @param itemXml
 * @param xpath
 * @return
 */
protected String makeItemNodeText(Item itemXml, String xpath) {
    //String text = "";
    List nodes = itemXml.selectNodes(xpath);
    Iterator iter = nodes.iterator();

    StringBuilder textbuf = new StringBuilder();
    while (iter.hasNext()) {
        Node node = (Node) iter.next();
        Node child = node.getFirstChild();
        if ((child != null) && child instanceof CharacterData) {
            CharacterData cdi = (CharacterData) child;
            textbuf.append(" " + cdi.getData());
        }
    }
    String text = textbuf.toString();
    return text;
}

From source file:org.webtestingexplorer.state.CustomizedPropertiesElementsState.java

private String getCharacterDataFromElement(Element e) {
    Node child = e.getFirstChild();
    if (child instanceof CharacterData) {
        CharacterData cd = (CharacterData) child;
        return cd.getData();
    }//from   ww  w  . java2 s  .c om
    return "";
}

From source file:uk.ac.cam.caret.sakai.rwiki.component.model.impl.RWikiEntityImpl.java

/**
 * {@inheritDoc}//from   w  w w .jav a2s  .  c  o  m
 */
public void fromXml(Element el, String defaultRealm) throws Exception {
    if (rwo == null)
        throw new RuntimeException(" Cant deserialise containers at the moment ");

    NodeList nl = el.getElementsByTagName("properties");
    // this is hard coded in BaseResourceProperties the element name
    // properties
    if (nl == null || nl.getLength() != 1)
        throw new Exception("Cant find a properties element in " + el.getNodeName() + " id: "
                + el.getAttribute(SchemaNames.ATTR_ID) + " pagename: "
                + el.getAttribute(SchemaNames.ATTR_PAGE_NAME));
    // only take the first properties
    Element properties = (Element) nl.item(0);

    ResourceProperties rp = new BaseResourceProperties(properties);

    nl = el.getElementsByTagName(SchemaNames.EL_WIKICONTENT);
    if (nl == null || nl.getLength() != 1)
        throw new Exception("Cant find a  wikiproperties element in " + el.getNodeName() + " id: "
                + el.getAttribute(SchemaNames.ATTR_ID) + " pagename: "
                + el.getAttribute(SchemaNames.ATTR_PAGE_NAME));
    // only accpet the first
    Element wikiContents = (Element) nl.item(0);

    nl = wikiContents.getChildNodes();
    StringBuffer content = new StringBuffer();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);
        if (n instanceof CharacterData) {
            CharacterData cdnode = (CharacterData) n;
            try {
                content.append(new String(Base64.decode(cdnode.getData()), "UTF-8"));
            } catch (Throwable t) {
                log.warn("Cant decode node content for " + cdnode);
            }
        }
    }

    String realm = rp.getProperty(RWikiEntity.RP_REALM);
    rwo.setId(rp.getProperty(RWikiEntity.RP_ID));

    rwo.setName(NameHelper.globaliseName(NameHelper.localizeName(rp.getProperty(RWikiEntity.RP_NAME), realm),
            defaultRealm));
    rwo.setOwner(rp.getProperty(RWikiEntity.RP_OWNER));
    rwo.setRealm(defaultRealm);
    rwo.setReferenced(rp.getProperty(RWikiEntity.RP_REFERENCED));
    // rwo.setRwikiobjectid(rp.getProperty("rwid"));
    rwo.setContent(content.toString());

    if (!rwo.getSha1().equals(rp.getProperty(RWikiEntity.RP_SHA1)))
        throw new Exception("Sha Checksum Missmatch on content " + rp.getProperty(RWikiEntity.RP_SHA1) + " != "
                + rwo.getSha1());
    rwo.setUser(rp.getProperty(RWikiEntity.RP_USER));
    rwo.setGroupAdmin(rp.getBooleanProperty(RWikiEntity.RP_GROUP_ADMIN));
    rwo.setGroupRead(rp.getBooleanProperty(RWikiEntity.RP_GROUP_READ));
    rwo.setGroupWrite(rp.getBooleanProperty(RWikiEntity.RP_GROUP_WRITE));
    rwo.setOwnerAdmin(rp.getBooleanProperty(RWikiEntity.RP_OWNER_ADMIN));
    rwo.setOwnerRead(rp.getBooleanProperty(RWikiEntity.RP_OWNER_READ));
    rwo.setOwnerWrite(rp.getBooleanProperty(RWikiEntity.RP_OWNER_WRITE));
    rwo.setPublicRead(rp.getBooleanProperty(RWikiEntity.RP_PUBLIC_READ));
    rwo.setPublicWrite(rp.getBooleanProperty(RWikiEntity.RP_PUBLIC_WRITE));
    rwo.setRevision(Integer.valueOf(rp.getProperty(RWikiEntity.RP_REVISION)));
    rwo.setVersion(new Date(rp.getLongProperty(RWikiEntity.RP_VERSION)));

}