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:org.eclipse.skalli.core.extension.DataMigration11.java

private void addPeople(Document doc, Element element, List<String> people) {
    Element setEntry = doc.createElement("no-comparator");
    element.appendChild(setEntry);//from w w  w . jav a 2 s  .c o m
    for (String userId : people) {
        Element memberElement = doc.createElement("org.eclipse.skalli.model.core.ProjectMember");
        element.appendChild(memberElement);

        Element userIdElement = doc.createElement("userID");
        memberElement.appendChild(userIdElement);
        userIdElement.setTextContent(userId);
    }
}

From source file:org.eclipse.skalli.core.issues.IssuesDataMigration19.java

/**
 * Changes from model version 18->19:
 * <ol>/*from  www.  j  ava  2s. com*/
 *   <li>renamed root element org.eclipse.skalli.model.ext.Issues to "issues"</li>
 *   <li>renamed root element org.eclipse.skalli.model.ext.Issue to "issue"</li>
 * </ol>
 */
@SuppressWarnings("nls")
@Override
public void migrate(Document doc) throws MigrationException {
    MigrationUtils.renameTag(doc, doc.getDocumentElement(), "entity-issues");
    MigrationUtils.renameAllTags(doc, "org.eclipse.skalli.model.ext.Issue", "issue");
    MigrationUtils.removeAllTags(doc, "extension");
    NodeList nodes = doc.getElementsByTagName("issuer");
    for (int i = 0; i < nodes.getLength(); ++i) {
        Element elem = (Element) nodes.item(i);
        elem.setTextContent(IssuesService.class.getName());
    }
    Element staleElem = MigrationUtils.getChild(doc.getDocumentElement(), "stale");
    if (staleElem == null) {
        staleElem = doc.createElement("stale");
        doc.getDocumentElement().appendChild(staleElem);
    }
    staleElem.setTextContent("true");
}

From source file:org.eclipse.skalli.core.persistence.XStreamPersistence.java

void mapTextContent(Element stringElement, Map<String, String> aliases) {
    String alias = stringElement.getTextContent();
    if (StringUtils.isNotBlank(alias)) {
        String mapped = aliases.get(alias);
        if (mapped != null) {
            stringElement.setTextContent(mapped);
        }/* w w  w .  j av a  2  s. co m*/
    }
}

From source file:org.eclipse.skalli.core.user.LocalUserDataMigration19.java

/**
 * Changes from model version 0->1://from  ww w.j a va 2 s  .c  om
 * <ol>
 *   <li>renamed root element org.eclipse.skalli.common.User to "user"</li>
 * </ol>
 */
@SuppressWarnings("nls")
@Override
public void migrate(Document doc) throws MigrationException {
    MigrationUtils.renameTag(doc, doc.getDocumentElement(), "entity-user");
    Element elem = MigrationUtils.getElementOfEntity(doc, "uuid");
    if (elem == null) {
        elem = doc.createElement("uuid");
        elem.setTextContent(UUID.randomUUID().toString());
        doc.getDocumentElement().insertBefore(elem, doc.getDocumentElement().getFirstChild());
    }
}

From source file:org.eclipse.smila.search.servlet.SMILASearchServlet.java

/**
 * Appends a list of index names to the document.
 *
 * @param doc/*from w  w  w .j  a  v  a 2s . c  om*/
 *          the document to append the list to
 */
protected void appendIndexList(final Document doc) {
    final LuceneIndexService indexService = Activator.getLuceneIndexService();
    if (indexService != null) {
        final Iterator<String> indexNames = indexService.getIndexNames();
        if (indexNames != null) {
            final Element indexNamesElement = doc.createElementNS(SearchService.NAMESPACE_SEARCH,
                    ELEMENT_INDEX_NAMES);
            while (indexNames.hasNext()) {
                final String indexName = indexNames.next();
                if (indexName != null) {
                    final Element nameElement = doc.createElement(ELEMENT_INDEX_NAME);
                    nameElement.setTextContent(indexName);
                    indexNamesElement.appendChild(nameElement);
                }
            }
            doc.getDocumentElement().appendChild(indexNamesElement);
        }
    }
}

From source file:org.eclipse.winery.common.ModelUtilities.java

public static Element buildPropertiesElement(Map<String, String> properties, String propNS) {
    Document document = null;/*ww w .  j av  a 2  s  . c o  m*/
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (ParserConfigurationException e) {
        System.out.println(e.getMessage());
    }

    Element root = document.createElement("Properties");
    root.setAttribute("xmlns", propNS);
    for (Entry<String, String> entry : properties.entrySet()) {
        if (null != entry.getKey() && null != entry.getValue()) {
            Element ele = document.createElementNS(propNS, entry.getKey());
            ele.setTextContent(entry.getValue());
            root.appendChild(ele);
        }
    }

    return root;
}

From source file:org.efaps.eclipse.wizards.CopyCIWizardPage.java

@Override
protected InputStream getInitialContents() {
    InputStream ret = null;//www. j a  v a 2 s  .c o m
    if (this.fileResource != null && this.fileResource.isAccessible()) {
        final URI uri = this.fileResource.getLocationURI();
        final File file = new File(uri);
        try {
            ret = new FileInputStream(file);

            final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            final DocumentBuilder docBuilder = factory.newDocumentBuilder();
            final Document doc = docBuilder.parse(file);
            // create the root element
            final Element root = doc.getDocumentElement();
            final NodeList children = root.getChildNodes();
            boolean def = false;
            boolean uuid = false;
            for (int i = 0; i < children.getLength(); i++) {
                if (children.item(i) instanceof Element) {
                    final Element child = (Element) children.item(i);
                    if ("uuid".equals(child.getNodeName())) {
                        child.setTextContent(UUID.randomUUID().toString());
                        uuid = true;
                    }
                    if ("definition".equals(child.getNodeName())) {
                        final NodeList defChildren = child.getChildNodes();
                        for (int j = 0; j < defChildren.getLength(); j++) {
                            if (defChildren.item(j) instanceof Element) {
                                final Element defChild = (Element) defChildren.item(j);
                                if ("name".equals(defChild.getNodeName())) {
                                    defChild.setTextContent(
                                            getFileName().replace("." + getFileExtension(), ""));
                                    break;
                                }
                            }
                        }
                        def = true;
                    }
                    if (def && uuid) {
                        break;
                    }
                }
            }

            final TransformerFactory transfac = TransformerFactory.newInstance();
            final Transformer trans = transfac.newTransformer();
            final Source source = new DOMSource(doc);
            final StreamResult result = new StreamResult(new StringWriter());
            trans.transform(source, result);
            ret = IOUtils.toInputStream(result.getWriter().toString());

        } catch (final FileNotFoundException e) {
            EfapsPlugin.getDefault().logError(getClass(), "FileNotFoundException", e);
        } catch (final ParserConfigurationException e) {
            EfapsPlugin.getDefault().logError(getClass(), "ParserConfigurationException", e);
        } catch (final SAXException e) {
            EfapsPlugin.getDefault().logError(getClass(), "SAXException", e);
        } catch (final IOException e) {
            EfapsPlugin.getDefault().logError(getClass(), "IOException", e);
        } catch (final TransformerConfigurationException e) {
            EfapsPlugin.getDefault().logError(getClass(), "TransformerConfigurationException", e);
        } catch (final TransformerException e) {
            EfapsPlugin.getDefault().logError(getClass(), "TransformerException", e);
        }
    }
    return ret;
}

From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java

/**
 * Creates the Metadata element for the manifest file which mainly includes the title of the pool
 * //from  www. j  a  v a2  s  . c  o  m
 * @param doc
 * @return
 */
public Element createManifestMetadata(Document doc, String title) {
    Element metadata = doc.createElementNS("http://www.imsglobal.org/xsd/imscp_v1p1", "metadata");

    // schema element
    Element schema = doc.createElementNS("http://www.imsglobal.org/xsd/imscp_v1p1", "schema");

    schema.setTextContent("IMS Content");
    metadata.appendChild(schema);

    // schema version element
    Element schemaVersion = doc.createElementNS("http://www.imsglobal.org/xsd/imscp_v1p1", "schemaversion");
    schemaVersion.setTextContent("2.1");
    metadata.appendChild(schemaVersion);
    Element lom = createLomElement(doc, null, title, null, null, "", null);
    metadata.appendChild(lom);

    return metadata;
}

From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java

/**
 * /*from   w w w. j a  v a  2s  .  c o m*/
 * @param doc
 * @param type
 * @param title
 * @param description
 * @param zip
 * @param mediaFiles
 * @return
 */
public Element createLomElement(Document doc, String type, String title, String description,
        ZipOutputStream zip, String subFolder, List<String> mediaFiles) {
    Element lom = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:lom");
    Element general = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:general");

    // <imsmd:identifier>QUE_1106</imsmd:identifier>
    if (type != null && type.length() > 0) {
        Element typeElement = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2",
                "imsmd:identifier");
        typeElement.setTextContent(type);
        general.appendChild(typeElement);
    }
    if (title != null && title.length() > 0) {
        Element titleElement = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:title");
        Element langstring = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:langstring");
        title = FormattedText.unEscapeHtml(title);
        langstring.setTextContent(title);
        titleElement.appendChild(langstring);
        general.appendChild(titleElement);
    }
    if (description != null && description.length() > 0) {
        Element descElement = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2",
                "imsmd:description");
        Element langstring = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:langstring");
        description = FormattedText.unEscapeHtml(description);
        if (zip != null && mediaFiles != null)
            description = translateEmbedData(zip, subFolder, subFolder, description, mediaFiles);
        langstring.setTextContent(description);
        descElement.appendChild(langstring);
        general.appendChild(descElement);
    }
    lom.appendChild(general);
    return lom;
}

From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java

/**
 * create outcomeDeclaration element which contains the score
 * /*from  w w w .  j a v a2  s .c o  m*/
 * @param document
 * @param points
 * @return
 */
private Element createOutcomeElement(Document document, String identifier, String baseType, String points) {
    Element outcomeDeclarationElement = document.createElement("outcomeDeclaration");
    outcomeDeclarationElement.setAttribute("baseType", baseType);
    outcomeDeclarationElement.setAttribute("cardinality", "single");
    outcomeDeclarationElement.setAttribute("identifier", identifier);
    if (points != null && points.length() > 0) {
        Element defaultValueElement = document.createElement("defaultValue");
        Element valueElement = document.createElement("value");
        valueElement.setTextContent(points);
        defaultValueElement.appendChild(valueElement);
        outcomeDeclarationElement.appendChild(defaultValueElement);
    }
    return outcomeDeclarationElement;
}