Seam SVN: r9436 - branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-27 10:26:15 -0400 (Mon, 27 Oct 2008)
New Revision: 9436
Modified:
branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
Log:
JBPAPP-1298
Modified: branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2008-10-27 13:58:40 UTC (rev 9435)
+++ branches/enterprise/JBPAPP_4_3_FP01/ui/src/main/java/org/jboss/seam/ui/renderkit/DecorateRendererBase.java 2008-10-27 14:26:15 UTC (rev 9436)
@@ -1,11 +1,14 @@
package org.jboss.seam.ui.renderkit;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.jboss.seam.contexts.Context;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.ui.component.UIDecorate;
import org.jboss.seam.ui.util.Decoration;
@@ -14,18 +17,58 @@
public class DecorateRendererBase extends RendererBase
{
-
+ // Place the attributes you want to store away
+ private Map<String, Object> originalValues = new HashMap<String, Object>();
+ // The list of attributes in the event scope to store away
+ String[] storeOriginals = new String[] {"invalid", "required"};
+
@Override
protected Class getComponentClass()
{
return UIDecorate.class;
}
+ /**
+ * Store away the attribute from the event context (if it is set)
+ *
+ * @param names The list of context keys to store away
+ * @param context The context to target
+ */
+ private void storeOriginalValues(String[] names, Context context)
+ {
+ for (String name : names)
+ {
+ if (context.isSet(name))
+ {
+ originalValues.put(name, context.get(name));
+ }
+ }
+ }
+
+ /**
+ * Restores the state of the event context. If the value is stored away, it is restored
+ * It it was not in the map, it was not in the context in the first place so clean
+ * up what we have placed there during this run.
+ *
+ * @param names The list of context keys to restore
+ */
+ private void restoreOriginalValues(String[] names, Context context) {
+ for (String name : names) {
+ if (originalValues.containsKey(name)) {
+ context.set(name, originalValues.get(name));
+ } else {
+ context.remove(name);
+ }
+ }
+ }
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException
{
UIDecorate decorate = (UIDecorate) component;
+ storeOriginalValues(storeOriginals, Contexts.getEventContext());
+
Contexts.getEventContext().set("invalid", Decoration.hasMessage(decorate, context));
Contexts.getEventContext().set("required", Decoration.hasRequired(component, context));
@@ -76,8 +119,7 @@
}
context.getResponseWriter().endElement("div");
- Contexts.getEventContext().remove("invalid");
- Contexts.getEventContext().remove("required");
+ restoreOriginalValues(storeOriginals, Contexts.getEventContext());
}
@Override
16 years, 1 month
Seam SVN: r9435 - branches/enterprise/JBPAPP_4_3_FP01/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-27 09:58:40 -0400 (Mon, 27 Oct 2008)
New Revision: 9435
Modified:
branches/enterprise/JBPAPP_4_3_FP01/doc/Seam_Reference_Guide/en-US/Events.xml
Log:
JBPAPP-1317
Modified: branches/enterprise/JBPAPP_4_3_FP01/doc/Seam_Reference_Guide/en-US/Events.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:53:01 UTC (rev 9434)
+++ branches/enterprise/JBPAPP_4_3_FP01/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:58:40 UTC (rev 9435)
@@ -1000,44 +1000,6 @@
also available, as <literal>org.jboss.seam.exception</literal>.
</para>
- <section>
- <title>Suppressing exception logging</title>
-
- <para>
- For the exception handlers defined in <literal>pages.xml</literal>, it is possible
- to declare the logging level at which the exception will be logged, or to even
- suppress the exception being logged altogether. The attributes <literal>log</literal>
- and <literal>logLevel</literal> can be used to control exception logging. By setting
- <literal>log="false"</literal> as per the following example, then no log message will
- be generated when the specified exception occurs:
- </para>
-
- <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" log="false">
- <redirect view-id="/register.xhtml">
- <message severity="warn">You must be a member to use this feature</message>
- </redirect>
- </exception>]]></programlisting>
-
- <para>
- If the <literal>log</literal> attribute is not specified, then it defaults to <literal>true</literal>
- (i.e. the exception will be logged). Alternatively, you can specify the <literal>logLevel</literal>
- to control at which log level the exception will be logged:
- </para>
-
- <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" logLevel="info">
- <redirect view-id="/register.xhtml">
- <message severity="warn">You must be a member to use this feature</message>
- </redirect>
- </exception>]]></programlisting>
-
- <para>
- The acceptable values for <literal>logLevel</literal> are: <literal>fatal, error, warn, info, debug</literal>
- or <literal>trace</literal>. If the <literal>logLevel</literal> is not specified, or if an invalid value is
- configured, then it will default to <literal>error</literal>.
- </para>
-
- </section>
-
</section>
<section>
16 years, 1 month
Seam SVN: r9434 - trunk/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-27 09:53:01 -0400 (Mon, 27 Oct 2008)
New Revision: 9434
Modified:
trunk/doc/Seam_Reference_Guide/en-US/Events.xml
Log:
mistake
Modified: trunk/doc/Seam_Reference_Guide/en-US/Events.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:41:08 UTC (rev 9433)
+++ trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:53:01 UTC (rev 9434)
@@ -1071,6 +1071,44 @@
also available, as <literal>org.jboss.seam.caughtException</literal>.
</para>
+ <section>
+ <title>Suppressing exception logging</title>
+
+ <para>
+ For the exception handlers defined in <literal>pages.xml</literal>, it is possible
+ to declare the logging level at which the exception will be logged, or to even
+ suppress the exception being logged altogether. The attributes <literal>log</literal>
+ and <literal>logLevel</literal> can be used to control exception logging. By setting
+ <literal>log="false"</literal> as per the following example, then no log message will
+ be generated when the specified exception occurs:
+ </para>
+
+ <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" log="false">
+ <redirect view-id="/register.xhtml">
+ <message severity="warn">You must be a member to use this feature</message>
+ </redirect>
+ </exception>]]></programlisting>
+
+ <para>
+ If the <literal>log</literal> attribute is not specified, then it defaults to <literal>true</literal>
+ (i.e. the exception will be logged). Alternatively, you can specify the <literal>logLevel</literal>
+ to control at which log level the exception will be logged:
+ </para>
+
+ <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" logLevel="info">
+ <redirect view-id="/register.xhtml">
+ <message severity="warn">You must be a member to use this feature</message>
+ </redirect>
+ </exception>]]></programlisting>
+
+ <para>
+ The acceptable values for <literal>logLevel</literal> are: <literal>fatal, error, warn, info, debug</literal>
+ or <literal>trace</literal>. If the <literal>logLevel</literal> is not specified, or if an invalid value is
+ configured, then it will default to <literal>error</literal>.
+ </para>
+
+ </section>
+
</section>
<section>
16 years, 1 month
Seam SVN: r9433 - trunk/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-27 09:41:08 -0400 (Mon, 27 Oct 2008)
New Revision: 9433
Modified:
trunk/doc/Seam_Reference_Guide/en-US/Events.xml
Log:
JBPAPP-1317
Modified: trunk/doc/Seam_Reference_Guide/en-US/Events.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:32:36 UTC (rev 9432)
+++ trunk/doc/Seam_Reference_Guide/en-US/Events.xml 2008-10-27 13:41:08 UTC (rev 9433)
@@ -1071,44 +1071,6 @@
also available, as <literal>org.jboss.seam.caughtException</literal>.
</para>
- <section>
- <title>Suppressing exception logging</title>
-
- <para>
- For the exception handlers defined in <literal>pages.xml</literal>, it is possible
- to declare the logging level at which the exception will be logged, or to even
- suppress the exception being logged altogether. The attributes <literal>log</literal>
- and <literal>logLevel</literal> can be used to control exception logging. By setting
- <literal>log="false"</literal> as per the following example, then no log message will
- be generated when the specified exception occurs:
- </para>
-
- <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" log="false">
- <redirect view-id="/register.xhtml">
- <message severity="warn">You must be a member to use this feature</message>
- </redirect>
- </exception>]]></programlisting>
-
- <para>
- If the <literal>log</literal> attribute is not specified, then it defaults to <literal>true</literal>
- (i.e. the exception will be logged). Alternatively, you can specify the <literal>logLevel</literal>
- to control at which log level the exception will be logged:
- </para>
-
- <programlisting role="XML"><![CDATA[ <exception class="org.jboss.seam.security.NotLoggedInException" logLevel="info">
- <redirect view-id="/register.xhtml">
- <message severity="warn">You must be a member to use this feature</message>
- </redirect>
- </exception>]]></programlisting>
-
- <para>
- The acceptable values for <literal>logLevel</literal> are: <literal>fatal, error, warn, info, debug</literal>
- or <literal>trace</literal>. If the <literal>logLevel</literal> is not specified, or if an invalid value is
- configured, then it will default to <literal>error</literal>.
- </para>
-
- </section>
-
</section>
<section>
16 years, 1 month
Seam SVN: r9432 - trunk/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-27 09:32:36 -0400 (Mon, 27 Oct 2008)
New Revision: 9432
Modified:
trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
Log:
minor. correcting the linestyle and color order in the border css shorthands.
Modified: trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Excel.xml 2008-10-27 12:10:54 UTC (rev 9431)
+++ trunk/doc/Seam_Reference_Guide/en-US/Excel.xml 2008-10-27 13:32:36 UTC (rev 9432)
@@ -2737,8 +2737,8 @@
</entry>
<entry valign="top">
<para>
- A shorthand for setting color and line style of the left edge
- of the cell, e.g style="xls-border-left: red thick"
+ A shorthand for setting line style and color of the left edge
+ of the cell, e.g style="xls-border-left: thick red"
</para>
</entry>
</row>
@@ -2779,7 +2779,7 @@
</entry>
<entry valign="top">
<para>
- A shorthand for setting color and line style of the top edge
+ A shorthand for setting line style and color of the top edge
of the cell, e.g style="xls-border-left: red thick"
</para>
</entry>
@@ -2821,8 +2821,8 @@
</entry>
<entry valign="top">
<para>
- A shorthand for setting color and line style of the right edge
- of the cell, e.g style="xls-border-right: red thick"
+ A shorthand for setting line style and color of the right edge
+ of the cell, e.g style="xls-border-right: thick red"
</para>
</entry>
</row>
@@ -2863,8 +2863,8 @@
</entry>
<entry valign="top">
<para>
- A shorthand for setting color and line style of the bottom edge
- of the cell, e.g style="xls-border-bottom: red thick"
+ A shorthand for setting line style and color of the bottom edge
+ of the cell, e.g style="xls-border-bottom: thick red"
</para>
</entry>
</row>
@@ -2874,8 +2874,8 @@
</entry>
<entry valign="top">
<para>
- A shorthand for setting color and line style all edges
- of the cell, e.g style="xls-border: red thick"
+ A shorthand for setting line style and color for all edges
+ of the cell, e.g style="xls-border: thick red"
</para>
</entry>
</row>
16 years, 1 month
Seam SVN: r9431 - trunk.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2008-10-27 08:10:54 -0400 (Mon, 27 Oct 2008)
New Revision: 9431
Modified:
trunk/release-process.txt
Log:
Minor correction in portlet bridge verification section.
Modified: trunk/release-process.txt
===================================================================
--- trunk/release-process.txt 2008-10-27 12:05:26 UTC (rev 9430)
+++ trunk/release-process.txt 2008-10-27 12:10:54 UTC (rev 9431)
@@ -366,7 +366,7 @@
for them to be removed as it is integrated with portal auth/>
* Upgrade the seam version in the seam portlet booking example
- download the src distribution of the PBR
- - edit the $PBR_SRC/examples/seam/booking/seamBookingPortlet/pom.xml file
+ - edit the $PBR_SRC/examples/seam/booking/pom.xml file
- adjust the seam version properties at the top of the file
- build the example by running "mvn install" in the $PBR_SRC/examples dir
- <NOTE: You need to remove the "javassist.jar" from both the EAR
16 years, 1 month
Seam SVN: r9430 - branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2008-10-27 08:05:26 -0400 (Mon, 27 Oct 2008)
New Revision: 9430
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java
Log:
JBPAPP-1301
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java 2008-10-27 02:07:29 UTC (rev 9429)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/main/org/jboss/seam/framework/Query.java 2008-10-27 12:05:26 UTC (rev 9430)
@@ -252,7 +252,7 @@
protected boolean isRestrictionParameterSet(Object parameterValue)
{
- return parameterValue != null && !"".equals(parameterValue) && parameterValue instanceof Collection ? !((Collection) parameterValue).isEmpty() : true;
+ return parameterValue != null && !"".equals(parameterValue) && ( parameterValue instanceof Collection ? !((Collection) parameterValue).isEmpty() : true );
}
16 years, 1 month
Seam SVN: r9429 - trunk/src/main/org/jboss/seam/security/permission.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2008-10-26 22:07:29 -0400 (Sun, 26 Oct 2008)
New Revision: 9429
Modified:
trunk/src/main/org/jboss/seam/security/permission/JpaPermissionStore.java
Log:
JBSEAM-3619
Modified: trunk/src/main/org/jboss/seam/security/permission/JpaPermissionStore.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/permission/JpaPermissionStore.java 2008-10-26 20:15:45 UTC (rev 9428)
+++ trunk/src/main/org/jboss/seam/security/permission/JpaPermissionStore.java 2008-10-27 02:07:29 UTC (rev 9429)
@@ -158,6 +158,15 @@
}
}
+ /**
+ * Creates a Query that returns a list of permission records for the specified parameters.
+ *
+ * @param target The target of the permission, may be null
+ * @param targets A set of permission targets, may be null
+ * @param recipient The permission recipient, may be null
+ * @param discrimination A discrimination (either user, role or both), required
+ * @return Query The query generated for the provided parameters
+ */
protected Query createPermissionQuery(Object target, Set targets, Principal recipient, Discrimination discrimination)
{
if (target != null && targets != null)
@@ -172,7 +181,8 @@
queryKey |= (discrimination.equals(Discrimination.role) ? 16 : 0);
queryKey |= (discrimination.equals(Discrimination.either) ? 32 : 0);
- boolean isRole = discrimination.equals(Discrimination.role) && rolePermissionClass != null;
+ boolean isRole = discrimination.equals(Discrimination.role);
+ boolean useRoleTable = isRole && rolePermissionClass != null;
if (!queryCache.containsKey(queryKey))
{
@@ -180,13 +190,13 @@
StringBuilder q = new StringBuilder();
q.append("select p from ");
- q.append(isRole ? rolePermissionClass.getName() : userPermissionClass.getName());
+ q.append(useRoleTable ? rolePermissionClass.getName() : userPermissionClass.getName());
q.append(" p");
if (target != null)
{
q.append(" where p.");
- q.append(isRole ? roleTargetProperty.getName() : targetProperty.getName());
+ q.append(useRoleTable ? roleTargetProperty.getName() : targetProperty.getName());
q.append(" = :target");
conditionsAdded = true;
}
@@ -194,7 +204,7 @@
if (targets != null)
{
q.append(" where p.");
- q.append(isRole ? roleTargetProperty.getName() : targetProperty.getName());
+ q.append(useRoleTable ? roleTargetProperty.getName() : targetProperty.getName());
q.append(" in (:targets)");
conditionsAdded = true;
}
@@ -369,8 +379,16 @@
Object instance = userPermissionClass.newInstance();
targetProperty.setValue(instance, identifierPolicy.getIdentifier(target));
actionProperty.setValue(instance, actionSet.toString());
- userProperty.setValue(instance, resolvePrincipalEntity(recipient));
+ if (recipientIsRole)
+ {
+ roleProperty.setValue(instance, resolvePrincipalEntity(recipient));
+ }
+ else
+ {
+ userProperty.setValue(instance, resolvePrincipalEntity(recipient));
+ }
+
if (discriminatorProperty.isSet())
{
PermissionDiscriminator discriminator = discriminatorProperty.getAnnotation();
16 years, 1 month
Seam SVN: r9428 - trunk/doc/Seam_Reference_Guide/en-US.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-26 16:15:45 -0400 (Sun, 26 Oct 2008)
New Revision: 9428
Modified:
trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
Log:
Minor. Remove references to some deleted tags.
Modified: trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Excel.xml 2008-10-26 20:10:03 UTC (rev 9427)
+++ trunk/doc/Seam_Reference_Guide/en-US/Excel.xml 2008-10-26 20:15:45 UTC (rev 9428)
@@ -1011,36 +1011,11 @@
<itemizedlist>
<listitem>
<para>
- <literal><e:font/></literal>
- —Zero or more font definitions (see
- <xref linkend="excel.cells.fonts" />
- ).
- </para>
- </listitem>
- <listitem>
- <para>
- <literal><e:border/></literal>
- —Zero or more border definitions (see
- <xref linkend="excel.cells.borders" />
- ).
- </para>
- </listitem>
- <listitem>
- <para>
- <literal><e:background/></literal>
- —Zero or more background definitions (see
- <xref linkend="excel.cells.backgrounds" />
- ).
- </para>
- </listitem>
- <listitem>
- <para>
Zero or more validation conditions (see
<xref linkend="excel.cells.validation" />
).
</para>
</listitem>
-
</itemizedlist>
<para>
<emphasis>Facets</emphasis>
16 years, 1 month
Seam SVN: r9427 - trunk/src/excel/org/jboss/seam/excel/jxl.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-26 16:10:03 -0400 (Sun, 26 Oct 2008)
New Revision: 9427
Modified:
trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
Log:
Minor. Local URLs now supported in template
Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java 2008-10-25 07:46:55 UTC (rev 9426)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java 2008-10-26 20:10:03 UTC (rev 9427)
@@ -50,671 +50,664 @@
* @author Nicklas Karlsson (nickarls(a)gmail.com)
* @author Daniel Roth (danielc.roth(a)gmail.com)
*/
-public class JXLExcelWorkbook implements ExcelWorkbook
-{
- private static final int CELL_DEFAULT_HEIGHT = 17;
- private static final int CELL_DEFAULT_WIDTH = 64;
+public class JXLExcelWorkbook implements ExcelWorkbook {
+ private static final int CELL_DEFAULT_HEIGHT = 17;
+ private static final int CELL_DEFAULT_WIDTH = 64;
- private Log log = Logging.getLog(getClass());
+ private Log log = Logging.getLog(getClass());
- // The maximum number of columns allowed by the Excel specification
- private static final int MAX_COLUMNS = 255;
+ // The maximum number of columns allowed by the Excel specification
+ private static final int MAX_COLUMNS = 255;
- // The maximum number of columns allowed by the Excel specification. This
- // will be worked around in future versions of this class by automatically
- // creating new sheets
- private static final int MAX_ROWS = 65535;
+ // The maximum number of columns allowed by the Excel specification. This
+ // will be worked around in future versions of this class by automatically
+ // creating new sheets
+ private static final int MAX_ROWS = 65535;
- // The default worksheet naming base
- private static final String DEFAULT_WORKSHEET_NAME = "Sheet{0}";
+ // The default worksheet naming base
+ private static final String DEFAULT_WORKSHEET_NAME = "Sheet{0}";
- // The temporary array of data which represents the binary worksheet. This
- // will be passed on to the DocumentStore
- private ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ // The temporary array of data which represents the binary worksheet. This
+ // will be passed on to the DocumentStore
+ private ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
- // The JExcelAPI abstraction of a workbook. There will only be one per
- // instance of this class
- private WritableWorkbook workbook;
+ // The JExcelAPI abstraction of a workbook. There will only be one per
+ // instance of this class
+ private WritableWorkbook workbook;
- // The JExcelAPI abstraction of a worksheet. This also represents the current
- // worksheet begin worked on
- private WritableSheet worksheet;
+ // The JExcelAPI abstraction of a worksheet. This also represents the
+ // current
+ // worksheet begin worked on
+ private WritableSheet worksheet;
- // The row index to start from. Used for placing a data block at another
- // location than the default top-left (0, 0)
- private int startRowIndex = 0;
+ // The row index to start from. Used for placing a data block at another
+ // location than the default top-left (0, 0)
+ private int startRowIndex = 0;
- // The current index of the row being worked on (the row where the next cell
- // will be added)
- private int currentRowIndex = 0;
+ // The current index of the row being worked on (the row where the next cell
+ // will be added)
+ private int currentRowIndex = 0;
- // The column index to start from. Used for placing a data block at another
- // location than the default top-left (0, 0)
- private int startColumnIndex = 0;
+ // The column index to start from. Used for placing a data block at another
+ // location than the default top-left (0, 0)
+ private int startColumnIndex = 0;
- // The current index of the column being worked on (the column where the next
- // cell will be added)
- private int currentColumnIndex = 0;
+ // The current index of the column being worked on (the column where the
+ // next
+ // cell will be added)
+ private int currentColumnIndex = 0;
- /*
- * The current index of the worksheet being worked on. It's not that
- * important right now (we are moving forward linearly, but later when be
- * support worksheets with more that 65k rows we have to keep track on where
- * we are because starting with the next column could mean jumping back
- * several worksheets. For this we will also require some sort of low- and
- * high-indexes for the current worksheet when we add support for multiple
- * user-defined worksheets in the workbook.
- */
- private int currentWorksheetIndex = 0;
+ /*
+ * The current index of the worksheet being worked on. It's not that
+ * important right now (we are moving forward linearly, but later when be
+ * support worksheets with more that 65k rows we have to keep track on where
+ * we are because starting with the next column could mean jumping back
+ * several worksheets. For this we will also require some sort of low- and
+ * high-indexes for the current worksheet when we add support for multiple
+ * user-defined worksheets in the workbook.
+ */
+ private int currentWorksheetIndex = 0;
- /**
- * The maximum row index we have seen. Used for determining where to place
- * the worksheet footer (if any)
- */
- private int maxRowIndex;
+ /**
+ * The maximum row index we have seen. Used for determining where to place
+ * the worksheet footer (if any)
+ */
+ private int maxRowIndex;
- private JXLHelper jxlHelper = new JXLHelper();
+ private JXLHelper jxlHelper = new JXLHelper();
- /**
- * Moves the row pointer to the next row. Used internally when adding data
- *
- */
- private void nextRow()
- {
- if (log.isTraceEnabled())
- {
- log.trace("Moving from row #0 to #1", currentRowIndex, currentRowIndex + 1);
- }
- currentRowIndex++;
- if (currentRowIndex >= MAX_ROWS)
- {
- throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel only supports {0} rows", MAX_COLUMNS));
- }
- }
+ /**
+ * Moves the row pointer to the next row. Used internally when adding data
+ *
+ */
+ private void nextRow() {
+ if (log.isTraceEnabled()) {
+ log.trace("Moving from row #0 to #1", currentRowIndex,
+ currentRowIndex + 1);
+ }
+ currentRowIndex++;
+ if (currentRowIndex >= MAX_ROWS) {
+ throw new ExcelWorkbookException(Interpolator.instance()
+ .interpolate("Excel only supports {0} rows", MAX_COLUMNS));
+ }
+ }
- /**
- * Moves the internal column pointer to the next column, called by the tag to
- * indicate that a new column has been started. If the pointer exceeds the
- * maximum allowed, throws an exception. Resets the styles and row indexes
- * etc.
- *
- */
- public void nextColumn()
- {
- if (log.isTraceEnabled())
- {
- log.trace("Moving from column #0 to #1", currentColumnIndex, currentColumnIndex + 1);
- }
- currentColumnIndex++;
- if (currentColumnIndex > MAX_COLUMNS)
- {
- throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel doesn't support more than {0} columns", MAX_COLUMNS));
- }
- if (currentRowIndex > maxRowIndex)
- {
- maxRowIndex = currentRowIndex;
- }
- currentRowIndex = startRowIndex;
- }
+ /**
+ * Moves the internal column pointer to the next column, called by the tag
+ * to indicate that a new column has been started. If the pointer exceeds
+ * the maximum allowed, throws an exception. Resets the styles and row
+ * indexes etc.
+ *
+ */
+ public void nextColumn() {
+ if (log.isTraceEnabled()) {
+ log.trace("Moving from column #0 to #1", currentColumnIndex,
+ currentColumnIndex + 1);
+ }
+ currentColumnIndex++;
+ if (currentColumnIndex > MAX_COLUMNS) {
+ throw new ExcelWorkbookException(Interpolator.instance()
+ .interpolate("Excel doesn't support more than {0} columns",
+ MAX_COLUMNS));
+ }
+ if (currentRowIndex > maxRowIndex) {
+ maxRowIndex = currentRowIndex;
+ }
+ currentRowIndex = startRowIndex;
+ }
- /**
- * Checks if the workbook contains a sheet
- *
- * @param name The name to look for
- * @return true if found, false otherwise
- */
- private boolean workbookContainsSheet(String name)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Checking if workbook contains sheet named #0", name);
- }
- if (workbook == null)
- {
- throw new ExcelWorkbookException("Can't search for sheets before creating a workbook");
- }
- boolean found = false;
- for (String sheetName : workbook.getSheetNames())
- {
- if (sheetName.equalsIgnoreCase(name))
- {
- return true;
- }
- }
- if (log.isTraceEnabled())
- {
- log.trace("Result: #0", found);
- }
- return found;
- }
+ /**
+ * Checks if the workbook contains a sheet
+ *
+ * @param name
+ * The name to look for
+ * @return true if found, false otherwise
+ */
+ private boolean workbookContainsSheet(String name) {
+ if (log.isTraceEnabled()) {
+ log.trace("Checking if workbook contains sheet named #0", name);
+ }
+ if (workbook == null) {
+ throw new ExcelWorkbookException(
+ "Can't search for sheets before creating a workbook");
+ }
+ boolean found = false;
+ for (String sheetName : workbook.getSheetNames()) {
+ if (sheetName.equalsIgnoreCase(name)) {
+ return true;
+ }
+ }
+ if (log.isTraceEnabled()) {
+ log.trace("Result: #0", found);
+ }
+ return found;
+ }
- /**
- * Creates a new worksheet (or selects one if it exists) in the workbook.
- * Will require a rework for auto-renaming when support for auto-adding of
- * new worksheets if there are more than 65k rows. Resets the internal state
- * (row- and column indexes, current styles etc)
- *
- * @param uiWorksheet The worksheet to create or select in the workbook
- */
- public void createOrSelectWorksheet(UIWorksheet uiWorksheet)
- {
- if (workbook == null)
- {
- throw new ExcelWorkbookException("You cannot create a worksheet before creating a workbook");
- }
- if (log.isDebugEnabled())
- {
- log.debug("Creating worksheet named #0 starting at column #1 and row #2", uiWorksheet.getName(), uiWorksheet.getStartColumn(), uiWorksheet.getStartRow());
- }
- if (workbookContainsSheet(uiWorksheet.getName()))
- {
- if (log.isTraceEnabled())
- {
- log.trace("Sheet found, selecting");
- }
- worksheet = workbook.getSheet(uiWorksheet.getName());
- }
- else
- {
- if (log.isTraceEnabled())
- {
- log.trace("Sheet not found, creating");
- }
- String name = uiWorksheet.getName() != null ? uiWorksheet.getName() : Interpolator.instance().interpolate(DEFAULT_WORKSHEET_NAME, currentWorksheetIndex + 1);
- worksheet = workbook.createSheet(name, currentWorksheetIndex);
- }
+ /**
+ * Creates a new worksheet (or selects one if it exists) in the workbook.
+ * Will require a rework for auto-renaming when support for auto-adding of
+ * new worksheets if there are more than 65k rows. Resets the internal state
+ * (row- and column indexes, current styles etc)
+ *
+ * @param uiWorksheet
+ * The worksheet to create or select in the workbook
+ */
+ public void createOrSelectWorksheet(UIWorksheet uiWorksheet) {
+ if (workbook == null) {
+ throw new ExcelWorkbookException(
+ "You cannot create a worksheet before creating a workbook");
+ }
+ if (log.isDebugEnabled()) {
+ log
+ .debug(
+ "Creating worksheet named #0 starting at column #1 and row #2",
+ uiWorksheet.getName(),
+ uiWorksheet.getStartColumn(), uiWorksheet
+ .getStartRow());
+ }
+ if (workbookContainsSheet(uiWorksheet.getName())) {
+ if (log.isTraceEnabled()) {
+ log.trace("Sheet found, selecting");
+ }
+ worksheet = workbook.getSheet(uiWorksheet.getName());
+ } else {
+ if (log.isTraceEnabled()) {
+ log.trace("Sheet not found, creating");
+ }
+ String name = uiWorksheet.getName() != null ? uiWorksheet.getName()
+ : Interpolator.instance().interpolate(
+ DEFAULT_WORKSHEET_NAME, currentWorksheetIndex + 1);
+ worksheet = workbook.createSheet(name, currentWorksheetIndex);
+ }
- jxlHelper.applyWorksheetSettings(worksheet, uiWorksheet);
- currentWorksheetIndex++;
- startColumnIndex = uiWorksheet.getStartColumn() == null ? 0 : uiWorksheet.getStartColumn();
- currentColumnIndex = startColumnIndex;
- startRowIndex = uiWorksheet.getStartRow() == null ? 0 : uiWorksheet.getStartRow();
- currentRowIndex = startRowIndex;
- maxRowIndex = currentRowIndex;
- }
+ jxlHelper.applyWorksheetSettings(worksheet, uiWorksheet);
+ currentWorksheetIndex++;
+ startColumnIndex = uiWorksheet.getStartColumn() == null ? 0
+ : uiWorksheet.getStartColumn();
+ currentColumnIndex = startColumnIndex;
+ startRowIndex = uiWorksheet.getStartRow() == null ? 0 : uiWorksheet
+ .getStartRow();
+ currentRowIndex = startRowIndex;
+ maxRowIndex = currentRowIndex;
+ }
- /**
- * Creates and adds a data cell to the worksheet using the data cell format.
- * If the cell format is null, initializes the cell format. Finally moves the
- * internal pointer to the next row.
- *
- * @param uiCell The cell to be created and added to the workbook
- * @param the type (header or data) of the cell
- */
- private void addCell(UICell uiCell)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Adding a cell with data #1 at column #2 and row #3", uiCell.getValue(), currentColumnIndex, currentRowIndex);
- }
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't add cells before creating worksheet");
- }
+ /**
+ * Creates and adds a data cell to the worksheet using the data cell format.
+ * If the cell format is null, initializes the cell format. Finally moves
+ * the internal pointer to the next row.
+ *
+ * @param uiCell
+ * The cell to be created and added to the workbook
+ * @param the
+ * type (header or data) of the cell
+ */
+ private void addCell(UICell uiCell) {
+ if (log.isTraceEnabled()) {
+ log.trace("Adding a cell with data #1 at column #2 and row #3",
+ uiCell.getValue(), currentColumnIndex, currentRowIndex);
+ }
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't add cells before creating worksheet");
+ }
- Object value = uiCell.getValue();
- // If value is null, just increment row counter (not for explicitly placed
- // single cells) and return;
- if (value == null)
- {
- if (uiCell.getColumn() == null && uiCell.getRow() == null)
- {
- nextRow();
- }
- return;
- }
+ Object value = uiCell.getValue();
+ // If value is null, just increment row counter (not for explicitly
+ // placed
+ // single cells) and return;
+ if (value == null) {
+ if (uiCell.getColumn() == null && uiCell.getRow() == null) {
+ nextRow();
+ }
+ return;
+ }
- // Determine where to really place the cell
- int useRow = uiCell.getRow() != null ? uiCell.getRow() : currentRowIndex;
- int useColumn = uiCell.getColumn() != null ? uiCell.getColumn() : currentColumnIndex;
+ // Determine where to really place the cell
+ int useRow = uiCell.getRow() != null ? uiCell.getRow()
+ : currentRowIndex;
+ int useColumn = uiCell.getColumn() != null ? uiCell.getColumn()
+ : currentColumnIndex;
- CellInfo cellInfo = jxlHelper.getCellInfo(uiCell);
- WritableCell cell = JXLHelper.createCell(useColumn, useRow, cellInfo.getCellType(), uiCell.getValue(), cellInfo.getCellFormat());
- if (cellInfo.getCellFeatures() != null)
- {
- cell.setCellFeatures(cellInfo.getCellFeatures());
- }
- try
- {
- worksheet.addCell(cell);
- }
- catch (WriteException e)
- {
- throw new ExcelWorkbookException("Could not add cell", e);
- }
- // Only increase row if cell had no explicit placing
- if (uiCell.getColumn() == null && uiCell.getRow() == null)
- {
- nextRow();
- }
- }
+ CellInfo cellInfo = jxlHelper.getCellInfo(uiCell);
+ WritableCell cell = JXLHelper.createCell(useColumn, useRow, cellInfo
+ .getCellType(), uiCell.getValue(), cellInfo.getCellFormat());
+ if (cellInfo.getCellFeatures() != null) {
+ cell.setCellFeatures(cellInfo.getCellFeatures());
+ }
+ try {
+ worksheet.addCell(cell);
+ } catch (WriteException e) {
+ throw new ExcelWorkbookException("Could not add cell", e);
+ }
+ // Only increase row if cell had no explicit placing
+ if (uiCell.getColumn() == null && uiCell.getRow() == null) {
+ nextRow();
+ }
+ }
- /**
- * Returns the binary data from the internal representation of the workbook
- *
- * @return the data
- * @throws ExcelWorkbookException If there is a problem producing the binary
- * data
- */
- public byte[] getBytes()
- {
- if (log.isTraceEnabled())
- {
- log.trace("Returning bytes from workbook");
- }
- if (workbook == null)
- {
- throw new ExcelWorkbookException("You can't get workbook data before creating a workbook");
- }
- // You will get an IndexOutOfBoundException if trying to write a workbook
- // without sheets,
- // creating a dummy. Could also throw an exception...
- if (workbook.getSheets().length == 0)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Creating dummy sheet");
- }
- workbook.createSheet("dummy", 0);
- }
- try
- {
- workbook.write();
- workbook.close();
- }
- catch (WriteException e)
- {
- throw new ExcelWorkbookException("There was an exception writing the workbook", e);
- }
- catch (IOException e)
- {
- throw new ExcelWorkbookException("There was an exception closing the workbook", e);
- }
- return byteStream.toByteArray();
- }
+ /**
+ * Returns the binary data from the internal representation of the workbook
+ *
+ * @return the data
+ * @throws ExcelWorkbookException
+ * If there is a problem producing the binary data
+ */
+ public byte[] getBytes() {
+ if (log.isTraceEnabled()) {
+ log.trace("Returning bytes from workbook");
+ }
+ if (workbook == null) {
+ throw new ExcelWorkbookException(
+ "You can't get workbook data before creating a workbook");
+ }
+ // You will get an IndexOutOfBoundException if trying to write a
+ // workbook
+ // without sheets,
+ // creating a dummy. Could also throw an exception...
+ if (workbook.getSheets().length == 0) {
+ if (log.isTraceEnabled()) {
+ log.trace("Creating dummy sheet");
+ }
+ workbook.createSheet("dummy", 0);
+ }
+ try {
+ workbook.write();
+ workbook.close();
+ } catch (WriteException e) {
+ throw new ExcelWorkbookException(
+ "There was an exception writing the workbook", e);
+ } catch (IOException e) {
+ throw new ExcelWorkbookException(
+ "There was an exception closing the workbook", e);
+ }
+ return byteStream.toByteArray();
+ }
- /**
- * Intitializes a new workbook. Must be called first. Not that pretty but the
- * API has different constructors for all permutations of workbook settings
- * and template usage
- *
- * @param uiWorkbook UIn Workbook to create
- * @throws ExcelWorkbookException if there were any errors creating the
- * workbook
- */
- public void createWorkbook(UIWorkbook uiWorkbook)
- {
- InputStream templateStream = null;
- if (uiWorkbook.getTemplateURI() != null)
- {
- try
- {
- templateStream = new URI(uiWorkbook.getTemplateURI()).toURL().openStream();
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not handle template URI", e);
- }
- }
- WorkbookSettings workbookSettings = null;
- if (uiWorkbook.hasSettings())
- {
- workbookSettings = jxlHelper.createWorkbookSettings(uiWorkbook);
- }
- if (log.isDebugEnabled())
- {
- log.debug("Creating workbook with creation type #0", uiWorkbook.getCreationType());
- }
- // The joys of multiple constructors and no setters...
- try
- {
- switch (uiWorkbook.getCreationType())
- {
- case WITH_SETTNGS_AND_TEMPLATE:
- workbook = Workbook.createWorkbook(byteStream, Workbook.getWorkbook(templateStream), workbookSettings);
- break;
- case WITH_SETTINGS_WITHOUT_TEMPLATE:
- workbook = Workbook.createWorkbook(byteStream, workbookSettings);
- break;
- case WITHOUT_SETTINGS_WITH_TEMPLATE:
- workbook = Workbook.createWorkbook(byteStream, Workbook.getWorkbook(templateStream));
- break;
- case WITHOUT_SETTINGS_OR_TEMPLATE:
- workbook = Workbook.createWorkbook(byteStream);
- break;
- }
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not create workbook", e);
- }
- if (uiWorkbook.getWorkbookProtected() != null)
- {
- workbook.setProtected(uiWorkbook.getWorkbookProtected());
- }
- currentWorksheetIndex = workbook.getNumberOfSheets();
- }
+ /**
+ * Intitializes a new workbook. Must be called first. Not that pretty but
+ * the API has different constructors for all permutations of workbook
+ * settings and template usage
+ *
+ * @param uiWorkbook
+ * UIn Workbook to create
+ * @throws ExcelWorkbookException
+ * if there were any errors creating the workbook
+ */
+ public void createWorkbook(UIWorkbook uiWorkbook) {
+ String urlString = uiWorkbook.getTemplateURI();
+ InputStream templateStream = null;
+ if (urlString != null) {
+ try {
+ if (urlString.indexOf("://") < 0) {
+ templateStream = getClass().getResourceAsStream(urlString);
+ } else {
+ templateStream = new URL(urlString).openStream();
+ }
+ } catch (Exception e) {
+ throw new ExcelWorkbookException(
+ "Could not handle template URI", e);
+ }
+ }
+ WorkbookSettings workbookSettings = null;
+ if (uiWorkbook.hasSettings()) {
+ workbookSettings = jxlHelper.createWorkbookSettings(uiWorkbook);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Creating workbook with creation type #0", uiWorkbook
+ .getCreationType());
+ }
+ // The joys of multiple constructors and no setters...
+ try {
+ switch (uiWorkbook.getCreationType()) {
+ case WITH_SETTNGS_AND_TEMPLATE:
+ workbook = Workbook.createWorkbook(byteStream, Workbook
+ .getWorkbook(templateStream), workbookSettings);
+ break;
+ case WITH_SETTINGS_WITHOUT_TEMPLATE:
+ workbook = Workbook
+ .createWorkbook(byteStream, workbookSettings);
+ break;
+ case WITHOUT_SETTINGS_WITH_TEMPLATE:
+ workbook = Workbook.createWorkbook(byteStream, Workbook
+ .getWorkbook(templateStream));
+ break;
+ case WITHOUT_SETTINGS_OR_TEMPLATE:
+ workbook = Workbook.createWorkbook(byteStream);
+ break;
+ }
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not create workbook", e);
+ }
+ if (uiWorkbook.getWorkbookProtected() != null) {
+ workbook.setProtected(uiWorkbook.getWorkbookProtected());
+ }
+ currentWorksheetIndex = workbook.getNumberOfSheets();
+ }
- /**
- * Gets the document type of the data for the DocumentStore
- *
- * @return the document type (Excel workbook)
- */
- public DocumentType getDocumentType()
- {
- return new DocumentData.DocumentType("xls", "application/vnd.ms-excel");
- }
+ /**
+ * Gets the document type of the data for the DocumentStore
+ *
+ * @return the document type (Excel workbook)
+ */
+ public DocumentType getDocumentType() {
+ return new DocumentData.DocumentType("xls", "application/vnd.ms-excel");
+ }
- /**
- * Applies column settings for the current column
- *
- * @param uiColumn the UI column to inspect for settings
- */
- public void applyColumnSettings(UIColumn uiColumn)
- {
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("You can't set column settings before creating a worksheet");
- }
- jxlHelper.applyColumnSettings(uiColumn, worksheet, currentColumnIndex);
- }
+ /**
+ * Applies column settings for the current column
+ *
+ * @param uiColumn
+ * the UI column to inspect for settings
+ */
+ public void applyColumnSettings(UIColumn uiColumn) {
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "You can't set column settings before creating a worksheet");
+ }
+ jxlHelper.applyColumnSettings(uiColumn, worksheet, currentColumnIndex);
+ }
- /**
- * Adds an image to the worksheet. First converts it to PNG since it's what
- * the library wants. If starting rows or columns are given, uses them,
- * otherwise uses the current indexes. If column- and rowspannings are given,
- * uses them, otherwise tries to determine them from the image dimensions and
- * default cell dimensions.
- *
- * @param uiImage The image to add
- */
- private void addImage(UIImage uiImage)
- {
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't add an image before creating a worksheet");
- }
+ /**
+ * Adds an image to the worksheet. First converts it to PNG since it's what
+ * the library wants. If starting rows or columns are given, uses them,
+ * otherwise uses the current indexes. If column- and rowspannings are
+ * given, uses them, otherwise tries to determine them from the image
+ * dimensions and default cell dimensions.
+ *
+ * @param uiImage
+ * The image to add
+ */
+ private void addImage(UIImage uiImage) {
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't add an image before creating a worksheet");
+ }
- BufferedImage image = null;
- ByteArrayOutputStream pngStream = null;
- try
- {
- image = ImageIO.read(new URI(uiImage.getURI()).toURL());
- pngStream = new ByteArrayOutputStream();
- ImageIO.write(image, "PNG", pngStream);
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not load or process image", e);
- }
+ BufferedImage image = null;
+ ByteArrayOutputStream pngStream = null;
+ try {
+ image = ImageIO.read(new URI(uiImage.getURI()).toURL());
+ pngStream = new ByteArrayOutputStream();
+ ImageIO.write(image, "PNG", pngStream);
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not load or process image",
+ e);
+ }
- int useStartColumn = uiImage.getStartColumn() == null ? currentColumnIndex : uiImage.getStartRow();
- int useStartRow = uiImage.getStartRow() == null ? currentRowIndex : uiImage.getStartRow();
- double estimatedRowSpan = (double)image.getHeight() / (double)CELL_DEFAULT_HEIGHT;
- double estimatedColSpan = (double)image.getWidth() / (double)CELL_DEFAULT_WIDTH;
- double useColumnSpan = uiImage.getColumnSpan() == null ? estimatedRowSpan : uiImage.getColumnSpan();
- double useRowSpan = uiImage.getRowSpan() == null ? estimatedColSpan : uiImage.getRowSpan();
+ int useStartColumn = uiImage.getStartColumn() == null ? currentColumnIndex
+ : uiImage.getStartRow();
+ int useStartRow = uiImage.getStartRow() == null ? currentRowIndex
+ : uiImage.getStartRow();
+ double estimatedRowSpan = (double) image.getHeight()
+ / (double) CELL_DEFAULT_HEIGHT;
+ double estimatedColSpan = (double) image.getWidth()
+ / (double) CELL_DEFAULT_WIDTH;
+ double useColumnSpan = uiImage.getColumnSpan() == null ? estimatedRowSpan
+ : uiImage.getColumnSpan();
+ double useRowSpan = uiImage.getRowSpan() == null ? estimatedColSpan
+ : uiImage.getRowSpan();
- worksheet.addImage(new WritableImage(useStartColumn, useStartRow, useColumnSpan, useRowSpan, pngStream.toByteArray()));
- }
+ worksheet.addImage(new WritableImage(useStartColumn, useStartRow,
+ useColumnSpan, useRowSpan, pngStream.toByteArray()));
+ }
- /**
- * Creates a hyperlink to an URL in the worksheet
- *
- * @param column The target column of the link (if null, defaults to current
- * column)
- * @param row The target row of the link (if null, defaults to current row)
- * @param url The target URL
- */
- private void addHyperlink(UIHyperlink uiHyperlink)
- {
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't add a hyperlink before creating a worksheet");
- }
+ /**
+ * Creates a hyperlink to an URL in the worksheet
+ *
+ * @param column
+ * The target column of the link (if null, defaults to current
+ * column)
+ * @param row
+ * The target row of the link (if null, defaults to current row)
+ * @param url
+ * The target URL
+ */
+ private void addHyperlink(UIHyperlink uiHyperlink) {
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't add a hyperlink before creating a worksheet");
+ }
- int useStartColumn = uiHyperlink.getStartColumn() == null ? currentColumnIndex : uiHyperlink.getStartColumn();
- int useStartRow = uiHyperlink.getStartRow() == null ? currentRowIndex : uiHyperlink.getStartRow();
- int useEndColumn = uiHyperlink.getEndColumn() == null ? useStartColumn : uiHyperlink.getEndColumn();
- int useEndRow = uiHyperlink.getEndRow() == null ? useStartRow : uiHyperlink.getEndRow();
- String useDescription = uiHyperlink.getDescription() == null ? uiHyperlink.getURL() : uiHyperlink.getDescription();
- URL useURL = null;
+ int useStartColumn = uiHyperlink.getStartColumn() == null ? currentColumnIndex
+ : uiHyperlink.getStartColumn();
+ int useStartRow = uiHyperlink.getStartRow() == null ? currentRowIndex
+ : uiHyperlink.getStartRow();
+ int useEndColumn = uiHyperlink.getEndColumn() == null ? useStartColumn
+ : uiHyperlink.getEndColumn();
+ int useEndRow = uiHyperlink.getEndRow() == null ? useStartRow
+ : uiHyperlink.getEndRow();
+ String useDescription = uiHyperlink.getDescription() == null ? uiHyperlink
+ .getURL()
+ : uiHyperlink.getDescription();
+ URL useURL = null;
- try
- {
- useURL = new URL(uiHyperlink.getURL());
- }
- catch (MalformedURLException e)
- {
- throw new ExcelWorkbookException("Bad url", e);
- }
- try
- {
- worksheet.addHyperlink(new WritableHyperlink(useStartColumn, useStartRow, useEndColumn, useEndRow, useURL, useDescription));
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not add hyperlink", e);
- }
- }
+ try {
+ useURL = new URL(uiHyperlink.getURL());
+ } catch (MalformedURLException e) {
+ throw new ExcelWorkbookException("Bad url", e);
+ }
+ try {
+ worksheet.addHyperlink(new WritableHyperlink(useStartColumn,
+ useStartRow, useEndColumn, useEndRow, useURL,
+ useDescription));
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not add hyperlink", e);
+ }
+ }
- /**
- * Adds an item (cell, image, hyperlink) to add to the worksheet
- *
- * @param item The item to add
- */
- public void addItem(WorksheetItem item)
- {
- if (!((UIComponent)item).isRendered()) {
- return;
- }
- switch (item.getItemType())
- {
- case cell:
- addCell((UICell) item);
- break;
- case hyperlink:
- addHyperlink((UIHyperlink) item);
- break;
- case image:
- addImage((UIImage) item);
- break;
- default:
- throw new ExcelWorkbookException(Interpolator.instance().interpolate("Unknown item type {0}", item.getItemType()));
- }
- }
+ /**
+ * Adds an item (cell, image, hyperlink) to add to the worksheet
+ *
+ * @param item
+ * The item to add
+ */
+ public void addItem(WorksheetItem item) {
+ if (!((UIComponent) item).isRendered()) {
+ return;
+ }
+ switch (item.getItemType()) {
+ case cell:
+ addCell((UICell) item);
+ break;
+ case hyperlink:
+ addHyperlink((UIHyperlink) item);
+ break;
+ case image:
+ addImage((UIImage) item);
+ break;
+ default:
+ throw new ExcelWorkbookException(Interpolator.instance()
+ .interpolate("Unknown item type {0}", item.getItemType()));
+ }
+ }
- /**
- * Executes a command for a worksheet
- *
- * @param command The command to execute
- */
- public void executeCommand(Command command)
- {
- switch (command.getCommandType())
- {
- case merge_cells:
- mergeCells((UIMergeCells) command);
- break;
- case group_columns:
- groupColumns((UIGroupColumns) command);
- break;
- case group_rows:
- groupRows((UIGroupRows) command);
- break;
- case add_row_pagebreak:
- addRowPageBreak((UIRowPageBreak) command);
- break;
- default:
- throw new ExcelWorkbookException(Interpolator.instance().interpolate("Unknown command #0", command.getCommandType()));
- }
- }
+ /**
+ * Executes a command for a worksheet
+ *
+ * @param command
+ * The command to execute
+ */
+ public void executeCommand(Command command) {
+ switch (command.getCommandType()) {
+ case merge_cells:
+ mergeCells((UIMergeCells) command);
+ break;
+ case group_columns:
+ groupColumns((UIGroupColumns) command);
+ break;
+ case group_rows:
+ groupRows((UIGroupRows) command);
+ break;
+ case add_row_pagebreak:
+ addRowPageBreak((UIRowPageBreak) command);
+ break;
+ default:
+ throw new ExcelWorkbookException(
+ Interpolator.instance().interpolate("Unknown command #0",
+ command.getCommandType()));
+ }
+ }
- /**
- * Adds a row page break to the worksheet
- *
- * @param command the page break command to interpret
- */
- private void addRowPageBreak(UIRowPageBreak command)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Adding row page break #0", command);
- }
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't add row page breaks before creating a worksheet");
- }
- int useRow = command.getRow() != null ? command.getRow() : currentRowIndex;
- worksheet.addRowPageBreak(useRow);
- }
+ /**
+ * Adds a row page break to the worksheet
+ *
+ * @param command
+ * the page break command to interpret
+ */
+ private void addRowPageBreak(UIRowPageBreak command) {
+ if (log.isTraceEnabled()) {
+ log.trace("Adding row page break #0", command);
+ }
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't add row page breaks before creating a worksheet");
+ }
+ int useRow = command.getRow() != null ? command.getRow()
+ : currentRowIndex;
+ worksheet.addRowPageBreak(useRow);
+ }
- /**
- * Groups worksheet rows
- *
- * @param command The group command to interpret
- */
- private void groupRows(UIGroupRows command)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Grouping rows #0", command);
- }
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't group rows before creating a worksheet");
- }
- if (command.getStartRow() == null || command.getEndRow() == null)
- {
- throw new ExcelWorkbookException("Must define starting and ending rows when grouping rows");
- }
- boolean collapse = command.getCollapse() == null ? false : command.getCollapse();
- try
- {
- worksheet.setRowGroup(command.getStartRow(), command.getEndRow(), collapse);
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not group columns", e);
- }
- }
+ /**
+ * Groups worksheet rows
+ *
+ * @param command
+ * The group command to interpret
+ */
+ private void groupRows(UIGroupRows command) {
+ if (log.isTraceEnabled()) {
+ log.trace("Grouping rows #0", command);
+ }
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't group rows before creating a worksheet");
+ }
+ if (command.getStartRow() == null || command.getEndRow() == null) {
+ throw new ExcelWorkbookException(
+ "Must define starting and ending rows when grouping rows");
+ }
+ boolean collapse = command.getCollapse() == null ? false : command
+ .getCollapse();
+ try {
+ worksheet.setRowGroup(command.getStartRow(), command.getEndRow(),
+ collapse);
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not group columns", e);
+ }
+ }
- /**
- * Groups columns in the worksheet
- *
- * @param command The group command to interpret
- */
- private void groupColumns(UIGroupColumns command)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Grouping columns #0", command);
- }
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't group columns before creating a worksheet");
- }
- if (command.getStartColumn() == null || command.getEndColumn() == null)
- {
- throw new ExcelWorkbookException("Must define starting and ending columns when grouping columns");
- }
- // JExcelAPI bug workaround
- for (int i = command.getStartColumn(); i <= command.getEndColumn(); i++)
- {
- worksheet.setColumnView(i, new CellView());
- }
- boolean collapse = command.getCollapse() == null ? false : command.getCollapse();
- try
- {
- worksheet.setColumnGroup(command.getStartColumn(), command.getEndColumn(), collapse);
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not group columns", e);
- }
- }
+ /**
+ * Groups columns in the worksheet
+ *
+ * @param command
+ * The group command to interpret
+ */
+ private void groupColumns(UIGroupColumns command) {
+ if (log.isTraceEnabled()) {
+ log.trace("Grouping columns #0", command);
+ }
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't group columns before creating a worksheet");
+ }
+ if (command.getStartColumn() == null || command.getEndColumn() == null) {
+ throw new ExcelWorkbookException(
+ "Must define starting and ending columns when grouping columns");
+ }
+ // JExcelAPI bug workaround
+ for (int i = command.getStartColumn(); i <= command.getEndColumn(); i++) {
+ worksheet.setColumnView(i, new CellView());
+ }
+ boolean collapse = command.getCollapse() == null ? false : command
+ .getCollapse();
+ try {
+ worksheet.setColumnGroup(command.getStartColumn(), command
+ .getEndColumn(), collapse);
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not group columns", e);
+ }
+ }
- /**
- * Merge cells in the worksheet
- *
- * @param command The merge command to interpret
- */
- private void mergeCells(UIMergeCells command)
- {
- if (log.isTraceEnabled())
- {
- log.trace("Merging cells #0", command);
- }
- if (worksheet == null)
- {
- throw new ExcelWorkbookException("Can't merge cells before creating a worksheet");
- }
- if (command.getStartColumn() == null || command.getStartRow() == null || command.getEndColumn() == null || command.getEndRow() == null)
- {
- throw new ExcelWorkbookException("All start/end columns/rows must be set when merging cells");
- }
- try
- {
- worksheet.mergeCells(command.getStartColumn(), command.getStartRow(), command.getEndColumn(), command.getEndRow());
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Couldn't merge cells", e);
- }
- }
+ /**
+ * Merge cells in the worksheet
+ *
+ * @param command
+ * The merge command to interpret
+ */
+ private void mergeCells(UIMergeCells command) {
+ if (log.isTraceEnabled()) {
+ log.trace("Merging cells #0", command);
+ }
+ if (worksheet == null) {
+ throw new ExcelWorkbookException(
+ "Can't merge cells before creating a worksheet");
+ }
+ if (command.getStartColumn() == null || command.getStartRow() == null
+ || command.getEndColumn() == null
+ || command.getEndRow() == null) {
+ throw new ExcelWorkbookException(
+ "All start/end columns/rows must be set when merging cells");
+ }
+ try {
+ worksheet
+ .mergeCells(command.getStartColumn(),
+ command.getStartRow(), command.getEndColumn(),
+ command.getEndRow());
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Couldn't merge cells", e);
+ }
+ }
- /**
- * Places an item in the worksheet footer
- *
- * @param item The item to add
- * @param colspan The number of columns to span
- */
- public void addWorksheetFooter(WorksheetItem item, int colspan)
- {
- currentColumnIndex = startColumnIndex;
- currentRowIndex = maxRowIndex;
- UIMergeCells mergeCommand = new UIMergeCells();
- mergeCommand.setStartColumn(currentColumnIndex);
- mergeCommand.setStartRow(currentRowIndex);
- mergeCommand.setEndColumn(currentColumnIndex + colspan - 1);
- mergeCommand.setEndRow(currentRowIndex);
- executeCommand(mergeCommand);
- addItem(item);
- }
+ /**
+ * Places an item in the worksheet footer
+ *
+ * @param item
+ * The item to add
+ * @param colspan
+ * The number of columns to span
+ */
+ public void addWorksheetFooter(WorksheetItem item, int colspan) {
+ currentColumnIndex = startColumnIndex;
+ currentRowIndex = maxRowIndex;
+ UIMergeCells mergeCommand = new UIMergeCells();
+ mergeCommand.setStartColumn(currentColumnIndex);
+ mergeCommand.setStartRow(currentRowIndex);
+ mergeCommand.setEndColumn(currentColumnIndex + colspan - 1);
+ mergeCommand.setEndRow(currentRowIndex);
+ executeCommand(mergeCommand);
+ addItem(item);
+ }
- /**
- * Places an item in the worksheet header
- *
- * @param item The item to add
- * @param colspan The number of columns to span
- */
- public void addWorksheetHeader(WorksheetItem item, int colspan)
- {
- UIMergeCells mergeCommand = new UIMergeCells();
- mergeCommand.setStartColumn(currentColumnIndex);
- mergeCommand.setStartRow(currentRowIndex);
- mergeCommand.setEndColumn(currentColumnIndex + colspan - 1);
- mergeCommand.setEndRow(currentRowIndex);
- executeCommand(mergeCommand);
- addItem(item);
- startRowIndex++;
- }
+ /**
+ * Places an item in the worksheet header
+ *
+ * @param item
+ * The item to add
+ * @param colspan
+ * The number of columns to span
+ */
+ public void addWorksheetHeader(WorksheetItem item, int colspan) {
+ UIMergeCells mergeCommand = new UIMergeCells();
+ mergeCommand.setStartColumn(currentColumnIndex);
+ mergeCommand.setStartRow(currentRowIndex);
+ mergeCommand.setEndColumn(currentColumnIndex + colspan - 1);
+ mergeCommand.setEndRow(currentRowIndex);
+ executeCommand(mergeCommand);
+ addItem(item);
+ startRowIndex++;
+ }
- /**
- * Sets stylesheets for the workbook
- *
- * @param stylesheets The stylesheet to register
- */
- public void setStylesheets(List<UILink> stylesheets)
- {
- try
- {
- jxlHelper.setStylesheets(stylesheets);
- }
- catch (Exception e)
- {
- throw new ExcelWorkbookException("Could not parse stylesheet", e);
- }
- }
+ /**
+ * Sets stylesheets for the workbook
+ *
+ * @param stylesheets
+ * The stylesheet to register
+ */
+ public void setStylesheets(List<UILink> stylesheets) {
+ try {
+ jxlHelper.setStylesheets(stylesheets);
+ } catch (Exception e) {
+ throw new ExcelWorkbookException("Could not parse stylesheet", e);
+ }
+ }
}
16 years, 1 month