You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ha...@apache.org on 2008/10/27 20:14:15 UTC
svn commit: r708280 - in
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter:
ExporterActionListener.java ExporterActionListenerTag.java
util/ExcelExporterUtil.java util/ExporterUtil.java util/PDFExporterUtil.java
Author: hazems
Date: Mon Oct 27 12:13:52 2008
New Revision: 708280
URL: http://svn.apache.org/viewvc?rev=708280&view=rev
Log:
Preparing the exportActionListener to move from Tomahawk sandbox to MyFaces Commons.
https://issues.apache.org/jira/browse/TOMAHAWK-1364
Removed:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExporterUtil.java
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListener.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListenerTag.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExcelExporterUtil.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/PDFExporterUtil.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListener.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListener.java?rev=708280&r1=708279&r2=708280&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListener.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListener.java Mon Oct 27 12:13:52 2008
@@ -26,7 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.custom.datascroller.HtmlDataScroller;
+import org.apache.myfaces.component.html.ext.HtmlDataTable;
import org.apache.myfaces.custom.exporter.util.ExcelExporterUtil;
import org.apache.myfaces.custom.exporter.util.ExporterConstants;
import org.apache.myfaces.custom.exporter.util.PDFExporterUtil;
@@ -47,16 +47,12 @@
public static final String FOR_KEY = "for";
- public static final String SHOWDISPLAYEDPAGEONLY_KEY = "showDisplayedPageOnly";
-
private String _fileType;
private String _fileName;
private String _for;
- private String _showDisplayedPageOnly;
-
public void processAction(ActionEvent event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -68,26 +64,18 @@
else {
try {
- /* get the source dataScroller component */
- HtmlDataScroller dataScroller = (HtmlDataScroller) ComponentUtils
+ /* get the source dataTable component */
+ HtmlDataTable dataTable = (HtmlDataTable) ComponentUtils
.findComponentById(facesContext, facesContext
.getViewRoot(), _for);
- if (!(dataScroller instanceof HtmlDataScroller))
+ if (!(dataTable instanceof HtmlDataTable))
{
throw new RuntimeException(
"exporterActionListener for attribute should contain a "
- + "dataScroller component id");
+ + "dataTable component id");
}
- /*
- * By default if the showDisplayedPageOnly is not specified, then the
- * default is false.
- */
- if (_showDisplayedPageOnly == null)
- {
- _showDisplayedPageOnly = "false";
- }
if (ExporterConstants.EXCEL_FILE_TYPE
.equalsIgnoreCase(_fileType))
@@ -96,7 +84,6 @@
/*
* Excel case. Generate the XLS to the response stream.
*/
-
Object contextResponse = facesContext.getExternalContext()
.getResponse();
@@ -104,8 +91,7 @@
{
ExcelExporterUtil.generateEXCEL(facesContext,
(HttpServletResponse) contextResponse,
- _fileName, dataScroller, Boolean
- .parseBoolean(_showDisplayedPageOnly));
+ _fileName, dataTable);
}
}
@@ -120,8 +106,7 @@
PDFExporterUtil.generatePDF(facesContext, httpResponse,
- _fileName, dataScroller, Boolean
- .parseBoolean(_showDisplayedPageOnly));
+ _fileName, dataTable);
}
/* save the seralized view and complete the response. */
@@ -162,14 +147,6 @@
public void setFor(String _for) {
this._for = _for;
}
-
- public String getShowDisplayedPageOnly() {
- return _showDisplayedPageOnly;
- }
-
- public void setShowDisplayedPageOnly(String showDisplayedPageOnly) {
- _showDisplayedPageOnly = showDisplayedPageOnly;
- }
public void restoreState(FacesContext context, Object state) {
String values[] = (String[]) state;
@@ -177,16 +154,14 @@
_for = values[0];
_fileName = values[1];
_fileType = values[2];
- _showDisplayedPageOnly = values[3];
}
public Object saveState(FacesContext context) {
- String values[] = new String[4];
+ String values[] = new String[3];
values[0] = _for;
values[1] = _fileName;
values[2] = _fileType;
- values[3] = _showDisplayedPageOnly;
return ((String[]) values);
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListenerTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListenerTag.java?rev=708280&r1=708279&r2=708280&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListenerTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/ExporterActionListenerTag.java Mon Oct 27 12:13:52 2008
@@ -40,7 +40,6 @@
private String _fileType;
private String _fileName;
private String _for;
- private String _showDisplayedPageOnly;
public int doStartTag() throws JspException {
@@ -77,7 +76,6 @@
exporterActionListener.setFor(_for);
exporterActionListener.setFileType(_fileType);
exporterActionListener.setFilename(_fileName);
- exporterActionListener.setShowDisplayedPageOnly(_showDisplayedPageOnly);
((ActionSource) component)
.addActionListener(exporterActionListener);
@@ -97,7 +95,6 @@
_fileType = null;
_fileName = null;
_for = null;
- _showDisplayedPageOnly = null;
}
public String getFilename() {
@@ -138,18 +135,4 @@
public void setFor(String _for) {
this._for = _for;
}
-
- public String getShowDisplayedPageOnly() {
- return _showDisplayedPageOnly;
- }
-
- /**
- * This attribute determines whether to generate only the current displayed dataTable page to the file.
- *
- * @JSFJspAttribute
- */
- public void setShowDisplayedPageOnly(String showDisplayedPageOnly) {
- _showDisplayedPageOnly = showDisplayedPageOnly;
- }
-
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExcelExporterUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExcelExporterUtil.java?rev=708280&r1=708279&r2=708280&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExcelExporterUtil.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/ExcelExporterUtil.java Mon Oct 27 12:13:52 2008
@@ -29,7 +29,6 @@
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
-import org.apache.myfaces.custom.datascroller.HtmlDataScroller;
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
@@ -76,34 +75,17 @@
* This method is used for adding the columns values to the HSSFSheet.
*/
private static void generateTableContent(FacesContext facesContext,
- HSSFSheet sheet, List columns, HtmlDataScroller dataScroller,
- boolean selectedPage) {
-
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
+ HSSFSheet sheet, List columns, HtmlDataTable dataTable) {
int numberOfColumns = columns.size();
- int numberOfRows = dataScroller.getRowCount();
+ int numberOfRows = dataTable.getRowCount();
int startFrom = 0;
- int currentIndex = 0;
- int endAt = numberOfRows;
-
- /* if the current page is selected only, then generate only in the report */
- if (selectedPage)
- {
- startFrom = (dataScroller.getPageIndex() - 1) * dataScroller.getRows();
- endAt = startFrom + dataScroller.getRows();
-
- if(endAt > numberOfRows)
- {
- endAt = numberOfRows;
- }
-
- }
+ int currentIndex = 1;
+ int endAt = numberOfRows;
/* fill the table with the data. */
for (int i = startFrom; i < endAt; ++i) {
- tomahawkDataTable.setRowIndex(i);
+ dataTable.setRowIndex(i);
HSSFRow row = sheet.createRow(currentIndex++);
for (int j = 0; j < numberOfColumns; ++j) {
UIColumn column = (UIColumn) columns.get(j);
@@ -141,21 +123,17 @@
* @return the (HSSFWorkbook) object.
*/
private static HSSFWorkbook generateExcelTableModel(
- FacesContext facesContext, HtmlDataScroller dataScroller,
- boolean selectedPage) {
+ FacesContext facesContext, HtmlDataTable dataTable) {
- HSSFWorkbook workbook = new HSSFWorkbook();
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
- HSSFSheet sheet = workbook.createSheet(tomahawkDataTable.getId());
- List columns = getColumns(tomahawkDataTable);
- int currentRowIndex = tomahawkDataTable.getRowIndex();
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet(dataTable.getId());
+ List columns = getColumns(dataTable);
+ int currentRowIndex = dataTable.getRowIndex();
addColumnHeaders(sheet, columns);
- generateTableContent(facesContext, sheet, columns, dataScroller,
- selectedPage);
+ generateTableContent(facesContext, sheet, columns, dataTable);
- tomahawkDataTable.setRowIndex(currentRowIndex);
+ dataTable.setRowIndex(currentRowIndex);
return workbook;
}
@@ -168,42 +146,22 @@
* @throws IOException
*/
public static void generateEXCEL(FacesContext facesContext,
- HttpServletResponse response, String fileName,
- HtmlDataScroller dataScroller, boolean selectedPage)
+ HttpServletResponse response, String fileName, HtmlDataTable dataTable)
throws IOException {
- /* get the dataScroller dataTable object */
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
-
/*
* By default if the fileName is not specified, then use the
* table id.
*/
if (fileName == null)
{
- fileName = tomahawkDataTable.getId();
+ fileName = dataTable.getId();
}
/* generate the excel model */
HSSFWorkbook generatedExcel = ExcelExporterUtil
- .generateExcelTableModel(facesContext, dataScroller,
- selectedPage);
+ .generateExcelTableModel(facesContext, dataTable);
writeExcelToResponse(response, generatedExcel, fileName);
}
-
-
-// public static void generateEXCEL(HSSFWorkbook workBook,
-// RenderResponse response, String filename) throws IOException {
-// response.setContentType("application/vnd.ms-excel");
-// response.setProperty(RenderResponse.EXPIRATION_CACHE, "0");
-// response.setProperty("Cache-Control",
-// "must-revalidate, post-check=0, pre-check=0");
-// response.setProperty("Pragma", "public");
-// response.setProperty("Content-disposition", "attachment;filename="
-// + filename + ".xls");
-//
-// workBook.write(response.getPortletOutputStream());
-// }
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/PDFExporterUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/PDFExporterUtil.java?rev=708280&r1=708279&r2=708280&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/PDFExporterUtil.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/exporter/util/PDFExporterUtil.java Mon Oct 27 12:13:52 2008
@@ -30,7 +30,6 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
-import org.apache.myfaces.custom.datascroller.HtmlDataScroller;
import org.apache.myfaces.custom.util.ComponentUtils;
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
@@ -91,34 +90,16 @@
* This method is used for adding the columns values to the pdfTable.
*/
private static void generateTableContent(FacesContext facesContext,
- PdfPTable pdfTable, List columns, HtmlDataScroller dataScroller,
- boolean selectedPage) {
+ PdfPTable pdfTable, List columns, HtmlDataTable dataTable) {
int numberOfColumns = columns.size();
- int numberOfRows = dataScroller.getRowCount();
+ int numberOfRows = dataTable.getRowCount();
int startFrom = 0;
int endAt = numberOfRows;
-
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
-
-
- /* if the current page is selected only, then generate only in the report */
- if (selectedPage)
- {
- startFrom = (dataScroller.getPageIndex() - 1) * dataScroller.getRows();
- endAt = startFrom + dataScroller.getRows();
-
- if(endAt > numberOfRows)
- {
- endAt = numberOfRows;
- }
-
- }
/* fill the table with the data. */
for (int i = startFrom; i < endAt; ++i) {
- tomahawkDataTable.setRowIndex(i);
+ dataTable.setRowIndex(i);
for (int j = 0; j < numberOfColumns; ++j) {
UIComponent valueHolder = (UIComponent) ((UIColumn) columns
.get(j)).getChildren().get(0);
@@ -135,18 +116,15 @@
* This method is used for creating the PDFTable model.
*/
public static PdfPTable generatePDFTableModel(FacesContext facesContext,
- HtmlDataScroller dataScroller, boolean selectedPage) {
+ HtmlDataTable dataTable) {
int numberOfColumns;
List columns = null;
PdfPTable pdfTable = null;
- /* get the parent dataTable component */
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
/* getting the HTMLDataTable Columns */
- columns = ComponentUtils.getHTMLDataTableColumns(tomahawkDataTable);
+ columns = ComponentUtils.getHTMLDataTableColumns(dataTable);
if (columns.size() == 0) {
return null;
@@ -161,7 +139,7 @@
generateTableHeader(pdfTable, columns);
generateTableContent(facesContext, pdfTable, columns,
- dataScroller, selectedPage);
+ dataTable);
return pdfTable;
}
@@ -171,21 +149,17 @@
* @param facesContext
* @param response
* @param fileName
- * @param dataScroller
+ * @param dataTable
*/
public static void generatePDF(FacesContext facesContext,
HttpServletResponse response, String fileName,
- HtmlDataScroller dataScroller, boolean selectedPage) throws Exception {
+ HtmlDataTable dataTable) throws Exception {
int currentRowIndex;
Document document = new Document();
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
PdfWriter.getInstance(document, byteArrayStream);
PdfPTable pdfTable = null;
-
- /* get the parent dataTable component */
- HtmlDataTable tomahawkDataTable = ExporterUtil
- .getDataTableFromDataScroller(facesContext, dataScroller);
/*
* By default if the fileName is not specified, then use the
@@ -193,13 +167,13 @@
*/
if (fileName == null)
{
- fileName = tomahawkDataTable.getId();
+ fileName = dataTable.getId();
}
- currentRowIndex = tomahawkDataTable.getRowIndex();
+ currentRowIndex = dataTable.getRowIndex();
// generate the PDF table model.
- pdfTable = generatePDFTableModel(facesContext, dataScroller, selectedPage);
+ pdfTable = generatePDFTableModel(facesContext, dataTable);
// open the document and write the generated PDF.
document.open();
@@ -209,7 +183,7 @@
// write the response headers.
setPDFResponseHeaders(response, byteArrayStream, fileName);
- tomahawkDataTable.setRowIndex(currentRowIndex);
+ dataTable.setRowIndex(currentRowIndex);
}
}