public static void cloneComment(final Cell sourceCell, final Cell newCell) {

		XSSFSheet sheet = (XSSFSheet) newCell.getSheet();
		CreationHelper factory = sheet.getWorkbook().getCreationHelper();
		Drawing drawing = sheet.createDrawingPatriarch();
		XSSFComment sourceComment = (XSSFComment) sourceCell.getCellComment();
		// Below code are from POI busy manual.
		// When the comment box is visible, have it show in a 1x3 space
		ClientAnchor anchor = createCommentAnchor(newCell, factory);
		// Create the comment and set the text+author
		Comment comment = drawing.createCellComment(anchor);
		RichTextString str = factory.createRichTextString(sourceComment.getString().toString());
		comment.setString(str);
		comment.setAuthor(sourceComment.getAuthor());
		// Assign the comment to the cell
		newCell.setCellComment(comment);
		comment.setColumn(newCell.getColumnIndex());
		comment.setRow(newCell.getRowIndex());
		// As POI doesn't has well support for comments,
		// So we have to use low level api to match the comments.
		matchCommentSettings(newCell, sourceCell);
	}

clone existing comments into new cell comment.

@param sourceCell
source cell.
@param newCell
target cell.

clone existing comments into new cell comment .


private static ClientAnchor createCommentAnchor(final Cell newCell, CreationHelper factory) {
		ClientAnchor anchor = factory.createClientAnchor();
		anchor.setCol1(newCell.getColumnIndex());
		anchor.setCol2(newCell.getColumnIndex() + 1);
		anchor.setRow1(newCell.getRowIndex());
		anchor.setRow2(newCell.getRowIndex() + 3);
		return anchor;
	}

private static ClientAnchor createCommentAnchor ( final Cell newCell , CreationHelper factory ) { ClientAnchor anchor = factory . createClientAnchor ( ) ; anchor . setCol1 ( newCell . getColumnIndex ( ) ) ; anchor . setCol2 ( newCell . getColumnIndex ( ) + 1 ) ; anchor . setRow1 ( newCell . getRowIndex ( ) ) ; anchor . setRow2 ( newCell . getRowIndex ( ) + 3 ) ; return anchor ; }

Creates the comment anchor.

@param newCell the new cell
@param factory the factory
@return the client anchor


public static void createOrInsertComment(final Cell cell, final String commentStr) {

		XSSFSheet sheet = (XSSFSheet) cell.getSheet();
		CreationHelper factory = sheet.getWorkbook().getCreationHelper();
		Drawing drawing = sheet.createDrawingPatriarch();
		Comment comment = cell.getCellComment();
		String originStr = "";
		if (comment == null) {
			// Below code are from POI busy manual.
			// When the comment box is visible, have it show in a 1x3 space
			ClientAnchor anchor = createCommentAnchor(cell, factory);
			// Create the comment and set the text+author
			comment = drawing.createCellComment(anchor);
		} else {
			originStr = comment.getString().getString()+"\n";
		}
		originStr +=  commentStr;
		RichTextString str = factory.createRichTextString(originStr);
		comment.setString(str);
		comment.setAuthor("");
		// Assign the comment to the cell
		cell.setCellComment(comment);
		comment.setColumn(cell.getColumnIndex());
		comment.setRow(cell.getRowIndex());
	}

Creates the or insert comment.

@param cell the cell
@param commentStr the comment str


private static void matchCommentSettings(final Cell newCell, final Cell sourceCell) {
		try {
			XSSFVMLDrawing sourceVml = getVmlDrawingFromCell(sourceCell);
			XSSFVMLDrawing targetVml = getVmlDrawingFromCell(newCell);
			CTShape sourceCtShape = getCtShapeFromVml(sourceCell, sourceVml);
			CTShape targetCtShape = getCtShapeFromVml(newCell, targetVml);
			targetCtShape.setType(sourceCtShape.getType());
			CTClientData sourceClientData = sourceCtShape.getClientDataArray(0);
			CTClientData targetClientData = targetCtShape.getClientDataArray(0);
			String[] anchorArray = sourceClientData.getAnchorList().get(0).split(",");
			int shiftRows = newCell.getRowIndex() - sourceCell.getRowIndex();
			/*
			 * AchorArray mappings: 0->col1 1->dx1 2->row1 3->dy1 4->col2 5->dx2 6-> row2
			 * 7->dy2
			 */
			anchorArray[2] = Integer.toString(Integer.parseInt(anchorArray[2].trim()) + shiftRows);
			anchorArray[6] = Integer.toString(Integer.parseInt(anchorArray[6].trim()) + shiftRows);
			targetClientData.getAnchorList().set(0, FacesUtility.strJoin(anchorArray, ","));
		} catch (Exception e) {
			LOG.log(Level.SEVERE, "matchCommentSettings error = " + e.getLocalizedMessage(), e);
		}
	}

Use low level API to match the comments setting.

@param newCell
target cell.
@param sourceCell
source cell.

Use low level API to match the comments setting .


private static XSSFVMLDrawing getVmlDrawingFromCell(final Cell cell) {
		XSSFSheet sourceSheet = (XSSFSheet) cell.getSheet();
		for (POIXMLDocumentPart sourcePart : sourceSheet.getRelations()) {
			if ((sourcePart != null) && (sourcePart instanceof XSSFVMLDrawing)) {
				return (XSSFVMLDrawing) sourcePart;
			}
		}
		return null;
	}

private static XSSFVMLDrawing getVmlDrawingFromCell ( final Cell cell ) { XSSFSheet sourceSheet = ( XSSFSheet ) cell . getSheet ( ) ; for ( POIXMLDocumentPart sourcePart : sourceSheet . getRelations ( ) ) { if ( ( sourcePart != null ) && ( sourcePart instanceof XSSFVMLDrawing ) ) { return ( XSSFVMLDrawing ) sourcePart ; } } return null ; }

Find vmldrawing part according to cell.

@param cell
cell.
@return vmldrawing.

Find vmldrawing part according to cell .


@SuppressWarnings("rawtypes")
	private static CTShape getCtShapeFromVml(final Cell sourceCell, XSSFVMLDrawing sourceVml)
			throws ReflectiveOperationException {
		Method findshape;
		// int parameter
		Class[] paramInt = new Class[2];
		paramInt[0] = Integer.TYPE;
		paramInt[1] = Integer.TYPE;
		findshape = sourceVml.getClass().getDeclaredMethod("findCommentShape", paramInt);
		findshape.setAccessible(true);
		return (CTShape) findshape.invoke(sourceVml, sourceCell.getRowIndex(), sourceCell.getColumnIndex());
	}

@
SuppressWarnings
(
"rawtypes"
)
private
static
CTShape
getCtShapeFromVml
(
final
Cell
sourceCell
,
XSSFVMLDrawing
sourceVml
)
throws
ReflectiveOperationException
{
Method
findshape
;
// int parameter
Class
[
]
paramInt
=
new
Class
[
2
]
;
paramInt
[
0
]
=
Integer
.
TYPE
;
paramInt
[
1
]
=
Integer
.
TYPE
;
findshape
=
sourceVml
.
getClass
(
)
.
getDeclaredMethod
(
"findCommentShape"
,
paramInt
)
;
findshape
.
setAccessible
(
true
)
;
return
(
CTShape
)
findshape
.
invoke
(
sourceVml
,
sourceCell
.
getRowIndex
(
)
,
sourceCell
.
getColumnIndex
(
)
)
;
}

Find CtShape from vml object. This class use reflection to invoke the
protected method in POI.

@param sourceCell            cell.
@param sourceVml            vml.
@return ctShape.
@throws ReflectiveOperationException the reflective operation exception
@throws SecurityException the security exception

Find CtShape from vml object . This class use reflection to invoke the protected method in POI .


private static CellStyle getCellStyleFromSourceCell(final Sheet destSheet, final Cell sourceCell) {
		Workbook wb = destSheet.getWorkbook();
		// Copy style from old cell and apply to new cell
		CellStyle newCellStyle = wb.createCellStyle();
		newCellStyle.cloneStyleFrom(sourceCell.getCellStyle());
		return newCellStyle;
	}

create cell style from source cell.

@param destSheet
dest sheet.
@param sourceCell
source cell.
@return cell style.


public static void convertCell(final SheetConfiguration sheetConfig, final FacesCell fcell, final Cell poiCell,
			final Map<String, CellRangeAddress> cellRangeMap, final int originRowIndex,
			final CellAttributesMap cellAttributesMap, final String saveAttrs) {
		CellRangeAddress caddress;
		String key = getCellIndexNumberKey(poiCell);
		caddress = cellRangeMap.get(key);
		if (caddress != null) {
			// has col or row span
			fcell.setColspan(caddress.getLastColumn() - caddress.getFirstColumn() + 1);
			fcell.setRowspan(caddress.getLastRow() - caddress.getFirstRow() + 1);
		}

		CellControlsUtility.setupControlAttributes(originRowIndex, fcell, poiCell, sheetConfig, cellAttributesMap);
		fcell.setHasSaveAttr(SaveAttrsUtility.isHasSaveAttr(poiCell, saveAttrs));

	}

public
static
void
convertCell
(
final
SheetConfiguration
sheetConfig
,
final
FacesCell
fcell
,
final
Cell
poiCell
,
final
Map
<
String
,
CellRangeAddress
>
cellRangeMap
,
final
int
originRowIndex
,
final
CellAttributesMap
cellAttributesMap
,
final
String
saveAttrs
)
{
CellRangeAddress
caddress
;
String
key
=
getCellIndexNumberKey
(
poiCell
)
;
caddress
=
cellRangeMap
.
get
(
key
)
;
if
(
caddress
!=
)
{
// has col or row span
fcell
.
setColspan
(
caddress
.
getLastColumn
(
)
caddress
.
getFirstColumn
(
)
+
1
)
;
fcell
.
setRowspan
(
caddress
.
getLastRow
(
)
caddress
.
getFirstRow
(
)
+
1
)
;
}
CellControlsUtility
.
setupControlAttributes
(
originRowIndex
,
fcell
,
poiCell
,
sheetConfig
,
cellAttributesMap
)
;
fcell
.
setHasSaveAttr
(
SaveAttrsUtility
.
isHasSaveAttr
(
poiCell
,
saveAttrs
)
)
;
}

set up facesCell's attribute from poiCell and others.

set up facesCell s attribute from poiCell and others .


public static int[] getRowColFromComponentAttributes(final UIComponent target) {

		int rowIndex = (Integer) target.getAttributes().get("data-row");
		int colIndex = (Integer) target.getAttributes().get("data-column");
		int[] list = new int[2];
		list[0] = rowIndex;
		list[1] = colIndex;
		return list;
	}

public static int [ ] getRowColFromComponentAttributes ( final UIComponent target ) { int rowIndex = ( Integer ) target . getAttributes ( ) . get ( "data-row" ) ; int colIndex = ( Integer ) target . getAttributes ( ) . get ( "data-column" ) ; int [ ] list = new int [ 2 ] ; list [ 0 ] = rowIndex ; list [ 1 ] = colIndex ; return list ; }

Gets the row col from component attributes.

@param target
the target
@return the row col from component attributes

Gets the row col from component attributes .


public static int getInitRowsFromConfig(final SheetConfiguration sheetConfig) {
		int initRows = 1;
		if ("Repeat".equalsIgnoreCase(sheetConfig.getFormBodyType())) {
			initRows = sheetConfig.getBodyInitialRows();
			if (initRows < 1) {
				initRows = 1;
			}
		}
		return initRows;
	}

public static int getInitRowsFromConfig ( final SheetConfiguration sheetConfig ) { int initRows = 1 ; if ( "Repeat" . equalsIgnoreCase ( sheetConfig . getFormBodyType ( ) ) ) { initRows = sheetConfig . getBodyInitialRows ( ) ; if ( initRows < 1 ) { initRows = 1 ; } } return initRows ; }

Gets the inits the rows from config.

@param sheetConfig
the sheet config
@return the inits the rows from config


public static FacesRow getFacesRowFromBodyRow(final int row, final List<FacesRow> bodyRows, final int topRow) {
		FacesRow frow = null;

		try {
			frow = bodyRows.get(row - topRow);

		} catch (Exception e) {
			LOG.log(Level.SEVERE, "getFacesRowFromBodyRow Error row = " + row + "top row = " + topRow + " ; error = "
					+ e.getLocalizedMessage(), e);
		}
		return frow;
	}

public
static
FacesRow
getFacesRowFromBodyRow
(
final
int
row
,
final
List
<
FacesRow
>
bodyRows
,
final
int
topRow
)
{
FacesRow
frow
=
;
try
{
frow
=
bodyRows
.
get
(
row
topRow
)
;
}
catch
(
Exception
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"getFacesRowFromBodyRow Error row = "
+
row
+
"top row = "
+
topRow
+
" ; error = "
+
e
.
getLocalizedMessage
(
)
,
e
)
;
}
return
frow
;
}

Gets the faces row from body row.

@param row
the row
@param bodyRows
the body rows
@param topRow
the top row
@return faces row


public static FacesCell getFacesCellFromBodyRow(final int row, final int col, final List<FacesRow> bodyRows,
			final int topRow, final int leftCol) {
		FacesCell cell = null;

		try {
			cell = bodyRows.get(row - topRow).getCells().get(col - leftCol);

		} catch (Exception e) {
			LOG.log(Level.SEVERE, "getFacesCellFromBodyRow Error row = " + row + " col = " + col + "top row = " + topRow
					+ " leftCol = " + leftCol + " ; error = " + e.getLocalizedMessage(), e);
		}
		return cell;
	}

public
static
FacesCell
getFacesCellFromBodyRow
(
final
int
row
,
final
int
col
,
final
List
<
FacesRow
>
bodyRows
,
final
int
topRow
,
final
int
leftCol
)
{
FacesCell
cell
=
;
try
{
cell
=
bodyRows
.
get
(
row
topRow
)
.
getCells
(
)
.
get
(
col
leftCol
)
;
}
catch
(
Exception
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"getFacesCellFromBodyRow Error row = "
+
row
+
" col = "
+
col
+
"top row = "
+
topRow
+
" leftCol = "
+
leftCol
+
" ; error = "
+
e
.
getLocalizedMessage
(
)
,
e
)
;
}
return
cell
;
}

Gets the faces cell from body row.

@param row
the row
@param col
the col
@param bodyRows
the body rows
@param topRow
the top row
@param leftCol
the left col
@return the faces cell from body row


public static Cell getPoiCellFromSheet(final int rowIndex, final int colIndex, final Sheet sheet1) {
		if ((sheet1 != null) && (sheet1.getRow(rowIndex) != null)) {
			return sheet1.getRow(rowIndex).getCell(colIndex);
		}
		return null;
	}

public static Cell getPoiCellFromSheet ( final int rowIndex , final int colIndex , final Sheet sheet1 ) { if ( ( sheet1 != null ) && ( sheet1 . getRow ( rowIndex ) != null ) ) { return sheet1 . getRow ( rowIndex ) . getCell ( colIndex ) ; } return null ; }

Gets the poi cell from sheet.

@param rowIndex
the row index
@param colIndex
the col index
@param sheet1
the sheet 1
@return the poi cell from sheet


public static String getSkeyFromPoiCell(final Cell poiCell) {
		return poiCell.getSheet().getSheetName() + "!"
				+ CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), poiCell.getRowIndex());
	}

public static String getSkeyFromPoiCell ( final Cell poiCell ) { return poiCell . getSheet ( ) . getSheetName ( ) + "!" + CellUtility . getCellIndexNumberKey ( poiCell . getColumnIndex ( ) , poiCell . getRowIndex ( ) ) ; }

Gets the skey from poi cell.

@param poiCell the poi cell
@return the skey from poi cell


public static TieCell getOrAddTieCellInMap(final Cell poiCell, HashMap<String, TieCell> tieCells) {
		String skey = CellUtility.getSkeyFromPoiCell(poiCell);
		TieCell tieCell = tieCells.get(skey);
		if (tieCell == null) {
			tieCell = new TieCell();
			tieCell.setSkey(skey);
			tieCells.put(skey, tieCell);
		}
		return tieCell;
	}

public static TieCell getOrAddTieCellInMap ( final Cell poiCell , HashMap < String , TieCell > tieCells ) { String skey = CellUtility . getSkeyFromPoiCell ( poiCell ) ; TieCell tieCell = tieCells . get ( skey ) ; if ( tieCell == null ) { tieCell = new TieCell ( ) ; tieCell . setSkey ( skey ) ; tieCells . put ( skey , tieCell ) ; } return tieCell ; }

Gets the or add tie cell in map.

@param poiCell the poi cell
@param tieCells the tie cells
@return the or add tie cell in map


public final String getCurrentDataContextName() {
		if (currentDataContextName == null) {
			StringBuilder sb = new StringBuilder();
			List<String> list = this.getCurrentDataContextNameList();
			for (int i = 0; i < list.size(); i++) {
				if (i > 0) {
					sb.append(":" + list.get(i));
				} else {
					sb.append(list.get(i));
				}
			}
			this.setCurrentDataContextName(sb.toString());
		}
		return currentDataContextName;
	}

public final String getCurrentDataContextName ( ) { if ( currentDataContextName == null ) { StringBuilder sb = new StringBuilder ( ) ; List < String > list = this . getCurrentDataContextNameList ( ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( i > 0 ) { sb . append ( ":" + list . get ( i ) ) ; } else { sb . append ( list . get ( i ) ) ; } } this . setCurrentDataContextName ( sb . toString ( ) ) ; } return currentDataContextName ; }

Gets the current data context name.

@return the currentDataContextName


public final Object evaluate(final String expression,
			final Map<String, Object> context) {
		JexlContext jexlContext = new MapContext(context);
		try {
			JexlEngine jexl = JEXL_LOCAL.get();
			Map<String, Expression> expMap = JEXL_MAP_LOCAL.get();
			Expression jexlExpression = expMap.get(expression);
			if (jexlExpression == null) {
				jexlExpression = jexl.createExpression(expression);
				expMap.put(expression, jexlExpression);
			}
			return jexlExpression.evaluate(jexlContext);
		} catch (Exception e) {
			throw new EvaluationException(e);
		}
	}

public final Object evaluate ( final String expression , final Map < String , Object > context ) { JexlContext jexlContext = new MapContext ( context ) ; try { JexlEngine jexl = JEXL_LOCAL . get ( ) ; Map < String , Expression > expMap = JEXL_MAP_LOCAL . get ( ) ; Expression jexlExpression = expMap . get ( expression ) ; if ( jexlExpression == null ) { jexlExpression = jexl . createExpression ( expression ) ; expMap . put ( expression , jexlExpression ) ; } return jexlExpression . evaluate ( jexlContext ) ; } catch ( Exception e ) { throw new EvaluationException ( e ) ; } }

Evaluate the expression.

@param expression
string input expression.
@param context
context map.
@return evaluated object.


public final Object evaluate(final Map<String, Object> context) {
		JexlContext jexlContext = new MapContext(context);
		try {
			return jExpression.evaluate(jexlContext);
		} catch (Exception e) {
			throw new EvaluationException(
					"An error occurred when evaluating expression "
							+ jExpression.getExpression(), e);
		}
	}

evaluate from giving context.

@param context
context.
@return object evaluated.


private void writeObject(final java.io.ObjectOutputStream out)
			throws IOException {
		this.rowIndex = this.getRow().getRowNum();
		out.defaultWriteObject();
	}

private void writeObject ( final java . io . ObjectOutputStream out ) throws IOException { this . rowIndex = this . getRow ( ) . getRowNum ( ) ; out . defaultWriteObject ( ) ; }

save the row before serialize.

@param out
outputstream.
@throws IOException
io exception.


public final void removeRow(final Integer sourceRowNum,
			final Row targetRow) {
		List<SerialRow> mapRowList = rowsMap.get(sourceRowNum);
		if (mapRowList != null) {
			mapRowList.remove(new SerialRow(targetRow, -1));
			rowsMap.put(sourceRowNum, mapRowList);
		}
	}

public final void removeRow ( final Integer sourceRowNum , final Row targetRow ) { List < SerialRow > mapRowList = rowsMap . get ( sourceRowNum ) ; if ( mapRowList != null ) { mapRowList . remove ( new SerialRow ( targetRow , - 1 ) ) ; rowsMap . put ( sourceRowNum , mapRowList ) ; } }

Removes the row.

@param sourceRowNum
the source row num
@param targetRow
the target row


public final void mergeMap(final RowsMapping addMap) {
		Map<Integer, List<SerialRow>> map = addMap.getRowsMap();
		for (Map.Entry<Integer, List<SerialRow>> entry : map.entrySet()) {
			List<SerialRow> entryRowList = entry.getValue();
			if ((entryRowList != null) && (!entryRowList.isEmpty())) {
				for (SerialRow row : entryRowList) {
					this.addRow(entry.getKey(), row.getRow());
				}
			}
		}
	}

public final void mergeMap ( final RowsMapping addMap ) { Map < Integer , List < SerialRow > > map = addMap . getRowsMap ( ) ; for ( Map . Entry < Integer , List < SerialRow > > entry : map . entrySet ( ) ) { List < SerialRow > entryRowList = entry . getValue ( ) ; if ( ( entryRowList != null ) && ( ! entryRowList . isEmpty ( ) ) ) { for ( SerialRow row : entryRowList ) { this . addRow ( entry . getKey ( ) , row . getRow ( ) ) ; } } } }


public final void recover(final Sheet sheet) {

		for (Map.Entry<Integer, List<SerialRow>> entry : this.getRowsMap()
				.entrySet()) {
			List<SerialRow> listRow = entry.getValue();
			for (SerialRow serialRow : listRow) {
				serialRow.recover(sheet);
			}
		}

	}

public final void recover ( final Sheet sheet ) { for ( Map . Entry < Integer , List < SerialRow > > entry : this . getRowsMap ( ) . entrySet ( ) ) { List < SerialRow > listRow = entry . getValue ( ) ; for ( SerialRow serialRow : listRow ) { serialRow . recover ( sheet ) ; } } }

recover rows mapping by using it's address.

@param sheet
sheet.

recover rows mapping by using it s address .


public static ChartType getChartType(final CTChart ctChart) {
        CTPlotArea plotArea = ctChart.getPlotArea();

        for (ChartType chartType : ChartType.values()) {
            if (chartType.isThisType(plotArea)) {
                return chartType;
            }
        }
        return null;
    }

public static ChartType getChartType ( final CTChart ctChart ) { CTPlotArea plotArea = ctChart . getPlotArea ( ) ; for ( ChartType chartType : ChartType . values ( ) ) { if ( chartType . isThisType ( plotArea ) ) { return chartType ; } } return null ; }

return chart type from CTChart object.

@param ctChart
object.
@return ChartType.


public static BasicStroke toStroke(final String style) {
        BasicStroke result = null;

        if (style != null) {
            float lineWidth = STROKE_DEFAULT_LINE_WIDTH;
            float[] dash = { STROKE_DEFAULT_DASH_WIDTH };
            float[] dot = { lineWidth };

            if (style.equalsIgnoreCase(STYLE_LINE)) {
                result = new BasicStroke(lineWidth);
            } else if (style.equalsIgnoreCase(STYLE_DASH)) {
                result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT,
                        BasicStroke.JOIN_MITER,
                        STROKE_MITER_LIMIT_STYLE_DASH, dash,
                        STROKE_DEFAULT_DASHPHASE);
            } else if (style.equalsIgnoreCase(STYLE_DOT)) {
                result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT,
                        BasicStroke.JOIN_MITER,
                        STROKE_MITER_LIMIT_STYLE_DOT, dot,
                        STROKE_DEFAULT_DASHPHASE);
            }
        }

        return result;
    }

public static BasicStroke toStroke ( final String style ) { BasicStroke result = null ; if ( style != null ) { float lineWidth = STROKE_DEFAULT_LINE_WIDTH ; float [ ] dash = { STROKE_DEFAULT_DASH_WIDTH } ; float [ ] dot = { lineWidth } ; if ( style . equalsIgnoreCase ( STYLE_LINE ) ) { result = new BasicStroke ( lineWidth ) ; } else if ( style . equalsIgnoreCase ( STYLE_DASH ) ) { result = new BasicStroke ( lineWidth , BasicStroke . CAP_BUTT , BasicStroke . JOIN_MITER , STROKE_MITER_LIMIT_STYLE_DASH , dash , STROKE_DEFAULT_DASHPHASE ) ; } else if ( style . equalsIgnoreCase ( STYLE_DOT ) ) { result = new BasicStroke ( lineWidth , BasicStroke . CAP_BUTT , BasicStroke . JOIN_MITER , STROKE_MITER_LIMIT_STYLE_DOT , dot , STROKE_DEFAULT_DASHPHASE ) ; } } return result ; }

Convert style string to stroke object.

@param style
One of STYLE_xxx.
@return Stroke for <i>style</i> or null if style not supported.


public static ChartData initChartDataFromXSSFChart(final String chartId,
            final XSSFChart chart, final XSSFWorkbook wb) {

        ThemesTable themeTable = wb.getStylesSource().getTheme();

        ChartData chartData = new ChartData();
        XSSFRichTextString chartTitle = chart.getTitle();
        if (chartTitle != null) {
            chartData.setTitle(chartTitle.toString());
        }
        CTChart ctChart = chart.getCTChart();
        ChartType chartType = ChartUtility.getChartType(ctChart);
        if (chartType == null) {
            throw new IllegalChartException("Unknown chart type");
        }

        chartData.setBgColor(
                ColorUtility.getBgColor(ctChart.getPlotArea(), themeTable));

        chartData.setId(chartId);
        chartData.setType(chartType);

        List<CTCatAx> ctCatAxList = ctChart.getPlotArea().getCatAxList();
        if ((ctCatAxList != null) && (!ctCatAxList.isEmpty())) {
            chartData.setCatAx(new ChartAxis(ctCatAxList.get(0)));
        }
        List<CTValAx> ctValAxList = ctChart.getPlotArea().getValAxList();
        if ((ctValAxList != null) && (!ctValAxList.isEmpty())) {
            chartData.setValAx(new ChartAxis(ctValAxList.get(0)));
        }

        ChartObject ctObj = chartType.createChartObject();

        if (ctObj == null) {
            throw new IllegalChartException("Cannot create chart object.");
        }

        setUpChartData(chartData, ctChart, themeTable, ctObj);

        return chartData;
    }

public
static
ChartData
initChartDataFromXSSFChart
(
final
String
chartId
,
final
XSSFChart
chart
,
final
XSSFWorkbook
wb
)
{
ThemesTable
themeTable
=
wb
.
getStylesSource
(
)
.
getTheme
(
)
;
ChartData
chartData
=
new
ChartData
(
)
;
XSSFRichTextString
chartTitle
=
chart
.
getTitle
(
)
;
if
(
chartTitle
!=
)
{
chartData
.
setTitle
(
chartTitle
.
toString
(
)
)
;
}
CTChart
ctChart
=
chart
.
getCTChart
(
)
;
ChartType
chartType
=
ChartUtility
.
getChartType
(
ctChart
)
;
if
(
chartType
==
)
{
throw
new
IllegalChartException
(
"Unknown chart type"
)
;
}
chartData
.
setBgColor
(
ColorUtility
.
getBgColor
(
ctChart
.
getPlotArea
(
)
,
themeTable
)
)
;
chartData
.
setId
(
chartId
)
;
chartData
.
setType
(
chartType
)
;
List
<
CTCatAx
>
ctCatAxList
=
ctChart
.
getPlotArea
(
)
.
getCatAxList
(
)
;
if
(
(
ctCatAxList
!=
)
&&
(
!
ctCatAxList
.
isEmpty
(
)
)
)
{
chartData
.
setCatAx
(
new
ChartAxis
(
ctCatAxList
.
get
(
0
)
)
)
;
}
List
<
CTValAx
>
ctValAxList
=
ctChart
.
getPlotArea
(
)
.
getValAxList
(
)
;
if
(
(
ctValAxList
!=
)
&&
(
!
ctValAxList
.
isEmpty
(
)
)
)
{
chartData
.
setValAx
(
new
ChartAxis
(
ctValAxList
.
get
(
0
)
)
)
;
}
ChartObject
ctObj
=
chartType
.
createChartObject
(
)
;
if
(
ctObj
==
)
{
throw
new
IllegalChartException
(
"Cannot create chart object."
)
;
}
setUpChartData
(
chartData
,
ctChart
,
themeTable
,
ctObj
)
;
return
chartData
;
}

init chart data.

@param chartId
chartId.
@param chart
chart.
@param wb
wb.
@return chartdata.


public static void setUpChartData(final ChartData chartData,
            final CTChart ctChart, final ThemesTable themeTable,
            final ChartObject ctObj) {

        Object chartObj = null;
        @SuppressWarnings("rawtypes")
        List plotCharts = ctObj.getChartListFromCtChart(ctChart);

        // chart object
        if (plotCharts != null && (!plotCharts.isEmpty())) {
            chartObj = plotCharts.get(0);
        }
        if (chartObj != null) {
            @SuppressWarnings("rawtypes")
            List bsers = ctObj.getSerListFromCtObjChart(chartObj);
            if (!AppUtils.emptyList(bsers)) {
                chartData.buildCategoryList(
                        ctObj.getCtAxDataSourceFromSerList(bsers));
                chartData.buildSeriesList(bsers, themeTable, ctObj);
            }
        }
    }

public
static
void
setUpChartData
(
final
ChartData
chartData
,
final
CTChart
ctChart
,
final
ThemesTable
themeTable
,
final
ChartObject
ctObj
)
{
Object
chartObj
=
;
@
SuppressWarnings
(
"rawtypes"
)
List
plotCharts
=
ctObj
.
getChartListFromCtChart
(
ctChart
)
;
// chart object
if
(
plotCharts
!=
&&
(
!
plotCharts
.
isEmpty
(
)
)
)
{
chartObj
=
plotCharts
.
get
(
0
)
;
}
if
(
chartObj
!=
)
{
@
SuppressWarnings
(
"rawtypes"
)
List
bsers
=
ctObj
.
getSerListFromCtObjChart
(
chartObj
)
;
if
(
!
AppUtils
.
emptyList
(
bsers
)
)
{
chartData
.
buildCategoryList
(
ctObj
.
getCtAxDataSourceFromSerList
(
bsers
)
)
;
chartData
.
buildSeriesList
(
bsers
,
themeTable
,
ctObj
)
;
}
}
}

build chartData for line chart. chartData include categoryList and
seriesList which used for generate jfreechart.

@param chartData
chart data.
@param ctChart
ct chart.
@param themeTable
themeTable used for get color with theme name.
@param ctObj
ct object.

build chartData for line chart . chartData include categoryList and seriesList which used for generate jfreechart .


public static void initXSSFAnchorsMap(final XSSFWorkbook wb,
            final ChartsData charsData) {

        Map<String, ClientAnchor> anchortMap = charsData
                .getChartAnchorsMap();
        Map<String, String> positionMap = charsData.getChartPositionMap();
        anchortMap.clear();
        positionMap.clear();
        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            initXSSFAnchorsMapForSheet(anchortMap, positionMap,
                    wb.getSheetAt(i));
        }
    }

public static void initXSSFAnchorsMap ( final XSSFWorkbook wb , final ChartsData charsData ) { Map < String , ClientAnchor > anchortMap = charsData . getChartAnchorsMap ( ) ; Map < String , String > positionMap = charsData . getChartPositionMap ( ) ; anchortMap . clear ( ) ; positionMap . clear ( ) ; for ( int i = 0 ; i < wb . getNumberOfSheets ( ) ; i ++ ) { initXSSFAnchorsMapForSheet ( anchortMap , positionMap , wb . getSheetAt ( i ) ) ; } }

retrieve anchor information from draw.xml for all the charts in the
workbook. then save them to anchors map.

@param wb
workbook.
@param charsData
the chars data

retrieve anchor information from draw . xml for all the charts in the workbook . then save them to anchors map .


private static void initXSSFAnchorsMapForSheet(
            final Map<String, ClientAnchor> anchortMap,
            final Map<String, String> positionMap, final XSSFSheet sheet) {
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
        CTDrawing ctDrawing = drawing.getCTDrawing();
        if (ctDrawing.sizeOfTwoCellAnchorArray() <= 0) {
            return;
        }
        List<CTTwoCellAnchor> alist = ctDrawing.getTwoCellAnchorList();
        for (int j = 0; j < alist.size(); j++) {
            CTTwoCellAnchor ctanchor = alist.get(j);
            String singleChartId = getAnchorAssociateChartId(ctanchor);
            if (singleChartId != null) {
                String chartId = sheet.getSheetName() + "!" + singleChartId;
                int dx1 = (int) ctanchor.getFrom().getColOff();
                int dy1 = (int) ctanchor.getFrom().getRowOff();
                int dx2 = (int) ctanchor.getTo().getColOff();
                int dy2 = (int) ctanchor.getTo().getRowOff();
                int col1 = ctanchor.getFrom().getCol();
                int row1 = ctanchor.getFrom().getRow();
                int col2 = ctanchor.getTo().getCol();
                int row2 = ctanchor.getTo().getRow();
                anchortMap.put(chartId, new XSSFClientAnchor(dx1, dy1, dx2,
                        dy2, col1, row1, col2, row2));
                positionMap.put(WebSheetUtility.getFullCellRefName(
                        sheet.getSheetName(), row1, col1), chartId);
            }
        }
    }

private static void initXSSFAnchorsMapForSheet ( final Map < String , ClientAnchor > anchortMap , final Map < String , String > positionMap , final XSSFSheet sheet ) { XSSFDrawing drawing = sheet . createDrawingPatriarch ( ) ; CTDrawing ctDrawing = drawing . getCTDrawing ( ) ; if ( ctDrawing . sizeOfTwoCellAnchorArray ( ) <= 0 ) { return ; } List < CTTwoCellAnchor > alist = ctDrawing . getTwoCellAnchorList ( ) ; for ( int j = 0 ; j < alist . size ( ) ; j ++ ) { CTTwoCellAnchor ctanchor = alist . get ( j ) ; String singleChartId = getAnchorAssociateChartId ( ctanchor ) ; if ( singleChartId != null ) { String chartId = sheet . getSheetName ( ) + "!" + singleChartId ; int dx1 = ( int ) ctanchor . getFrom ( ) . getColOff ( ) ; int dy1 = ( int ) ctanchor . getFrom ( ) . getRowOff ( ) ; int dx2 = ( int ) ctanchor . getTo ( ) . getColOff ( ) ; int dy2 = ( int ) ctanchor . getTo ( ) . getRowOff ( ) ; int col1 = ctanchor . getFrom ( ) . getCol ( ) ; int row1 = ctanchor . getFrom ( ) . getRow ( ) ; int col2 = ctanchor . getTo ( ) . getCol ( ) ; int row2 = ctanchor . getTo ( ) . getRow ( ) ; anchortMap . put ( chartId , new XSSFClientAnchor ( dx1 , dy1 , dx2 , dy2 , col1 , row1 , col2 , row2 ) ) ; positionMap . put ( WebSheetUtility . getFullCellRefName ( sheet . getSheetName ( ) , row1 , col1 ) , chartId ) ; } } }

Inits the XSSF anchors map for sheet.

@param anchortMap
the anchort map
@param positionMap
the position map
@param sheet
the sheet


private static String getAnchorAssociateChartId(
            final CTTwoCellAnchor ctanchor) {

        if (ctanchor.getGraphicFrame() == null) {
            return null;
        }

        Node parentNode = ctanchor.getGraphicFrame().getGraphic()
                .getGraphicData().getDomNode();

        NodeList childNodes = parentNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node childNode = childNodes.item(i);
            if ((childNode != null)
                    && ("c:chart".equalsIgnoreCase(childNode.getNodeName()))
                    && (childNode.hasAttributes())) {
                String rId = getChartIdFromChildNodeAttributes(
                        childNode.getAttributes());
                if (rId != null) {
                    return rId;
                }
            }
        }
        return null;
    }

private static String getAnchorAssociateChartId ( final CTTwoCellAnchor ctanchor ) { if ( ctanchor . getGraphicFrame ( ) == null ) { return null ; } Node parentNode = ctanchor . getGraphicFrame ( ) . getGraphic ( ) . getGraphicData ( ) . getDomNode ( ) ; NodeList childNodes = parentNode . getChildNodes ( ) ; for ( int i = 0 ; i < childNodes . getLength ( ) ; i ++ ) { Node childNode = childNodes . item ( i ) ; if ( ( childNode != null ) && ( "c:chart" . equalsIgnoreCase ( childNode . getNodeName ( ) ) ) && ( childNode . hasAttributes ( ) ) ) { String rId = getChartIdFromChildNodeAttributes ( childNode . getAttributes ( ) ) ; if ( rId != null ) { return rId ; } } } return null ; }

Gets the anchor associate chart id.

@param ctanchor
the ctanchor
@return the anchor associate chart id


private static String getChartIdFromChildNodeAttributes(
            final NamedNodeMap attrs) {
        for (int j = 0; j < attrs.getLength(); j++) {
            Attr attribute = (Attr) attrs.item(j);
            if ("r:id".equalsIgnoreCase(attribute.getName())) {
                return attribute.getValue();
            }
        }
        return null;
    }

private static String getChartIdFromChildNodeAttributes ( final NamedNodeMap attrs ) { for ( int j = 0 ; j < attrs . getLength ( ) ; j ++ ) { Attr attribute = ( Attr ) attrs . item ( j ) ; if ( "r:id" . equalsIgnoreCase ( attribute . getName ( ) ) ) { return attribute . getValue ( ) ; } } return null ; }

Gets the chart id from child node attributes.

@param attrs
the attrs
@return the chart id from child node attributes

Gets the chart id from child node attributes .


@SuppressWarnings("rawtypes")
	private int buildEachObjects(String fullName,
			final ConfigBuildRef configBuildRef, final int atRow,
			final Map<String, Object> context,
			final List<RowsMapping> currentRowsMappingList,
			final Collection itemsCollection, final String objClassName) {

		int index = 0;
		int insertPosition = atRow;
		String thisObjClassName = objClassName;

		// loop through each object in the collection
		for (Object obj : itemsCollection) {
			// gather and cache object class name which used for add row
			if (thisObjClassName == null) {
				thisObjClassName = obj.getClass().getName();
				configBuildRef.getCollectionObjNameMap().put(this.var,
						thisObjClassName);
			}
			RowsMapping unitRowsMapping = new RowsMapping();
			context.put(var, obj);
			CommandUtility.insertEachTemplate(this.getConfigRange(),
					configBuildRef, index, insertPosition, unitRowsMapping);
			ConfigRange currentRange = ConfigurationUtility
					.buildCurrentRange(this.getConfigRange(),
							configBuildRef.getSheet(), insertPosition);
			currentRowsMappingList.add(unitRowsMapping);

			String unitFullName = fullName + "." + index;
			currentRange.getAttrs().setAllowAdd(false);
			if ((this.allowAdd != null)
					&& ("true".equalsIgnoreCase(this.allowAdd.trim()))) {
				currentRange.getAttrs().setAllowAdd(true);
				configBuildRef.setBodyAllowAdd(true);
			}
			configBuildRef.putShiftAttrs(unitFullName,
					currentRange.getAttrs(),
					new RowsMapping(unitRowsMapping));

			int length = currentRange.buildAt(unitFullName, configBuildRef,
					insertPosition, context, currentRowsMappingList);
			currentRange.getAttrs().setFinalLength(length);
			insertPosition += length;
			currentRowsMappingList.remove(unitRowsMapping);
			index++;
			context.remove(var);
		}
		return insertPosition;
	}

Builds the each objects.

@param fullName
the full name
@param configBuildRef
the config build ref
@param atRow
the at row
@param context
the context
@param currentRowsMappingList
the current rows mapping list
@param itemsCollection
the items collection
@param objClassName
the obj class name
@return the int


public final void saveDataInContext(final Cell poiCell,
			final String strValue) {

		String saveAttr = SaveAttrsUtility.prepareContextAndAttrsForCell(poiCell, ConfigurationUtility.getFullNameFromRow(poiCell.getRow()), this);
		if (saveAttr!= null) {
			SaveAttrsUtility.saveDataToObjectInContext(
							parent.getSerialDataContext().getDataContext(),
							saveAttr, strValue, parent.getExpEngine());
			parent.getHelper().getWebSheetLoader().setUnsavedStatus(
							RequestContext.getCurrentInstance(), true);
		}
	}

public final void saveDataInContext ( final Cell poiCell , final String strValue ) { String saveAttr = SaveAttrsUtility . prepareContextAndAttrsForCell ( poiCell , ConfigurationUtility . getFullNameFromRow ( poiCell . getRow ( ) ) , this ) ; if ( saveAttr != null ) { SaveAttrsUtility . saveDataToObjectInContext ( parent . getSerialDataContext ( ) . getDataContext ( ) , saveAttr , strValue , parent . getExpEngine ( ) ) ; parent . getHelper ( ) . getWebSheetLoader ( ) . setUnsavedStatus ( RequestContext . getCurrentInstance ( ) , true ) ; } }

Save data in context.

@param poiCell
the poi cell
@param strValue
the str value


public final void reCalc() {

		parent.getFormulaEvaluator().clearAllCachedResultValues();
		try {
			parent.getFormulaEvaluator().evaluateAll();
		} catch (Exception ex) {
			// skip the formula exception when recalc but log it
			LOG.log(Level.SEVERE,
					" recalc formula error : " + ex.getLocalizedMessage(),
					ex);
		}

	}


public final Cell getPoiCellWithRowColFromTab(final int rowIndex,
			final int colIndex, final String tabName) {
		if (parent.getWb() != null) {

			return CellUtility.getPoiCellFromSheet(rowIndex, colIndex,
					parent.getWb().getSheet(parent.getSheetConfigMap()
							.get(tabName).getSheetName()));
		}
		return null;
	}

public final Cell getPoiCellWithRowColFromTab ( final int rowIndex , final int colIndex , final String tabName ) { if ( parent . getWb ( ) != null ) { return CellUtility . getPoiCellFromSheet ( rowIndex , colIndex , parent . getWb ( ) . getSheet ( parent . getSheetConfigMap ( ) . get ( tabName ) . getSheetName ( ) ) ) ; } return null ; }

Gets the poi cell with row col from tab.

@param rowIndex
the row index
@param colIndex
the col index
@param tabName
the tab name
@return the poi cell with row col from tab

Gets the poi cell with row col from tab .


public final FacesCell getFacesCellWithRowColFromCurrentPage(
			final int rowIndex, final int colIndex) {
		if (parent.getBodyRows() != null) {
			int top = parent.getCurrent().getCurrentTopRow();
			int left = parent.getCurrent().getCurrentLeftColumn();
			return parent.getBodyRows().get(rowIndex - top).getCells()
					.get(colIndex - left);
		}
		return null;
	}

public final FacesCell getFacesCellWithRowColFromCurrentPage ( final int rowIndex , final int colIndex ) { if ( parent . getBodyRows ( ) != null ) { int top = parent . getCurrent ( ) . getCurrentTopRow ( ) ; int left = parent . getCurrent ( ) . getCurrentLeftColumn ( ) ; return parent . getBodyRows ( ) . get ( rowIndex - top ) . getCells ( ) . get ( colIndex - left ) ; } return null ; }

Gets the faces cell with row col from current page.

@param rowIndex
the row index
@param colIndex
the col index
@return the faces cell with row col from current page

Gets the faces cell with row col from current page .


public final void restoreDataContext(final String fullName) {

		String[] parts = fullName.split(":");

		if (!isNeedRestore(fullName, parts)) {
			return;
		}

		boolean stopSkip = false;
		List<String> list = parent.getCurrent()
				.getCurrentDataContextNameList();
		int listSize = list.size();

		// prepare collection data in context.
		// must loop through the full name which may have multiple
		// layer.
		// i.e. E.department.1:E.employee.0
		// need prepare department.1 and employee.0

		for (int i = 0; i < parts.length; i++) {
			String part = parts[i];
			boolean skip = false;
			if ((!stopSkip) && (i < listSize)) {
				String listPart = list.get(i);
				if (part.equalsIgnoreCase(listPart)) {
					skip = true;
				}
			}
			if (!skip) {
				stopSkip = true;
				startRestoreDataContext(part);
			}
		}
		if (stopSkip) {
			parent.getCurrent().setCurrentDataContextName(fullName);
		}

		return;
	}

Restore data context.

@param fullName
the full name


public final CollectionObject getLastCollect(final String fullName) {
		String[] parts = fullName.split(":");
		String part = parts[parts.length - 1];
		return startRestoreDataContext(part);
	}

public final CollectionObject getLastCollect ( final String fullName ) { String [ ] parts = fullName . split ( ":" ) ; String part = parts [ parts . length - 1 ] ; return startRestoreDataContext ( part ) ; }

Get last collect object from full name.

Last collect contain each command, collection and index.

@param fullName
the full name
@return the collection object

Get last collect object from full name .


private boolean isNeedRestore(final String fullName,
			final String[] parts) {
		if (fullName == null) {
			return false;
		}
		if ((parent.getCurrent().getCurrentDataContextName() != null)
				&& (parent.getCurrent().getCurrentDataContextName()
						.toLowerCase()
						.startsWith(fullName.toLowerCase()))) {
			return false;
		}

		return ((parts != null) && (parts.length > 1));
	}

private boolean isNeedRestore ( final String fullName , final String [ ] parts ) { if ( fullName == null ) { return false ; } if ( ( parent . getCurrent ( ) . getCurrentDataContextName ( ) != null ) && ( parent . getCurrent ( ) . getCurrentDataContextName ( ) . toLowerCase ( ) . startsWith ( fullName . toLowerCase ( ) ) ) ) { return false ; } return ( ( parts != null ) && ( parts . length > 1 ) ) ; }

Checks if is need restore.

@param fullName
the full name
@param parts
the parts
@return true, if is need restore


private CollectionObject startRestoreDataContext(final String part) {
		if (part.startsWith(TieConstants.EACH_COMMAND_FULL_NAME_PREFIX)) {
			String[] varparts = part.split("\\.");
			CollectionObject collect = new CollectionObject();

			collect.setEachCommand(
					CommandUtility
							.getEachCommandFromPartsName(
									parent.getCurrentSheetConfig()
											.getCommandIndexMap(),
									varparts));
			collect.setLastCollection(ConfigurationUtility
					.transformToCollectionObject(parent.getExpEngine(),
							collect.getEachCommand().getItems(),
							parent.getSerialDataContext()
									.getDataContext()));
			collect.setLastCollectionIndex(
					CommandUtility.prepareCollectionDataInContext(varparts,
							collect.getLastCollection(),
							parent.getSerialDataContext()
									.getDataContext()));
			return collect;
		}
		return null;
	}

private CollectionObject startRestoreDataContext ( final String part ) { if ( part . startsWith ( TieConstants . EACH_COMMAND_FULL_NAME_PREFIX ) ) { String [ ] varparts = part . split ( "\\." ) ; CollectionObject collect = new CollectionObject ( ) ; collect . setEachCommand ( CommandUtility . getEachCommandFromPartsName ( parent . getCurrentSheetConfig ( ) . getCommandIndexMap ( ) , varparts ) ) ; collect . setLastCollection ( ConfigurationUtility . transformToCollectionObject ( parent . getExpEngine ( ) , collect . getEachCommand ( ) . getItems ( ) , parent . getSerialDataContext ( ) . getDataContext ( ) ) ) ; collect . setLastCollectionIndex ( CommandUtility . prepareCollectionDataInContext ( varparts , collect . getLastCollection ( ) , parent . getSerialDataContext ( ) . getDataContext ( ) ) ) ; return collect ; } return null ; }

Start restore data context.

@param part
the part
@return the collection object


public final void shiftRowRef(final Sheet sheet, final int shiftnum) {
		try {
			this.setFirstRowRef(sheet
					.getRow(attrs.getFirstRowAddr().getRow() + shiftnum)
					.getCell(attrs.getFirstRowAddr().getColumn(),
							MissingCellPolicy.CREATE_NULL_AS_BLANK),
					false);
			this.setLastRowPlusRef(sheet,
					attrs.getLastRowPlusAddr().getColumn(),
					attrs.getLastRowPlusAddr().getRow() + shiftnum - 1,
					false);

			if (commandList != null) {
				for (ConfigCommand command : commandList) {
					command.shiftRowRef(sheet, shiftnum);
				}
			}

		} catch (Exception ex) {
			LOG.log(Level.SEVERE,
					"shiftRowRef error =" + ex.getLocalizedMessage(), ex);
		}
	}

public
final
void
shiftRowRef
(
final
Sheet
sheet
,
final
int
shiftnum
)
{
try
{
this
.
setFirstRowRef
(
sheet
.
getRow
(
attrs
.
getFirstRowAddr
(
)
.
getRow
(
)
+
shiftnum
)
.
getCell
(
attrs
.
getFirstRowAddr
(
)
.
getColumn
(
)
,
MissingCellPolicy
.
CREATE_NULL_AS_BLANK
)
,
false
)
;
this
.
setLastRowPlusRef
(
sheet
,
attrs
.
getLastRowPlusAddr
(
)
.
getColumn
(
)
,
attrs
.
getLastRowPlusAddr
(
)
.
getRow
(
)
+
shiftnum
1
,
false
)
;
if
(
commandList
!=
)
{
for
(
ConfigCommand
command
:
commandList
)
{
command
.
shiftRowRef
(
sheet
,
shiftnum
)
;
}
}
}
catch
(
Exception
ex
)
{
LOG
.
log
(
Level
.
SEVERE
,
"shiftRowRef error ="
+
ex
.
getLocalizedMessage
(
)
,
ex
)
;
}
}

Shift row ref.

@param sheet
the sheet
@param shiftnum
the shiftnum


public final void setFirstRowRef(final Cell pFirstRowRef,
			final boolean alsoCreateAddr) {
		this.attrs.setFirstRowRef(pFirstRowRef);
		if (alsoCreateAddr) {
			this.setFirstRowAddr(new SerialCellAddress(pFirstRowRef));
		}
	}

public final void setFirstRowRef ( final Cell pFirstRowRef , final boolean alsoCreateAddr ) { this . attrs . setFirstRowRef ( pFirstRowRef ) ; if ( alsoCreateAddr ) { this . setFirstRowAddr ( new SerialCellAddress ( pFirstRowRef ) ) ; } }

set first cell also set static relative address firstCellAddress.

@param pFirstRowRef
first cell.
@param alsoCreateAddr
whether need create cell address.

set first cell also set static relative address firstCellAddress .


public final void setLastRowPlusRef(final Sheet sheet,
			final int rightCol, final int lastRow,
			final boolean alsoSetAddr) {

		if ((lastRow >= 0) && (sheet != null) && (rightCol >= 0)) {
			Row row = sheet.getRow(lastRow + 1);
			if (row == null) {
				row = sheet.createRow(lastRow + 1);
			}
			Cell cell = row.getCell(rightCol);
			if (cell == null) {
				cell = row.getCell(rightCol,
						MissingCellPolicy.CREATE_NULL_AS_BLANK);
				this.attrs.setLastCellCreated(true);
			} else {
				this.attrs.setLastCellCreated(false);
			}
			this.attrs.setLastRowPlusRef(cell);
			if (alsoSetAddr) {
				this.setLastRowPlusAddr(new SerialCellAddress(cell));
			}
		} else {
			this.attrs.setLastRowPlusRef(null);
			if (alsoSetAddr) {
				this.attrs.setLastRowPlusAddr(null);
			}
		}
	}

public final void setLastRowPlusRef ( final Sheet sheet , final int rightCol , final int lastRow , final boolean alsoSetAddr ) { if ( ( lastRow >= 0 ) && ( sheet != null ) && ( rightCol >= 0 ) ) { Row row = sheet . getRow ( lastRow + 1 ) ; if ( row == null ) { row = sheet . createRow ( lastRow + 1 ) ; } Cell cell = row . getCell ( rightCol ) ; if ( cell == null ) { cell = row . getCell ( rightCol , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; this . attrs . setLastCellCreated ( true ) ; } else { this . attrs . setLastCellCreated ( false ) ; } this . attrs . setLastRowPlusRef ( cell ) ; if ( alsoSetAddr ) { this . setLastRowPlusAddr ( new SerialCellAddress ( cell ) ) ; } } else { this . attrs . setLastRowPlusRef ( null ) ; if ( alsoSetAddr ) { this . attrs . setLastRowPlusAddr ( null ) ; } } }

set last cell also set static relative address lastCellAddress.

@param sheet
sheet.
@param rightCol
rightColumn.
@param lastRow
lastRow.
@param alsoSetAddr
whether need create cell address.

set last cell also set static relative address lastCellAddress .


private void buildCellsForRow(final Row row, final String fullName,
			final Map<String, Object> context,
			final ConfigBuildRef configBuildRef,
			ShiftFormulaRef shiftFormulaRef) {
		if ((row == null)
				|| !ConfigurationUtility.isStaticRowRef(this, row)) {
			return;
		}
		for (Cell cell : row) {
			buildSingleCell(cell, context, configBuildRef, shiftFormulaRef);
		}
		ConfigurationUtility.setFullNameInHiddenColumn(row, fullName);
	}

private void buildCellsForRow ( final Row row , final String fullName , final Map < String , Object > context , final ConfigBuildRef configBuildRef , ShiftFormulaRef shiftFormulaRef ) { if ( ( row == null ) || ! ConfigurationUtility . isStaticRowRef ( this , row ) ) { return ; } for ( Cell cell : row ) { buildSingleCell ( cell , context , configBuildRef , shiftFormulaRef ) ; } ConfigurationUtility . setFullNameInHiddenColumn ( row , fullName ) ; }

Builds the cells for row.

@param row
the row
@param fullName
the full name
@param context
the context
@param configBuildRef
the config build ref
@param shiftFormulaRef
the shift formula ref


private void buildSingleCell(final Cell cell,
			final Map<String, Object> context,
			final ConfigBuildRef configBuildRef,
			final ShiftFormulaRef shiftFormulaRef) {
		try {
			CommandUtility.evaluate(context, cell,
					configBuildRef.getEngine());
			if (cell.getCellTypeEnum() == CellType.FORMULA) {
				// rebuild formula if necessary for dynamic row
				String originFormula = cell.getCellFormula();
				shiftFormulaRef.setFormulaChanged(0);
				ConfigurationUtility.buildCellFormulaForShiftedRows(
						configBuildRef.getSheet(),
						configBuildRef.getWbWrapper(), shiftFormulaRef,
						cell, cell.getCellFormula());
				if (shiftFormulaRef.getFormulaChanged() > 0) {
					configBuildRef.getCachedCells().put(cell,
							originFormula);
				}
			}

		} catch (Exception ex) {
			LOG.log(Level.SEVERE,
					"build cell ( row = " + cell.getRowIndex()
							+ " column = " + cell.getColumnIndex()
							+ " error = " + ex.getLocalizedMessage(),
					ex);
		}
	}

Builds the single cell.

@param cell
the cell
@param context
the context
@param configBuildRef
the config build ref
@param shiftFormulaRef
the shift formula ref


private void readObject(final java.io.ObjectInputStream in)
			throws IOException {
		try {
			in.defaultReadObject();
			Gson objGson = new GsonBuilder().setPrettyPrinting().create();
			Type listType = new TypeToken<Map<String, Object>>() {
			}.getType();
			this.dataContext = objGson.fromJson(mapToJson, listType);
		} catch (EncryptedDocumentException | ClassNotFoundException e) {
			LOG.log(Level.SEVERE,
					" error in readObject of serialWorkbook : "
							+ e.getLocalizedMessage(),
					e);
		}
	}

load the workbook from saving.

@param in
inputstream.
@throws IOException
io exception.


public final void buildCategoryList(final CTAxDataSource ctAxDs) {

		List<ParsedCell> cells = new ArrayList<>();
		try {
			String fullRangeName = ctAxDs.getStrRef().getF();
			String sheetName = WebSheetUtility
					.getSheetNameFromFullCellRefName(fullRangeName);
			CellRangeAddress region = CellRangeAddress.valueOf(
					WebSheetUtility.removeSheetNameFromFullCellRefName(
							fullRangeName));
			for (int row = region.getFirstRow(); row <= region
					.getLastRow(); row++) {
				for (int col = region.getFirstColumn(); col <= region
						.getLastColumn(); col++) {
					cells.add(new ParsedCell(sheetName, row, col));
				}
			}

		} catch (Exception ex) {
			LOG.log(Level.FINE, "failed in buildCategoryList", ex);
		}
		this.setCategoryList(cells);
	}

public
final
void
buildCategoryList
(
final
CTAxDataSource
ctAxDs
)
{
List
<
ParsedCell
>
cells
=
new
ArrayList
<>
(
)
;
try
{
String
fullRangeName
=
ctAxDs
.
getStrRef
(
)
.
getF
(
)
;
String
sheetName
=
WebSheetUtility
.
getSheetNameFromFullCellRefName
(
fullRangeName
)
;
CellRangeAddress
region
=
CellRangeAddress
.
valueOf
(
WebSheetUtility
.
removeSheetNameFromFullCellRefName
(
fullRangeName
)
)
;
for
(
int
row
=
region
.
getFirstRow
(
)
;
row
<=
region
.
getLastRow
(
)
;
row
++
)
{
for
(
int
col
=
region
.
getFirstColumn
(
)
;
col
<=
region
.
getLastColumn
(
)
;
col
++
)
{
cells
.
add
(
new
ParsedCell
(
sheetName
,
row
,
col
)
)
;
}
}
}
catch
(
Exception
ex
)
{
LOG
.
log
(
Level
.
FINE
,
"failed in buildCategoryList"
,
ex
)
;
}
this
.
setCategoryList
(
cells
)
;
}

build categotry list.

@param ctAxDs
ctaxdatasource.


@SuppressWarnings("rawtypes")
	public final void buildSeriesList(final List bsers,
			final ThemesTable themeTable, final ChartObject ctObj) {

		List<ChartSeries> lseriesList = new ArrayList<>();
		try {
			for (int index = 0; index < bsers.size(); index++) {
				Object ctObjSer = bsers.get(index);
				ChartSeries ctSer = buildChartSeriesInList(themeTable,
						ctObj, ctObjSer, index);
				lseriesList.add(ctSer);
			}
		} catch (Exception ex) {
			LOG.log(Level.FINE, "failed in buildSerialList", ex);
		}
		this.setSeriesList(lseriesList);
	}

@
SuppressWarnings
(
"rawtypes"
)
public
final
void
buildSeriesList
(
final
List
bsers
,
final
ThemesTable
themeTable
,
final
ChartObject
ctObj
)
{
List
<
ChartSeries
>
lseriesList
=
new
ArrayList
<>
(
)
;
try
{
for
(
int
index
=
0
;
index
<
bsers
.
size
(
)
;
index
++
)
{
Object
ctObjSer
=
bsers
.
get
(
index
)
;
ChartSeries
ctSer
=
buildChartSeriesInList
(
themeTable
,
ctObj
,
ctObjSer
,
index
)
;
lseriesList
.
add
(
ctSer
)
;
}
}
catch
(
Exception
ex
)
{
LOG
.
log
(
Level
.
FINE
,
"failed in buildSerialList"
,
ex
)
;
}
this
.
setSeriesList
(
lseriesList
)
;
}

build series list.

@param bsers
bsers.
@param themeTable
themetable.
@param ctObj
ctobj.


private ChartSeries buildChartSeriesInList(final ThemesTable themeTable,
			final ChartObject ctObj, final Object ctObjSer, final int index) {
		ChartSeries ctSer = new ChartSeries();
		ctSer.setSeriesLabel(new ParsedCell(
				ctObj.getSeriesLabelFromCTSer(ctObjSer)));
		ctSer.setSeriesColor(ColorUtility.geColorFromSpPr(index,
				ctObj.getShapePropertiesFromCTSer(ctObjSer),
				themeTable, ctObj.isLineColor()));
		List<ParsedCell> cells = new ArrayList<>();
		String fullRangeName = (ctObj
				.getCTNumDataSourceFromCTSer(ctObjSer)).getNumRef()
						.getF();
		String sheetName = WebSheetUtility
				.getSheetNameFromFullCellRefName(fullRangeName);
		CellRangeAddress region = CellRangeAddress
				.valueOf(WebSheetUtility
						.removeSheetNameFromFullCellRefName(
								fullRangeName));
		for (int row = region.getFirstRow(); row <= region
				.getLastRow(); row++) {
			for (int col = region.getFirstColumn(); col <= region
					.getLastColumn(); col++) {
				cells.add(new ParsedCell(sheetName, row, col));
			}
		}
		ctSer.setValueList(cells);
		ctSer.setValueColorList(getColorListFromDPTWithValueList(
				ctObj.getDPtListFromCTSer(ctObjSer), cells,
				themeTable, ctObj));
		return ctSer;
	}

private ChartSeries buildChartSeriesInList ( final ThemesTable themeTable , final ChartObject ctObj , final Object ctObjSer , final int index ) { ChartSeries ctSer = new ChartSeries ( ) ; ctSer . setSeriesLabel ( new ParsedCell ( ctObj . getSeriesLabelFromCTSer ( ctObjSer ) ) ) ; ctSer . setSeriesColor ( ColorUtility . geColorFromSpPr ( index , ctObj . getShapePropertiesFromCTSer ( ctObjSer ) , themeTable , ctObj . isLineColor ( ) ) ) ; List < ParsedCell > cells = new ArrayList <> ( ) ; String fullRangeName = ( ctObj . getCTNumDataSourceFromCTSer ( ctObjSer ) ) . getNumRef ( ) . getF ( ) ; String sheetName = WebSheetUtility . getSheetNameFromFullCellRefName ( fullRangeName ) ; CellRangeAddress region = CellRangeAddress . valueOf ( WebSheetUtility . removeSheetNameFromFullCellRefName ( fullRangeName ) ) ; for ( int row = region . getFirstRow ( ) ; row <= region . getLastRow ( ) ; row ++ ) { for ( int col = region . getFirstColumn ( ) ; col <= region . getLastColumn ( ) ; col ++ ) { cells . add ( new ParsedCell ( sheetName , row , col ) ) ; } } ctSer . setValueList ( cells ) ; ctSer . setValueColorList ( getColorListFromDPTWithValueList ( ctObj . getDPtListFromCTSer ( ctObjSer ) , cells , themeTable , ctObj ) ) ; return ctSer ; }

Builds the chart series in list.

@param themeTable
the theme table
@param ctObj
the ct obj
@param ctObjSer
the ct obj ser
@param index
the index
@return the chart series


private List<XColor> getColorListFromDPTWithValueList(
			final List<CTDPt> dptList, final List<ParsedCell> cells,
			final ThemesTable themeTable, final ChartObject ctObj) {
		List<XColor> colors = new ArrayList<>();
		if ((dptList != null) && (cells != null)) {

			for (int index = 0; index < cells.size(); index++) {
				CTDPt dpt = getDPtFromListWithIndex(dptList, index);
				CTShapeProperties ctSpPr = null;
				if (dpt != null) {
					ctSpPr = dpt.getSpPr();
				}
				colors.add(ColorUtility.geColorFromSpPr(index, ctSpPr,
						themeTable, ctObj.isLineColor()));
			}
		}
		return colors;

	}

private List < XColor > getColorListFromDPTWithValueList ( final List < CTDPt > dptList , final List < ParsedCell > cells , final ThemesTable themeTable , final ChartObject ctObj ) { List < XColor > colors = new ArrayList <> ( ) ; if ( ( dptList != null ) && ( cells != null ) ) { for ( int index = 0 ; index < cells . size ( ) ; index ++ ) { CTDPt dpt = getDPtFromListWithIndex ( dptList , index ) ; CTShapeProperties ctSpPr = null ; if ( dpt != null ) { ctSpPr = dpt . getSpPr ( ) ; } colors . add ( ColorUtility . geColorFromSpPr ( index , ctSpPr , themeTable , ctObj . isLineColor ( ) ) ) ; } } return colors ; }

get color list from dpt.

@param dptList
dpt.
@param cells
cells.
@param themeTable
themetable.
@param ctObj
ctobj.
@return list of xcolor.


private CTDPt getDPtFromListWithIndex(final List<CTDPt> dptList,
			final int index) {

		if (dptList != null) {
			for (CTDPt dpt : dptList) {
				if (dpt.getIdx().getVal() == index) {
					return dpt;
				}
			}
		}
		return null;
	}

private CTDPt getDPtFromListWithIndex ( final List < CTDPt > dptList , final int index ) { if ( dptList != null ) { for ( CTDPt dpt : dptList ) { if ( dpt . getIdx ( ) . getVal ( ) == index ) { return dpt ; } } } return null ; }

get dpt from list.

@param dptList
dptlist.
@param index
index.
@return ctdpt.


public final void setCommandIndexMap(
			final Map<String, Command> pcommandIndexMap) {
		if (pcommandIndexMap instanceof HashMap) {
			this.commandIndexMap = (HashMap<String, Command>) pcommandIndexMap;
		} else {
			this.commandIndexMap = new HashMap<>();
			this.commandIndexMap.putAll(pcommandIndexMap);
		}
	}

public final void setCommandIndexMap ( final Map < String , Command > pcommandIndexMap ) { if ( pcommandIndexMap instanceof HashMap ) { this . commandIndexMap = ( HashMap < String , Command > ) pcommandIndexMap ; } else { this . commandIndexMap = new HashMap <> ( ) ; this . commandIndexMap . putAll ( pcommandIndexMap ) ; } }

Sets the command index map.

@param pcommandIndexMap
the command index map


public static void getPictruesMap(final Workbook wb,
			final Map<String, Picture> picMap) {
		if (wb instanceof XSSFWorkbook) {
			getXSSFPictruesMap((XSSFWorkbook) wb, picMap);
		}
		return;
	}

public static void getPictruesMap ( final Workbook wb , final Map < String , Picture > picMap ) { if ( wb instanceof XSSFWorkbook ) { getXSSFPictruesMap ( ( XSSFWorkbook ) wb , picMap ) ; } return ; }

Gets the pictrues map.

@param wb
the wb
@param picMap
the pic map


private static void getXSSFPictruesMap(final XSSFWorkbook wb,
			final Map<String, Picture> picMap) {

		picMap.clear();
		List<XSSFPictureData> pictures = wb.getAllPictures();
		if (pictures.isEmpty()) {
			return;
		}
		for (int i = 0; i < wb.getNumberOfSheets(); i++) {
			XSSFSheet sheet = wb.getSheetAt(i);
			for (POIXMLDocumentPart dr : sheet.getRelations()) {
				try {
					indexPictureInMap(picMap, sheet, dr);
				} catch (Exception ex) {
					LOG.log(Level.SEVERE, "Load Picture error = "
							+ ex.getLocalizedMessage(), ex);
				}
			}
		}

		return;

	}

private
static
void
getXSSFPictruesMap
(
final
XSSFWorkbook
wb
,
final
Map
<
String
,
Picture
>
picMap
)
{
picMap
.
clear
(
)
;
List
<
XSSFPictureData
>
pictures
=
wb
.
getAllPictures
(
)
;
if
(
pictures
.
isEmpty
(
)
)
{
return
;
}
for
(
int
i
=
0
;
i
<
wb
.
getNumberOfSheets
(
)
;
i
++
)
{
XSSFSheet
sheet
=
wb
.
getSheetAt
(
i
)
;
for
(
POIXMLDocumentPart
dr
:
sheet
.
getRelations
(
)
)
{
try
{
indexPictureInMap
(
picMap
,
sheet
,
dr
)
;
}
catch
(
Exception
ex
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Load Picture error = "
+
ex
.
getLocalizedMessage
(
)
,
ex
)
;
}
}
}
return
;
}

Gets the XSSF pictrues map.

@param wb
the wb
@param picMap
the pic map


private static void indexPictureInMap(final Map<String, Picture> picMap,
			final XSSFSheet sheet, final POIXMLDocumentPart dr) {
		if (dr instanceof XSSFDrawing) {
			XSSFDrawing drawing = (XSSFDrawing) dr;
			List<XSSFShape> shapes = drawing.getShapes();
			for (XSSFShape shape : shapes) {
				if (shape instanceof XSSFPicture) {
					XSSFPicture pic = (XSSFPicture) shape;
					XSSFClientAnchor anchor = pic.getPreferredSize();
					CTMarker ctMarker = anchor.getFrom();
					String picIndex = WebSheetUtility.getFullCellRefName(
							sheet.getSheetName(), ctMarker.getRow(),
							ctMarker.getCol());
					picMap.put(picIndex, pic);
				}
			}
		}
	}

private static void indexPictureInMap ( final Map < String , Picture > picMap , final XSSFSheet sheet , final POIXMLDocumentPart dr ) { if ( dr instanceof XSSFDrawing ) { XSSFDrawing drawing = ( XSSFDrawing ) dr ; List < XSSFShape > shapes = drawing . getShapes ( ) ; for ( XSSFShape shape : shapes ) { if ( shape instanceof XSSFPicture ) { XSSFPicture pic = ( XSSFPicture ) shape ; XSSFClientAnchor anchor = pic . getPreferredSize ( ) ; CTMarker ctMarker = anchor . getFrom ( ) ; String picIndex = WebSheetUtility . getFullCellRefName ( sheet . getSheetName ( ) , ctMarker . getRow ( ) , ctMarker . getCol ( ) ) ; picMap . put ( picIndex , pic ) ; } } } }

save pciture in map with index.

@param picMap
pciture map.
@param sheet
sheet.
@param dr
documentme part.


public static String generatePictureStyle(final Sheet sheet1,
			final FacesCell fcell, final Cell cell, final Picture pic) {

		ClientAnchor anchor = pic.getClientAnchor();
		if (anchor != null) {
			AnchorSize anchorSize = getAnchorSize(sheet1, fcell, cell,
					anchor);
			if (anchorSize != null) {
				return "MARGIN-LEFT:"
						+ String.format("%.2f", anchorSize.getPercentLeft())
						+ "%;MARGIN-TOP:"
						+ String.format("%.2f", anchorSize.getPercentTop())
						+ "%;width:" + String.format("%.2f",
								anchorSize.getPercentWidth())
						+ "%;";
			}
		}
		return "";

	}

public static String generatePictureStyle ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final Picture pic ) { ClientAnchor anchor = pic . getClientAnchor ( ) ; if ( anchor != null ) { AnchorSize anchorSize = getAnchorSize ( sheet1 , fcell , cell , anchor ) ; if ( anchorSize != null ) { return "MARGIN-LEFT:" + String . format ( "%.2f" , anchorSize . getPercentLeft ( ) ) + "%;MARGIN-TOP:" + String . format ( "%.2f" , anchorSize . getPercentTop ( ) ) + "%;width:" + String . format ( "%.2f" , anchorSize . getPercentWidth ( ) ) + "%;" ; } } return "" ; }

Generate picture style.

@param sheet1
the sheet 1
@param fcell
the fcell
@param cell
the cell
@param pic
the pic
@return the string


public static String generateChartStyle(final Sheet sheet1,
			final FacesCell fcell, final Cell cell, final String chartId,
			final Map<String, ClientAnchor> anchorsMap) {

		ClientAnchor anchor = anchorsMap.get(chartId);
		if (anchor != null) {
			AnchorSize anchorSize = getAnchorSize(sheet1, fcell, cell,
					anchor);
			if (anchorSize != null) {
				return "MARGIN-LEFT:"
						+ String.format("%.2f", anchorSize.getPercentLeft())
						+ "%;MARGIN-TOP:"
						+ String.format("%.2f", anchorSize.getPercentTop())
						+ "%;width:"
						+ String.format("%.2f",
								anchorSize.getPercentWidth())
						+ "%;height:135%;";
			}
		}
		return "";
	}

public static String generateChartStyle ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final String chartId , final Map < String , ClientAnchor > anchorsMap ) { ClientAnchor anchor = anchorsMap . get ( chartId ) ; if ( anchor != null ) { AnchorSize anchorSize = getAnchorSize ( sheet1 , fcell , cell , anchor ) ; if ( anchorSize != null ) { return "MARGIN-LEFT:" + String . format ( "%.2f" , anchorSize . getPercentLeft ( ) ) + "%;MARGIN-TOP:" + String . format ( "%.2f" , anchorSize . getPercentTop ( ) ) + "%;width:" + String . format ( "%.2f" , anchorSize . getPercentWidth ( ) ) + "%;height:135%;" ; } } return "" ; }

Generate chart style.

@param sheet1
the sheet 1
@param fcell
the fcell
@param cell
the cell
@param chartId
the chart id
@param anchorsMap
the anchors map
@return the string


public static AnchorSize getAnchorSize(final Sheet sheet1,
			final FacesCell fcell, final Cell cell,
			final ClientAnchor anchor) {

		if (!(sheet1 instanceof XSSFSheet)) {
			return null;
		}
		double picWidth = 0.0;
		double picHeight = 0.0;
		int left = anchor.getDx1()
				/ org.apache.poi.util.Units.EMU_PER_PIXEL;
		int top = (int) ((double) anchor.getDy1()
				/ org.apache.poi.util.Units.EMU_PER_PIXEL
				/ WebSheetUtility.PICTURE_HEIGHT_ADJUST);
		int right = anchor.getDx2()
				/ org.apache.poi.util.Units.EMU_PER_PIXEL;
		int bottom = (int) ((double) anchor.getDy2()
				/ org.apache.poi.util.Units.EMU_PER_PIXEL
				/ WebSheetUtility.PICTURE_HEIGHT_ADJUST);

		double cellWidth = 0.0;
		double cellHeight = 0.0;

		if ((cell != null) && (fcell != null)) {
			for (int col = cell.getColumnIndex(); col < cell
					.getColumnIndex() + fcell.getColspan(); col++) {
				cellWidth += sheet1.getColumnWidthInPixels(col);
			}
			double lastCellWidth = sheet1.getColumnWidthInPixels(
					cell.getColumnIndex() + fcell.getColspan() - 1);

			for (int rowIndex = cell.getRowIndex(); rowIndex < cell
					.getRowIndex() + fcell.getRowspan(); rowIndex++) {
				cellHeight += WebSheetUtility.pointsToPixels(
						sheet1.getRow(rowIndex).getHeightInPoints());
			}
			double lastCellHeight = WebSheetUtility.pointsToPixels(sheet1
					.getRow(cell.getRowIndex() + fcell.getRowspan() - 1)
					.getHeightInPoints());

			picWidth = cellWidth - lastCellWidth + right - left;
			picHeight = cellHeight - lastCellHeight + bottom - top;
		} else {
			for (short col = anchor.getCol1(); col < anchor
					.getCol2(); col++) {
				picWidth += sheet1.getColumnWidthInPixels(col);
			}
			for (int rowindex = anchor.getRow1(); rowindex < anchor
					.getRow2(); rowindex++) {
				Row row = sheet1.getRow(rowindex);
				if (row != null) {
					picHeight += WebSheetUtility
							.pointsToPixels(row.getHeightInPoints());
				}
			}
		}

		return new AnchorSize(left, top, (int) picWidth, (int) picHeight,
				cellWidth, cellHeight);

	}

public static AnchorSize getAnchorSize ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final ClientAnchor anchor ) { if ( ! ( sheet1 instanceof XSSFSheet ) ) { return null ; } double picWidth = 0.0 ; double picHeight = 0.0 ; int left = anchor . getDx1 ( ) / org . apache . poi . util . Units . EMU_PER_PIXEL ; int top = ( int ) ( ( double ) anchor . getDy1 ( ) / org . apache . poi . util . Units . EMU_PER_PIXEL / WebSheetUtility . PICTURE_HEIGHT_ADJUST ) ; int right = anchor . getDx2 ( ) / org . apache . poi . util . Units . EMU_PER_PIXEL ; int bottom = ( int ) ( ( double ) anchor . getDy2 ( ) / org . apache . poi . util . Units . EMU_PER_PIXEL / WebSheetUtility . PICTURE_HEIGHT_ADJUST ) ; double cellWidth = 0.0 ; double cellHeight = 0.0 ; if ( ( cell != null ) && ( fcell != null ) ) { for ( int col = cell . getColumnIndex ( ) ; col < cell . getColumnIndex ( ) + fcell . getColspan ( ) ; col ++ ) { cellWidth += sheet1 . getColumnWidthInPixels ( col ) ; } double lastCellWidth = sheet1 . getColumnWidthInPixels ( cell . getColumnIndex ( ) + fcell . getColspan ( ) - 1 ) ; for ( int rowIndex = cell . getRowIndex ( ) ; rowIndex < cell . getRowIndex ( ) + fcell . getRowspan ( ) ; rowIndex ++ ) { cellHeight += WebSheetUtility . pointsToPixels ( sheet1 . getRow ( rowIndex ) . getHeightInPoints ( ) ) ; } double lastCellHeight = WebSheetUtility . pointsToPixels ( sheet1 . getRow ( cell . getRowIndex ( ) + fcell . getRowspan ( ) - 1 ) . getHeightInPoints ( ) ) ; picWidth = cellWidth - lastCellWidth + right - left ; picHeight = cellHeight - lastCellHeight + bottom - top ; } else { for ( short col = anchor . getCol1 ( ) ; col < anchor . getCol2 ( ) ; col ++ ) { picWidth += sheet1 . getColumnWidthInPixels ( col ) ; } for ( int rowindex = anchor . getRow1 ( ) ; rowindex < anchor . getRow2 ( ) ; rowindex ++ ) { Row row = sheet1 . getRow ( rowindex ) ; if ( row != null ) { picHeight += WebSheetUtility . pointsToPixels ( row . getHeightInPoints ( ) ) ; } } } return new AnchorSize ( left , top , ( int ) picWidth , ( int ) picHeight , cellWidth , cellHeight ) ; }

Gets the anchor size.

@param sheet1
the sheet 1
@param fcell
the fcell
@param cell
the cell
@param anchor
the anchor
@return the anchor size


public Pattern getPattern() {
	if ((this.pattern == null) && (alias != null)) {
		this.pattern = Pattern.compile("\\s*" + ParserUtility.wildcardToRegex(alias));
	}
	return pattern;
}

public Pattern getPattern ( ) { if ( ( this . pattern == null ) && ( alias != null ) ) { this . pattern = Pattern . compile ( "\\s*" + ParserUtility . wildcardToRegex ( alias ) ) ; } return pattern ; }


public StreamedContent getChart() throws IOException {
		FacesContext context = FacesContext.getCurrentInstance();

		if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
			// So, we're rendering the HTML. Return a stub StreamedContent so
			// that it will generate right URL.
			LOG.fine(" return empty chart picture");
			return new DefaultStreamedContent();
		} else {
			// So, browser is requesting the image. Return a real
			// StreamedContent with the image bytes.
			String chartId = context.getExternalContext()
					.getRequestParameterMap().get("chartViewId");

			BufferedImage bufferedImg = (BufferedImage) FacesContext
					.getCurrentInstance().getExternalContext()
					.getSessionMap().get(chartId);
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			ImageIO.write(bufferedImg, "png", os);
			FacesContext.getCurrentInstance().getExternalContext()
					.getSessionMap().remove(chartId);
			return new DefaultStreamedContent(new ByteArrayInputStream(
					os.toByteArray()), "image/png");
		}
	}

Return real chart picture when browser requesting the image.

@return empty chart ( phase == render) or real chart ( browser request).
@throws IOException
exception.

Return real chart picture when browser requesting the image .


public final void recover(final Sheet sheet) {

		if (this.cellAddr != null) {
			this.setCell(sheet.getRow(this.cellAddr.getRow())
					.getCell(this.cellAddr.getColumn()));
		}

	}

public final void recover ( final Sheet sheet ) { if ( this . cellAddr != null ) { this . setCell ( sheet . getRow ( this . cellAddr . getRow ( ) ) . getCell ( this . cellAddr . getColumn ( ) ) ) ; } }

recover cell by using it's address.

@param sheet
sheet.


public static String getRowStyle(final Workbook wb, final Cell poiCell,
			final String inputType, final float rowHeight,
			final int rowspan) {

		CellStyle cellStyle = poiCell.getCellStyle();
		if ((cellStyle != null) && (rowspan == 1)) {
			short fontIdx = cellStyle.getFontIndex();
			Font font = wb.getFontAt(fontIdx);
			float maxHeight = rowHeight;
			if (!inputType.isEmpty()) {
				maxHeight = Math.min(font.getFontHeightInPoints() + 8f,
						rowHeight);
			}
			return "height:" + WebSheetUtility.pointsToPixels(maxHeight)
					+ "px;";
		}
		return "";
	}

public static String getRowStyle ( final Workbook wb , final Cell poiCell , final String inputType , final float rowHeight , final int rowspan ) { CellStyle cellStyle = poiCell . getCellStyle ( ) ; if ( ( cellStyle != null ) && ( rowspan == 1 ) ) { short fontIdx = cellStyle . getFontIndex ( ) ; Font font = wb . getFontAt ( fontIdx ) ; float maxHeight = rowHeight ; if ( ! inputType . isEmpty ( ) ) { maxHeight = Math . min ( font . getFontHeightInPoints ( ) + 8f , rowHeight ) ; } return "height:" + WebSheetUtility . pointsToPixels ( maxHeight ) + "px;" ; } return "" ; }

Gets the row style.

@param wb
the wb
@param poiCell
the poi cell
@param inputType
the input type
@param rowHeight
the row height
@param rowspan
the rowspan
@return the row style


public static String getCellFontStyle(final Workbook wb,
			final Cell poiCell) {

		CellStyle cellStyle = poiCell.getCellStyle();
		StringBuilder webStyle = new StringBuilder();
		if (cellStyle != null) {
			short fontIdx = cellStyle.getFontIndex();
			Font font = wb.getFontAt(fontIdx);
			if (font.getItalic()) {
				webStyle.append("font-style: italic;");
			}
			if (font.getBold()) {
				webStyle.append("font-weight: bold;");
			}
			webStyle.append(
					"font-size: " + font.getFontHeightInPoints() + "pt;");
			String decoration = getCellFontDecoration(font);
			if (decoration.length() > 0) {
				webStyle.append("text-decoration:" + decoration + ";");
			}
			webStyle.append(getCellFontColor(font));

		}
		return webStyle.toString();

	}

public
static
String
getCellFontStyle
(
final
Workbook
wb
,
final
Cell
poiCell
)
{
CellStyle
cellStyle
=
poiCell
.
getCellStyle
(
)
;
StringBuilder
webStyle
=
new
StringBuilder
(
)
;
if
(
cellStyle
!=
)
{
short
fontIdx
=
cellStyle
.
getFontIndex
(
)
;
Font
font
=
wb
.
getFontAt
(
fontIdx
)
;
if
(
font
.
getItalic
(
)
)
{
webStyle
.
append
(
"font-style: italic;"
)
;
}
if
(
font
.
getBold
(
)
)
{
webStyle
.
append
(
"font-weight: bold;"
)
;
}
webStyle
.
append
(
"font-size: "
+
font
.
getFontHeightInPoints
(
)
+
"pt;"
)
;
String
decoration
=
getCellFontDecoration
(
font
)
;
if
(
decoration
.
length
(
)
>
0
)
{
webStyle
.
append
(
"text-decoration:"
+
decoration
+
";"
)
;
}
webStyle
.
append
(
getCellFontColor
(
font
)
)
;
}
return
webStyle
.
toString
(
)
;
}

Gets the cell font style.

@param wb
the wb
@param poiCell
the poi cell
@return the cell font style


private static String getCellFontColor(final Font font) {
		short[] rgbfix = { TieConstants.RGB_MAX, TieConstants.RGB_MAX,
				TieConstants.RGB_MAX };
		if (font instanceof XSSFFont) {
			XSSFColor color = ((XSSFFont) font).getXSSFColor();
			if (color != null) {
				rgbfix = ColorUtility.getTripletFromXSSFColor(color);
			}
		}
		if (rgbfix[0] != TieConstants.RGB_MAX) {
			return "color:rgb(" + FacesUtility.strJoin(rgbfix, ",") + ");";
		}
		return "";
	}

private static String getCellFontColor ( final Font font ) { short [ ] rgbfix = { TieConstants . RGB_MAX , TieConstants . RGB_MAX , TieConstants . RGB_MAX } ; if ( font instanceof XSSFFont ) { XSSFColor color = ( ( XSSFFont ) font ) . getXSSFColor ( ) ; if ( color != null ) { rgbfix = ColorUtility . getTripletFromXSSFColor ( color ) ; } } if ( rgbfix [ 0 ] != TieConstants . RGB_MAX ) { return "color:rgb(" + FacesUtility . strJoin ( rgbfix , "," ) + ");" ; } return "" ; }

get cell font color.

@param font
font.
@return String font color.


private static String getCellFontDecoration(final Font font) {
		StringBuilder decoration = new StringBuilder();
		if (font.getUnderline() != 0) {
			decoration.append(" underline");
		}
		if (font.getStrikeout()) {
			decoration.append(" line-through");
		}
		return decoration.toString();
	}

private
static
String
getCellFontDecoration
(
final
Font
font
)
{
StringBuilder
decoration
=
new
StringBuilder
(
)
;
if
(
font
.
getUnderline
(
)
!=
0
)
{
decoration
.
append
(
" underline"
)
;
}
if
(
font
.
getStrikeout
(
)
)
{
decoration
.
append
(
" line-through"
)
;
}
return
decoration
.
toString
(
)
;
}

Get font decoration.

@param font
font.
@return font decoration.


public static String getCellStyle(final Workbook wb, final Cell poiCell,
			final String inputType) {

		CellStyle cellStyle = poiCell.getCellStyle();
		StringBuilder webStyle = new StringBuilder();
		if (cellStyle != null) {
			if (!inputType.isEmpty()) {
				webStyle.append(getAlignmentFromCell(poiCell, cellStyle));
				webStyle.append(getVerticalAlignmentFromCell(cellStyle));
			}

			webStyle.append(ColorUtility.getBgColorFromCell(wb, poiCell,
					cellStyle));
		}
		return webStyle.toString();

	}

public static String getCellStyle ( final Workbook wb , final Cell poiCell , final String inputType ) { CellStyle cellStyle = poiCell . getCellStyle ( ) ; StringBuilder webStyle = new StringBuilder ( ) ; if ( cellStyle != null ) { if ( ! inputType . isEmpty ( ) ) { webStyle . append ( getAlignmentFromCell ( poiCell , cellStyle ) ) ; webStyle . append ( getVerticalAlignmentFromCell ( cellStyle ) ) ; } webStyle . append ( ColorUtility . getBgColorFromCell ( wb , poiCell , cellStyle ) ) ; } return webStyle . toString ( ) ; }

Gets the cell style.

@param wb
the wb
@param poiCell
the poi cell
@param inputType
the input type
@return the cell style


public static String getColumnStyle(final Workbook wb,
			final FacesCell fcell, final Cell poiCell,
			final float rowHeight) {

		String inputType = fcell.getInputType();
		CellStyle cellStyle = poiCell.getCellStyle();
		StringBuilder webStyle = new StringBuilder();
		if (cellStyle != null) {
			if (fcell.isContainPic() || fcell.isContainChart()) {
				webStyle.append("vertical-align: top;");
			} else {
				webStyle.append(getAlignmentFromCell(poiCell, cellStyle));
				webStyle.append(getVerticalAlignmentFromCell(cellStyle));
			}
			webStyle.append(ColorUtility.getBgColorFromCell(wb, poiCell,
					cellStyle));
			webStyle.append(getRowStyle(wb, poiCell, inputType, rowHeight,
					fcell.getRowspan()));
		} else {
			webStyle.append(getAlignmentFromCellType(poiCell));
		}
		return webStyle.toString();

	}

public
static
String
getColumnStyle
(
final
Workbook
wb
,
final
FacesCell
fcell
,
final
Cell
poiCell
,
final
float
rowHeight
)
{
String
inputType
=
fcell
.
getInputType
(
)
;
CellStyle
cellStyle
=
poiCell
.
getCellStyle
(
)
;
StringBuilder
webStyle
=
new
StringBuilder
(
)
;
if
(
cellStyle
!=
)
{
if
(
fcell
.
isContainPic
(
)
||
fcell
.
isContainChart
(
)
)
{
webStyle
.
append
(
"vertical-align: top;"
)
;
}
else
{
webStyle
.
append
(
getAlignmentFromCell
(
poiCell
,
cellStyle
)
)
;
webStyle
.
append
(
getVerticalAlignmentFromCell
(
cellStyle
)
)
;
}
webStyle
.
append
(
ColorUtility
.
getBgColorFromCell
(
wb
,
poiCell
,
cellStyle
)
)
;
webStyle
.
append
(
getRowStyle
(
wb
,
poiCell
,
inputType
,
rowHeight
,
fcell
.
getRowspan
(
)
)
)
;
}
else
{
webStyle
.
append
(
getAlignmentFromCellType
(
poiCell
)
)
;
}
return
webStyle
.
toString
(
)
;
}

Gets the column style.

@param wb
the wb
@param fcell
the fcell
@param poiCell
the poi cell
@param rowHeight
the row height
@return the column style


private static String getAlignmentFromCell(final Cell poiCell,
			final CellStyle cellStyle) {

		String style = "";
		switch (cellStyle.getAlignmentEnum()) {
		case LEFT:
			style = TieConstants.TEXT_ALIGN_LEFT;
			break;
		case RIGHT:
			style = TieConstants.TEXT_ALIGN_RIGHT;
			break;
		case CENTER:
			style = TieConstants.TEXT_ALIGN_CENTER;
			break;
		case GENERAL:
			style = getAlignmentFromCellType(poiCell);
			break;
		default:
			break;
		}
		return style;
	}

private static String getAlignmentFromCell ( final Cell poiCell , final CellStyle cellStyle ) { String style = "" ; switch ( cellStyle . getAlignmentEnum ( ) ) { case LEFT : style = TieConstants . TEXT_ALIGN_LEFT ; break ; case RIGHT : style = TieConstants . TEXT_ALIGN_RIGHT ; break ; case CENTER : style = TieConstants . TEXT_ALIGN_CENTER ; break ; case GENERAL : style = getAlignmentFromCellType ( poiCell ) ; break ; default : break ; } return style ; }

Gets the alignment from cell.

@param poiCell
the poi cell
@param cellStyle
the cell style
@return the alignment from cell


private static String getVerticalAlignmentFromCell(
			final CellStyle cellStyle) {

		String style = "";
		switch (cellStyle.getVerticalAlignmentEnum()) {
		case TOP:
			style = TieConstants.VERTICAL_ALIGN_TOP;
			break;
		case CENTER:
			style = TieConstants.VERTICAL_ALIGN_CENTER;
			break;
		case BOTTOM:
			style = TieConstants.VERTICAL_ALIGN_BOTTOM;
			break;
		default:
			break;
		}
		return style;
	}

private static String getVerticalAlignmentFromCell ( final CellStyle cellStyle ) { String style = "" ; switch ( cellStyle . getVerticalAlignmentEnum ( ) ) { case TOP : style = TieConstants . VERTICAL_ALIGN_TOP ; break ; case CENTER : style = TieConstants . VERTICAL_ALIGN_CENTER ; break ; case BOTTOM : style = TieConstants . VERTICAL_ALIGN_BOTTOM ; break ; default : break ; } return style ; }

Gets the vertical alignment from cell.

@param cellStyle
the cell style

@return the vertical alignment from cell


public static int calcTotalHeight(final Sheet sheet1,
			final int firstRow, final int lastRow,
			final int additionalHeight) {

		int totalHeight = additionalHeight;
		for (int i = firstRow; i <= lastRow; i++) {

			totalHeight += sheet1.getRow(i).getHeight();
		}
		return totalHeight;
	}

public static int calcTotalHeight ( final Sheet sheet1 , final int firstRow , final int lastRow , final int additionalHeight ) { int totalHeight = additionalHeight ; for ( int i = firstRow ; i <= lastRow ; i ++ ) { totalHeight += sheet1 . getRow ( i ) . getHeight ( ) ; } return totalHeight ; }

Calc total height.

@param sheet1
the sheet 1
@param firstRow
the first row
@param lastRow
the last row
@param additionalHeight
the additional height
@return the int


public static void setupCellStyle(final Workbook wb,
			final FacesCell fcell, final Cell poiCell,
			final float rowHeight) {

		CellStyle cellStyle = poiCell.getCellStyle();
		if ((cellStyle != null) && (!cellStyle.getLocked())) {
			// not locked
			if (fcell.getInputType().isEmpty()) {
				fcell.setInputType(
						CellStyleUtility.getInputTypeFromCellType(poiCell));
			}
			if (fcell.getControl().isEmpty()
					&& (!fcell.getInputType().isEmpty())) {
				fcell.setControl("text");
			}
			setInputStyleBaseOnInputType(fcell, poiCell);

		}
		String webStyle = getCellStyle(wb, poiCell, fcell.getInputType())
				+ getCellFontStyle(wb, poiCell)
				+ getRowStyle(wb, poiCell, fcell.getInputType(), rowHeight,
						fcell.getRowspan());
		fcell.setStyle(webStyle);
		fcell.setColumnStyle(getColumnStyle(wb, fcell, poiCell, rowHeight));
	}

public
static
void
setupCellStyle
(
final
Workbook
wb
,
final
FacesCell
fcell
,
final
Cell
poiCell
,
final
float
rowHeight
)
{
CellStyle
cellStyle
=
poiCell
.
getCellStyle
(
)
;
if
(
(
cellStyle
!=
)
&&
(
!
cellStyle
.
getLocked
(
)
)
)
{
// not locked
if
(
fcell
.
getInputType
(
)
.
isEmpty
(
)
)
{
fcell
.
setInputType
(
CellStyleUtility
.
getInputTypeFromCellType
(
poiCell
)
)
;
}
if
(
fcell
.
getControl
(
)
.
isEmpty
(
)
&&
(
!
fcell
.
getInputType
(
)
.
isEmpty
(
)
)
)
{
fcell
.
setControl
(
"text"
)
;
}
setInputStyleBaseOnInputType
(
fcell
,
poiCell
)
;
}
String
webStyle
=
getCellStyle
(
wb
,
poiCell
,
fcell
.
getInputType
(
)
)
+
getCellFontStyle
(
wb
,
poiCell
)
+
getRowStyle
(
wb
,
poiCell
,
fcell
.
getInputType
(
)
,
rowHeight
,
fcell
.
getRowspan
(
)
)
;
fcell
.
setStyle
(
webStyle
)
;
fcell
.
setColumnStyle
(
getColumnStyle
(
wb
,
fcell
,
poiCell
,
rowHeight
)
)
;
}

Setup cell style.

@param wb
the wb
@param fcell
the fcell
@param poiCell
the poi cell
@param rowHeight
the row height


@SuppressWarnings("deprecation")
	private static String getInputTypeFromCellType(final Cell cell) {

		String inputType = TieConstants.CELL_INPUT_TYPE_TEXT;
		if (cell.getCellTypeEnum() == CellType.NUMERIC) {
			inputType = TieConstants.CELL_INPUT_TYPE_DOUBLE;
		}
		CellStyle style = cell.getCellStyle();
		if (style != null) {
			int formatIndex = style.getDataFormat();
			String formatString = style.getDataFormatString();
			if (DateUtil.isADateFormat(formatIndex, formatString)) {
				inputType = TieConstants.CELL_INPUT_TYPE_DATE;
			} else {
				if (isAPercentageCell(formatString)) {
					inputType = TieConstants.CELL_INPUT_TYPE_PERCENTAGE;
				}
			}
		}
		return inputType;
	}

@ SuppressWarnings ( "deprecation" ) private static String getInputTypeFromCellType ( final Cell cell ) { String inputType = TieConstants . CELL_INPUT_TYPE_TEXT ; if ( cell . getCellTypeEnum ( ) == CellType . NUMERIC ) { inputType = TieConstants . CELL_INPUT_TYPE_DOUBLE ; } CellStyle style = cell . getCellStyle ( ) ; if ( style != null ) { int formatIndex = style . getDataFormat ( ) ; String formatString = style . getDataFormatString ( ) ; if ( DateUtil . isADateFormat ( formatIndex , formatString ) ) { inputType = TieConstants . CELL_INPUT_TYPE_DATE ; } else { if ( isAPercentageCell ( formatString ) ) { inputType = TieConstants . CELL_INPUT_TYPE_PERCENTAGE ; } } } return inputType ; }

Gets the input type from cell type.

@param cell
the cell
@return the input type from cell type


public static Set<String> getResourcePaths(final FacesContext context,
			final String path) {
		return context.getExternalContext().getResourcePaths(path);
	}

public static Set < String > getResourcePaths ( final FacesContext context , final String path ) { return context . getExternalContext ( ) . getResourcePaths ( path ) ; }

return faces context resource path.

@param context
face context.
@param path
path.
@return a set of path.


public static InputStream getResourceAsStream(
			final FacesContext context, final String path) {
		return context.getExternalContext().getResourceAsStream(path);
	}

public static InputStream getResourceAsStream ( final FacesContext context , final String path ) { return context . getExternalContext ( ) . getResourceAsStream ( path ) ; }

get resource file as stream.

@param context
faces context.
@param path
resource file path.
@return stream.


public static String removePrefixPath(final String prefix,
			final String resource) {
		String normalizedResource = resource;
		if (normalizedResource.startsWith(prefix)) {
			normalizedResource = normalizedResource
					.substring(prefix.length() - 1);
		}

		return normalizedResource;
	}

public static String removePrefixPath ( final String prefix , final String resource ) { String normalizedResource = resource ; if ( normalizedResource . startsWith ( prefix ) ) { normalizedResource = normalizedResource . substring ( prefix . length ( ) - 1 ) ; } return normalizedResource ; }

remove prefix path of the full path.

@param prefix
prefix string.
@param resource
normal resource.
@return removed path.


public static boolean evalInputType(final String input,
			final String type) {

		Scanner scanner = new Scanner(input);
		boolean ireturn = false;
		if ("Integer".equalsIgnoreCase(type)) {
			ireturn = scanner.hasNextInt();
		} else if ("Double".equalsIgnoreCase(type)) {
			ireturn = scanner.hasNextDouble();
		} else if ("Boolean".equalsIgnoreCase(type)) {
			ireturn = scanner.hasNextBoolean();
		} else if ("Byte".equalsIgnoreCase(type)) {
			ireturn = scanner.hasNextByte();
		} else if (type.toLowerCase().startsWith("text")) {
			ireturn = true;
		}
		scanner.close();
		return ireturn;
	}

public static boolean evalInputType ( final String input , final String type ) { Scanner scanner = new Scanner ( input ) ; boolean ireturn = false ; if ( "Integer" . equalsIgnoreCase ( type ) ) { ireturn = scanner . hasNextInt ( ) ; } else if ( "Double" . equalsIgnoreCase ( type ) ) { ireturn = scanner . hasNextDouble ( ) ; } else if ( "Boolean" . equalsIgnoreCase ( type ) ) { ireturn = scanner . hasNextBoolean ( ) ; } else if ( "Byte" . equalsIgnoreCase ( type ) ) { ireturn = scanner . hasNextByte ( ) ; } else if ( type . toLowerCase ( ) . startsWith ( "text" ) ) { ireturn = true ; } scanner . close ( ) ; return ireturn ; }

evaluate input type.

@param input
input string.
@param type
input type.
@return true if input meet type, otherwise false.


@SuppressWarnings("unchecked")
	public static <T> T findBean(final String beanName) {
		FacesContext context = FacesContext.getCurrentInstance();
		return (T) context.getApplication().evaluateExpressionGet(context,
				TieConstants.EL_START + beanName + TieConstants.EL_END,
				Object.class);
	}

@ SuppressWarnings ( "unchecked" ) public static < T > T findBean ( final String beanName ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; return ( T ) context . getApplication ( ) . evaluateExpressionGet ( context , TieConstants . EL_START + beanName + TieConstants . EL_END , Object . class ) ; }

Find bean in context.

@param <T>
This is the type parameter.
@param beanName
bean name.
@return bean object.


public static String strJoin(final short[] aArr, final String sSep) {
		StringBuilder sbStr = new StringBuilder();
		for (int i = 0, il = aArr.length; i < il; i++) {
			if (i > 0) {
				sbStr.append(sSep);
			}
			sbStr.append(aArr[i]);
		}
		return sbStr.toString();
	}

public static String strJoin ( final short [ ] aArr , final String sSep ) { StringBuilder sbStr = new StringBuilder ( ) ; for ( int i = 0 , il = aArr . length ; i < il ; i ++ ) { if ( i > 0 ) { sbStr . append ( sSep ) ; } sbStr . append ( aArr [ i ] ) ; } return sbStr . toString ( ) ; }

join string.

@param aArr
attribute list.
@param sSep
seperator string.
@return joined string.


public static double round(final double value, final int places) {
		if (places < 0) {
			throw new IllegalArgumentException();
		}

		BigDecimal bd = BigDecimal.valueOf(value);
		bd = bd.setScale(places, RoundingMode.HALF_UP);
		return bd.doubleValue();
	}

public static double round ( final double value , final int places ) { if ( places < 0 ) { throw new IllegalArgumentException ( ) ; } BigDecimal bd = BigDecimal . valueOf ( value ) ; bd = bd . setScale ( places , RoundingMode . HALF_UP ) ; return bd . doubleValue ( ) ; }

round number according to decimal places.

@param value
double value.
@param places
decimal places.
@return rounded number.

round number according to decimal places .


public String getTabType() {

		int sheetId = webFormTabView.getActiveIndex();
		if ((sheetId >= 0) && (tabs != null)) {
			if (sheetId >= tabs.size()) {
				sheetId = 0;
			}
			tabType = tabs.get(sheetId).type.toLowerCase();
		} else {
			tabType = TieConstants.TAB_TYPE_NONE;
		}
		return tabType;
	}

public String getTabType ( ) { int sheetId = webFormTabView . getActiveIndex ( ) ; if ( ( sheetId >= 0 ) && ( tabs != null ) ) { if ( sheetId >= tabs . size ( ) ) { sheetId = 0 ; } tabType = tabs . get ( sheetId ) . type . toLowerCase ( ) ; } else { tabType = TieConstants . TAB_TYPE_NONE ; } return tabType ; }


public String getTabStyle() {

		String tabStyle = TieConstants.TAB_STYLE_VISIBLE;
		int sheetId = webFormTabView.getActiveIndex();
		if ((sheetId >= 0) && (sheetId < tabs.size())) {
			tabStyle = TieConstants.TAB_STYLE_INVISIBLE;

		}

		return tabStyle;
	}

public String getTabStyle ( ) { String tabStyle = TieConstants . TAB_STYLE_VISIBLE ; int sheetId = webFormTabView . getActiveIndex ( ) ; if ( ( sheetId >= 0 ) && ( sheetId < tabs . size ( ) ) ) { tabStyle = TieConstants . TAB_STYLE_INVISIBLE ; } return tabStyle ; }


public String getDefaultDatePattern() {
		if (defaultDatePattern == null) {
			DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
			defaultDatePattern = ((SimpleDateFormat) formatter).toLocalizedPattern();
		}
		return defaultDatePattern;
	}

public String getDefaultDatePattern ( ) { if ( defaultDatePattern == null ) { DateFormat formatter = DateFormat . getDateInstance ( DateFormat . SHORT , Locale . getDefault ( ) ) ; defaultDatePattern = ( ( SimpleDateFormat ) formatter ) . toLocalizedPattern ( ) ; } return defaultDatePattern ; }

Gets the default date pattern.

@return the default date pattern


public String getDecimalSeparatorByDefaultLocale() {
		final DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(getDefaultLocale());
		return "" + nf.getDecimalFormatSymbols().getDecimalSeparator();
	}

public String getDecimalSeparatorByDefaultLocale ( ) { final DecimalFormat nf = ( DecimalFormat ) DecimalFormat . getInstance ( getDefaultLocale ( ) ) ; return "" + nf . getDecimalFormatSymbols ( ) . getDecimalSeparator ( ) ; }

Gets the decimal separator by default locale.

@return the decimal separator by default locale

Gets the decimal separator by default locale .


public String getThousandSeparatorByDefaultLocale() {
		final DecimalFormat nf = (DecimalFormat) DecimalFormat.getInstance(getDefaultLocale());
		return "" + nf.getDecimalFormatSymbols().getGroupingSeparator();
	}

public String getThousandSeparatorByDefaultLocale ( ) { final DecimalFormat nf = ( DecimalFormat ) DecimalFormat . getInstance ( getDefaultLocale ( ) ) ; return "" + nf . getDecimalFormatSymbols ( ) . getGroupingSeparator ( ) ; }

Gets the thousand separator by default locale.

@return the thousand separator by default locale

Gets the thousand separator by default locale .


public void setTieCommandAliasList(String aliasListJson) {

		Gson gson = new Gson();

		Type aliasListType = new TypeToken<ArrayList<TieCommandAlias>>(){}.getType();

		this.tieCommandAliasList = gson.fromJson(aliasListJson, aliasListType);
	}

public void setTieCommandAliasList ( String aliasListJson ) { Gson gson = new Gson ( ) ; Type aliasListType = new TypeToken < ArrayList < TieCommandAlias > > ( ) { } . getType ( ) ; this . tieCommandAliasList = gson . fromJson ( aliasListJson , aliasListType ) ; }

Sets the tie command alias list.

@param aliasListJson the new tie command alias list


private List<Integer> buildFormWatchList(
			final XSSFEvaluationWorkbook wbWrapper, final Sheet sheet) {

		List<Integer> watchList = new ArrayList<>();

		ConfigRange cRange = this.getConfigRange();
		List<ConfigCommand> commandList = cRange.getCommandList();
		if (commandList.isEmpty()) {
			// if no command then no dynamic changes. then no need formula
			// shifts.
			return watchList;
		}
		int lastStaticRow = commandList.get(0).getTopRow() - 1;
		if (lastStaticRow < 0) {
			lastStaticRow = this.getTopRow();
		}

		int sheetIndex = sheet.getWorkbook().getSheetIndex(sheet);

		for (int i = this.getTopRow(); i <= this.getLastRow(); i++) {
			Row row = sheet.getRow(i);
			for (Cell cell : row) {
				if (cell.getCellTypeEnum() == CellType.FORMULA) {

					buildWatchListForCell(wbWrapper, sheetIndex, cell,
							watchList, lastStaticRow);

				}
			}
		}

		return watchList;

	}

Watch list serve for formula changes. Basically all the rows appeared in
the formula in the current sheet will be watched. Note if the cell
reference is from other sheet or workbooks, it will be ignored.

@param wbWrapper
XSSFEvaluationWorkbook used for formula parse.
@param sheet
current sheet.
@return List row number for monitoring.

Watch list serve for formula changes . Basically all the rows appeared in the formula in the current sheet will be watched . Note if the cell reference is from other sheet or workbooks it will be ignored .


private void buildWatchListForCell(
			final XSSFEvaluationWorkbook wbWrapper, final int sheetIndex,
			final Cell cell, final List<Integer> watchList, final int lastStaticRow) {
		String formula = cell.getCellFormula();

		Ptg[] ptgs = FormulaParser.parse(formula, wbWrapper,
				FormulaType.CELL, sheetIndex);

		for (int k = 0; k < ptgs.length; k++) {
			Object ptg = ptgs[k];
			// For area formula, only first row is watched.
			// Reason is the lastRow must shift same rows with
			// firstRow.
			// Otherwise it's difficult to calculate.
			// In case some situation cannot fit, then should make
			// change to the formula.
			int areaInt = ShiftFormulaUtility
					.getFirstSupportedRowNumFromPtg(ptg);
			if (areaInt >= 0) {
				addToWatchList(areaInt, lastStaticRow, watchList);
			}
		}

		// when insert row, the formula may changed. so here is the
		// workaround.
		// change formula to user formula to preserve the row
		// changes.
		cell.setCellType(CellType.STRING);
		cell.setCellValue(TieConstants.USER_FORMULA_PREFIX + formula
				+ TieConstants.USER_FORMULA_SUFFIX);
	}

Builds the watch list for cell.

@param wbWrapper
the wb wrapper
@param sheetIndex
the sheet index
@param cell
the cell
@param watchList
the watch list
@param lastStaticRow
the last static row


private void addToWatchList(final int addRow, final int lastStaticRow,
			final List<Integer> watchList) {
		if ((addRow > lastStaticRow) && !(watchList.contains(addRow))) {
			watchList.add(addRow);
		}
	}

private void addToWatchList ( final int addRow , final int lastStaticRow , final List < Integer > watchList ) { if ( ( addRow > lastStaticRow ) && ! ( watchList . contains ( addRow ) ) ) { watchList . add ( addRow ) ; } }

Only rows in dynamic area will be added to watch list.

@param addRow
row want to add.
@param lastStaticRow
last static row.
@param watchList
watch list.

Only rows in dynamic area will be added to watch list .


public static boolean isCommandString(final String str) {
		if (str == null) {
			return false;
		}
		return str.startsWith(TieConstants.COMMAND_PREFIX);
	}

public static boolean isCommandString ( final String str ) { if ( str == null ) { return false ; } return str . startsWith ( TieConstants . COMMAND_PREFIX ) ; }

check it's a command comment.

@param str
comment string.
@return ture if it's command.


public static void parseWidgetAttributes(final Cell cell,
			final String newComment,
			final CellAttributesMap cellAttributesMap) {

		if ((newComment == null) || (newComment.isEmpty())) {
			return;
		}
		int widgetStart = newComment
				.indexOf(TieConstants.METHOD_WIDGET_PREFIX);
		int elStart = newComment.indexOf(TieConstants.EL_START_BRACKET);
		if ((widgetStart < 0) || (widgetStart >= elStart)) {
			return;
		}

		String type = newComment.substring(
				widgetStart + TieConstants.METHOD_WIDGET_PREFIX.length(),
				elStart);

		String values = getStringBetweenBracket(newComment);
		if (values == null) {
			return;
		}
		// map's key is sheetName!$columnIndex$rowIndex
		String key = getAttributeKeyInMapByCell(cell);
		// one cell only has one control widget
		cellAttributesMap.getCellInputType().put(key, type);
		List<CellFormAttributes> inputs = cellAttributesMap
				.getCellInputAttributes().get(key);
		if (inputs == null) {
			inputs = new ArrayList<>();
			cellAttributesMap.getCellInputAttributes().put(key, inputs);
		}
		parseInputAttributes(inputs, values);

		parseSpecialAttributes(key, type, inputs, cellAttributesMap);

	}

Parses the widget attributes.

@param cell
the cell
@param newComment
the new comment
@param cellAttributesMap
the cell attributes map


public static String getAttributeKeyInMapByCell(final Cell cell) {
		if (cell == null) {
			return null;
		}
		// map's key is sheetName!$columnIndex$rowIndex
		return cell.getSheet().getSheetName() + "!"
				+ CellUtility.getCellIndexNumberKey(cell);

	}

get attribute key in map by cell.

@param cell
input cell.
@return key.


public static void parseValidateAttributes(final Cell cell,
			final String newComment,
			final CellAttributesMap cellAttributesMap) {

		if ((newComment == null) || (newComment.isEmpty())) {
			return;
		}
		if (!newComment.startsWith(TieConstants.METHOD_VALIDATE_PREFIX)) {
			return;
		}

		String values = getStringBetweenBracket(newComment);
		if (values == null) {
			return;
		}
		// map's key is sheetName!$columnIndex$rowIndex
		String key = getAttributeKeyInMapByCell(cell);
		List<CellFormAttributes> attrs = cellAttributesMap
				.getCellValidateAttributes().get(key);
		if (attrs == null) {
			attrs = new ArrayList<>();
			cellAttributesMap.getCellValidateAttributes().put(key, attrs);
		}
		parseValidateAttributes(attrs, values);

	}

Parses the validate attributes.

@param cell
the cell
@param newComment
the new comment
@param cellAttributesMap
the cell attributes map