/** * Creates a JExcelAPI date display format * * @param mask The format mask * @return The display format * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/write/DateFormat.html">DateFormat</a> */ public static DisplayFormat createDateFormat(String mask) { if (log.isTraceEnabled()) { log.trace("Creating date format for mask #0", mask); } try { return (DisplayFormat) getConstant(DATEFORMATS_CLASSNAME, mask.toUpperCase()); } catch (NoSuchFieldException e) { // Look! An empty catch block! But this one is documented. We are using // this to see if there is a constant // defines for this in the class return null; } }
/** * Checks if the workbook contains a sheet * * @param name * The name to look for * @return true if found, false otherwise */ private boolean workbookContainsSheet(String name) { if (log.isTraceEnabled()) { log.trace("Checking if workbook contains sheet named #0", name); } if (workbook == null) { throw new ExcelWorkbookException( "Can't search for sheets before creating a workbook"); } boolean found = false; for (String sheetName : workbook.getSheetNames()) { if (sheetName.equalsIgnoreCase(name)) { return true; } } if (log.isTraceEnabled()) { log.trace("Result: #0", found); } return found; }
private void inject(Object target) { if (log.isTraceEnabled()) { log.trace("Injecting members of component '#0'", getComponent().getName()); } getGuiceInjector().injectMembers(target); }
/** * Creates a JExcelAPI number display format * * @param formatMask The format mask * @return The display format * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/write/NumberFormat.html">NumberFormat</a> */ public static DisplayFormat createNumberFormat(String formatMask) { if (log.isTraceEnabled()) { log.trace("Creating number format for mask #0", formatMask); } try { return (DisplayFormat) getConstant(NUMBERFORMATS_CLASSNAME, formatMask); } catch (NoSuchFieldException e) { // Look! An empty catch block! But this one is documented. We are using // this to see if there is a constant // defines for this in the class return null; } }
/** * Moves the row pointer to the next row. Used internally when adding data * */ private void nextRow() { if (log.isTraceEnabled()) { log.trace("Moving from row #0 to #1", currentRowIndex, currentRowIndex + 1); } currentRowIndex++; if (currentRowIndex >= MAX_ROWS) { throw new ExcelWorkbookException(Interpolator.instance() .interpolate("Excel only supports {0} rows", MAX_ROWS)); } }
/** * Moves the internal column pointer to the next column, called by the tag * to indicate that a new column has been started. If the pointer exceeds * the maximum allowed, throws an exception. Resets the styles and row * indexes etc. * */ public void nextColumn() { if (log.isTraceEnabled()) { log.trace("Moving from column #0 to #1", currentColumnIndex, currentColumnIndex + 1); } currentColumnIndex++; if (currentColumnIndex > MAX_COLUMNS) { throw new ExcelWorkbookException(Interpolator.instance() .interpolate("Excel doesn't support more than {0} columns", MAX_COLUMNS)); } if (currentRowIndex > maxRowIndex) { maxRowIndex = currentRowIndex; } currentRowIndex = startRowIndex; }
/** * Creates a JExcelAPI representation of a page orientation * * @param orientation The type of orientation to create * @return The page orientation representation */ public static PageOrientation createPageOrientation(String orientation) { if (log.isTraceEnabled()) { log.trace("Creating page orientation for #0", orientation); } try { return orientation == null ? PageOrientation.LANDSCAPE : (PageOrientation) getConstant(PAGE_ORIENTATION_CLASS_NAME, orientation.toUpperCase()); } catch (NoSuchFieldException e) { 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 * * @param paperSize The type of paper size to create * @return The paper size representation */ public static PaperSize createPaperSize(String paperSize) { if (log.isTraceEnabled()) { log.trace("Creating paper size for #0", paperSize); } try { return paperSize == null ? PaperSize.A4 : (PaperSize) getConstant(PAPER_SIZE_CLASS_NAME, paperSize.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Page size {0} not supported, try {1}", paperSize, getValidConstantsSuggestion(PAPER_SIZE_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Creates a JExcelAPI representation of an alignment * * @param alignment The requested alignment * @return The alignment representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/Alignment.html">Alignment</a> */ public static Alignment createAlignment(String alignment) { if (log.isTraceEnabled()) { log.trace("Creating alignment for #0", alignment); } try { return alignment == null ? Alignment.LEFT : (Alignment) getConstant(ALIGNMENT_CLASS_NAME, alignment.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Alignment {0} not supported, try {1}", alignment, getValidConstantsSuggestion(ALIGNMENT_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Creates a JExcelAPI representation of a pattern * * @param pattern The requested pattern * @return The pattern representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/Pattern.html">Pattern</a> */ public static Pattern createPattern(String pattern) { if (log.isTraceEnabled()) { log.trace("Creating pattern for #0", pattern); } try { return pattern == null ? Pattern.SOLID : (Pattern) getConstant(PATTERN_CLASS_NAME, pattern.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Pattern {0} not supported, try {1}", pattern, getValidConstantsSuggestion(PATTERN_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Adds a row page break to the worksheet * * @param command * the page break command to interpret */ private void addRowPageBreak(UIRowPageBreak command) { if (log.isTraceEnabled()) { log.trace("Adding row page break #0", command); } if (worksheet == null) { throw new ExcelWorkbookException( "Can't add row page breaks before creating a worksheet"); } int useRow = command.getRow() != null ? command.getRow() : currentRowIndex; worksheet.addRowPageBreak(useRow); }
/** * Creates a JExcelAPI representation of an underline style * * @param mask The requested underline style * @return The underline style representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/UnderlineStyle.html">UnderlineStyle</a> */ private static UnderlineStyle createUnderlineStyle(String underlineStyle) { if (log.isTraceEnabled()) { log.trace("Creating underline style for #0", underlineStyle); } try { return underlineStyle == null ? UnderlineStyle.NO_UNDERLINE : (UnderlineStyle) getConstant(UNDERLINE_STYLE_CLASS_NAME, underlineStyle.toUpperCase()); } catch (NoSuchFieldException e) { 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 vertical alignment * * @param verticalAlignment The requested alignment * @return The alignment representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/VerticalAlignment.html">VerticalAlignment</a> */ public static VerticalAlignment createVerticalAlignment(String verticalAlignment) { if (log.isTraceEnabled()) { log.trace("Creating verical alignment for #0", verticalAlignment); } try { return verticalAlignment == null ? VerticalAlignment.BOTTOM : (VerticalAlignment) getConstant(VERTICAL_ALIGNMENT_CLASS_NAME, verticalAlignment.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Verical alignment {0} not supported, try {1}", verticalAlignment, getValidConstantsSuggestion(VERTICAL_ALIGNMENT_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Creates a JExcelAPI representation of an script style * * @param mask The requested script style * @return The script style representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/ScriptStyle.html">ScriptStyle</a> */ private static ScriptStyle createScriptStyle(String scriptStyle) { if (log.isTraceEnabled()) { log.trace("Creating script style for #0", scriptStyle); } try { return scriptStyle == null ? ScriptStyle.NORMAL_SCRIPT : (ScriptStyle) getConstant(SCRIPT_STYLE_CLASS_NAME, scriptStyle.toUpperCase()); } catch (NoSuchFieldException e) { 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 orientation * * @param orientation The requested orientation * @return The orientation representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/Orientation.html">Orientation</a> */ public static Orientation createOrientation(String orientation) { if (log.isTraceEnabled()) { log.trace("Creating orientation for #0", orientation); } try { return orientation == null ? Orientation.HORIZONTAL : (Orientation) getConstant(ORIENTATION_CLASS_NAME, orientation.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Orientation {0} not supported, try {1}", orientation, getValidConstantsSuggestion(ORIENTATION_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Creates a JExcelAPI representation of a border line style * * @param borderLineStyle The requested border line style * @return The border line style representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/BorderLineStyle.html">BorderLineStyle</a> */ public static BorderLineStyle createLineStyle(String borderLineStyle) { if (log.isTraceEnabled()) { log.trace("Creating border line style for #0", borderLineStyle); } try { return borderLineStyle == null ? BorderLineStyle.NONE : (BorderLineStyle) getConstant(BORDER_LINE_STYLE_CLASS_NAME, borderLineStyle.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Border line style {0} not supported, try {1}", borderLineStyle, getValidConstantsSuggestion(BORDER_LINE_STYLE_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Creates a JExcelAPI representation of a border * * @param border The requested border * @return border representation * @see <a * href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6/docs/jxl/format/Border.html">Border</a> */ public static Border createBorder(String border) { if (log.isTraceEnabled()) { log.trace("Creating border for #0", border); } try { return border == null ? Border.ALL : (Border) getConstant(BORDER_CLASS_NAME, border.toUpperCase()); } catch (NoSuchFieldException e) { String message = Interpolator.instance().interpolate("Border {0} not supported, try {1}", border, getValidConstantsSuggestion(BORDER_CLASS_NAME)); throw new ExcelWorkbookException(message, e); } }
/** * Applies column settings to a column * * @param uiColumn The settings to apply * @param worksheet The worksheet to apply the column to * @param columnIndex The column index to the column */ public void applyColumnSettings(UIColumn uiColumn, WritableSheet worksheet, int columnIndex) { ColumnStyle columnStyle = new ColumnStyle(parser.getCascadedStyleMap(uiColumn)); if (log.isTraceEnabled()) { log.trace("Applying column settings #0 on column #1", columnStyle, columnIndex); } CellView cellView = worksheet.getColumnView(columnIndex); if (columnStyle.autoSize != null) { cellView.setAutosize(columnStyle.autoSize); } if (columnStyle.hidden != null) { cellView.setHidden(columnStyle.hidden); } if (columnStyle.width != null) { cellView.setSize(columnStyle.width); } worksheet.setColumnView(columnIndex, cellView); }
/** * Creates a JExcelAPI header or footer representation. Processes the left, * center and right facets using a helper method * * @param uiHeaderFooter The UI header or footer to interpret * @param headerFooter The JExcelAPI header or footer representation to add * to * @return The JExcelAPI header or footer representation */ public static HeaderFooter createHeaderFooter(UIComponent uiHeaderFooter, HeaderFooter headerFooter) { if (log.isTraceEnabled()) { log.trace("Processing header/footer #0", uiHeaderFooter); } processHeaderFooterFacet(headerFooter.getLeft(), uiHeaderFooter.getFacet("left")); processHeaderFooterFacet(headerFooter.getCentre(), uiHeaderFooter.getFacet("center")); processHeaderFooterFacet(headerFooter.getRight(), uiHeaderFooter.getFacet("right")); return headerFooter; }
/** * Gets the cell type for a cell. Tries to look it up in a cache based on the * component id of the cell. If it's not found, it's created and cached. * * @param uiCell The cell to look up * @return The data type of a cell */ private CellType getCellDataType(UICell uiCell) { if (log.isTraceEnabled()) { log.trace("Getting cell data type from cache for #0", uiCell.getId()); } CellType cellDataType = cellInfoCache.getCachedCellType(uiCell.getId()); if (cellDataType == null) { CellStyle cellStyle = new CellStyle(parser.getCascadedStyleMap(uiCell)); cellDataType = cellStyle.forceType != null ? CellType.valueOf(cellStyle.forceType) : uiCell.getDataType(); cellInfoCache.setCachedCellType(uiCell.getId(), cellDataType); } return cellDataType; }