[seam-commits] Seam SVN: r8986 - in trunk: examples/excel/view and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Sep 11 16:10:57 EDT 2008


Author: nickarls
Date: 2008-09-11 16:10:57 -0400 (Thu, 11 Sep 2008)
New Revision: 8986

Added:
   trunk/src/excel/org/jboss/seam/excel/ui/UIFooter.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIHeader.java
Removed:
   trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooter.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommand.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommands.java
Modified:
   trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
   trunk/examples/excel/view/people.xhtml
   trunk/src/excel/META-INF/faces-config.xml
   trunk/src/excel/META-INF/seam-excel.taglib.xml
   trunk/src/excel/org/jboss/seam/excel/jxl/JXLFactory.java
   trunk/src/excel/org/jboss/seam/excel/jxl/JXLHelper.java
Log:
JBSEAM-3236. Dropped the header/footer/commands/command structure for a header and footer tag that parses a single string.

Modified: trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Excel.xml	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/doc/Seam_Reference_Guide/en-US/Excel.xml	2008-09-11 20:10:57 UTC (rev 8986)
@@ -1725,9 +1725,8 @@
    <section id="excel.headersfooters">
       <title>Headers and footers</title>
       <para>
-         Headers and footers are childrens of worksheets and worksheet templates
-         and parents of header and footer commands They add headers and footers
-         to printed worksheets.
+         Headers and footers are childrens of worksheets and contain facets which
+         in turn contains a string with commands that are parsed.
       </para>
       <informaltable>
          <tgroup cols="2">
@@ -1737,7 +1736,7 @@
                <row>
                   <entry valign="top">
                      <para>
-                        <literal>&lt;e:headerFooter&gt;</literal>
+                        <literal>&lt;e:header&gt;</literal>
                      </para>
                   </entry>
                   <entry valign="top">
@@ -1747,9 +1746,7 @@
                      <itemizedlist>
                         <listitem>
                            <para>
-                              <literal>type</literal>
-                              &#8212;The type of the header or footer. The value
-                              is string that can be either "header" or "footer".
+                              <literal>none</literal>
                            </para>
                         </listitem>
                      </itemizedlist>
@@ -1794,11 +1791,6 @@
             </tbody>
          </tgroup>
       </informaltable>
-      <para>
-         The <literal>&lt;e:headerFooterCommands&gt;</literal>
-         is just a nesting container in order to support multiple header/footer
-         commands.
-      </para>
       <informaltable>
          <tgroup cols="2">
             <colspec colnum="1" colwidth="1*" />
@@ -1807,7 +1799,7 @@
                <row>
                   <entry valign="top">
                      <para>
-                        <literal>&lt;e:headerFooterCommands&gt;</literal>
+                        <literal>&lt;e:footer&gt;</literal>
                      </para>
                   </entry>
                   <entry valign="top">
@@ -1826,7 +1818,9 @@
                      </para>
                      <itemizedlist>
                         <listitem>
-                           <para>Zero or more header/footer commands.</para>
+                           <para>
+                              <literal>none</literal>
+                           </para>
                         </listitem>
                      </itemizedlist>
                      <para>
@@ -1835,9 +1829,25 @@
                      <itemizedlist>
                         <listitem>
                            <para>
-                              <literal>none</literal>
+                              <literal>left</literal>
+                              &#8212;The contents of the left header/footer
+                              part.
                            </para>
                         </listitem>
+                        <listitem>
+                           <para>
+                              <literal>center</literal>
+                              &#8212;The contents of the center header/footer
+                              part.
+                           </para>
+                        </listitem>
+                        <listitem>
+                           <para>
+                              <literal>right</literal>
+                              &#8212;The contents of the right header/footer
+                              part.
+                           </para>
+                        </listitem>
                      </itemizedlist>
                   </entry>
                </row>
@@ -1845,8 +1855,8 @@
          </tgroup>
       </informaltable>
       <para>
-         Header/footer commands adds actual commands to the header or footer in
-         the location where the containing facet points.
+         The content of the facets is a string that can contain various #-delimited
+         commands as follows:
       </para>
       <informaltable>
          <tgroup cols="2">
@@ -1855,119 +1865,171 @@
             <tbody>
                <row>
                   <entry valign="top">
+                     <para>#date#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the current date</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#page_number#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the current page number</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#time#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the current time</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#total_pages#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the total page count</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#worksheet_name#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the worksheet name</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#workbook_name#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>Inserts the workbook name</para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#bold#</para>
+                  </entry>
+                  <entry valign="top">
                      <para>
-                        <literal>&lt;e:headerFooterCommand&gt;</literal>
+                        Toggles bold font, use another #bold# to 
+                        turn it off
                      </para>
                   </entry>
+               </row>
+               <row>
                   <entry valign="top">
+                     <para>#italics#</para>
+                  </entry>
+                  <entry valign="top">
                      <para>
-                        <emphasis>Attributes</emphasis>
+                        Toggles italic font, use another #italic# to 
+                        turn it off
                      </para>
-                     <itemizedlist>
-                        <listitem>
-                           <para>
-                              <literal>command</literal>
-                              &#8212;The command to execute. The value is a
-                              string
-                              <itemizedlist>
-                                 <listitem>
-                                    "append" - appends the text in the
-                                    <literal>parameter</literal>
-                                 </listitem>
-                                 <listitem>
-                                    "date" - appends the current date
-                                 </listitem>
-                                 <listitem>
-                                    "page_number" - appends the page number
-                                 </listitem>
-                                 <listitem>"time" - appends the time</listitem>
-                                 <listitem>
-                                    "total_pages" - appends the total page count
-                                 </listitem>
-                                 <listitem>
-                                    "workbook_name" - appends the workbook name
-                                 </listitem>
-                                 <listitem>
-                                    "worksheet_name" - appends the worksheet
-                                    name
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_bold" - toggles bold font
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_italics" - toggles italics
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_double_underline" - toggles double
-                                    underlining
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_outline" - toggles outline
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_shadow" - toggles shadow
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_strikethrough" - toggles
-                                    strikethrough
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_subscript" - toggles subscript
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_superscript" - toggles superscript
-                                 </listitem>
-                                 <listitem>
-                                    "toggle_underline" - toggles underline
-                                 </listitem>
-                                 <listitem>
-                                    "font_name" - sets the font name given in
-                                    the
-                                    <literal>parameter</literal>
-                                 </listitem>
-                                 <listitem>
-                                    "font_size" - sets the font size given in
-                                    the
-                                    <literal>parameter</literal>
-                                 </listitem>
-                              </itemizedlist>
-                           </para>
-                        </listitem>
-                        <listitem>
-                           <para>
-                              <literal>parameter</literal>
-                              &#8212;The parameter for some commands. Used by
-                              the font_name, font_size and append commands. The
-                              font_name parameter is a string that represents
-                              the requested font name, the font_size parameter
-                              is a number that represents the requested font
-                              size and the append parameter is a string of text
-                              to be appended to the header/footer.
-                           </para>
-                        </listitem>
-                     </itemizedlist>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#underline#</para>
+                  </entry>
+                  <entry valign="top">
                      <para>
-                        <emphasis>Child elemenents</emphasis>
+                        Toggles underlining, use another #underline# to 
+                        turn it off
                      </para>
-                     <itemizedlist>
-                        <listitem>
-                           <para>
-                              <literal>none</literal>
-                           </para>
-                        </listitem>
-                     </itemizedlist>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#double_underline#</para>
+                  </entry>
+                  <entry valign="top">
                      <para>
-                        <emphasis>Facets</emphasis>
+                        Toggles double underlining, use another #double_underline# to 
+                        turn it off
                      </para>
-                     <itemizedlist>
-                        <listitem>
-                           <para>
-                              <literal>none</literal>
-                           </para>
-                        </listitem>
-                     </itemizedlist>
                   </entry>
                </row>
+               <row>
+                  <entry valign="top">
+                     <para>#outline#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Toggles outlined font, use another #outline# to 
+                        turn it off
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#shadow#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Toggles shadowed font, use another #shadow# to 
+                        turn it off
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#strikethrough#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Toggles strikethrough font, use another #strikethrough# to 
+                        turn it off
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#subscript#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Toggles subscripted font, use another #subscript# to 
+                        turn it off
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#superscript#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Toggles superscript font, use another #superscript# to 
+                        turn it off
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#font_name#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Sets font name, used like #font_name=Verdana"
+                     </para>
+                  </entry>
+               </row>
+               <row>
+                  <entry valign="top">
+                     <para>#font_size#</para>
+                  </entry>
+                  <entry valign="top">
+                     <para>
+                        Sets font size, use like #font_size=12#
+                     </para>
+                  </entry>
+               </row>
             </tbody>
          </tgroup>
       </informaltable>
@@ -1975,18 +2037,18 @@
          <![CDATA[
             <e:workbook>
                <e:worksheet>         
-                  <e:headerFooter type="header">
+                  <e:header>
                      <f:facet name="left">
-                        <e:headerFooterCommands>
-                           <e:headerFooterCommand command="page_number"/>
-                        </e:headerFooterCommands>
+                        This document was made on #date# and has #total_pages# pages
                      </f:facet>
-                  </e:headerFooter>
+                     <f:facet name="right">
+                        #time#
+                     </f:facet>
+                  </e:header>
                <e:worksheet>
             </e:workbook>
          ]]>
       </programlisting>
-      <para>Defines a header with the page number in the left corner.</para>
    </section>
    <section id="excel.printareatitles">
       <title>Print areas and titles</title>

Modified: trunk/examples/excel/view/people.xhtml
===================================================================
--- trunk/examples/excel/view/people.xhtml	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/examples/excel/view/people.xhtml	2008-09-11 20:10:57 UTC (rev 8986)
@@ -5,6 +5,11 @@
 
 <e:workbook type="#{exportType}">
 	<e:worksheet name="People" value="#{people}" var="person">
+		<e:header>
+			<f:facet name="left">
+				The date is #date# and the time is #time#
+			</f:facet>
+		</e:header>
 		<e:column style="xls-column-autosize: true">
 			<f:facet name="header">
 				<e:cell value="Name" style="xls-font: red bold 10 Verdana"/>

Modified: trunk/src/excel/META-INF/faces-config.xml
===================================================================
--- trunk/src/excel/META-INF/faces-config.xml	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/META-INF/faces-config.xml	2008-09-11 20:10:57 UTC (rev 8986)
@@ -21,18 +21,14 @@
         <component-class>org.jboss.seam.excel.ui.UIWorksheet</component-class>
     </component>    
     <component>
-        <component-type>org.jboss.seam.excel.ui.UIHeaderFooter</component-type>
-        <component-class>org.jboss.seam.excel.ui.UIHeaderFooter</component-class>
+        <component-type>org.jboss.seam.excel.ui.UIHeader</component-type>
+        <component-class>org.jboss.seam.excel.ui.UIHeader</component-class>
     </component>    
     <component>
-        <component-type>org.jboss.seam.excel.ui.UIHeaderFooterCommands</component-type>
-        <component-class>org.jboss.seam.excel.ui.UIHeaderFooterCommands</component-class>
+        <component-type>org.jboss.seam.excel.ui.UIFooter</component-type>
+        <component-class>org.jboss.seam.excel.ui.UIFooter</component-class>
     </component>    
     <component>
-        <component-type>org.jboss.seam.excel.ui.UIHeaderFooterCommand</component-type>
-        <component-class>org.jboss.seam.excel.ui.UIHeaderFooterCommand</component-class>
-    </component>    
-    <component>
         <component-type>org.jboss.seam.excel.ui.UIPrintArea</component-type>
         <component-class>org.jboss.seam.excel.ui.UIPrintArea</component-class>
     </component>    

Modified: trunk/src/excel/META-INF/seam-excel.taglib.xml
===================================================================
--- trunk/src/excel/META-INF/seam-excel.taglib.xml	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/META-INF/seam-excel.taglib.xml	2008-09-11 20:10:57 UTC (rev 8986)
@@ -35,27 +35,20 @@
     </tag>
 
     <tag>
-        <tag-name>headerFooter</tag-name>
+        <tag-name>header</tag-name>
         <component>
-            <component-type>org.jboss.seam.excel.ui.UIHeaderFooter</component-type>
+            <component-type>org.jboss.seam.excel.ui.UIHeader</component-type>
         </component>
     </tag>
 
     <tag>
-        <tag-name>headerFooterCommands</tag-name>
+        <tag-name>footer</tag-name>
         <component>
-            <component-type>org.jboss.seam.excel.ui.UIHeaderFooterCommands</component-type>
+            <component-type>org.jboss.seam.excel.ui.UIFooter</component-type>
         </component>
     </tag>
 
     <tag>
-        <tag-name>headerFooterCommand</tag-name>
-        <component>
-            <component-type>org.jboss.seam.excel.ui.UIHeaderFooterCommand</component-type>
-        </component>
-    </tag>
-
-    <tag>
         <tag-name>printArea</tag-name>
         <component>
             <component-type>org.jboss.seam.excel.ui.UIPrintArea</component-type>

Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLFactory.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLFactory.java	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLFactory.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -1,13 +1,16 @@
 package org.jboss.seam.excel.jxl;
 
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 
 import jxl.HeaderFooter;
+import jxl.HeaderFooter.Contents;
 import jxl.biff.DisplayFormat;
 import jxl.biff.FontRecord;
 import jxl.format.Alignment;
@@ -27,14 +30,13 @@
 import org.jboss.seam.core.Interpolator;
 import org.jboss.seam.excel.ExcelWorkbookException;
 import org.jboss.seam.excel.css.CellStyle;
-import org.jboss.seam.excel.ui.UIHeaderFooter;
-import org.jboss.seam.excel.ui.UIHeaderFooterCommand;
+import org.jboss.seam.excel.ui.ExcelComponent;
 import org.jboss.seam.log.Log;
 import org.jboss.seam.log.Logging;
 
 /**
  * Factory for creating JExcelAPI objects
- *
+ * 
  * @author karlsnic
  */
 public class JXLFactory
@@ -51,10 +53,29 @@
    private static final String PATTERN_CLASS_NAME = "jxl.format.Pattern";
    private static final String PAGE_ORIENTATION_CLASS_NAME = "jxl.format.PageOrientation";
    private static final String PAPER_SIZE_CLASS_NAME = "jxl.format.PaperSize";
-   private static final String HEADER_FOOTER_COMMAND_CLASS_NAME = "org.jboss.seam.excel.UIHeaderFooterCommand";
    private static final String SCRIPT_STYLE_CLASS_NAME = "jxl.format.ScriptStyle";
    private static final String UNDERLINE_STYLE_CLASS_NAME = "jxl.format.UnderlineStyle";
-   
+
+   private static final String HEADERFOOTER_COMMAND_MARKER = "#";
+   private static final String HEADERFOOTER_PAIR_DELIMITER = "=";
+
+   private static final String HF_CMD_FONT_SIZE = "font_size";
+   private static final String HF_CMD_FONT_NAME = "font_name";
+   private static final String HF_CMD_UNDERLINE = "underline";
+   private static final String HF_CMD_SUPERSCRIPT = "superscript";
+   private static final String HF_CMD_SUBSCRIPT = "subscript";
+   private static final String HF_CMD_STRIKETHROUGH = "strikethrough";
+   private static final String HF_CMD_SHADOW = "shadow";
+   private static final String HF_CMD_OUTLINE = "outline";
+   private static final String HF_CMD_ITALICS = "italics";
+   private static final String HF_CMD_DOUBLE_UNDERLINE = "double_underline";
+   private static final String HF_CMD_BOLD = "bold";
+   private static final String HF_CMD_WORKSHEET_NAME = "worksheet_name";
+   private static final String HF_CMD_WORKBOOK_NAME = "workbook_name";
+   private static final String HF_CMD_TOTAL_PAGES = "total_pages";
+   private static final String HF_CMD_TIME = "time";
+   private static final String HF_CMD_PAGE_NUMBER = "page_number";
+
    private static final Log log = Logging.getLog(JXLFactory.class);
 
    /**
@@ -63,27 +84,30 @@
     * @param text The text to check
     * @return True if border line style, false otherwise
     */
-   public static boolean isBorderLineStyle(String text) {
+   public static boolean isBorderLineStyle(String text)
+   {
       return getValidContants(BORDER_LINE_STYLE_CLASS_NAME).contains(text.toLowerCase());
    }
-   
+
    /**
     * Checks if text is a pattern
     * 
     * @param text The text to check
     * @return True if pattern, false otherwise
     */
-   public static boolean isPattern(String text) {
+   public static boolean isPattern(String text)
+   {
       return getValidContants(PATTERN_CLASS_NAME).contains(text.toLowerCase());
    }
-   
+
    /**
     * Checks if text is a color
     * 
     * @param text The text to check
     * @return True if color, false otherwise
     */
-   public static boolean isColor(String text) {
+   public static boolean isColor(String text)
+   {
       return getValidContants(COLOR_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -93,7 +117,8 @@
     * @param text The text to check
     * @return True if alignment, false otherwise
     */
-   public static boolean isAlignment(String text) {
+   public static boolean isAlignment(String text)
+   {
       return getValidContants(ALIGNMENT_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -103,7 +128,8 @@
     * @param text The text to check
     * @return True if orientation, false otherwise
     */
-   public static boolean isOrientation(String text) {
+   public static boolean isOrientation(String text)
+   {
       return getValidContants(ORIENTATION_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -113,7 +139,8 @@
     * @param text The text to check
     * @return True if vertical alignment, false otherwise
     */
-   public static boolean isVerticalAlignment(String text) {
+   public static boolean isVerticalAlignment(String text)
+   {
       return getValidContants(VERTICAL_ALIGNMENT_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -123,7 +150,8 @@
     * @param text The text to check
     * @return True if underline style, false otherwise
     */
-   public static boolean isUnderlineStyle(String text) {
+   public static boolean isUnderlineStyle(String text)
+   {
       return getValidContants(UNDERLINE_STYLE_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -133,7 +161,8 @@
     * @param text The text to check
     * @return True if script style, false otherwise
     */
-   public static boolean isScriptStyle(String text) {
+   public static boolean isScriptStyle(String text)
+   {
       return getValidContants(SCRIPT_STYLE_CLASS_NAME).contains(text.toLowerCase());
    }
 
@@ -143,9 +172,10 @@
     * @param className The class to examine
     * @return A list of constants
     */
-   private static List<String> getValidContants(String className) {
+   private static List<String> getValidContants(String className)
+   {
       List<String> constants = new ArrayList<String>();
-      
+
       if (log.isTraceEnabled())
       {
          log.trace("Getting valid constants from #0", className);
@@ -171,7 +201,7 @@
       }
       return constants;
    }
-   
+
    /**
     * Gets a suggestion string of available constants from a class.
     * 
@@ -189,10 +219,11 @@
          buffer.append(i++ == 0 ? field : ", " + field);
       }
       return Interpolator.instance().interpolate("[#0]", buffer.toString());
-   }   
-   
+   }
+
    /**
     * Gets a constant from a class
+    * 
     * @param className The class name to examine
     * @param fieldName The field to read
     * @return The constant
@@ -216,8 +247,8 @@
       {
          throw new ExcelWorkbookException(Interpolator.instance().interpolate("Could not read field #0 from class #1", fieldName, className), e);
       }
-   }   
-   
+   }
+
    /**
     * Creates a JExcelAPI representation of an alignment
     * 
@@ -242,7 +273,7 @@
          throw new ExcelWorkbookException(message, e);
       }
    }
-   
+
    /**
     * Creates a JExcelAPI representation of an script style
     * 
@@ -266,8 +297,8 @@
          String message = Interpolator.instance().interpolate("Script style {0} not supported, try {1}", scriptStyle, getValidConstantsSuggestion(SCRIPT_STYLE_CLASS_NAME));
          throw new ExcelWorkbookException(message, e);
       }
-   }   
-   
+   }
+
    /**
     * Creates a JExcelAPI representation of an underline style
     * 
@@ -291,8 +322,8 @@
          String message = Interpolator.instance().interpolate("Underline style {0} not supported, try {1}", underlineStyle, getValidConstantsSuggestion(UNDERLINE_STYLE_CLASS_NAME));
          throw new ExcelWorkbookException(message, e);
       }
-   }   
- 
+   }
+
    /**
     * Creates a JExcelAPI representation of a font
     * 
@@ -304,32 +335,40 @@
    public static FontRecord createFont(CellStyle.Font fontspecs) throws WriteException
    {
       WritableFont font = null;
-      if (fontspecs.family != null) {
+      if (fontspecs.family != null)
+      {
          font = new WritableFont(WritableFont.createFont(fontspecs.family));
       }
       else
       {
          font = new WritableFont(WritableFont.ARIAL);
       }
-      if (fontspecs.pointSize != null) {
+      if (fontspecs.pointSize != null)
+      {
          font.setPointSize(fontspecs.pointSize);
       }
-      if (fontspecs.color != null) {
+      if (fontspecs.color != null)
+      {
          font.setColour(createColor(fontspecs.color));
       }
-      if (fontspecs.bold != null) {
+      if (fontspecs.bold != null)
+      {
          font.setBoldStyle(fontspecs.bold ? WritableFont.BOLD : WritableFont.NO_BOLD);
       }
-      if (fontspecs.italic != null) {
+      if (fontspecs.italic != null)
+      {
          font.setItalic(fontspecs.italic);
       }
-      if (fontspecs.struckOut != null) {
+      if (fontspecs.struckOut != null)
+      {
          font.setStruckout(fontspecs.struckOut);
       }
-      if (fontspecs.scriptStyle != null) {
+      if (fontspecs.scriptStyle != null)
+      {
          font.setScriptStyle(createScriptStyle(fontspecs.scriptStyle));
       }
-      if (fontspecs.underlineStyle != null) {
+      if (fontspecs.underlineStyle != null)
+      {
          font.setUnderlineStyle(createUnderlineStyle(fontspecs.underlineStyle));
       }
       return font;
@@ -362,7 +401,6 @@
       }
    }
 
-
    /**
     * Creates a JExcelAPI date display format
     * 
@@ -545,7 +583,7 @@
          throw new ExcelWorkbookException(message, e);
       }
    }
-   
+
    /**
     * Creates a JExcelAPI representation of a page orientation
     * 
@@ -567,7 +605,7 @@
          String message = Interpolator.instance().interpolate("Page orientation {0} not supported, try {1}", orientation, getValidConstantsSuggestion(PAGE_ORIENTATION_CLASS_NAME));
          throw new ExcelWorkbookException(message, e);
       }
-   }   
+   }
 
    /**
     * Creates a JExcelAPI representation of a paper size
@@ -591,7 +629,7 @@
          throw new ExcelWorkbookException(message, e);
       }
    }
-   
+
    /**
     * Creates a JExcelAPI header or footer representation. Processes the left,
     * center and right facets using a helper method
@@ -601,24 +639,24 @@
     *           to
     * @return The JExcelAPI header or footer representation
     */
-   public static HeaderFooter createHeaderFooter(UIHeaderFooter uiHeaderFooter, HeaderFooter headerFooter)
+   public static HeaderFooter createHeaderFooter(UIComponent uiHeaderFooter, HeaderFooter headerFooter)
    {
       if (log.isTraceEnabled())
       {
          log.trace("Processing header/footer #0", uiHeaderFooter);
       }
-      processHeaderFooterFacet(headerFooter.getLeft(), uiHeaderFooter.getFacet(UIHeaderFooter.LEFT_FACET));
-      processHeaderFooterFacet(headerFooter.getCentre(), uiHeaderFooter.getFacet(UIHeaderFooter.CENTER_FACET));
-      processHeaderFooterFacet(headerFooter.getRight(), uiHeaderFooter.getFacet(UIHeaderFooter.RIGHT_FACET));
+      processHeaderFooterFacet(headerFooter.getLeft(), uiHeaderFooter.getFacet("left"));
+      processHeaderFooterFacet(headerFooter.getCentre(), uiHeaderFooter.getFacet("middle"));
+      processHeaderFooterFacet(headerFooter.getRight(), uiHeaderFooter.getFacet("right"));
       return headerFooter;
    }
 
    /**
     * Processes a header or footer facet. A header or footer facet in JExcelAPI
     * is split into three parts, left, center and right and the UI
-    * representation has facets with the same namings. Gets the requested
-    * facet from the UI component and calls helper methods for processing the
-    * header commands in sequence
+    * representation has facets with the same namings. Gets the requested facet
+    * from the UI component and calls helper methods for processing the header
+    * commands in sequence
     * 
     * @param headerFooter The JExcelAPI header or footer facet to process
     * @param facetName The name of the facet to process (left, center, right)
@@ -635,83 +673,139 @@
       {
          return;
       }
-      for (UIComponent child : facet.getChildren())
+      String facetContent = null;
+      try
       {
-         if (child.getClass() == UIHeaderFooterCommand.class)
+         facetContent = ExcelComponent.cmp2String(FacesContext.getCurrentInstance(), facet);
+      }
+      catch (IOException e)
+      {
+         throw new ExcelWorkbookException("Could not get content from header facet", e);
+      }
+      if (facetContent == null)
+      {
+         return;
+      }
+      facetContent = facetContent.trim();
+      int firstHash;
+      int secondHash;
+      String command;
+      String pre;
+      while (!"".equals(facetContent))
+      {
+         firstHash = -1;
+         secondHash = -1;
+         firstHash = facetContent.indexOf(HEADERFOOTER_COMMAND_MARKER);
+         if (firstHash >= 0)
          {
-            processHeaderFooterCommand(contents, (UIHeaderFooterCommand) child);
+            secondHash = facetContent.indexOf(HEADERFOOTER_COMMAND_MARKER, firstHash + 1);
          }
+         if (firstHash >= 0 && secondHash >= 0 && firstHash != secondHash)
+         {
+            pre = facetContent.substring(0, firstHash);
+            if (!"".equals(pre))
+            {
+               contents.append(pre);
+            }
+            command = facetContent.substring(firstHash + 1, secondHash);
+            processCommand(contents, command);
+            facetContent = facetContent.substring(secondHash + 1);
+         }
+         else
+         {
+            contents.append(facetContent);
+            facetContent = "";
+         }
       }
    }
 
    /**
-    * Processes a header command and applies it to the JExcelAPI header contents
+    * Processes a header or footer command, adding itself to the contents
     * 
-    * @param contents The contents to apply the command to (left, center, right)
-    * @param command The command to interpret
+    * @param contents The target contents
+    * @param command The command to execute
     */
-   private static void processHeaderFooterCommand(HeaderFooter.Contents contents, UIHeaderFooterCommand command)
+   private static void processCommand(Contents contents, String command)
    {
-      if (log.isTraceEnabled())
+      command = command.toLowerCase();
+      if (command.startsWith("date"))
       {
-         log.trace("Processing header/footer command #0", command);
+         contents.appendDate();
       }
-      switch (command.getCommand())
+      else if (command.startsWith(HF_CMD_PAGE_NUMBER))
       {
-      case append:
-         contents.append((String) command.getParameter());
-         break;
-      case date:
-         contents.appendDate();
-         break;
-      case page_number:
          contents.appendPageNumber();
-         break;
-      case time:
+      }
+      else if (command.startsWith(HF_CMD_TIME))
+      {
          contents.appendTime();
-         break;
-      case total_pages:
+      }
+      else if (command.startsWith(HF_CMD_TOTAL_PAGES))
+      {
          contents.appendTotalPages();
-         break;
-      case workbook_name:
+      }
+      else if (command.startsWith(HF_CMD_WORKBOOK_NAME))
+      {
          contents.appendWorkbookName();
-         break;
-      case worksheet_name:
+      }
+      else if (command.startsWith(HF_CMD_WORKSHEET_NAME))
+      {
          contents.appendWorkSheetName();
-         break;
-      case font_name:
-         contents.setFontName((String) command.getParameter());
-         break;
-      case font_size:
-         contents.setFontSize((Integer) command.getParameter());
-         break;
-      case toggle_bold:
+      }
+      else if (command.startsWith(HF_CMD_BOLD))
+      {
          contents.toggleBold();
-         break;
-      case toggle_italics:
+      }
+      else if (command.startsWith(HF_CMD_DOUBLE_UNDERLINE))
+      {
+         contents.toggleDoubleUnderline();
+      }
+      else if (command.startsWith(HF_CMD_ITALICS))
+      {
          contents.toggleItalics();
-         break;
-      case toggle_double_underline:
-         contents.toggleDoubleUnderline();
-         break;
-      case toggle_outline:
+      }
+      else if (command.startsWith(HF_CMD_OUTLINE))
+      {
          contents.toggleOutline();
-         break;
-      case toggle_shadow:
+      }
+      else if (command.startsWith(HF_CMD_SHADOW))
+      {
          contents.toggleShadow();
-         break;
-      case toggle_strikethrough:
+      }
+      else if (command.startsWith(HF_CMD_STRIKETHROUGH))
+      {
          contents.toggleStrikethrough();
-         break;
-      case toggle_subscript:
+      }
+      else if (command.startsWith(HF_CMD_SUBSCRIPT))
+      {
          contents.toggleSubScript();
-         break;
-      case toggle_superscript:
+      }
+      else if (command.startsWith(HF_CMD_SUPERSCRIPT))
+      {
          contents.toggleSuperScript();
-         break;
-      default:
-         String message = Interpolator.instance().interpolate("Header/Footer command {0} not supported, try {1}", command.getCommand(), getValidConstantsSuggestion(HEADER_FOOTER_COMMAND_CLASS_NAME));
-         throw new ExcelWorkbookException(message);
       }
-   }      
+      else if (command.startsWith(HF_CMD_UNDERLINE))
+      {
+         contents.toggleUnderline();
+      }
+      else if (command.startsWith(HF_CMD_FONT_NAME))
+      {
+         String[] parts = command.split(HEADERFOOTER_PAIR_DELIMITER);
+         if (parts.length != 2)
+         {
+            log.warn("Header/Footer font name error in #0", command);
+         }
+         contents.setFontName(parts[1].trim());
+      }
+      else if (command.startsWith(HF_CMD_FONT_SIZE))
+      {
+         String[] parts = command.split(HEADERFOOTER_PAIR_DELIMITER);
+         if (parts.length != 2)
+         {
+            log.warn("Header/Footer font size error in #0", command);
+         }
+         contents.setFontSize(Integer.parseInt(parts[1].trim()));
+      }
+   }
+
 }

Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLHelper.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLHelper.java	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLHelper.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -36,7 +36,8 @@
 import org.jboss.seam.excel.ui.UICell;
 import org.jboss.seam.excel.ui.UICellBase;
 import org.jboss.seam.excel.ui.UIColumn;
-import org.jboss.seam.excel.ui.UIHeaderFooter;
+import org.jboss.seam.excel.ui.UIFooter;
+import org.jboss.seam.excel.ui.UIHeader;
 import org.jboss.seam.excel.ui.UILink;
 import org.jboss.seam.excel.ui.UIPrintArea;
 import org.jboss.seam.excel.ui.UIPrintTitles;
@@ -415,20 +416,12 @@
             UIPrintTitles printTitles = (UIPrintTitles) child;
             settings.setPrintTitles(printTitles.getFirstCol(), printTitles.getFirstRow(), printTitles.getLastCol(), printTitles.getLastRow());
          }
-         else if (child.getClass() == UIHeaderFooter.class)
-         {
-            UIHeaderFooter headerFooter = (UIHeaderFooter) child;
-            switch (headerFooter.getType())
-            {
-            case header:
-               settings.setHeader(JXLFactory.createHeaderFooter(headerFooter, settings.getHeader()));
-               break;
-            case footer:
-               settings.setFooter(JXLFactory.createHeaderFooter(headerFooter, settings.getFooter()));
-               break;
-            default:
-               throw new ExcelWorkbookException("Header/Footer type " + headerFooter.getType() + " not supported, try [header, footer]");
-            }
+         else if (child.getClass() == UIHeader.class) {
+            UIHeader uiHeader = (UIHeader) child;
+            settings.setHeader(JXLFactory.createHeaderFooter(uiHeader, settings.getHeader()));
+         } else if (child.getClass() == UIFooter.class) {
+            UIFooter uiFooter = (UIFooter) child;
+            settings.setFooter(JXLFactory.createHeaderFooter(uiFooter, settings.getFooter()));
          }
       }
    }

Added: trunk/src/excel/org/jboss/seam/excel/ui/UIFooter.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIFooter.java	                        (rev 0)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIFooter.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -0,0 +1,17 @@
+package org.jboss.seam.excel.ui;
+
+public class UIFooter extends ExcelComponent
+{
+   public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIFooter";
+
+   public static final String LEFT_FACET = "left";
+   public static final String CENTER_FACET = "center";
+   public static final String RIGHT_FACET = "right";
+
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_TYPE;
+   }
+
+}

Added: trunk/src/excel/org/jboss/seam/excel/ui/UIHeader.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIHeader.java	                        (rev 0)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIHeader.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -0,0 +1,17 @@
+package org.jboss.seam.excel.ui;
+
+public class UIHeader extends ExcelComponent
+{
+   public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIHeader";
+
+   public static final String LEFT_FACET = "left";
+   public static final String CENTER_FACET = "center";
+   public static final String RIGHT_FACET = "right";
+
+   @Override
+   public String getFamily()
+   {
+      return COMPONENT_TYPE;
+   }
+
+}

Deleted: trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooter.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooter.java	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooter.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -1,34 +0,0 @@
-package org.jboss.seam.excel.ui;
-
-public class UIHeaderFooter extends ExcelComponent
-{
-   public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIHeaderFooter";
-
-   public static final String LEFT_FACET = "left";
-   public static final String CENTER_FACET = "center";
-   public static final String RIGHT_FACET = "right";
-
-   public enum Type
-   {
-      header, footer
-   }
-
-   private Type type;
-
-   public Type getType()
-   {
-      return (Type) valueOf("type", type);
-   }
-
-   public void setType(Type type)
-   {
-      this.type = type;
-   }
-
-   @Override
-   public String getFamily()
-   {
-      return COMPONENT_TYPE;
-   }
-
-}

Deleted: trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommand.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommand.java	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommand.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -1,41 +0,0 @@
-package org.jboss.seam.excel.ui;
-
-public class UIHeaderFooterCommand extends ExcelComponent
-{
-   public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIHeaderFooterCommand";
-
-   public enum Command
-   {
-      append, date, page_number, time, total_pages, workbook_name, worksheet_name, toggle_bold, toggle_double_underline, toggle_italics, toggle_outline, toggle_shadow, toggle_strikethrough, toggle_subscript, toggle_superscript, toggle_underline, font_name, font_size
-   }
-
-   private Command command;
-   private Object parameter;
-
-   public Command getCommand()
-   {
-      return (Command) valueOf("command", command);
-   }
-
-   public void setCommand(Command command)
-   {
-      this.command = command;
-   }
-
-   public Object getParameter()
-   {
-      return valueOf("parameter", parameter);
-   }
-
-   public void setParameter(Object parameter)
-   {
-      this.parameter = parameter;
-   }
-
-   @Override
-   public String getFamily()
-   {
-      return COMPONENT_TYPE;
-   }
-
-}

Deleted: trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommands.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommands.java	2008-09-11 15:19:14 UTC (rev 8985)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIHeaderFooterCommands.java	2008-09-11 20:10:57 UTC (rev 8986)
@@ -1,13 +0,0 @@
-package org.jboss.seam.excel.ui;
-
-public class UIHeaderFooterCommands extends ExcelComponent
-{
-   public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIHeaderFooterCommands";
-
-   @Override
-   public String getFamily()
-   {
-      return COMPONENT_TYPE;
-   }
-
-}




More information about the seam-commits mailing list