Exemplo n.º 1
0
  /**
   * Check to ensure that a docbook row has the required number of columns for a table.
   *
   * @param row The DOM row element to be checked.
   * @param numColumns The number of entry elements that should exist in the row.
   * @return True if the row has the required number of entries, otherwise false.
   */
  public static boolean validateTableRow(final Node row, final int numColumns) {
    assert row != null;
    assert row.getNodeName().equals("row") || row.getNodeName().equals("tr");

    if (row.getNodeName().equals("row")) {
      final List<Node> entries = XMLUtilities.getDirectChildNodes(row, "entry");
      final List<Node> entryTbls = XMLUtilities.getDirectChildNodes(row, "entrytbl");

      if ((entries.size() + entryTbls.size()) <= numColumns) {
        for (final Node entryTbl : entryTbls) {
          if (!validateEntryTbl((Element) entryTbl)) return false;
        }
        return true;
      } else {
        return false;
      }
    } else {
      final List<Node> nodes = XMLUtilities.getDirectChildNodes(row, "td", "th");

      return nodes.size() <= numColumns;
    }
  }
Exemplo n.º 2
0
  /**
   * Check to ensure that a Docbook tgroup isn't missing an row entries, using number of cols
   * defined for the tgroup.
   *
   * @param tgroup The DOM tgroup element to be checked.
   * @return True if the tgroup has the required number of entries, otherwise false.
   */
  public static boolean validateTableGroup(final Element tgroup) {
    assert tgroup != null;
    assert tgroup.getNodeName().equals("tgroup");

    final Integer numColumns = Integer.parseInt(tgroup.getAttribute("cols"));

    // Check that all the thead, tbody and tfoot elements have the correct number of entries.
    final List<Node> nodes = XMLUtilities.getDirectChildNodes(tgroup, "thead", "tbody", "tfoot");
    for (final Node ele : nodes) {
      // Find all child nodes that are a row
      final NodeList children = ele.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        final Node node = children.item(i);
        if (node.getNodeName().equals("row") || node.getNodeName().equals("tr")) {
          if (!validateTableRow(node, numColumns)) return false;
        }
      }
    }

    return true;
  }