public void traverse()

in doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java [1966:2090]


        public void traverse() throws AptParseException {
            int captionIndex = -1;
            int nextLineIndex = 0;
            int init = 2;
            int[] justification = null;
            int rows = 0;
            int columns = 0;
            StringBuilder[] cells = null;
            boolean[] headers = null;
            boolean grid;

            AptParser.this.sink.table();

            while (nextLineIndex < textLength) {
                int i = text.indexOf("*--", nextLineIndex);
                if (i < 0) {
                    captionIndex = nextLineIndex;
                    break;
                }

                String line;
                i = text.indexOf('\n', nextLineIndex);
                if (i < 0) {
                    line = text.substring(nextLineIndex);
                    nextLineIndex = textLength;
                } else {
                    line = text.substring(nextLineIndex, i);
                    nextLineIndex = i + 1;
                }
                int lineLength = line.length();

                if (line.indexOf("*--") == 0) {
                    if (init == 2) {
                        init = 1;
                        justification = parseJustification(line, lineLength);
                        columns = justification.length;
                        cells = new StringBuilder[columns];
                        headers = new boolean[columns];
                        for (i = 0; i < columns; ++i) {
                            cells[i] = new StringBuilder();
                            headers[i] = false;
                        }
                    } else {
                        if (traverseRow(cells, headers, justification)) {
                            ++rows;
                        }
                        justification = parseJustification(line, lineLength);
                    }
                } else {
                    if (init == 1) {
                        init = 0;
                        grid = (AptParser.charAt(line, lineLength, 0) == PIPE);
                        AptParser.this.sink.tableRows(justification, grid);
                    }

                    line = replaceAll(line, "\\|", "\\u007C");

                    StringTokenizer cellLines = new StringTokenizer(line, "|", true);

                    i = 0;
                    boolean processedGrid = false;
                    while (cellLines.hasMoreTokens()) {
                        String cellLine = cellLines.nextToken();
                        if ("|".equals(cellLine)) {
                            if (processedGrid) {
                                headers[i] = true;
                            } else {
                                processedGrid = true;
                                headers[i] = false;
                            }
                            continue;
                        }
                        processedGrid = false;
                        cellLine = replaceAll(cellLine, "\\", "\\u00A0"); // linebreak
                        // Escaped special characters: \~, \=, \-, \+, \*, \[, \], \<, \>, \{, \}, \\.
                        cellLine = replaceAll(cellLine, "\\u00A0~", "\\~");
                        cellLine = replaceAll(cellLine, "\\u00A0=", "\\=");
                        cellLine = replaceAll(cellLine, "\\u00A0-", "\\-");
                        cellLine = replaceAll(cellLine, "\\u00A0+", "\\+");
                        cellLine = replaceAll(cellLine, "\\u00A0*", "\\*");
                        cellLine = replaceAll(cellLine, "\\u00A0[", "\\[");
                        cellLine = replaceAll(cellLine, "\\u00A0]", "\\]");
                        cellLine = replaceAll(cellLine, "\\u00A0<", "\\<");
                        cellLine = replaceAll(cellLine, "\\u00A0>", "\\>");
                        cellLine = replaceAll(cellLine, "\\u00A0{", "\\{");
                        cellLine = replaceAll(cellLine, "\\u00A0}", "\\}");
                        cellLine = replaceAll(cellLine, "\\u00A0u", "\\u");
                        cellLine = replaceAll(cellLine, "\\u00A0\\u00A0", "\\\\");
                        cellLine = cellLine.trim();

                        StringBuilder cell = cells[i];
                        if (cellLine.length() > 0) {
                            // line break in table cells
                            if (cell.toString().trim().endsWith("\\u00A0")) {
                                cell.append("\\\n");
                            } else {
                                if (cell.length() != 0) {
                                    // Always add a space for multi line tables cells
                                    cell.append(" ");
                                }
                            }

                            cell.append(cellLine);
                        }

                        ++i;
                        if (i == columns) {
                            break;
                        }
                    }
                }
            }
            if (rows == 0) {
                throw new AptParseException("no table rows");
            }
            AptParser.this.sink.tableRows_();

            if (captionIndex >= 0) {
                AptParser.this.sink.tableCaption();
                AptParser.this.doTraverseText(text, captionIndex, textLength, AptParser.this.sink);
                AptParser.this.sink.tableCaption_();
            }

            AptParser.this.sink.table_();
        }