
org.gramar.base.function.LowercaseFirstFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gramar Show documentation
Show all versions of gramar Show documentation
A lightweght, pure-Java component that makes composite software architecture design patterns extremely consumable through code generation.
The newest version!
package org.gramar.base.function;
import java.util.List;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class LowercaseFirstFunction implements XPathFunction {
public LowercaseFirstFunction() {
}
@Override
public Object evaluate(List args) throws XPathFunctionException {
String original = null;
Object val = args.get(0);
if (val instanceof String) {
original = (String) val;
} else if (val instanceof NodeList) {
NodeList nl = (NodeList) val;
Node item = nl.item(0);
if (item == null) {
throw new XPathFunctionException("argument for lowercaseFirst() is null");
}
original = item.getNodeValue();
}
if (original.length() == 0) {
throw new XPathFunctionException("argument for lowercaseFirst() has length 0");
}
return original.substring(0, 1).toLowerCase() + original.substring(1);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy