Search in sources :

Example 76 with Text

use of org.w3c.dom.Text in project sling by apache.

the class XmlRenderer method testFailure.

@Override
public void testFailure(Failure failure) throws Exception {
    super.testFailure(failure);
    failures.add(failure.getDescription());
    Element nested = doc.createElement("failure");
    Element currentTest = testElements.get(failure.getDescription());
    currentTest.appendChild(nested);
    String message = failure.getMessage();
    if (message != null && message.length() > 0) {
        nested.setAttribute("message", message);
    }
    nested.setAttribute("type", failure.getClass().getName());
    String strace = getException(failure.getException());
    strace = BaseTestRunner.getFilteredTrace(strace);
    Text trace = doc.createTextNode(strace);
    nested.appendChild(trace);
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 77 with Text

use of org.w3c.dom.Text in project winery by eclipse.

the class GenericArtifactsResource method storeProperties.

private void storeProperties(ArtifactTemplateId artifactTemplateId, DefinitionsChildId typeId, String name) {
    // We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate):
    // getAny() does not always return "w3c.dom.element" anymore
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        GenericArtifactsResource.LOGGER.error(e.getMessage(), e);
        return;
    }
    Document doc = builder.newDocument();
    String namespace = QNames.QNAME_ARTIFACT_TYPE_WAR.getNamespaceURI();
    Element root = doc.createElementNS(namespace, "WSProperties");
    doc.appendChild(root);
    Element element = doc.createElementNS(namespace, "ServiceEndpoint");
    Text text = doc.createTextNode("/services/" + name + "Port");
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "PortType");
    text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name);
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "InvocationType");
    text = doc.createTextNode("SOAP/HTTP");
    element.appendChild(text);
    root.appendChild(element);
    Properties properties = new Properties();
    properties.setAny(root);
    final IRepository repository = RepositoryFactory.getRepository();
    final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
    artifactTemplate.setProperties(properties);
    try {
        repository.setElement(artifactTemplateId, artifactTemplate);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) Properties(org.eclipse.winery.model.tosca.TEntityTemplate.Properties) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 78 with Text

use of org.w3c.dom.Text in project gradle by gradle.

the class ClassDocPropertiesBuilder method build.

/**
 * Builds the properties of the given class
 */
void build(ClassDoc classDoc) {
    Element thead = getChild(classDoc.getPropertiesTable(), "thead");
    Element tr = getChild(thead, "tr");
    List<Element> header = children(tr, "td");
    if (header.size() < 1) {
        throw new RuntimeException(String.format("Expected at least 1 <td> in <thead>/<tr>, found: %s", header));
    }
    Map<String, Element> inheritedValueTitleMapping = new HashMap<String, Element>();
    List<Element> valueTitles = new ArrayList<Element>();
    for (int i = 1; i < header.size(); i++) {
        Element element = header.get(i);
        Element override = findChild(element, "overrides");
        if (override != null) {
            element.removeChild(override);
            inheritedValueTitleMapping.put(override.getTextContent(), element);
        }
        Node firstChild = element.getFirstChild();
        if (firstChild instanceof Text) {
            firstChild.setTextContent(firstChild.getTextContent().replaceFirst("^\\s+", ""));
        }
        Node lastChild = element.getLastChild();
        if (lastChild instanceof Text) {
            lastChild.setTextContent(lastChild.getTextContent().replaceFirst("\\s+$", ""));
        }
        valueTitles.add(element);
    }
    // adding the properties from the super class onto the inheriting class
    Map<String, PropertyDoc> props = new TreeMap<String, PropertyDoc>();
    List<ClassDoc> superTypes = classDoc.getSuperTypes();
    for (ClassDoc superType : superTypes) {
        LOG.info("Getting properties for {}", superType.getName());
        for (PropertyDoc propertyDoc : superType.getClassProperties()) {
            Map<String, ExtraAttributeDoc> additionalValues = new LinkedHashMap<String, ExtraAttributeDoc>();
            for (ExtraAttributeDoc attributeDoc : propertyDoc.getAdditionalValues()) {
                String key = attributeDoc.getKey();
                if (inheritedValueTitleMapping.get(key) != null) {
                    ExtraAttributeDoc newAttribute = new ExtraAttributeDoc(inheritedValueTitleMapping.get(key), attributeDoc.getValueCell());
                    additionalValues.put(newAttribute.getKey(), newAttribute);
                } else {
                    additionalValues.put(key, attributeDoc);
                }
            }
            props.put(propertyDoc.getName(), propertyDoc.forClass(classDoc, additionalValues.values()));
        }
    }
    for (Element row : children(classDoc.getPropertiesTable(), "tr")) {
        List<Element> cells = children(row, "td");
        if (cells.size() != header.size()) {
            throw new RuntimeException(String.format("Expected %s <td> elements in <tr>, found: %s", header.size(), tr));
        }
        String propName = cells.get(0).getTextContent().trim();
        PropertyMetaData property = classDoc.getClassMetaData().findProperty(propName);
        if (property == null) {
            throw new RuntimeException(String.format("No metadata for property '%s.%s'. Available properties: %s", classDoc.getName(), propName, classDoc.getClassMetaData().getPropertyNames()));
        }
        Map<String, ExtraAttributeDoc> additionalValues = new LinkedHashMap<String, ExtraAttributeDoc>();
        if (!superTypes.isEmpty()) {
            PropertyDoc overriddenProp = props.get(propName);
            if (overriddenProp != null) {
                for (ExtraAttributeDoc attributeDoc : overriddenProp.getAdditionalValues()) {
                    additionalValues.put(attributeDoc.getKey(), attributeDoc);
                }
            }
        }
        for (int i = 1; i < header.size(); i++) {
            if (cells.get(i).getFirstChild() == null) {
                continue;
            }
            ExtraAttributeDoc attributeDoc = new ExtraAttributeDoc(valueTitles.get(i - 1), cells.get(i));
            additionalValues.put(attributeDoc.getKey(), attributeDoc);
        }
        PropertyDoc propertyDoc = new PropertyDoc(property, javadocConverter.parse(property, listener).getDocbook(), new ArrayList<ExtraAttributeDoc>(additionalValues.values()));
        if (propertyDoc.getDescription() == null) {
            throw new RuntimeException(String.format("Docbook content for '%s.%s' does not contain a description paragraph.", classDoc.getName(), propName));
        }
        props.put(propName, propertyDoc);
    }
    for (PropertyDoc propertyDoc : props.values()) {
        classDoc.addClassProperty(propertyDoc);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Text(org.w3c.dom.Text) PropertyMetaData(org.gradle.build.docs.dsl.source.model.PropertyMetaData) PropertyDoc(org.gradle.build.docs.dsl.docbook.model.PropertyDoc) ExtraAttributeDoc(org.gradle.build.docs.dsl.docbook.model.ExtraAttributeDoc) ClassDoc(org.gradle.build.docs.dsl.docbook.model.ClassDoc)

Example 79 with Text

use of org.w3c.dom.Text in project gradle by gradle.

the class JavadocConverter method adjustGetterComment.

private void adjustGetterComment(DocCommentImpl docComment) {
    // Replace 'Returns the ...' with 'The ...'
    List<Element> nodes = docComment.getDocbook();
    if (nodes.isEmpty()) {
        return;
    }
    Element firstNode = nodes.get(0);
    if (!firstNode.getNodeName().equals("para") || !(firstNode.getFirstChild() instanceof Text)) {
        return;
    }
    Text comment = (Text) firstNode.getFirstChild();
    Pattern getterPattern = Pattern.compile("returns\\s+(the|whether)\\s+", Pattern.CASE_INSENSITIVE);
    Matcher matcher = getterPattern.matcher(comment.getData());
    if (matcher.lookingAt()) {
        String theOrWhether = matcher.group(1).toLowerCase(Locale.US);
        comment.setData(StringUtils.capitalize(theOrWhether) + " " + comment.getData().substring(matcher.end()));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 80 with Text

use of org.w3c.dom.Text in project Lucee by lucee.

the class XMLTextStruct method replaceWholeText.

// used only with java 7, do not set @Override
public Text replaceWholeText(String content) throws DOMException {
    Text oldText = text;
    Document doc = XMLUtil.getDocument(text);
    Text newText = doc.createTextNode(content);
    Node parent = oldText.getParentNode();
    parent.replaceChild(XMLCaster.toRawNode(newText), XMLCaster.toRawNode(oldText));
    return oldText;
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document)

Aggregations

Text (org.w3c.dom.Text)166 Element (org.w3c.dom.Element)93 Document (org.w3c.dom.Document)64 Node (org.w3c.dom.Node)58 NodeList (org.w3c.dom.NodeList)35 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)23 DocumentBuilder (javax.xml.parsers.DocumentBuilder)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 IOException (java.io.IOException)14 Attr (org.w3c.dom.Attr)14 InputSource (org.xml.sax.InputSource)11 StringReader (java.io.StringReader)10 SAXException (org.xml.sax.SAXException)8 ArrayList (java.util.ArrayList)7 DOMException (org.w3c.dom.DOMException)7 Test (org.junit.Test)6 DOMSource (javax.xml.transform.dom.DOMSource)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 HashMap (java.util.HashMap)4 DocumentFragment (org.w3c.dom.DocumentFragment)4