⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlproducer.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        writer.print(cssRef.getReference());
        if (isGenerateXHTML())
        {
          writer.println(" />");
        }
        else
        {
          writer.println(">");
        }
      }
      else
      {
        writer.println("<style type=\"text/css\">");
        writer.print(cssRef.getReference());
        writer.println("</style>");
      }
      writer.flush();

      // now copy all cached content into the root stream
      pout.flush();
      pout.close();
      final byte[] data = content.toByteArray();
      content.close();
      content = null;
      pout = null;

      final InflaterInputStream infIn
          = new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(data)));
      final InputStreamReader inReader = new InputStreamReader(infIn);

      IOUtils.getInstance().copyWriter(inReader, writer);

      inReader.close();
      writer.flush();
      filesystem.close();
    }
    catch (IOException ioe)
    {
      throw new FunctionProcessingException("Failed to write", ioe);
    }

    isOpen = false;
  }

  /**
   * End the page and generate the table for the page.
   */
  public void endPage()
  {
    if (isDummy() == false)
    {
      generatePage(layoutGrid());
    }
    pout.println("</table></p>");
    clearCells();
  }

  /**
   * Start a new page, start a new table.
   *
   * @param name the page name
   */
  public void beginPage(final String name)
  {
    if (name != null)
    {
      pout.println(isGenerateXHTML() ? "<hr />" : "<hr>");
      pout.println("<h3>");
      pout.println(name);
      pout.println("</h3>");
      pout.println(isGenerateXHTML() ? "<hr />" : "<hr>");
    }
    pout.println("<p>");
    pout.println("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
    //pout.println("<table border=\"2\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">");
  }

  /**
   * Gets the TableProducer implementation of this TableProducer.
   *
   * @return the TableProducers TableCellDataFactory, which is used to create
   * the TableCellData.
   */
  public TableCellDataFactory getCellDataFactory()
  {
    return cellDataFactory;
  }

  /**
   * Returns true, if the TableProducer is open. Only open producers
   * are able to write TableCells or to create TableCellData from Elements.
   *
   * @return checks, whether the TableProducer is open.
   */
  public boolean isOpen()
  {
    return isOpen;
  }

  /**
   * Merges the backgrounds and creates the StyleSheet information for
   * the cell background.
   *
   * @param background the (unmerged) background styles.
   * @return the background style sheet definition.
   */
  protected String createHtmlBackgroundStyle(final List background)
  {
    final TableCellBackground bg = createTableCellStyle(background);
    if (bg == null)
    {
      return null;
    }
    return styleCollection.getBackgroundStyle(bg);
  }

  /**
   * Generates and writes the HTML table specified by the given TableGridLayout.
   *
   * @param layout the layouted cells.
   */
  private void generatePage(final TableGridLayout layout)
  {
    pout.println();

    for (int y = 0; y < layout.getHeight(); y++)
    {
      final int lastRowHeight = layout.getRowEnd(y) - layout.getRowStart(y);

      pout.println("<tr style=\"height:" + lastRowHeight + "pt\">");
//      boolean printed = false;
      for (int x = 0; x < layout.getWidth(); x++)
      {
        final TableGridLayout.Element gridElement = layout.getData(x, y);
        // no element defined for the given cell...
        if (gridElement == null)
        {
          final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
          pout.println("<!-- No Element -->");
          pout.println("<td style=\"width:" + width + "pt\"></td>");
//          printed = true;
          continue;
        }

        // no data cell defined, but there exists a background defintion
        // for that cell.
        final TableGridPosition gridPosition = gridElement.getRoot();
        if (gridPosition == null || gridPosition.isInvalidCell())
        {
          final int width = layout.getColumnEnd(x) - layout.getColumnStart(x);
          if (gridPosition == null)
          {
            pout.println("<!-- gridposition is null -->");
          }
          else
          {
            pout.println("<!-- is invalid cell -->");
          }

          pout.print("<td style=\"width:");
          pout.print(width);
          pout.print("pt");

          final String style = createHtmlBackgroundStyle(gridElement.getBackground());
          if (style != null)
          {
            pout.print("; ");
            pout.print(style);
          }
          pout.println("\"></td>");
//          printed = true;
          continue;
        }

        // a spanned field
        if (gridPosition.isOrigin(x, y) == false)
        {
          // this is a spanned field.
          continue;
        }

        // real data ...
        final HtmlCellData cellData = (HtmlCellData) gridPosition.getElement();

        pout.print("    <td style=\"width:");
        pout.print((int) gridPosition.getBounds().getWidth());
        pout.print("pt");
        pout.print("; height:");
        pout.print((int) gridPosition.getBounds().getHeight());
        pout.print("pt");
        final String style = createHtmlBackgroundStyle(gridElement.getBackground());
        if (style != null)
        {
          pout.print("; ");
          pout.print(style);
        }
        pout.print("\" ");

        if (gridPosition.getRowSpan() > 1)
        {
          pout.print(" rowspan=\"");
          pout.print(gridPosition.getRowSpan());
          pout.print("\"");
        }
        if (gridPosition.getColSpan() > 1)
        {
          pout.print(" colspan=\"");
          pout.print(gridPosition.getColSpan());
          pout.print("\"");
        }
        pout.print(">");

        if (styleCollection.isRegistered(cellData.getStyle()))
        {
          // stylesheet defined in the header
          pout.print("<div class=\"");
          pout.print(styleCollection.lookupName(cellData.getStyle()));
          pout.print("\">");
        }
        else
        {
          // stylesheet defined as inline style
          pout.print("<div style=\"");
          pout.print(styleCollection.createStyleSheetDefinition(cellData.getStyle()));
          pout.print("\">");
        }

        cellData.write(pout, filesystem);

        pout.print("</div>");
        pout.println("</td>");

        x += gridPosition.getColSpan() - 1;
//        printed = true;
      }
/*
      if (!printed)
      {
        //Log.debug ("The Row at " + y + " was not printed");
      }
*/
      pout.println("</tr>");
    }
  }

  /**
   * Configures the table producer by reading the configuration settings from
   * the given map.
   *
   * @param configuration the configuration supplied by the table processor.
   */
  public void configure(final Properties configuration)
  {
    super.configure(configuration);
    this.cellDataFactory = new HtmlCellDataFactory(styleCollection, isGenerateXHTML());
  }

  protected boolean isGenerateXHTML ()
  {
    return getProperty(GENERATE_XHTML, "false").equals("true");
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -