protected void writeElementContent(Element element) throws IOException {
        boolean trim = format.isTrimText();
        boolean oldPreserve=preserve;
        if (trim) { //verify we have to before more expensive test
          preserve=isElementSpacePreserved(element);
          trim = !preserve;
        }
        if (trim) {
            // concatenate adjacent text nodes together
            // so that whitespace trimming works properly
            Text lastTextNode = null;
            StringBuilder buffer = null;
            boolean textOnly = true;
            for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
                Node node = element.node(i);
                if ( node instanceof Text ) {
                    if ( lastTextNode == null ) {
                        lastTextNode = (Text) node;
                    }
                    else {
                        if (buffer == null) {
                            buffer = new StringBuilder( lastTextNode.getText() );
                        }
                      buffer.append( node.getText() );
                    }
                }
                else {
                    if (!textOnly && format.isPadText()) {
                        writer.write(PAD_TEXT);
                    }

                    textOnly = false;

                    if ( lastTextNode != null ) {
                        if ( buffer != null ) {
                            writeString( buffer.toString() );
                            buffer = null;
                        }
                        else {
                            writeString( lastTextNode.getText() );
                        }
                        lastTextNode = null;

                        if (format.isPadText()) {
                            writer.write(PAD_TEXT);
                        }
                    }
                    writeNode(node);
                }
            }
            if ( lastTextNode != null ) {
                if (!textOnly && format.isPadText()) {
                    writer.write(PAD_TEXT);
                }
                if ( buffer != null ) {
                    writeString( buffer.toString() );
                    buffer = null;
                }
                else {
                    writeString( lastTextNode.getText() );
                }
                lastTextNode = null;
            }
        }
        else {
            Node lastTextNode = null;
            for ( int i = 0, size = element.nodeCount(); i < size; i++ ) {
                Node node = element.node(i);
                if (node instanceof Text) {
                    writeNode(node);
                    lastTextNode = node;
                } else {
                    if ((lastTextNode != null) && format.isPadText()) {
                        writer.write(PAD_TEXT);
                    }
                    writeNode(node);
                    if ((lastTextNode != null) && format.isPadText()) {
                        writer.write(PAD_TEXT);
                    }
                    lastTextNode = null;
                }
            }
        }
        preserve=oldPreserve;
    }
Outputs the content of the given element. If whitespace trimming is
enabled then all adjacent text nodes are appended together before
the whitespace trimming occurs to avoid problems with multiple
text nodes being created due to text content that spans parser buffers
in a SAX parser.
@param element the element to write
@throws IOException if the element could not be written
xmppserver/src/main/java/org/jivesoftware/util/XMLWriter.java