public static void writeComment()

in src/main/java/org/apache/maven/shared/utils/xml/XmlWriterUtil.java [188:244]


    public static void writeComment(XMLWriter writer, String comment, int indent, int indentSize, int columnSize)
            throws IOException {
        if (comment == null) {
            comment = "null";
        }

        if (indent < 0) {
            indent = 0;
        }

        if (indentSize < 0) {
            indentSize = 0;
        }

        if (columnSize < 0) {
            columnSize = DEFAULT_COLUMN_LINE;
        }

        String indentation = StringUtils.repeat(" ", indent * indentSize);
        int magicNumber = indentation.length() + columnSize - "-->".length() - 1;
        String[] sentences = StringUtils.split(comment, CRLF);

        StringBuffer line = new StringBuffer(indentation + "<!-- ");
        for (String sentence : sentences) {
            String[] words = StringUtils.split(sentence, " ");
            for (String word : words) {
                StringBuilder sentenceTmp = new StringBuilder(line.toString());
                sentenceTmp.append(word).append(' ');
                if (sentenceTmp.length() > magicNumber) {
                    if (line.length() != indentation.length() + "<!-- ".length()) {
                        if (magicNumber - line.length() > 0) {
                            line.append(StringUtils.repeat(" ", magicNumber - line.length()));
                        }

                        line.append("-->").append(CRLF);
                        writer.writeMarkup(line.toString());
                    }
                    line = new StringBuffer(indentation + "<!-- ");
                    line.append(word).append(' ');
                } else {
                    line.append(word).append(' ');
                }
            }

            if (magicNumber - line.length() > 0) {
                line.append(StringUtils.repeat(" ", magicNumber - line.length()));
            }
        }

        if (line.length() <= magicNumber) {
            line.append(StringUtils.repeat(" ", magicNumber - line.length()));
        }

        line.append("-->").append(CRLF);

        writer.writeMarkup(line.toString());
    }