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

Sun, 17 Sep 2023 12:15:14 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Sep 2023 12:15:14 +0200
branch
configure-evo
changeset 57
df03772f7429
parent 41
75ee588d5d9e
child 64
00586d892855
permissions
-rw-r--r--

invert logic of dependency check

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) {
                final var v = node.getNodeValue();
                return v == null ? "" : v;
            }
        }
        return "";
    }

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

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

    /**
     * Creates an identifier from the given string that can be used as an identifier in a POSIX shell script.
     * <p>
     * If the given string does not contain any character that is illegal in a POSIX shell variable or function name,
     * the string is returned unmodified.
     *
     * @param s the input string
     * @return the sanitized string
     */
    public static String shId(String s) {
        // TODO: implement
        return s;
    }
}

mercurial