class NodeHelper {

    public static Text addText(final TextContainer container,
            final String text) {
        if ((text == null) || text.isEmpty()) {
            return null;
        }
        final String append = text.trim();
        if (append.isEmpty()) {
            return null;
        }
        final Text textNode;
        final Node lastChild = container.getLastChild();
        if (lastChild instanceof Text) {
            textNode = (Text) lastChild;
            final String value = textNode.getNodeValue().trim();
            final StringBuilder str = new StringBuilder();
            str.append(value);
            final char first = append.charAt(0);
            if ((first != '.') && (first != ',') && (first != '!')
                    && (first != '?')) {
                str.append(' ');
            }
            str.append(append);
            textNode.setNodeValue(str.toString());
        } else {
            final Document document = container.getOwnerDocument();
            final Node node = document.createTextNode(append);
            final XmlNodeFactory<? extends XmlNode> factory =
                container.getNodeFactory();
            textNode = new Text(node, factory);
            container.appendChild(textNode);
        }
        return textNode;
    }

    private  NodeHelper();

}