[seam-commits] Seam SVN: r8636 - in trunk: examples/excel/resources/WEB-INF and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Aug 8 09:34:18 EDT 2008
Author: danielc.roth
Date: 2008-08-08 09:34:18 -0400 (Fri, 08 Aug 2008)
New Revision: 8636
Modified:
trunk/examples/excel/build.xml
trunk/examples/excel/resources/WEB-INF/components.xml
trunk/examples/excel/src/org/jboss/seam/excel/ExcelTest.java
trunk/examples/excel/view/home.xhtml
trunk/src/excel/org/jboss/seam/excel/ExcelFactory.java
trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
trunk/src/excel/org/jboss/seam/excel/excel-2.1.xsd
trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
Log:
JBSEAM-3241
Modified: trunk/examples/excel/build.xml
===================================================================
--- trunk/examples/excel/build.xml 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/examples/excel/build.xml 2008-08-08 13:34:18 UTC (rev 8636)
@@ -6,7 +6,7 @@
<property name="example.name" value="jboss-seam-excel"/>
<!-- Libraries -->
- <property name="seam.ui.lib" value="yes"/>
+ <property name="seam.ui.lib" value="yes"/>
<property name="seam.excel.lib" value="yes"/>
<property name="seam.debug.lib" value="yes"/>
<property name="facelets.lib" value="yes"/>
Modified: trunk/examples/excel/resources/WEB-INF/components.xml
===================================================================
--- trunk/examples/excel/resources/WEB-INF/components.xml 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/examples/excel/resources/WEB-INF/components.xml 2008-08-08 13:34:18 UTC (rev 8636)
@@ -1,14 +1,19 @@
-<components xmlns="http://jboss.com/products/seam/components"
- xmlns:pdf="http://jboss.com/products/seam/pdf"
- xmlns:core="http://jboss.com/products/seam/core"
- xmlns:framework="http://jboss.com/products/seam/framework"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
+<components xmlns="http://jboss.com/products/seam/components" xmlns:excel="http://jboss.com/products/seam/excel"
+ xmlns:core="http://jboss.com/products/seam/core" xmlns:framework="http://jboss.com/products/seam/framework"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.1.xsd
- http://jboss.com/products/seam/pdf http://jboss.com/products/seam/pdf-2.1.xsd
+ http://jboss.com/products/seam/excel http://jboss.com/products/seam/excel-2.1.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
- <core:init debug="true" jndi-pattern="@jndiPattern@" />
+ <core:init debug="true" jndi-pattern="@jndiPattern@" />
+ <!-- Just a sample of how you may register own ExcelWorkbooks -->
+ <excel:excelFactory>
+ <property name="implementations">
+ <key>jxl</key><value>org.jboss.seam.excel.jxl.JXLExcelWorkbook</value>
+ </property>
+ </excel:excelFactory>
+
</components>
Modified: trunk/examples/excel/src/org/jboss/seam/excel/ExcelTest.java
===================================================================
--- trunk/examples/excel/src/org/jboss/seam/excel/ExcelTest.java 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/examples/excel/src/org/jboss/seam/excel/ExcelTest.java 2008-08-08 13:34:18 UTC (rev 8636)
@@ -3,14 +3,19 @@
import java.util.LinkedList;
import java.util.List;
+import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
@Name("excelTest")
+ at Scope(ScopeType.SESSION)
public class ExcelTest
{
+ private List<Person> people = new LinkedList<Person>();
+
public List<Person> getPeople()
{
List<Person> ret = new LinkedList<Person>();
@@ -21,6 +26,19 @@
return ret;
}
+
+ public List<Person> getResult()
+ {
+ return people;
+ }
+
+ public void search() {
+ this.people = getPeople();
+ }
+
+ public void clear() {
+ this.people = new LinkedList<Person>();
+ }
public class Person
{
Modified: trunk/examples/excel/view/home.xhtml
===================================================================
--- trunk/examples/excel/view/home.xhtml 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/examples/excel/view/home.xhtml 2008-08-08 13:34:18 UTC (rev 8636)
@@ -1,50 +1,52 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:e="http://jboss.com/products/seam/excel"
- xmlns:s="http://jboss.com/products/seam/taglib">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-<title>Microsoft® Excel® Export examples</title>
-<link href="css/screen.css" rel="stylesheet" type="text/css" />
-</head>
-<body id="excelHome">
-<f:view>
-
- <h:outputText value="Microsoft® Excel® Export examples"
- style="header"></h:outputText>
- <br />
- <br />
-
- <h:outputLink value="jxl.seam">
- <h:outputText>Export as Excel® spreadsheet</h:outputText>
- </h:outputLink>
- <br />
-
- <h:outputLink value="jxl.seam">
- <h:outputText>Export as comma separated file</h:outputText>
- </h:outputLink>
- <br />
- <br />
-
- <h:form id="excelExport">
- <h:dataTable value="#{excelTest.people}" var="person" id="excelTable"
- columnClasses="left, right">
- <h:column>
- <f:facet name="header">Name</f:facet>
- <h:outputText value="#{person.name} #{person.lastName}"></h:outputText>
- </h:column>
- <h:column>
- <f:facet name="header">Age</f:facet>
- <h:outputText value="#{person.age}"></h:outputText>
- </h:column>
- </h:dataTable>
- <h:commandLink value="Export table"
- action="#{org.jboss.seam.excel.excelExporter.export('excelExport:excelTable')}" />
- </h:form>
-
-</f:view>
-</body>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:a4j="http://richfaces.org/a4j" xmlns:f="http://java.sun.com/jsf/core" xmlns:e="http://jboss.com/products/seam/excel"
+ xmlns:s="http://jboss.com/products/seam/taglib" xmlns:rich="http://richfaces.ajax4jsf.org/rich">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>Microsoft® Excel® Export examples</title>
+<link href="css/screen.css" rel="stylesheet" type="text/css" />
+</head>
+<body id="excelHome">
+<f:view>
+
+ <h:outputText value="Microsoft® Excel® Export examples" style="header"></h:outputText>
+ <br />
+ <br />
+
+ <h:outputLink value="jxl.seam">
+ <h:outputText>Export as Excel® spreadsheet</h:outputText>
+ </h:outputLink>
+ <br />
+
+ <h:outputLink value="jxl.seam">
+ <h:outputText>Export as comma separated file</h:outputText>
+ </h:outputLink>
+ <br />
+ <br />
+
+ <h:form id="excelExport">
+ <a4j:commandButton value="Search" reRender="searchResults" action="#{excelTest.search}" />
+ <a4j:commandButton value="Clear" reRender="searchResults" action="#{excelTest.clear}" />
+
+
+ <a4j:outputPanel id="searchResults">
+
+ <rich:dataTable value="#{excelTest.result}" var="person" id="excelTable" columnClasses="left, right">
+ <rich:column>
+ <f:facet name="header">Name</f:facet>
+ <h:outputText value="#{person.name} #{person.lastName}"></h:outputText>
+ </rich:column>
+ <rich:column>
+ <f:facet name="header">Age</f:facet>
+ <h:outputText value="#{person.age}"></h:outputText>
+ </rich:column>
+ </rich:dataTable>
+ <h:commandLink value="Export table" action="#{org.jboss.seam.excel.excelExporter.export('excelExport:excelTable')}" />
+
+ </a4j:outputPanel>
+ </h:form>
+
+</f:view>
+</body>
</html>
\ No newline at end of file
Modified: trunk/src/excel/org/jboss/seam/excel/ExcelFactory.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ExcelFactory.java 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/src/excel/org/jboss/seam/excel/ExcelFactory.java 2008-08-08 13:34:18 UTC (rev 8636)
@@ -1,23 +1,36 @@
package org.jboss.seam.excel;
+import java.util.HashMap;
+import java.util.Map;
+
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.core.Interpolator;
+import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.excel.csv.CsvExcelWorkbook;
+import org.jboss.seam.excel.jxl.JXLExcelWorkbook;
+import org.jboss.seam.util.Strings;
@Name("org.jboss.seam.excel.excelFactory")
@Scope(ScopeType.STATELESS)
@AutoCreate
+ at BypassInterceptors
public class ExcelFactory
{
- public final static String DEFAULT_IMPL = "jxl";
- public final static String DEFAULT_NS = "org.jboss.seam.excel";
+ private static Map<String, Class<? extends ExcelWorkbook>> defaultImplementations;
- private String namespace;
+ private Map<String, Class> implementations;
+ static
+ {
+ defaultImplementations = new HashMap<String, Class<? extends ExcelWorkbook>>();
+ defaultImplementations.put("csv", CsvExcelWorkbook.class);
+ defaultImplementations.put("jxl", JXLExcelWorkbook.class);
+ }
+
public static ExcelFactory instance()
{
return (ExcelFactory) Component.getInstance(ExcelFactory.class);
@@ -26,29 +39,50 @@
public ExcelWorkbook getExcelWorkbook(String type)
{
- String namespace = DEFAULT_NS;
- String impl = DEFAULT_IMPL;
+ Class<? extends ExcelWorkbook> clazz;
- namespace = this.namespace != null ? this.namespace : DEFAULT_NS;
- impl = !"".equals(type) ? type : DEFAULT_IMPL;
+ ExcelWorkbook excelWorkbook;
- ExcelWorkbook excelWorkbook = (ExcelWorkbook) Component.getInstance(namespace + "." + impl);
- if (excelWorkbook == null)
+ if (Strings.isEmpty(type))
{
- throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not create excel workbook with namespace '#0' and type #1", namespace, type));
+ type = "jxl";
}
+
+ if (implementations != null && implementations.get(type) != null)
+ {
+ clazz = implementations.get(type);
+ }
+ else
+ {
+ clazz = defaultImplementations.get(type);
+ }
+
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("Unable to create workbook of type " + type);
+ }
+
+ try
+ {
+ excelWorkbook = clazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("The class provided could not be instanciated " + type, e);
+ }
+
return excelWorkbook;
}
- public String getNamespace()
+ public Map<String, Class> getImplementations()
{
- return namespace;
+ return implementations;
}
- public void setNamespace(String namespace)
+ public void setImplementations(Map<String, Class> implementations)
{
- this.namespace = namespace;
+ this.implementations = implementations;
}
-}
+}
\ No newline at end of file
Modified: trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java 2008-08-08 13:34:18 UTC (rev 8636)
@@ -5,33 +5,26 @@
import java.util.Map;
import java.util.TreeMap;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.excel.Command;
import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentData.DocumentType;
+import org.jboss.seam.excel.Command;
import org.jboss.seam.excel.ExcelWorkbook;
import org.jboss.seam.excel.ExcelWorkbookException;
import org.jboss.seam.excel.Template;
import org.jboss.seam.excel.WorksheetItem;
-import org.jboss.seam.document.DocumentData.DocumentType;
import org.jboss.seam.excel.ui.UICell;
import org.jboss.seam.excel.ui.UIColumn;
import org.jboss.seam.excel.ui.UIImage;
import org.jboss.seam.excel.ui.UIWorkbook;
import org.jboss.seam.excel.ui.UIWorksheet;
-/*
- * 10 minute (quite poor) implementation of csv excel workbook...
- * Perhaps better would be to use some kind of.
+/**
+ * 10 minute (quite poor) implementation of csv excel workbook... Perhaps better
+ * would be to use some kind of library for this.
*
* Use at own risk.. :)
- *
+ *
*/
- at Name("org.jboss.seam.excel.csv")
- at Scope(ScopeType.EVENT)
- at BypassInterceptors
public class CsvExcelWorkbook implements ExcelWorkbook
{
int column = 0;
@@ -140,22 +133,18 @@
public void addTemplate(Template template)
{
- // TODO Auto-generated method stub
}
public void applyWorksheetSettings(UIWorksheet uiWorksheet)
{
- // TODO Auto-generated method stub
}
public void applyColumnSettings(UIColumn uiColumn)
{
- // TODO Auto-generated method stub
}
public void executeCommand(Command command)
{
- // TODO Auto-generated method stub
}
}
Modified: trunk/src/excel/org/jboss/seam/excel/excel-2.1.xsd
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/excel-2.1.xsd 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/src/excel/org/jboss/seam/excel/excel-2.1.xsd 2008-08-08 13:34:18 UTC (rev 8636)
@@ -1,53 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified"
- targetNamespace="http://jboss.com/products/seam/excel"
- xmlns:excel="http://jboss.com/products/seam/excel"
- xmlns:components="http://jboss.com/products/seam/components"
- attributeFormDefault="unqualified">
- <xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="components-2.1.xsd"/>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:doc="http://jboss.com/products/seam/document" xmlns:excel="http://jboss.com/products/seam/excel"
+ xmlns:components="http://jboss.com/products/seam/components" targetNamespace="http://jboss.com/products/seam/document" elementFormDefault="qualified"
+ attributeFormDefault="unqualified">
- <xs:element name="document-store">
- <xs:annotation>
- <xs:documentation>
- The Excel document store is used to store rendered documents for download on a later request.
- </xs:documentation>
- </xs:annotation>
- <xs:complexType mixed="true">
- <xs:attributeGroup ref="components:attlist.component"/>
- <xs:attributeGroup ref="excel:attlist.docstore"/>
- </xs:complexType>
- </xs:element>
- <xs:attributeGroup name="attlist.docstore">
- <xs:attribute name="error-page" type="components:string">
- <xs:annotation>
- <xs:documentation>
- When a document had expired or otherwise cannot be loaded, this page is displayed.
- </xs:documentation>
- </xs:annotation>
- </xs:attribute>
- <xs:attribute name="use-extensions" type="components:boolean">
- <xs:annotation>
- <xs:documentation>
- Controls whether or not the URLs for documents should contain their correct file name extensions.
- Using file name extensions requires additional configuration in web.xml.
- </xs:documentation>
- </xs:annotation>
- </xs:attribute>
- </xs:attributeGroup>
+ <xs:import namespace="http://jboss.com/products/seam/components" schemaLocation="components-2.1.xsd" />
- <xs:element name="excel-factory">
- <xs:annotation>
- <xs:documentation>
- Factory creating excel workbook instances
- </xs:documentation>
- </xs:annotation>
- <xs:complexType mixed="true">
- <xs:attributeGroup ref="components:attlist.component"/>
- <xs:attributeGroup ref="excel:attlist.namespace"/>
- </xs:complexType>
- </xs:element>
- <xs:attributeGroup name="attlist.namespace">
- <xs:attribute name="namespace" type="components:string"/>
- </xs:attributeGroup>
+ <xs:element name="excel-factory">
+ <xs:annotation>
+ <xs:documentation>Factory creating excel workbook instances</xs:documentation>
+ </xs:annotation>
+ <xs:complexType mixed="true">
+ <xs:element name="implementations" type="components:mapProperty" />
+ </xs:complexType>
+ </xs:element>
+
+
+
</xs:schema>
Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java 2008-08-08 11:58:04 UTC (rev 8635)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java 2008-08-08 13:34:18 UTC (rev 8636)
@@ -20,18 +20,14 @@
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.core.Interpolator;
-import org.jboss.seam.excel.Command;
import org.jboss.seam.document.DocumentData;
+import org.jboss.seam.document.DocumentData.DocumentType;
+import org.jboss.seam.excel.Command;
import org.jboss.seam.excel.ExcelWorkbook;
import org.jboss.seam.excel.ExcelWorkbookException;
import org.jboss.seam.excel.Template;
import org.jboss.seam.excel.WorksheetItem;
-import org.jboss.seam.document.DocumentData.DocumentType;
import org.jboss.seam.excel.jxl.JXLTemplates.CellInfo;
import org.jboss.seam.excel.ui.UICell;
import org.jboss.seam.excel.ui.UIColumn;
@@ -54,9 +50,6 @@
* @author Daniel Roth (danielc.roth at gmail.com)
* @version 0.2
*/
- at Name("org.jboss.seam.excel.jxl")
- at Scope(ScopeType.EVENT)
- at BypassInterceptors
public class JXLExcelWorkbook implements ExcelWorkbook
{
private static final int CELL_DEFAULT_HEIGHT = 17;
More information about the seam-commits
mailing list