src/main/java/de/unixwork/uwproj/Util.java

Wed, 06 Sep 2023 22:55:42 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 06 Sep 2023 22:55:42 +0200
changeset 40
b42bfc9e9983
parent 0
src/main/java/de/unixwork/uwproj/Xml.java@38775db5fdf5
child 41
75ee588d5d9e
permissions
-rw-r--r--

first minor code improvements

package de.unixwork.uwproj;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Util {
    /**
     * Returns the text content of the given element.
     *
     * @param elm the element
     * @return the contents or empty string if there are no contents
     */
    public static String getContent(Element elm) {
        NodeList nodes = elm.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            var node = nodes.item(i);
            if (node.getNodeType() == Node.TEXT_NODE) {
                return node.getTextContent();
            }
        }
        return "";
    }

    public static boolean isNullOrBlank(String s) {
        return s == null || s.isBlank();
    }

    public static boolean isNotNullOrBlank(String s) {
        return s != null && !s.isBlank();
    }
}

mercurial