Пример #1
0
  /**
   * This method process the cells in a <code>Document</code> and generates a portion of the <code>
   * Document</code>.
   *
   * <p>This method assumes that records are sorted by row and then column.
   *
   * @param root The <code>Node</code> of the <code>Document</code> we are building that we will
   *     append our cell <code>Node</code> objects. This <code>Node</code> should be a TAG_TABLE
   *     tag.
   * @throws IOException If any I/O error occurs.
   */
  protected void processColumns(Node root) throws IOException {

    for (Iterator<ColumnRowInfo> e = decoder.getColumnRowInfos(); e.hasNext(); ) {

      ColumnRowInfo ci = e.next();
      if (ci.isColumn()) {
        ColumnStyle cStyle =
            new ColumnStyle(
                "Default",
                SxcConstants.COLUMN_STYLE_FAMILY,
                SxcConstants.DEFAULT_STYLE,
                ci.getSize(),
                null);

        Style result[] = styleCat.getMatching(cStyle);
        String styleName;
        if (result.length == 0) {

          cStyle.setName("co" + colStyles++);
          styleName = cStyle.getName();
          Debug.log(Debug.TRACE, "No existing style found, adding " + styleName);
          styleCat.add(cStyle);
        } else {
          ColumnStyle existingStyle = (ColumnStyle) result[0];
          styleName = existingStyle.getName();
          Debug.log(Debug.TRACE, "Existing style found : " + styleName);
        }

        // Create an element node for the new row
        Element colElement = doc.createElement(TAG_TABLE_COLUMN);
        colElement.setAttribute(ATTRIBUTE_TABLE_STYLE_NAME, styleName);
        if (ci.getRepeated() != 1) {
          String repeatStr = String.valueOf(ci.getRepeated());
          colElement.setAttribute(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED, repeatStr);
        }
        root.appendChild(colElement);
      }
    }
  }
Пример #2
0
  /**
   * This method traverses a <i>table:table-cell</i> element {@code Node}.
   *
   * @param node a <i>table:table-cell</i> {@code Node}.
   * @throws IOException if any I/O error occurs.
   */
  protected void traverseCell(Node node) throws IOException {

    NamedNodeMap cellAtt = node.getAttributes();

    fmt.clearFormatting();

    // Get the type of data in the cell
    Node tableValueTypeNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE_TYPE);

    // Get the number of columns this cell is repeated
    Node colsRepeatedNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);

    // Get the style type
    Node tableStyleNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_STYLE_NAME);

    String styleName = "";

    if (tableStyleNode != null) {
      styleName = tableStyleNode.getNodeValue();
    }

    CellStyle cStyle = null;

    if (styleName.equalsIgnoreCase("Default")) {

      Debug.log(Debug.TRACE, "No defined Style Attribute was found");

    } else if (styleName.length() != 0) {

      cStyle =
          (CellStyle)
              styleCat.lookup(
                  styleName, SxcConstants.TABLE_CELL_STYLE_FAMILY, null, CellStyle.class);
    }

    if (cStyle != null) {
      Format definedFormat = cStyle.getFormat();
      fmt = new Format(definedFormat);
    }

    // There is a number of cols repeated attribute
    if (colsRepeatedNode != null) {
      // Get the number of times the cell is repeated
      String colsRepeatedString = colsRepeatedNode.getNodeValue();
      colsRepeated = Integer.parseInt(colsRepeatedString);
    } else {
      // The cell is not repeated
      colsRepeated = 1;
    }

    // if there is no style we need to check to see if there is a default
    // cell style defined in the table-column's

    if (fmt.isDefault() && styleName.length() == 0) {
      int index = 1;
      for (Iterator<ColumnRowInfo> e = ColumnRowList.iterator(); e.hasNext(); ) {
        ColumnRowInfo cri = e.next();
        if (cri.isColumn()) {
          if (colID >= index && colID < (index + cri.getRepeated())) {
            fmt = new Format(cri.getFormat());
          }
          index += cri.getRepeated();
        }
      }
    }

    if (tableValueTypeNode != null) {

      String cellType = tableValueTypeNode.getNodeValue();

      if (cellType.equalsIgnoreCase(CELLTYPE_STRING)) {

        // has text:p tag
        fmt.setCategory(CELLTYPE_STRING);
        Node tableStringValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_STRING_VALUE);
        Debug.log(Debug.TRACE, "Cell Type String :  " + tableStringValueNode);
        if (tableStringValueNode != null) {
          fmt.setValue(tableStringValueNode.getNodeValue());
        }

      } else if (cellType.equalsIgnoreCase(CELLTYPE_FLOAT)) {

        // has table:value attribute
        // has text:p tag

        // Determine the number of decimal places StarCalc
        // is displaying for this floating point output.
        fmt.setCategory(CELLTYPE_FLOAT);
        fmt.setDecimalPlaces(getDecimalPlaces(node));
        Node tableValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE);
        fmt.setValue(tableValueNode.getNodeValue());

      } else if (cellType.equalsIgnoreCase(CELLTYPE_TIME)) {

        // has table:time-value attribute
        // has text:p tag - which is the value we convert

        fmt.setCategory(CELLTYPE_TIME);
        Node tableTimeNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_TIME_VALUE);
        fmt.setValue(tableTimeNode.getNodeValue());

      } else if (cellType.equalsIgnoreCase(CELLTYPE_DATE)) {

        // has table:date-value attribute
        // has text:p tag - which is the value we convert

        fmt.setCategory(CELLTYPE_DATE);
        Node tableDateNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_DATE_VALUE);
        fmt.setValue(tableDateNode.getNodeValue());

      } else if (cellType.equalsIgnoreCase(CELLTYPE_CURRENCY)) {

        // has table:currency
        // has table:value attribute
        // has text:p tag

        fmt.setCategory(CELLTYPE_CURRENCY);
        fmt.setDecimalPlaces(getDecimalPlaces(node));
        Node tableValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE);
        fmt.setValue(tableValueNode.getNodeValue());

      } else if (cellType.equalsIgnoreCase(CELLTYPE_BOOLEAN)) {

        // has table:boolean-value attribute
        // has text:p tag - which is the value we convert

        fmt.setCategory(CELLTYPE_BOOLEAN);
        Node tableBooleanNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_BOOLEAN_VALUE);
        fmt.setValue(tableBooleanNode.getNodeValue());

      } else if (cellType.equalsIgnoreCase(CELLTYPE_PERCENT)) {

        // has table:value attribute
        // has text:p tag

        fmt.setCategory(CELLTYPE_PERCENT);
        fmt.setDecimalPlaces(getDecimalPlaces(node));
        Node tableValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_VALUE);
        fmt.setValue(tableValueNode.getNodeValue());

      } else {

        Debug.log(Debug.TRACE, "No defined value type" + cellType);
        // Should never get here

      }
    }

    Node tableFormulaNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_FORMULA);

    if (tableFormulaNode != null) {
      if (tableValueTypeNode
          == null) { // If there is no value-type Node we must assume string-value
        fmt.setCategory(CELLTYPE_STRING);
        Node tableStringValueNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_STRING_VALUE);
        fmt.setValue(tableStringValueNode.getNodeValue());
      }
      String cellFormula = tableFormulaNode.getNodeValue();
      addCell(cellFormula);
    } else {

      // Text node, Date node, or Time node

      Debug.log(Debug.INFO, "TextNode, DateNode, TimeNode or BooleanNode\n");
      // This handles the case where we have style information but no content
      if (node.hasChildNodes()) {
        NodeList childList = node.getChildNodes();
        int len = childList.getLength();

        for (int i = 0; i < len; i++) {
          Node child = childList.item(i);
          if (child.getNodeType() == Node.ELEMENT_NODE) {
            String childName = child.getNodeName();
            if (childName.equals(TAG_PARAGRAPH)) {
              traverseParagraph(child);
            }
          }
        }
      } else if (!fmt.isDefault()) {
        addCell("");
      }
    }

    // Increase the column counter by the number of times the
    // last cell was repeated.
    colID += colsRepeated;

    // Re-initialize the number of columns repeated before processing
    // the next cell data.
    colsRepeated = 1;
  }