示例#1
0
 /**
  * Transform the passed blocks to make them columns, that is insert them in an enclosing "div" (or
  * group) with the appropriate styles.
  *
  * @param blocks the blocks to transform. Presumably all column macro blocks.
  * @param columnWidth the relative width to give to each column.
  */
 private void makeColumns(List<MacroBlock> blocks, double columnWidth) {
   Iterator<MacroBlock> it = blocks.iterator();
   while (it.hasNext()) {
     MacroBlock probablyColumn = it.next();
     if (probablyColumn.getId().equals(ColumnMacro.MACRO_NAME)) {
       ColumnStyle style = new ColumnStyle();
       style.setWidth(columnWidth + "%");
       if (it.hasNext()) {
         style.setPaddingRight(COLUMN_RIGHT_PADDING_STYLE);
       }
       Map<String, String> params =
           Collections.singletonMap(PARAMETER_STYLE, style.getStyleAsString());
       Block colParent = new GroupBlock(new HashMap<String, String>(params));
       colParent.addChild(probablyColumn.clone());
       probablyColumn.getParent().replaceChild(colParent, probablyColumn);
     }
     // FIXME Should we cry and throw an exception if ever we meet something else than a column
     // macro right under
     // a section macro ?
   }
 }
示例#2
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);
      }
    }
  }
  /**
   * This method traverses the <i>table:table-column</i> {@code Node}.
   *
   * <p>Not yet implemented.
   *
   * @param node A <i>table:table-column</i> {@code Node}.
   * @throws IOException If any I/O error occurs.
   */
  protected void traverseTableColumn(Node node) throws IOException {

    Debug.log(Debug.TRACE, "traverseColumn() : ");
    NamedNodeMap cellAtt = node.getAttributes();
    Node tableStyleNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_STYLE_NAME);
    Node tableNumColRepeatingNode = cellAtt.getNamedItem(ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED);
    Node tableDefaultCellStyle = cellAtt.getNamedItem(ATTRIBUTE_DEFAULT_CELL_STYLE);

    int repeatedColumns = 1;
    int columnWidth = 0;
    ColumnRowInfo col = new ColumnRowInfo(ColumnRowInfo.COLUMN);

    if (tableNumColRepeatingNode != null) {
      Debug.log(
          Debug.TRACE,
          "traverseColumn() repeated-cols : " + tableNumColRepeatingNode.getNodeValue());
      repeatedColumns = Integer.parseInt(tableNumColRepeatingNode.getNodeValue());
      col.setRepeated(repeatedColumns);
    }

    String cellStyleName = "";

    if (tableDefaultCellStyle != null) {
      cellStyleName = tableDefaultCellStyle.getNodeValue();

      Debug.log(Debug.TRACE, "traverseColumn() default-cell-style : " + cellStyleName);
    }

    CellStyle cellStyle = null;

    if (cellStyleName.equalsIgnoreCase("Default") || cellStyleName.length() == 0) {

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

    } else {

      cellStyle =
          (CellStyle)
              styleCat.lookup(
                  cellStyleName, SxcConstants.TABLE_CELL_STYLE_FAMILY, null, CellStyle.class);
    }

    if (cellStyle != null) {
      Format defaultFmt = new Format(cellStyle.getFormat());
      col.setFormat(defaultFmt);
    }

    String styleName = "";

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

    if (styleName.equalsIgnoreCase("Default") || styleName.length() == 0) {

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

    } else {

      ColumnStyle cStyle =
          (ColumnStyle)
              styleCat.lookup(styleName, SxcConstants.COLUMN_STYLE_FAMILY, null, ColumnStyle.class);

      columnWidth = cStyle != null ? cStyle.getColWidth() : 0;
      col.setSize(columnWidth);
      Debug.log(Debug.TRACE, "traverseColumn() Column Width : " + columnWidth);
    }
    ColumnRowList.add(col);
  }