[seam-commits] Seam SVN: r13506 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/css and 6 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Jul 26 03:46:17 EDT 2010


Author: nickarls
Date: 2010-07-26 03:46:16 -0400 (Mon, 26 Jul 2010)
New Revision: 13506

Added:
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/CSSNames.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/Parser.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilder.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilders.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleMap.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleStringParser.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/CellFormatFactory.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/ComponentStyle.java
Modified:
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Background.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Border.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormat.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Colour.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Font.java
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/util/ReflectionUtil.java
   sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
   sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java
   sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
Log:
dump of the (untested) css port/strip from Seam 2

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/CSSNames.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/CSSNames.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/CSSNames.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,53 @@
+package org.jboss.seam.spreadsheet.css;
+
+public class CSSNames
+{
+   public static final String FONT_FAMILY = "xls-font-family";
+   public static final String FONT_SIZE = "xls-font-size";
+   public static final String FONT_COLOR = "xls-font-color";
+   public static final String FONT_ITALIC = "xls-font-italic";
+   public static final String FONT_SCRIPT_STYLE = "xls-font-script-style";
+   public static final String FONT_STRUCK_OUT = "xls-font-struck-out";
+   public static final String FONT_UNDERLINE_STYLE = "xls-font-underline-style";
+   public static final String FONT_BOLD = "xls-font-bold";
+   public static final String FONT = "xls-font";
+
+   public static final String BACKGROUND_PATTERN = "xls-background-pattern";
+   public static final String BACKGROUND_COLOR = "xls-background-color";
+   public static final String BACKGROUND = "xls-background";
+
+   public static final String BORDER_LEFT_COLOR = "xls-border-left-color";
+   public static final String BORDER_LEFT_LINE_STYLE = "xls-border-left-line-style";
+   public static final String BORDER_LEFT = "xls-border-left";
+
+   public static final String BORDER_TOP_COLOR = "xls-border-top-color";
+   public static final String BORDER_TOP_LINE_STYLE = "xls-border-top-line-style";
+   public static final String BORDER_TOP = "xls-border-top";
+
+   public static final String BORDER_RIGHT_COLOR = "xls-border-right-color";
+   public static final String BORDER_RIGHT_LINE_STYLE = "xls-border-right-line-style";
+   public static final String BORDER_RIGHT = "xls-border-right";
+
+   public static final String BORDER_BOTTOM_COLOR = "xls-border-bottom-color";
+   public static final String BORDER_BOTTOM_LINE_STYLE = "xls-border-bottom-line-style";
+   public static final String BORDER_BOTTOM = "xls-border-bottom";
+
+   public static final String BORDER = "xls-border";
+
+   public static final String ALIGNMENT = "xls-alignment";
+   public static final String FORMAT_MASK = "xls-format-mask";
+   public static final String INDENTATION = "xls-indentation";
+   public static final String LOCKED = "xls-locked";
+   public static final String ORIENTATION = "xls-orientation";
+   public static final String SHRINK_TO_FIT = "xls-shrink-to-fit";
+   public static final String VERICAL_ALIGNMENT = "xls-vertical-alignment";
+   public static final String WRAP = "xls-wrap";
+   public static final String FORCE_TYPE = "xls-force-type";
+
+   public static final String COLUMN_WIDTH = "xls-column-width";
+   public static final String COLUMN_WIDTHS = "xls-column-widths";
+   public static final String COLUMN_AUTO_SIZE = "xls-column-autosize";
+   public static final String COLUMN_HIDDEN = "xls-column-hidden";
+   public static final String COLUMN_EXPORT = "xls-column-export";
+
+}

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/Parser.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/Parser.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/Parser.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,115 @@
+package org.jboss.seam.spreadsheet.css;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+
+public class Parser
+{
+   private static final String STYLE_SHORTHAND_SEPARATOR = " ";
+   private static final String LEFT_BRACE = "{";
+   private static final String RIGHT_BRACE = "}";
+
+   private Map<String, PropertyBuilder> propertyBuilders = PropertyBuilders.getPropertyBuilders();
+
+   private Map<String, StyleMap> definedStyleClasses = new HashMap<String, StyleMap>();
+
+   public void loadStylesheet(URL stylesheet)
+   {
+      try
+      {
+         definedStyleClasses.putAll(parseStylesheet(stylesheet));
+      }
+      catch (MalformedURLException e)
+      {
+         throw new SpreadsheetException(String.format("Malformed URL for stylesheet %s", stylesheet), e);
+      }
+      catch (IOException e)
+      {
+         throw new SpreadsheetException(String.format("Could not read CSS from stylesheet %s", stylesheet), e);
+      }
+   }
+
+   private Map<String, StyleMap> parseStylesheet(URL url) throws MalformedURLException, IOException
+   {
+      Map<String, StyleMap> styleClasses = new HashMap<String, StyleMap>();
+      String css = readCSS(url.openStream()).toLowerCase();
+      int firstBrace = -1;
+      int secondBrace = -1;
+      while (!"".equals(css))
+      {
+         firstBrace = css.indexOf(LEFT_BRACE);
+         if (firstBrace >= 0)
+         {
+            secondBrace = css.indexOf(RIGHT_BRACE, firstBrace + 1);
+         }
+         if (firstBrace >= 0 && secondBrace >= 0 && firstBrace != secondBrace)
+         {
+            String styleName = css.substring(0, firstBrace).trim();
+            if (styleName.startsWith("."))
+            {
+               styleName = styleName.substring(1);
+            }
+            String styleString = css.substring(firstBrace + 1, secondBrace).trim();
+            StyleMap styleMap = StyleStringParser.of(styleString, propertyBuilders).parse();
+            styleClasses.put(styleName, styleMap);
+            css = css.substring(secondBrace + 1);
+         }
+         else
+         {
+            css = "";
+         }
+      }
+      return styleClasses;
+   }
+
+   private static String readCSS(InputStream in) throws IOException
+   {
+      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+      StringBuilder builder = new StringBuilder();
+      String line;
+      while ((line = reader.readLine()) != null)
+      {
+         builder.append(line);
+      }
+      reader.close();
+      return builder.toString();
+   }
+
+   public StyleMap parseStyle(String style)
+   {
+      if (style == null)
+      {
+         return new StyleMap();
+      }
+      return StyleStringParser.of(style, propertyBuilders).parse();
+   }
+
+   public StyleMap parseStyleClasses(String styleClasses)
+   {
+      if (styleClasses == null)
+      {
+         return new StyleMap();
+      }
+      StyleMap styleMap = new StyleMap();
+      String[] trimmedClasses = StyleStringParser.trimArray(styleClasses.split(STYLE_SHORTHAND_SEPARATOR));
+      for (String styleClass : trimmedClasses)
+      {
+         if (!definedStyleClasses.containsKey(styleClass))
+         {
+            System.out.println(String.format("Unknown style class #0", styleClass));
+            continue;
+         }
+         styleMap.putAll(definedStyleClasses.get(styleClass));
+      }
+      return null;
+   }
+
+}
\ No newline at end of file

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilder.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilder.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilder.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,6 @@
+package org.jboss.seam.spreadsheet.css;
+
+public interface PropertyBuilder
+{
+   public StyleMap parseProperty(String key, String[] values);
+}
\ No newline at end of file

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilders.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilders.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/PropertyBuilders.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,509 @@
+package org.jboss.seam.spreadsheet.css;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+
+public class PropertyBuilders
+{
+   private static final String COLUMN_WIDTH_WILDCARD = "*";
+
+   public static Map<String, PropertyBuilder> getPropertyBuilders()
+   {
+      Map<String, PropertyBuilder> propertyBuilders = new HashMap<String, PropertyBuilder>();
+      propertyBuilders.put(CSSNames.FONT_FAMILY, new PropertyBuilders.FontFamily());
+      propertyBuilders.put(CSSNames.FONT_SIZE, new PropertyBuilders.FontSize());
+      propertyBuilders.put(CSSNames.FONT_COLOR, new PropertyBuilders.FontColor());
+      propertyBuilders.put(CSSNames.FONT_ITALIC, new PropertyBuilders.FontItalic());
+      propertyBuilders.put(CSSNames.FONT_SCRIPT_STYLE, new PropertyBuilders.FontScriptStyle());
+      propertyBuilders.put(CSSNames.FONT_STRUCK_OUT, new PropertyBuilders.FontStruckOut());
+      propertyBuilders.put(CSSNames.FONT_UNDERLINE_STYLE, new PropertyBuilders.FontUnderlineStyle());
+      propertyBuilders.put(CSSNames.FONT_BOLD, new PropertyBuilders.FontBold());
+      propertyBuilders.put(CSSNames.FONT, new PropertyBuilders.FontShorthand());
+      propertyBuilders.put(CSSNames.BACKGROUND_PATTERN, new PropertyBuilders.BackgroundPattern());
+      propertyBuilders.put(CSSNames.BACKGROUND_COLOR, new PropertyBuilders.BackgroundColor());
+      propertyBuilders.put(CSSNames.BACKGROUND, new PropertyBuilders.BackgroundShorthand());
+      propertyBuilders.put(CSSNames.BORDER_LEFT_COLOR, new PropertyBuilders.BorderLeftColor());
+      propertyBuilders.put(CSSNames.BORDER_LEFT_LINE_STYLE, new PropertyBuilders.BorderLeftLineStyle());
+      propertyBuilders.put(CSSNames.BORDER_LEFT, new PropertyBuilders.BorderLeftShorthand());
+      propertyBuilders.put(CSSNames.BORDER_TOP_COLOR, new PropertyBuilders.BorderTopColor());
+      propertyBuilders.put(CSSNames.BORDER_TOP_LINE_STYLE, new PropertyBuilders.BorderTopLineStyle());
+      propertyBuilders.put(CSSNames.BORDER_TOP, new PropertyBuilders.BorderTopShorthand());
+      propertyBuilders.put(CSSNames.BORDER_RIGHT_COLOR, new PropertyBuilders.BorderRightColor());
+      propertyBuilders.put(CSSNames.BORDER_RIGHT_LINE_STYLE, new PropertyBuilders.BorderRightLineStyle());
+      propertyBuilders.put(CSSNames.BORDER_RIGHT, new PropertyBuilders.BorderRightShorthand());
+      propertyBuilders.put(CSSNames.BORDER_BOTTOM_COLOR, new PropertyBuilders.BorderBottomColor());
+      propertyBuilders.put(CSSNames.BORDER_BOTTOM_LINE_STYLE, new PropertyBuilders.BorderBottomLineStyle());
+      propertyBuilders.put(CSSNames.BORDER_BOTTOM, new PropertyBuilders.BorderBottomShorthand());
+      propertyBuilders.put(CSSNames.BORDER, new PropertyBuilders.BorderShorthand());
+      propertyBuilders.put(CSSNames.FORMAT_MASK, new PropertyBuilders.FormatMask());
+      propertyBuilders.put(CSSNames.ALIGNMENT, new PropertyBuilders.Alignment());
+      propertyBuilders.put(CSSNames.INDENTATION, new PropertyBuilders.Indentation());
+      propertyBuilders.put(CSSNames.ORIENTATION, new PropertyBuilders.Orientation());
+      propertyBuilders.put(CSSNames.LOCKED, new PropertyBuilders.Locked());
+      propertyBuilders.put(CSSNames.SHRINK_TO_FIT, new PropertyBuilders.ShrinkToFit());
+      propertyBuilders.put(CSSNames.WRAP, new PropertyBuilders.Wrap());
+      propertyBuilders.put(CSSNames.VERICAL_ALIGNMENT, new PropertyBuilders.VericalAlignment());
+      propertyBuilders.put(CSSNames.COLUMN_WIDTH, new PropertyBuilders.ColumnWidth());
+      propertyBuilders.put(CSSNames.COLUMN_AUTO_SIZE, new PropertyBuilders.ColumnAutoSize());
+      propertyBuilders.put(CSSNames.COLUMN_HIDDEN, new PropertyBuilders.ColumnHidden());
+      propertyBuilders.put(CSSNames.COLUMN_EXPORT, new PropertyBuilders.ColumnExport());
+      propertyBuilders.put(CSSNames.COLUMN_WIDTHS, new PropertyBuilders.ColumnWidths());
+      propertyBuilders.put(CSSNames.FORCE_TYPE, new PropertyBuilders.ForceType());
+      return propertyBuilders;
+   }
+
+   public static class ForceType extends StringPropertyBuilder
+   {
+   }
+
+   public static class ColumnWidths implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            String indexedKey = CSSNames.COLUMN_WIDTHS + i;
+            if (COLUMN_WIDTH_WILDCARD.equals(value))
+            {
+               // Skip it, just moving along
+            }
+            else if (isNumeric(value))
+            {
+               styleMap.put(indexedKey, Integer.parseInt(value));
+            }
+            else
+            {
+               throw new SpreadsheetException(String.format("Column widths must be numerical or *, not #0", value));
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class ColumnWidth extends IntegerPropertyBuilder
+   {
+   }
+
+   public static class ColumnAutoSize extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class ColumnHidden extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class ColumnExport extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class BorderBottomLineStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderBottomColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderBottomShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Colour.isColour(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_BOTTOM_COLOR, value);
+            }
+            else if (BorderLineStyle.isBorderLineStyle(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_BOTTOM_LINE_STYLE, value);
+            }
+            else
+            {
+               throw new SpreadsheetException("Border bottom shorthand can only handle line style and color");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class BorderRightLineStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderRightColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderRightShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Colour.isColour(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_RIGHT_COLOR, value);
+            }
+            else if (BorderLineStyle.isBorderLineStyle(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_RIGHT_LINE_STYLE, value);
+            }
+            else
+            {
+               throw new SpreadsheetException("Border right shorthand can only handle line style and color");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class BorderTopLineStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderTopColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderTopShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Colour.isColour(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_TOP_COLOR, value);
+            }
+            else if (BorderLineStyle.isBorderLineStyle(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_TOP_LINE_STYLE, value);
+            }
+            else
+            {
+               throw new SpreadsheetException("Border top shorthand can only handle line style and color");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class BorderLeftLineStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderLeftColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class BorderLeftShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Colour.isColour(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_LEFT_COLOR, value);
+            }
+            else if (BorderLineStyle.isBorderLineStyle(values[i]))
+            {
+               styleMap.put(CSSNames.BORDER_LEFT_LINE_STYLE, value);
+            }
+            else
+            {
+               throw new SpreadsheetException("Border left shorthand can only handle line style and color");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class BorderShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Colour.isColour(value))
+            {
+               styleMap.put(CSSNames.BORDER_LEFT_COLOR, values[1]);
+               styleMap.put(CSSNames.BORDER_RIGHT_COLOR, values[1]);
+               styleMap.put(CSSNames.BORDER_TOP_COLOR, values[1]);
+               styleMap.put(CSSNames.BORDER_BOTTOM_COLOR, values[1]);
+            }
+            else if (BorderLineStyle.isBorderLineStyle(value))
+            {
+               styleMap.put(CSSNames.BORDER_LEFT_LINE_STYLE, values[0]);
+               styleMap.put(CSSNames.BORDER_RIGHT_LINE_STYLE, values[0]);
+               styleMap.put(CSSNames.BORDER_TOP_LINE_STYLE, values[0]);
+               styleMap.put(CSSNames.BORDER_BOTTOM_LINE_STYLE, values[0]);
+            }
+            else
+            {
+               throw new SpreadsheetException("Border shorthand can only handle line style and color");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class BackgroundColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class BackgroundPattern extends StringPropertyBuilder
+   {
+   }
+
+   public static class BackgroundShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (Pattern.isPattern(values[i]))
+            {
+               styleMap.put(CSSNames.BACKGROUND_PATTERN, value);
+            }
+            else if (Colour.isColour(values[i]))
+            {
+               styleMap.put(CSSNames.BACKGROUND_COLOR, value);
+            }
+            else
+            {
+               throw new SpreadsheetException("Background shorthand can only handle color and pattern");
+            }
+         }
+         return styleMap;
+      }
+   }
+
+   public static class FontFamily extends MergingStringPropertyBuilder
+   {
+   }
+
+   private static String collectString(String[] values, String delimiter)
+   {
+      StringBuffer buffer = new StringBuffer();
+      for (int i = 0; i < values.length; i++)
+      {
+         if (i > 0)
+         {
+            buffer.append(delimiter);
+         }
+         buffer.append(values[i]);
+      }
+      return buffer.toString();
+   }
+
+   private static class MergingStringPropertyBuilder extends StringPropertyBuilder
+   {
+      @Override
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         String concatValues = collectString(values, " ");
+         return super.parseProperty(key, new String[] { concatValues });
+      }
+   }
+
+   public static class FontSize extends IntegerPropertyBuilder
+   {
+   }
+
+   public static class FontColor extends StringPropertyBuilder
+   {
+   }
+
+   public static class FontItalic extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class FontScriptStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class FontUnderlineStyle extends StringPropertyBuilder
+   {
+   }
+
+   public static class FontBold extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class FontStruckOut extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class FontShorthand implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+
+         String valueString = collectString(values, " ");
+         int firstQuote = valueString.indexOf("'");
+         int lastQuote = valueString.lastIndexOf("'");
+         if (firstQuote > 0 && lastQuote > 0 && firstQuote != lastQuote)
+         {
+            String fontName = valueString.substring(firstQuote, lastQuote);
+            styleMap.put(CSSNames.FONT_FAMILY, fontName);
+            String pre = valueString.substring(0, firstQuote - 1).trim();
+            String post = valueString.substring(lastQuote + 1).trim();
+            valueString = pre + post;
+            values = valueString.split(" ");
+         }
+
+         for (int i = 0; i < values.length; i++)
+         {
+            String value = values[i];
+            if (ScriptStyle.isScriptStyle(value))
+            {
+               styleMap.put(CSSNames.FONT_SCRIPT_STYLE, value);
+            }
+            else if (Colour.isColour(value))
+            {
+               styleMap.put(CSSNames.FONT_COLOR, value);
+            }
+            else if (UnderlineStyle.isUnderlineStyle(value))
+            {
+               styleMap.put(CSSNames.FONT_UNDERLINE_STYLE, value);
+            }
+            else if ("italic".equals(value.toLowerCase()))
+            {
+               styleMap.put(CSSNames.FONT_ITALIC, Boolean.TRUE);
+            }
+            else if ("bold".equals(value.toLowerCase()))
+            {
+               styleMap.put(CSSNames.FONT_BOLD, Boolean.TRUE);
+            }
+            else if ("struck_out".equals(value.toLowerCase()))
+            {
+               styleMap.put(CSSNames.FONT_STRUCK_OUT, Boolean.TRUE);
+            }
+            else if (isNumeric(value))
+            {
+               styleMap.put(CSSNames.FONT_SIZE, Integer.parseInt(value));
+            }
+            else
+            {
+               styleMap.put(CSSNames.FONT_FAMILY, value);
+            }
+         }
+
+         return styleMap;
+      }
+   }
+
+   private static boolean isNumeric(String value)
+   {
+      try
+      {
+         Integer.parseInt(value);
+      }
+      catch (NumberFormatException e)
+      {
+         return false;
+      }
+      return true;
+   }
+
+   private static boolean isBoolean(String value)
+   {
+      return "true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value);
+   }
+
+   public static class VericalAlignment extends StringPropertyBuilder
+   {
+   }
+
+   public static class Wrap extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class ShrinkToFit extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class Locked extends BooleanPropertyBuilder
+   {
+   }
+
+   public static class Orientation extends StringPropertyBuilder
+   {
+   }
+
+   public static class Indentation extends IntegerPropertyBuilder
+   {
+   }
+
+   public static class Alignment extends StringPropertyBuilder
+   {
+   }
+
+   public static class FormatMask extends MergingStringPropertyBuilder
+   {
+   }
+
+   private static class StringPropertyBuilder implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         StyleMap styleMap = new StyleMap();
+         styleMap.put(key, values[0]);
+         return styleMap;
+      }
+   }
+
+   private static class IntegerPropertyBuilder implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         String value = values[0];
+         if (!isNumeric(value))
+         {
+            throw new SpreadsheetException(String.format("%s is not a number in #s", value, key));
+         }
+         StyleMap styleMap = new StyleMap();
+         styleMap.put(key, Integer.parseInt(value));
+         return styleMap;
+      }
+   }
+
+   private static class BooleanPropertyBuilder implements PropertyBuilder
+   {
+      public StyleMap parseProperty(String key, String[] values)
+      {
+         String value = values[0];
+         if (!isBoolean(value))
+         {
+            throw new SpreadsheetException(String.format("%s is not a boolean in #s", value, key));
+         }
+         StyleMap styleMap = new StyleMap();
+         styleMap.put(key, Boolean.parseBoolean(value));
+         return styleMap;
+      }
+   }
+}
\ No newline at end of file

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleMap.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleMap.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleMap.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,8 @@
+package org.jboss.seam.spreadsheet.css;
+
+import java.util.HashMap;
+
+public class StyleMap extends HashMap<String, Object>
+{
+   private static final long serialVersionUID = 1L;
+}

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleStringParser.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleStringParser.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/css/StyleStringParser.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,98 @@
+package org.jboss.seam.spreadsheet.css;
+
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class StyleStringParser
+{
+   private static final char STYLE_SEPARATOR = ';';
+   private static final String KEY_VALUE_SEPARATOR = ":";
+   private static final String STYLE_SHORTHAND_SEPARATOR = " ";
+   private static final char ESCAPE_CHAR = '\'';
+   
+   private String styleString;
+   private Map<String, PropertyBuilder> propertyBuilderMap;
+   private StyleMap styleMap = new StyleMap();
+   private boolean escaping = false;
+   
+   public static StyleStringParser of(String styleString, Map<String, PropertyBuilder> propertyBuilderMap)
+   {
+      return new StyleStringParser(styleString, propertyBuilderMap);
+   }
+   
+   protected StyleStringParser(String styleString, Map<String, PropertyBuilder> propertyBuilderMap)
+   {
+      this.styleString = styleString;
+      this.propertyBuilderMap = propertyBuilderMap;
+   }
+   
+   private void addStyle(StringBuilder styleBuilder)
+   {
+      String styleString = styleBuilder.toString();
+      int keyValueBreakpointIndex = styleString.indexOf(KEY_VALUE_SEPARATOR);
+      if (keyValueBreakpointIndex < 0)
+      {
+         System.out.println(String.format("Key-value separator character #0 not found in style #1, dropping", KEY_VALUE_SEPARATOR + styleBuilder.toString()));
+         return;
+      }
+      String styleName = styleString.substring(0, keyValueBreakpointIndex).toLowerCase().trim();
+      if (!propertyBuilderMap.containsKey(styleName))
+      {
+         System.out.println(String.format("No property builder (unknown style) for property #0", styleName));
+         return;
+      }
+      PropertyBuilder propertyBuilder = propertyBuilderMap.get(styleName);
+      String styleValue = styleString.substring(keyValueBreakpointIndex + 1);
+      System.out.println(String.format("Parsed style #0 to #1 => #2", styleString, styleName, styleValue));
+      String[] styleValues = trimArray(styleValue.trim().split(STYLE_SHORTHAND_SEPARATOR));
+      styleMap.putAll(propertyBuilder.parseProperty(styleName, styleValues));
+   }
+   
+   public static String[] trimArray(String[] array)
+   {
+      List<String> validValues = new ArrayList<String>();
+      for (int i = 0; i < array.length; i++)
+      {
+         if (!"".equals(array[i]) && !" ".equals(array[i]))
+         {
+            validValues.add(array[i].toLowerCase().trim());
+         }
+      }
+      return validValues.toArray(new String[validValues.size()]);
+   }
+   
+   public StyleMap parse()
+   {
+      CharacterIterator iterator = new StringCharacterIterator(styleString);
+      StringBuilder styleBuilder = new StringBuilder();
+      for (char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next())
+      {
+         if (ESCAPE_CHAR == c)
+         {
+            escaping = !escaping;
+         }
+         else if (STYLE_SEPARATOR == c && !escaping)
+         {
+            addStyle(styleBuilder);
+            styleBuilder = new StringBuilder();
+         }
+         else
+         {
+            styleBuilder.append(c);
+         }
+      }
+      if (styleBuilder.length() > 0)
+      {
+         addStyle(styleBuilder);
+      }
+      
+      if (escaping)
+      {
+         System.out.println(String.format("Unbalanced escape characters #0 in style #1", ESCAPE_CHAR, styleBuilder.toString()));
+      }
+      return styleMap;
+   }
+}
\ No newline at end of file

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/CellFormatFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/CellFormatFactory.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/CellFormatFactory.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,15 @@
+package org.jboss.seam.spreadsheet.jsf;
+
+import org.jboss.seam.spreadsheet.css.StyleMap;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class CellFormatFactory
+{
+
+   public static CellFormat getCellFormat(StyleMap styleMap)
+   {
+      CellFormat cellFormat = new CellFormat();
+      return cellFormat;
+   }
+
+}

Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/ComponentStyle.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/ComponentStyle.java	                        (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jsf/ComponentStyle.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -0,0 +1,80 @@
+package org.jboss.seam.spreadsheet.jsf;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+
+import org.jboss.seam.spreadsheet.css.Parser;
+import org.jboss.seam.spreadsheet.css.StyleMap;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+import org.jboss.seam.spreadsheet.util.ReflectionUtil;
+
+public class ComponentStyle
+{
+   private static final String STYLE_CLASS_ATTRIBUTE = "styleClass";
+   private static final String STYLE_ATTRIBUTE = "style";
+
+   private Parser parser = new Parser();
+
+   public void load(URL stylesheet)
+   {
+      parser.loadStylesheet(stylesheet);
+   }
+
+   public CellFormat getCellFormat(UIComponent component)
+   {
+      List<StyleMap> styleMaps = getStyleMapHierarchy(component);
+      List<CellFormat> cellFormats = getCellFormats(styleMaps);
+      return CellFormat.merge(cellFormats);
+   }
+
+   private List<StyleMap> getStyleMapHierarchy(UIComponent component)
+   {
+      List<StyleMap> styleMaps = new ArrayList<StyleMap>();
+      UIComponent currentComponent = component;
+      while (currentComponent != null)
+      {
+         styleMaps.add(getStyleMap(currentComponent));
+         if (currentComponent.getParent() != null)
+         {
+            currentComponent = currentComponent.getParent();
+         }
+         else
+         {
+            currentComponent = null;
+         }
+      }
+      return styleMaps;
+   }
+
+   private List<CellFormat> getCellFormats(List<StyleMap> styleMaps)
+   {
+      List<CellFormat> cellFormats = new ArrayList<CellFormat>();
+      for (StyleMap styleMap : styleMaps)
+      {
+         cellFormats.add(CellFormatFactory.getCellFormat(styleMap));
+      }
+      return cellFormats;
+   }
+
+   private StyleMap getStyleMap(UIComponent component)
+   {
+      StyleMap styleMap = new StyleMap();
+      styleMap.putAll(parser.parseStyleClasses(getStyleClassProperty(component)));
+      styleMap.putAll(parser.parseStyle(getStyleProperty(component)));
+      return styleMap;
+   }
+
+   private String getStyleProperty(UIComponent component)
+   {
+      return (String) ReflectionUtil.readRawField(component, STYLE_ATTRIBUTE);
+   }
+
+   private String getStyleClassProperty(UIComponent component)
+   {
+      return (String) ReflectionUtil.readRawField(component, STYLE_CLASS_ATTRIBUTE);
+   }
+
+}

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -34,7 +34,7 @@
    private SettingsHelper settingsHelper = new SettingsHelper();
 
    @Inject
-   private Events events;
+//   private Events events;
 
    @Override
    public SpreadsheetWriter processWorkbook(Workbook workbook) throws SpreadsheetException
@@ -81,7 +81,7 @@
    private void processWorksheet(Worksheet worksheet, List<Command> workbookCommands)
    {
       cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
-      events.worksheetCreated(worksheet);
+//      events.worksheetCreated(worksheet);
       WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
       if (worksheet.getSettings() != null)
       {
@@ -100,7 +100,7 @@
       for (Command command : commands)
       {
          JxlCommand jxlCommand = CommandFactory.getJxlCommand(command, jxlWorksheet);
-         events.commandExecuted(command);
+//         events.commandExecuted(command);
          jxlCommand.execute();
       }
    }
@@ -109,7 +109,7 @@
    {
       try
       {
-         events.cellAdded(cell);
+//         events.cellAdded(cell);
          jxlWorksheet.addCell(cellFactory.createCell(cell, cellFormatResolver));
          if (cell.getCellSpan() != null)
          {

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Background.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Background.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Background.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -6,7 +6,20 @@
 {
    public enum Pattern
    {
-      GRAY_25, GRAY_50, GRAY_75, NONE, PATTERN1, PATTERN10, PATTERN11, PATTERN12, PATTERN13, PATTERN14, PATTERN2, PATTERN3, PATTERN4, PATTERN5, PATTERN6, PATTERN7, PATTERN8, PATTERN9, SOLID
+      GRAY_25, GRAY_50, GRAY_75, NONE, PATTERN1, PATTERN10, PATTERN11, PATTERN12, PATTERN13, PATTERN14, PATTERN2, PATTERN3, PATTERN4, PATTERN5, PATTERN6, PATTERN7, PATTERN8, PATTERN9, SOLID;
+      
+      public static boolean isPattern(String pattern)
+      {
+         try
+         {
+            valueOf(pattern);
+         }
+         catch (IllegalArgumentException e)
+         {
+            return false;
+         }
+         return true;
+      }      
    }
 
    private Colour colour;

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Border.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Border.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Border.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -2,8 +2,6 @@
 
 import static org.jboss.seam.spreadsheet.util.HashUtil.same;
 
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
-
 public class Border
 {
    public enum BorderType
@@ -13,7 +11,20 @@
 
    public enum BorderLineStyle
    {
-      DASH_DOT, DASH_DOT_DOT, DASHED, DOTTED, DOUBLE, HAIR, MEDIUM, MEDIUM_DASH_DOT, MEDIUM_DASH_DOT_DOT, MEDIUM_DASHED, NONE, SLANTED_DASH_DOT, THICK, THIN
+      DASH_DOT, DASH_DOT_DOT, DASHED, DOTTED, DOUBLE, HAIR, MEDIUM, MEDIUM_DASH_DOT, MEDIUM_DASH_DOT_DOT, MEDIUM_DASHED, NONE, SLANTED_DASH_DOT, THICK, THIN;
+      
+      public static boolean isBorderLineStyle(String borderLineStyle)
+      {
+         try
+         {
+            valueOf(borderLineStyle);
+         }
+         catch (IllegalArgumentException e)
+         {
+            return false;
+         }
+         return true;
+      }      
    }
 
    private BorderType borderType;

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormat.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormat.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormat.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -267,4 +267,14 @@
       return same(font, otherCellFormat.getFont()) && same(alignment, otherCellFormat.getAlignment()) && same(background, otherCellFormat.getBackground()) && same(borders, otherCellFormat.getBorders()) && same(indentation, otherCellFormat.getIndentation()) && same(locked, otherCellFormat.getLocked()) && same(orientation, otherCellFormat.getOrientation()) && same(shrinkToFit, otherCellFormat.getShrinkToFit()) && same(verticalAlignment, otherCellFormat.getVerticalAlignment()) && same(wrap, otherCellFormat.getWrap()) && same(mask, otherCellFormat.getMask());
    }
 
+   public static CellFormat merge(List<CellFormat> cellFormats)
+   {
+      CellFormat newCellFormat = new CellFormat();
+      for (CellFormat cellFormat : cellFormats)
+      {
+         newCellFormat.merge(cellFormat);
+      }
+      return newCellFormat;
+   }
+
 }

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Colour.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Colour.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Colour.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -2,5 +2,18 @@
 
 public enum Colour
 {
-   AQUA, AUTOMATIC, BLACK, BLUE, BLUE_GREY, BLUE2, BRIGHT_GREEN, BROWN, CORAL, DARK_BLUE, DARK_BLUE2, DARK_GREEN, DARK_PURPLE, DARK_RED, DARK_RED2, DARK_TEAL, DARK_YELLOW, DEFAULT_BACKGROUND, DEFAULT_BACKGROUND1, GOLD, GRAY_25, GRAY_50, GRAY_80, GREEN, GREY_25_PERCENT, GREY_40_PERCENT, GREY_50_PERCENT, GREY_80_PERCENT, ICE_BLUE, INDIGO, IVORY, LAVENDER, LIGHT_BLUE, LIGHT_GREEN, LIGHT_ORANGE, LIGHT_TURQUOISE, LIGHT_TURQUOISE2, LIME, OCEAN_BLUE, OLIVE_GREEN, ORANGE, PALE_BLUE, PALETTE_BLACK, PERIWINKLE, PINK, PINK2, PLUM, PLUM2, RED, ROSE, SEA_GREEN, SKY_BLUE, TAN, TEAL, TEAL2, TURQOISE2, TURQUOISE, UNKNOWN, VERY_LIGHT_YELLOW, VIOLET, VIOLET2, WHITE, YELLOW, YELLOW2
+   AQUA, AUTOMATIC, BLACK, BLUE, BLUE_GREY, BLUE2, BRIGHT_GREEN, BROWN, CORAL, DARK_BLUE, DARK_BLUE2, DARK_GREEN, DARK_PURPLE, DARK_RED, DARK_RED2, DARK_TEAL, DARK_YELLOW, DEFAULT_BACKGROUND, DEFAULT_BACKGROUND1, GOLD, GRAY_25, GRAY_50, GRAY_80, GREEN, GREY_25_PERCENT, GREY_40_PERCENT, GREY_50_PERCENT, GREY_80_PERCENT, ICE_BLUE, INDIGO, IVORY, LAVENDER, LIGHT_BLUE, LIGHT_GREEN, LIGHT_ORANGE, LIGHT_TURQUOISE, LIGHT_TURQUOISE2, LIME, OCEAN_BLUE, OLIVE_GREEN, ORANGE, PALE_BLUE, PALETTE_BLACK, PERIWINKLE, PINK, PINK2, PLUM, PLUM2, RED, ROSE, SEA_GREEN, SKY_BLUE, TAN, TEAL, TEAL2, TURQOISE2, TURQUOISE, UNKNOWN, VERY_LIGHT_YELLOW, VIOLET, VIOLET2, WHITE, YELLOW, YELLOW2;
+
+   public static boolean isColour(String colour)
+   {
+      try
+      {
+         valueOf(colour);
+      }
+      catch (IllegalArgumentException e)
+      {
+         return false;
+      }
+      return true;
+   }
 }

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Font.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Font.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/Font.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -6,12 +6,38 @@
 {
    public enum ScriptStyle
    {
-      NORMAL_SCRIPT, SUBSCRIPT, SUPERSCRIPT
+      NORMAL_SCRIPT, SUBSCRIPT, SUPERSCRIPT;
+
+      public static boolean isScriptStyle(String scriptStyle)
+      {
+         try
+         {
+            valueOf(scriptStyle);
+         }
+         catch (IllegalArgumentException e)
+         {
+            return false;
+         }
+         return true;
+      }
    };
 
    public enum UnderlineStyle
    {
-      NO_UNDERLINE, SINGLE, SINGLE_ACCOUNTING, DOUBLE, DOUBLE_ACCOUNTING
+      NO_UNDERLINE, SINGLE, SINGLE_ACCOUNTING, DOUBLE, DOUBLE_ACCOUNTING;
+
+      public static boolean isUnderlineStyle(String underlineStyle)
+      {
+         try
+         {
+            valueOf(underlineStyle);
+         }
+         catch (IllegalArgumentException e)
+         {
+            return false;
+         }
+         return true;
+      }
    };
 
    private String fontName;

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/util/ReflectionUtil.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/util/ReflectionUtil.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/util/ReflectionUtil.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -72,6 +72,32 @@
       return null;
    }
 
+   public static Object readRawField(Object instance, String fieldName)
+   {
+      Field field;
+      try
+      {
+         field = instance.getClass().getField(fieldName);
+      }
+      catch (Exception e)
+      {
+         throw new SpreadsheetException(String.format("Could not access field %s from %s", fieldName, instance), e);
+      }
+      if (field != null)
+      {
+         field.setAccessible(true);
+         try
+         {
+            return field.get(instance);
+         }
+         catch (Exception e)
+         {
+            throw new SpreadsheetException(String.format("Could not read field %s from %s", fieldName, instance), e);
+         }
+      }
+      return null;
+   }
+
    private Object getByField(Object instance, String fieldName)
    {
       try

Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -7,6 +7,9 @@
 import org.jboss.seam.spreadsheet.SpreadsheetException;
 import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
 import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font;
 import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -23,7 +26,7 @@
    {
       return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
    }
-   
+
    @Test
    public void freshWorkbookStateTest()
    {
@@ -31,7 +34,7 @@
       Assert.assertTrue(workbook.getWorksheets().isEmpty());
       Assert.assertTrue(workbook.getCellFormatRules().isEmpty());
    }
-   
+
    @Test(expected = SpreadsheetException.class)
    public void noWorksheetsFailTest()
    {
@@ -39,9 +42,10 @@
       @SuppressWarnings("unused")
       jxl.Workbook jxlWorkbook = getWorkbook(workbook);
    }
-   
+
    @Test
-   public void workbookSettingsTest() {
+   public void workbookSettingsTest()
+   {
       Workbook workbook = new Workbook();
       workbook.getWorksheets().add(Worksheet.named("foo"));
       WorkbookSettings settings = new WorkbookSettings();
@@ -50,4 +54,35 @@
       workbook.setSettings(settings);
       workbookToFile(workbook, "c:/temp/foo.xls");
    }
+
+   @Test
+   public void performanceTest()
+   {
+      long time1 = System.currentTimeMillis();
+      Workbook workbook = new Workbook();
+      CellFormat cellFormat = new CellFormat();
+      Font font = new Font();
+      font.setFontName("Times New Roman");
+      font.setBold(true);
+      font.setColour(Colour.RED);
+      font.setPointSize(20);
+      cellFormat.setFont(font);
+      for (int i = 0; i < 1; i++)
+      {
+         Worksheet worksheet = Worksheet.named("Sheet " + i);
+         workbook.getWorksheets().add(worksheet);
+         for (int c = 0; c < 256; c++)
+         {
+            for (int r = 0; r < 65536; r++)
+            {
+               Cell cell = Cell.of("foo", Coordinate.of(c, r));
+               cell.setCellFormat(cellFormat);
+               worksheet.getCells().add(cell);
+            }
+         }
+      }
+      long time2 = System.currentTimeMillis();
+      workbookToFile(workbook, "c:/temp/performance.xls");
+      System.out.println(time2 - time1);
+   }
 }

Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorksheetTest.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -2,11 +2,27 @@
 
 import junit.framework.Assert;
 
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
 import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 
+ at RunWith(Arquillian.class)
 public class WorksheetTest extends SpreadsheetTest
 {
+
+   @Deployment
+   public static JavaArchive getArchive()
+   {
+      return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+   }
    
    @Test
    public void freshWorksheetStateTest()
@@ -17,20 +33,34 @@
       Assert.assertTrue(worksheet.getCommands().isEmpty());
       Assert.assertNull(worksheet.getSettings());
    }
-   
+
    @Test
-   public void usedRangeTest() {
+   public void worksheetSettingsTest()
+   {
       Worksheet worksheet = Worksheet.named("foo");
+      worksheet.getCells().add(Cell.of("foo", Coordinate.ORIGO));
+      WorksheetSettings settings = new WorksheetSettings();
+      settings.setHorizontalFreeze(5);
+      worksheet.setSettings(settings);
+      Workbook wb = new Workbook();
+      wb.getWorksheets().add(worksheet);
+      Assert.assertEquals(5, getWorkbook(wb).getSheet(0).getSettings().getHorizontalFreeze());
+   }
+
+   @Test
+   public void usedRangeTest()
+   {
+      Worksheet worksheet = Worksheet.named("foo");
       Assert.assertEquals(Range.of(0, 0, 0, 0), worksheet.getUsedRange());
    }
-   
+
    @Test
-   public void usedRangeTest2() {
+   public void usedRangeTest2()
+   {
       Worksheet worksheet = Worksheet.named("foo");
       worksheet.getCells().add(Cell.of("foo", Coordinate.of(10, 10)));
       worksheet.getCells().add(Cell.of("bar", Coordinate.of(20, 20)));
       Assert.assertEquals(Range.of(10, 10, 20, 20), worksheet.getUsedRange());
    }
-   
-   
+
 }

Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java	2010-07-25 12:39:28 UTC (rev 13505)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java	2010-07-26 07:46:16 UTC (rev 13506)
@@ -135,7 +135,7 @@
       try
       {
          FileOutputStream out = new FileOutputStream(fileName);
-         out.write(sw.processWorkbook(workbook).writeWorkbook());
+         out.write(getSpreadsheetWriter().processWorkbook(workbook).writeWorkbook());
          out.flush();
          out.close();
       }



More information about the seam-commits mailing list