Input: convert xssf color to color . [CODESPLIT] public static Color xssfClrToClr ( final XSSFColor xssfColor ) { short [ ] rgb = getTripletFromXSSFColor ( xssfColor ) ; return new Color ( rgb [ 0 ] , rgb [ 1 ] , rgb [ 2 ] ) ; }


Input: Return index number for giving index name . e . g . tx1 return 1 . [CODESPLIT] private static int getThemeIndexFromName ( final String idxName ) { final String [ ] idxArray = { "bg1" , "tx1" , "bg2" , "tx2" , "accent1" , "accent2" , "accent3" , "accent4" , "accent5" , "accent6" , "hlink" , "folHlink" } ; try { for ( int i = 0 ; i < idxArray . length ; i ++ ) { if ( idxArray [ i ] . equalsIgnoreCase ( idxName ) ) { return i ; } } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "error in getThemeIndexFromName :" + ex . getLocalizedMessage ( ) , ex ) ; } return - 1 ; }


Input:
Convert xssfcolor to triple let numbers . [CODESPLIT] public static short [ ] getTripletFromXSSFColor ( final XSSFColor xssfColor ) { short [ ] rgbfix = { RGB8BITS , RGB8BITS , RGB8BITS } ; if ( xssfColor != null ) { byte [ ] rgb = xssfColor . getRGBWithTint ( ) ; if ( rgb == null ) { rgb = xssfColor . getRGB ( ) ; } // Bytes are signed, so values of 128+ are negative!
 // 0: red, 1: green, 2: blue
 rgbfix [ 0 ] = ( short ) ( ( rgb [ 0 ] < 0 ) ? ( rgb [ 0 ] + RGB8BITS ) : rgb [ 0 ] ) ; rgbfix [ 1 ] = ( short ) ( ( rgb [ 1 ] < 0 ) ? ( rgb [ 1 ] + RGB8BITS ) : rgb [ 1 ] ) ; rgbfix [ 2 ] = ( short ) ( ( rgb [ 2 ] < 0 ) ? ( rgb [ 2 ] + RGB8BITS ) : rgb [ 2 ] ) ; } return rgbfix ; }


Input:
Gets the bg color from cell . [CODESPLIT] static String getBgColorFromCell ( final Workbook wb , final Cell poiCell , final CellStyle cellStyle ) { String style = "" ; if ( poiCell instanceof HSSFCell ) { int bkColorIndex = cellStyle . getFillForegroundColor ( ) ; HSSFColor color = HSSFColor . getIndexHash ( ) . get ( bkColorIndex ) ; if ( color != null ) { // correct color for customPalette
 HSSFPalette palette = ( ( HSSFWorkbook ) wb ) . getCustomPalette ( ) ; HSSFColor color2 = palette . getColor ( bkColorIndex ) ; if ( ! color . getHexString ( ) . equalsIgnoreCase ( color2 . getHexString ( ) ) ) { color = color2 ; } style = "background-color:rgb(" + FacesUtility . strJoin ( color . getTriplet ( ) , "," ) + ");" ; } } else if ( poiCell instanceof XSSFCell ) { XSSFColor color = ( ( XSSFCell ) poiCell ) . getCellStyle ( ) . getFillForegroundColorColor ( ) ; if ( color != null ) { style = "background-color:rgb(" + FacesUtility . strJoin ( getTripletFromXSSFColor ( color ) , "," ) + ");" ; } } return style ; }


Input: find component according it s class . [CODESPLIT] private static String findComponentNameFromClass ( final UIComponent component ) { String cname = component . getClass ( ) . getSimpleName ( ) ; if ( supportComponents . contains ( cname ) ) { return cname ; } return null ; }


Input: populate attributes . [CODESPLIT] public static void populateAttributes ( final UIComponent component , final FacesCell fcell , final Map < String , Map < String , String > > defaultControlMap ) { List < CellFormAttributes > inputAttrs = fcell . getInputAttrs ( ) ; String cname = findComponentNameFromClass ( component ) ; if ( cname == null ) { return ; } Map < String , String > defaultMap = defaultControlMap . get ( cname ) ; if ( defaultMap == null ) { defaultMap = new HashMap <> ( ) ; defaultControlMap . put ( cname , defaultMap ) ; } for ( Map . Entry < String , String > entry : defaultMap . entrySet ( ) ) { setObjectProperty ( component , entry . getKey ( ) , entry . getValue ( ) , true ) ; } for ( CellFormAttributes attr : inputAttrs ) { String propertyName = attr . getType ( ) ; String propertyValue = attr . getValue ( ) ; if ( ! defaultMap . containsKey ( propertyName ) ) { String defaultValue = getObjectPropertyValue ( component , propertyName , true ) ; defaultMap . put ( propertyName , defaultValue ) ; } setObjectProperty ( component , propertyName , propertyValue , true ) ; } }


Input: match parameter of method . [CODESPLIT] private static AttributesType matchParaMeterOfMethod ( final Object obj , final String methodName ) { for ( AttributesType attr : AttributesType . values ( ) ) { try { obj . getClass ( ) . getMethod ( methodName , new Class [ ] { attr . clazz } ) ; return attr ; } catch ( Exception ex ) { LOG . log ( Level . FINE , " error in matchParaMeterOfMethod = " + ex . getLocalizedMessage ( ) , ex ) ; } } return null ; }


Input: set object property . [CODESPLIT] public static void setObjectProperty ( final Object obj , final String propertyName , final String propertyValue , final boolean ignoreNonExisting ) { try { String methodName = "set" + Character . toUpperCase ( propertyName . charAt ( 0 ) ) + propertyName . substring ( 1 ) ; AttributesType parameterType = matchParaMeterOfMethod ( obj , methodName ) ; if ( parameterType != null ) { Method method = obj . getClass ( ) . getMethod ( methodName , new Class [ ] { parameterType . clazz } ) ; method . invoke ( obj , convertToObject ( parameterType , propertyValue ) ) ; } } catch ( Exception e ) { String msg = "failed to set property '" + propertyName + "' to value '" + propertyValue + "' for object " + obj ; if ( ignoreNonExisting ) { LOG . log ( Level . FINE , msg , e ) ; } else { LOG . warning ( msg ) ; throw new IllegalArgumentException ( e ) ; } } }


Input: get object property value . [CODESPLIT] public static String getObjectPropertyValue ( final Object obj , final String propertyName , final boolean ignoreNonExisting ) { try { Method method = obj . getClass ( ) . getMethod ( "get" + Character . toUpperCase ( propertyName . charAt ( 0 ) ) + propertyName . substring ( 1 ) ) ; return ( String ) method . invoke ( obj ) ; } catch ( Exception e ) { String msg = "failed to get property '" + propertyName + "' for object " + obj ; if ( ignoreNonExisting ) { LOG . log ( Level . FINE , msg , e ) ; } else { LOG . warning ( msg ) ; throw new IllegalArgumentException ( e ) ; } } return null ; }


Input: Setup control attributes . [CODESPLIT] public static void setupControlAttributes ( final int originRowIndex , final FacesCell fcell , final Cell poiCell , final SheetConfiguration sheetConfig , final CellAttributesMap cellAttributesMap ) { int rowIndex = originRowIndex ; if ( rowIndex < 0 ) { rowIndex = poiCell . getRowIndex ( ) ; } String skey = poiCell . getSheet ( ) . getSheetName ( ) + "!" + CellUtility . getCellIndexNumberKey ( poiCell . getColumnIndex ( ) , rowIndex ) ; Map < String , String > commentMap = cellAttributesMap . getTemplateCommentMap ( ) . get ( "$$" ) ; if ( commentMap != null ) { String comment = commentMap . get ( skey ) ; if ( comment != null ) { CommandUtility . createCellComment ( poiCell , comment , sheetConfig . getFinalCommentMap ( ) ) ; } } String widgetType = cellAttributesMap . getCellInputType ( ) . get ( skey ) ; if ( widgetType != null ) { fcell . setControl ( widgetType . toLowerCase ( ) ) ; fcell . setInputAttrs ( cellAttributesMap . getCellInputAttributes ( ) . get ( skey ) ) ; fcell . setSelectItemAttrs ( cellAttributesMap . getCellSelectItemsAttributes ( ) . get ( skey ) ) ; fcell . setDatePattern ( cellAttributesMap . getCellDatePattern ( ) . get ( skey ) ) ; } }


Input: Find cell validate attributes . [CODESPLIT] public static List < CellFormAttributes > findCellValidateAttributes ( final Map < String , List < CellFormAttributes > > validateMaps , final int originRowIndex , final Cell cell ) { String key = cell . getSheet ( ) . getSheetName ( ) + "!" + CellUtility . getCellIndexNumberKey ( cell . getColumnIndex ( ) , originRowIndex ) ; return validateMaps . get ( key ) ; }


Input: Setup faces cell picture charts . [CODESPLIT] public final void setupFacesCellPictureCharts ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final String fId ) { if ( parent . getPicturesMap ( ) != null ) { setupFacesCellPicture ( sheet1 , fcell , cell , fId ) ; } if ( parent . getCharsData ( ) . getChartsMap ( ) != null ) { setupFacesCellCharts ( sheet1 , fcell , cell , fId ) ; } }


Input: Setup faces cell charts . [CODESPLIT] private void setupFacesCellCharts ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final String fId ) { try { String chartId = parent . getCharsData ( ) . getChartPositionMap ( ) . get ( fId ) ; if ( chartId != null ) { BufferedImage img = parent . getCharsData ( ) . getChartsMap ( ) . get ( chartId ) ; if ( img != null ) { fcell . setContainChart ( true ) ; fcell . setChartId ( chartId ) ; fcell . setChartStyle ( PicturesUtility . generateChartStyle ( sheet1 , fcell , cell , chartId , parent . getCharsData ( ) . getChartAnchorsMap ( ) ) ) ; } } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "setupFacesCell Charts error = " + ex . getMessage ( ) , ex ) ; } }


Input: Setup faces cell picture . [CODESPLIT] private void setupFacesCellPicture ( final Sheet sheet1 , final FacesCell fcell , final Cell cell , final String fId ) { try { Picture pic = parent . getPicturesMap ( ) . get ( fId ) ; if ( pic != null ) { fcell . setContainPic ( true ) ; fcell . setPictureId ( fId ) ; fcell . setPictureStyle ( PicturesUtility . generatePictureStyle ( sheet1 , fcell , cell , pic ) ) ; } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "setupFacesCell Picture error = " + ex . getMessage ( ) , ex ) ; } }


Input: initial chart map for specified workbook . [CODESPLIT] private void initChartsMap ( final Workbook wb ) { try { if ( wb instanceof XSSFWorkbook ) { initXSSFChartsMap ( ( XSSFWorkbook ) wb , parent . getCharsData ( ) ) ; } } catch ( Exception e ) { LOG . log ( Level . SEVERE , "getChartsMap Error Exception = " + e . getLocalizedMessage ( ) , e ) ; } }


Input: return cell Value for paredCell . ParsedCell contain sheetName / row / col which normally is parsed from String like : Sheet1!B2 . [CODESPLIT] public final String getParsedCellValue ( final ParsedCell pCell ) { String result = "" ; try { Cell poiCell = parent . getWb ( ) . getSheet ( pCell . getSheetName ( ) ) . getRow ( pCell . getRow ( ) ) . getCell ( pCell . getCol ( ) ) ; result = CellUtility . getCellValueWithoutFormat ( poiCell ) ; } catch ( Exception ex ) { LOG . log ( Level . FINE , "error getParsedCellValue :" + ex . getLocalizedMessage ( ) , ex ) ; } return result ; }


Input: create default category dataset for JfreeChart with giving chartData . [CODESPLIT] private DefaultPieDataset createPieDataset ( final ChartData chartData ) { DefaultPieDataset dataset = new DefaultPieDataset ( ) ; List < ParsedCell > categoryList = chartData . getCategoryList ( ) ; for ( ChartSeries chartSeries : chartData . getSeriesList ( ) ) { List < ParsedCell > valueList = chartSeries . getValueList ( ) ; for ( int i = 0 ; i < categoryList . size ( ) ; i ++ ) { try { String sCategory = getParsedCellValue ( categoryList . get ( i ) ) ; String sValue = getParsedCellValue ( valueList . get ( i ) ) ; dataset . setValue ( sCategory , Double . parseDouble ( sValue ) ) ; } catch ( Exception ex ) { LOG . log ( Level . FINE , "error in creatPieDataset : " + ex . getLocalizedMessage ( ) , ex ) ; } } } return dataset ; }


Input: return pie chart title from chartData . [CODESPLIT] private String getPieTitle ( final ChartData chartData ) { for ( ChartSeries chartSeries : chartData . getSeriesList ( ) ) { if ( chartSeries != null ) { return getParsedCellValue ( chartSeries . getSeriesLabel ( ) ) ; } } return "" ; }


Input:
Set color of series . [CODESPLIT] public final void setSeriesStyle ( final JFreeChart chart , final int seriesIndex , final String style ) { if ( chart != null && style != null ) { BasicStroke stroke = ChartUtility . toStroke ( style ) ; Plot plot = chart . getPlot ( ) ; if ( plot instanceof CategoryPlot ) { CategoryPlot categoryPlot = chart . getCategoryPlot ( ) ; CategoryItemRenderer cir = categoryPlot . getRenderer ( ) ; try { cir . setSeriesStroke ( seriesIndex , stroke ) ; // series line
 // style
 } catch ( Exception e ) { LOG . log ( Level . SEVERE , "Error setting style '" + style + "' for series '" + Integer . toString ( seriesIndex ) + "' of chart '" + chart . toString ( ) + "': " + e . getLocalizedMessage ( ) , e ) ; } } else if ( plot instanceof XYPlot ) { XYPlot xyPlot = chart . getXYPlot ( ) ; XYItemRenderer xyir = xyPlot . getRenderer ( ) ; try { xyir . setSeriesStroke ( seriesIndex , stroke ) ; // series line
 // style
 } catch ( Exception e ) { LOG . log ( Level . SEVERE , "Error setting style '" + style + "' for series '" + Integer . toString ( seriesIndex ) + "' of chart '" + chart . toString ( ) + "': " + e . getLocalizedMessage ( ) , e ) ; } } else { LOG . log ( Level . FINE , "setSeriesColor() unsupported plot: {}" , plot . toString ( ) ) ; } } }


Input:
Create jfree bar chart . [CODESPLIT] public JFreeChart createAreaChart ( final ChartData chartData ) { PlotOrientation orientation = PlotOrientation . VERTICAL ; // create the chart...
 final JFreeChart chart = ChartFactory . createAreaChart ( chartData . getTitle ( ) , // chart title
 chartData . getCatAx ( ) . getTitle ( ) , // x axis label
 chartData . getValAx ( ) . getTitle ( ) , // y axis label
 createDataset ( chartData ) , // data
 orientation , true , // include legend
 false , // tooltips
 false // urls
 ) ; setupStyle ( chart , chartData ) ; return chart ; }


Input:
Create jfree bar chart . [CODESPLIT] public JFreeChart createBarChart ( final ChartData chartData , final boolean vertical ) { PlotOrientation orientation = PlotOrientation . VERTICAL ; if ( ! vertical ) { orientation = PlotOrientation . HORIZONTAL ; } // create the chart...
 final JFreeChart chart = ChartFactory . createBarChart ( chartData . getTitle ( ) , // chart title
 chartData . getCatAx ( ) . getTitle ( ) , // x axis label
 chartData . getValAx ( ) . getTitle ( ) , // y axis label
 createDataset ( chartData ) , // data
 orientation , true , // include legend
 false , // tooltips
 false // urls
 ) ; setupBarStyle ( chart , chartData ) ; return chart ; }


Input:
Create jfree bar chart . [CODESPLIT] public JFreeChart createPieChart ( final ChartData chartData ) { // create the chart...
 final JFreeChart chart = ChartFactory . createPieChart ( getPieTitle ( chartData ) , // chart title
 createPieDataset ( chartData ) , // data
 true , // include legend
 false , // tooltips
 false // urls
 ) ; setupPieStyle ( chart , chartData ) ; return chart ; }


Input:
create pie 3d chart . [CODESPLIT] public JFreeChart createPie3DChart ( final ChartData chartData ) { // create the chart...
 final JFreeChart chart = ChartFactory . createPieChart3D ( getPieTitle ( chartData ) , // chart title
 createPieDataset ( chartData ) , // data
 true , // include legend
 false , // tooltips
 false // urls
 ) ; setupPieStyle ( chart , chartData ) ; return chart ; }


Input:
finalize the style for jfreechart . The default setting is different from jfreechart and Excel . We try to minimize the difference . [CODESPLIT] private void setupStyle ( final JFreeChart chart , final ChartData chartData ) { CategoryPlot plot = ( CategoryPlot ) chart . getPlot ( ) ; List < ChartSeries > seriesList = chartData . getSeriesList ( ) ; BasicStroke bLine = new BasicStroke ( 2.0f ) ; for ( int i = 0 ; i < seriesList . size ( ) ; i ++ ) { Color cColor = ColorUtility . xssfClrToClr ( seriesList . get ( i ) . getSeriesColor ( ) . getXssfColor ( ) ) ; plot . getRenderer ( ) . setSeriesPaint ( i , cColor ) ; plot . getRenderer ( ) . setSeriesStroke ( i , bLine ) ; } plot . setBackgroundPaint ( ColorUtility . xssfClrToClr ( chartData . getBgColor ( ) . getXssfColor ( ) ) ) ; // below are modifications for default setting in excel chart
 // to-do: need read setting from xml in future
 plot . setOutlineVisible ( false ) ; plot . setRangeGridlinesVisible ( true ) ; plot . setRangeGridlinePaint ( Color . BLACK ) ; plot . setRangeGridlineStroke ( new BasicStroke ( TieConstants . DEFAULT_BASIC_STROKE ) ) ; plot . setRangeAxisLocation ( AxisLocation . BOTTOM_OR_LEFT ) ; chart . setBackgroundPaint ( Color . WHITE ) ; LegendTitle legend = chart . getLegend ( ) ; legend . setPosition ( RectangleEdge . RIGHT ) ; legend . setFrame ( BlockBorder . NONE ) ; }


Input:
finalize the style for jfreechart . The default setting is different from jfreechart and Excel . We try to minimize the difference . [CODESPLIT] private void setupPieStyle ( final JFreeChart chart , final ChartData chartData ) { PiePlot plot = ( PiePlot ) chart . getPlot ( ) ; List < ChartSeries > seriesList = chartData . getSeriesList ( ) ; List < ParsedCell > categoryList = chartData . getCategoryList ( ) ; BasicStroke bLine = new BasicStroke ( 2.0f ) ; for ( int i = 0 ; i < seriesList . size ( ) ; i ++ ) { ChartSeries chartSeries = seriesList . get ( i ) ; List < XColor > valueColorList = chartSeries . getValueColorList ( ) ; for ( int index = 0 ; index < categoryList . size ( ) ; index ++ ) { try { String sCategory = getParsedCellValue ( categoryList . get ( index ) ) ; Color cColor = ColorUtility . xssfClrToClr ( valueColorList . get ( index ) . getXssfColor ( ) ) ; plot . setSectionPaint ( sCategory , cColor ) ; plot . setSectionOutlineStroke ( sCategory , bLine ) ; } catch ( Exception ex ) { LOG . log ( Level . FINE , "SetupPieStyle error = " + ex . getLocalizedMessage ( ) , ex ) ; } } } plot . setBackgroundPaint ( ColorUtility . xssfClrToClr ( chartData . getBgColor ( ) . getXssfColor ( ) ) ) ; // below are modifications for default setting in excel chart
 // to-do: need read setting from xml in future
 plot . setOutlineVisible ( false ) ; plot . setLegendItemShape ( new Rectangle ( TieConstants . DEFAULT_LEGENT_ITEM_SHAPE_WIDTH , TieConstants . DEFAULT_LEGENT_ITEM_SHAPE_HEIGHT ) ) ; chart . setBackgroundPaint ( Color . WHITE ) ; LegendTitle legend = chart . getLegend ( ) ; legend . setPosition ( RectangleEdge . RIGHT ) ; legend . setFrame ( BlockBorder . NONE ) ; }


Input: finalize the style for barchart . This will call setupStyle common first . [CODESPLIT] private void setupBarStyle ( final JFreeChart chart , final ChartData chartData ) { setupStyle ( chart , chartData ) ; CategoryPlot plot = ( CategoryPlot ) chart . getPlot ( ) ; BarRenderer renderer = ( BarRenderer ) plot . getRenderer ( ) ; renderer . setBarPainter ( new StandardBarPainter ( ) ) ; renderer . setItemMargin ( TieConstants . DEFAULT_BAR_STYLE_ITEM_MARGIN ) ; plot . setForegroundAlpha ( TieConstants . DEFAULT_BARSTYLE_FOREGROUND_ALPHA ) ; }


Input: create default category dataset for JfreeChart with giving chartData . [CODESPLIT] private DefaultCategoryDataset createDataset ( final ChartData chartData ) { DefaultCategoryDataset dataset = new DefaultCategoryDataset ( ) ; List < ParsedCell > categoryList = chartData . getCategoryList ( ) ; for ( ChartSeries chartSeries : chartData . getSeriesList ( ) ) { String seriesLabel = getParsedCellValue ( chartSeries . getSeriesLabel ( ) ) ; List < ParsedCell > valueList = chartSeries . getValueList ( ) ; for ( int i = 0 ; i < categoryList . size ( ) ; i ++ ) { try { String sCategory = getParsedCellValue ( categoryList . get ( i ) ) ; String sValue = getParsedCellValue ( valueList . get ( i ) ) ; dataset . addValue ( Double . parseDouble ( sValue ) , seriesLabel , sCategory ) ; } catch ( Exception ex ) { LOG . log ( Level . FINE , "error in creatDataset : " + ex . getLocalizedMessage ( ) , ex ) ; } } } return dataset ; }


Input: initial chart map for XSSF format file . XSSF file is actually the only format in POI support chart object . [CODESPLIT] private void initXSSFChartsMap ( final XSSFWorkbook wb , final ChartsData chartsData ) { initAnchorsMap ( wb , chartsData ) ; Map < String , ClientAnchor > anchorMap = chartsData . getChartAnchorsMap ( ) ; Map < String , BufferedImage > chartMap = chartsData . getChartsMap ( ) ; Map < String , ChartData > chartDataMap = chartsData . getChartDataMap ( ) ; chartMap . clear ( ) ; chartDataMap . clear ( ) ; for ( int i = 0 ; i < wb . getNumberOfSheets ( ) ; i ++ ) { XSSFSheet sheet = wb . getSheetAt ( i ) ; XSSFDrawing drawing = sheet . createDrawingPatriarch ( ) ; List < XSSFChart > charts = drawing . getCharts ( ) ; if ( ( charts != null ) && ( ! charts . isEmpty ( ) ) ) { for ( XSSFChart chart : charts ) { generateSingleXSSFChart ( chart , getChartIdFromParent ( chart , sheet . getSheetName ( ) ) , sheet , anchorMap , chartMap , chartDataMap ) ; } } } }


Input: Gets the chart id from parent . [CODESPLIT] private String getChartIdFromParent ( final XSSFChart chart , final String sheetName ) { if ( chart . getParent ( ) != null ) { for ( RelationPart rp : chart . getParent ( ) . getRelationParts ( ) ) { if ( rp . getDocumentPart ( ) == chart ) { return sheetName + "!" + rp . getRelationship ( ) . getId ( ) ; } } } return null ; }


Input: initial anchors map for specified workbook . Excel put the chart position information in draw . xml instead of chart . xml . anchors map contains the information getting from draw . xml . [CODESPLIT] private void initAnchorsMap ( final Workbook wb , final ChartsData chartsData ) { try { if ( wb instanceof XSSFWorkbook ) { ChartUtility . initXSSFAnchorsMap ( ( XSSFWorkbook ) wb , chartsData ) ; } } catch ( Exception e ) { LOG . log ( Level . SEVERE , "Web Form getAnchorsMap Error Exception = " + e . getLocalizedMessage ( ) , e ) ; } }


Input: Generate single XSSF chart . [CODESPLIT] private void generateSingleXSSFChart ( final XSSFChart chart , final String chartId , final XSSFSheet sheet , final Map < String , ClientAnchor > anchorMap , final Map < String , BufferedImage > chartMap , final Map < String , ChartData > chartDataMap ) { ClientAnchor anchor ; try { anchor = anchorMap . get ( chartId ) ; if ( anchor != null ) { ChartData chartData = ChartUtility . initChartDataFromXSSFChart ( chartId , chart , ( XSSFWorkbook ) parent . getWb ( ) ) ; chartDataMap . put ( chartId , chartData ) ; JFreeChart jchart = createChart ( chartData ) ; if ( jchart != null ) { AnchorSize anchorSize = PicturesUtility . getAnchorSize ( sheet , null , null , anchor ) ; BufferedImage img = jchart . createBufferedImage ( anchorSize . getWidth ( ) , anchorSize . getHeight ( ) ) ; chartMap . put ( chartId , img ) ; } } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "generate chart for " + chartId + " error = " + ex . getLocalizedMessage ( ) , ex ) ; } }


Input: Transform to collection object . [CODESPLIT] @ SuppressWarnings ( "rawtypes" ) public static Collection transformToCollectionObject ( final ExpressionEngine engine , final String collectionName , final Map < String , Object > context ) { Object collectionObject = engine . evaluate ( collectionName , context ) ; if ( ! ( collectionObject instanceof Collection ) ) { throw new EvaluationException ( collectionName + " expression is not a collection" ) ; } return ( Collection ) collectionObject ; }


Input: Gets the full name from row . [CODESPLIT] public static String getFullNameFromRow ( final Row row ) { if ( row != null ) { Cell cell = row . getCell ( TieConstants . HIDDEN_FULL_NAME_COLUMN ) ; if ( cell != null ) { return cell . getStringCellValue ( ) ; } } return null ; }


Input: Re build upper level formula . [CODESPLIT] public static void reBuildUpperLevelFormula ( final ConfigBuildRef configBuildRef , final String actionFullName ) { Map < Cell , String > cachedMap = configBuildRef . getCachedCells ( ) ; Map < String , List < RowsMapping > > rowsMap = new HashMap <> ( ) ; for ( Map . Entry < Cell , String > entry : cachedMap . entrySet ( ) ) { Cell cell = entry . getKey ( ) ; String originFormula = entry . getValue ( ) ; if ( originFormula != null ) { setupUpperLevelFormula ( cell , originFormula , actionFullName , rowsMap , configBuildRef ) ; } } }


Input:
Setup upper level formula . [CODESPLIT] private static void setupUpperLevelFormula ( final Cell cell , final String originFormula , final String actionFullName , final Map < String , List < RowsMapping > > rowsMap , final ConfigBuildRef configBuildRef ) { String fullName = getFullNameFromRow ( cell . getRow ( ) ) ; // check wither it's upper level
 if ( actionFullName . startsWith ( fullName + ":" ) ) { // get rows mapping for upper level row
 List < RowsMapping > currentRowsMappingList = rowsMap . get ( fullName ) ; if ( currentRowsMappingList == null ) { currentRowsMappingList = gatherRowsMappingByFullName ( configBuildRef , fullName ) ; rowsMap . put ( fullName , currentRowsMappingList ) ; } ShiftFormulaRef shiftFormulaRef = new ShiftFormulaRef ( configBuildRef . getWatchList ( ) , currentRowsMappingList ) ; shiftFormulaRef . setFormulaChanged ( 0 ) ; buildCellFormulaForShiftedRows ( configBuildRef . getSheet ( ) , configBuildRef . getWbWrapper ( ) , shiftFormulaRef , cell , originFormula ) ; if ( shiftFormulaRef . getFormulaChanged ( ) > 0 ) { configBuildRef . getCachedCells ( ) . put ( cell , originFormula ) ; } } }


Input:
Builds the cell formula for shifted rows . [CODESPLIT] public static void buildCellFormulaForShiftedRows ( final Sheet sheet , final XSSFEvaluationWorkbook wbWrapper , final ShiftFormulaRef shiftFormulaRef , final Cell cell , final String originFormula ) { // only shift when there's watchlist exist.
 if ( ( shiftFormulaRef . getWatchList ( ) != null ) && ( ! shiftFormulaRef . getWatchList ( ) . isEmpty ( ) ) ) { Ptg [ ] ptgs = FormulaParser . parse ( originFormula , wbWrapper , FormulaType . CELL , sheet . getWorkbook ( ) . getSheetIndex ( sheet ) ) ; Ptg [ ] convertedFormulaPtg = ShiftFormulaUtility . convertSharedFormulas ( ptgs , shiftFormulaRef ) ; if ( shiftFormulaRef . getFormulaChanged ( ) > 0 ) { // only change formula when indicator is true
 cell . setCellFormula ( FormulaRenderer . toFormulaString ( wbWrapper , convertedFormulaPtg ) ) ; } } }


Input: Gather rows mapping by full name . [CODESPLIT] public static List < RowsMapping > gatherRowsMappingByFullName ( final ConfigBuildRef configBuildRef , final String fullName ) { List < RowsMapping > list = new ArrayList <> ( ) ; Map < String , ConfigRangeAttrs > shiftMap = configBuildRef . getShiftMap ( ) ; for ( Map . Entry < String , ConfigRangeAttrs > entry : shiftMap . entrySet ( ) ) { String fname = entry . getKey ( ) ; if ( fname . startsWith ( fullName + ":" ) || fname . equals ( fullName ) ) { ConfigRangeAttrs attrs = entry . getValue ( ) ; list . add ( attrs . getUnitRowsMapping ( ) ) ; } } return list ; }


Input: Increase index number in shift map . [CODESPLIT] public static void changeIndexNumberInShiftMap ( final Map < String , ConfigRangeAttrs > shiftMap , final Map < String , String > changeMap ) { for ( Map . Entry < String , String > entry : changeMap . entrySet ( ) ) { String key = entry . getKey ( ) ; String newKey = entry . getValue ( ) ; ConfigRangeAttrs attrs = shiftMap . get ( key ) ; if ( attrs != null ) { shiftMap . remove ( key ) ; shiftMap . put ( newKey , attrs ) ; } } }


Input: Increase upper level final length . [CODESPLIT] public static void changeUpperLevelFinalLength ( final Map < String , ConfigRangeAttrs > shiftMap , final String addedFullName , final int increasedLength ) { String [ ] parts = addedFullName . split ( ":" ) ; StringBuilder fname = new StringBuilder ( ) ; for ( int i = 0 ; i < ( parts . length - 1 ) ; i ++ ) { if ( i == 0 ) { fname . append ( parts [ i ] ) ; } else { fname . append ( ":" ) . append ( parts [ i ] ) ; } String sname = fname . toString ( ) ; shiftMap . get ( sname ) . setFinalLength ( shiftMap . get ( sname ) . getFinalLength ( ) + increasedLength ) ; } }


Input: Change index number in hidden column . [CODESPLIT] public static void changeIndexNumberInHiddenColumn ( final ConfigBuildRef configBuildRef , final int startRowIndex , final String fullName , final Map < String , String > changeMap , final int steps ) { String searchName = fullName . substring ( 0 , fullName . lastIndexOf ( ' ' ) + 1 ) ; Sheet sheet = configBuildRef . getSheet ( ) ; for ( int i = startRowIndex ; i <= sheet . getLastRowNum ( ) ; i ++ ) { Row row = sheet . getRow ( i ) ; String fname = getFullNameFromRow ( row ) ; if ( ( fname != null ) && ( fname . indexOf ( searchName ) >= 0 ) ) { int sindex = fname . indexOf ( searchName ) ; String snum = fname . substring ( sindex + searchName . length ( ) ) ; int sufindex = snum . indexOf ( ' ' ) ; String suffix = "" ; if ( sufindex > 0 ) { snum = snum . substring ( 0 , sufindex ) ; suffix = ":" ; } int increaseNum = Integer . parseInt ( snum ) + steps ; String realFullName = fname . substring ( sindex ) ; String changeName = fname . replace ( searchName + snum + suffix , searchName + increaseNum + suffix ) ; if ( changeMap . get ( realFullName ) == null ) { changeMap . put ( realFullName , changeName . substring ( sindex ) ) ; } setFullNameInHiddenColumn ( row , changeName ) ; } else { return ; } } }


Input: Sets the full name in hidden column . [CODESPLIT] public static void setFullNameInHiddenColumn ( final Row row , final String fullName ) { Cell cell = row . getCell ( TieConstants . HIDDEN_FULL_NAME_COLUMN , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; cell . setCellValue ( fullName ) ; }


Input: Gets the original row num in hidden column . [CODESPLIT] public static int getOriginalRowNumInHiddenColumn ( final Row row ) { if ( row != null ) { Cell cell = row . getCell ( TieConstants . HIDDEN_ORIGIN_ROW_NUMBER_COLUMN , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; String rowNum = cell . getStringCellValue ( ) ; try { if ( ( rowNum != null ) && ( ! rowNum . isEmpty ( ) ) && ( WebSheetUtility . isNumeric ( rowNum ) ) ) { return Integer . parseInt ( rowNum ) ; } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "getOriginalRowNumInHiddenColumn rowNum = " + rowNum + " error = " + ex . getLocalizedMessage ( ) , ex ) ; } } return - 1 ; }


Input: Sets the original row num in hidden column . [CODESPLIT] public static void setOriginalRowNumInHiddenColumn ( final Row row , final int rowNum ) { Cell cell = row . getCell ( TieConstants . HIDDEN_ORIGIN_ROW_NUMBER_COLUMN , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; cell . setCellValue ( Integer . toString ( rowNum ) ) ; cell . setCellType ( CellType . STRING ) ; }


Input:
Find parent rows mapping from shift map . [CODESPLIT] public static List < RowsMapping > findParentRowsMappingFromShiftMap ( final String [ ] parts , final Map < String , ConfigRangeAttrs > shiftMap ) { StringBuilder fullName = new StringBuilder ( ) ; List < RowsMapping > rowsMappingList = new ArrayList <> ( ) ; /**
		 * skip first one and last one. first one is line no. last one is it's
		 * self.
		 */ for ( int i = 1 ; i < parts . length - 1 ; i ++ ) { String part = parts [ i ] ; if ( fullName . length ( ) == 0 ) { fullName . append ( part ) ; } else { fullName . append ( ":" + part ) ; } if ( fullName . length ( ) > 0 ) { ConfigRangeAttrs rangeAttrs = shiftMap . get ( fullName . toString ( ) ) ; if ( rangeAttrs != null ) { rowsMappingList . add ( rangeAttrs . getUnitRowsMapping ( ) ) ; } } } return rowsMappingList ; }


Input:
Find child rows mapping from shift map . [CODESPLIT] public static List < RowsMapping > findChildRowsMappingFromShiftMap ( final String fullName , final NavigableMap < String , ConfigRangeAttrs > shiftMap ) { List < RowsMapping > rowsMappingList = new ArrayList <> ( ) ; NavigableMap < String , ConfigRangeAttrs > tailmap = shiftMap . tailMap ( fullName , false ) ; for ( Map . Entry < String , ConfigRangeAttrs > entry : tailmap . entrySet ( ) ) { String key = entry . getKey ( ) ; // check it's children
 if ( key . startsWith ( fullName ) ) { rowsMappingList . add ( entry . getValue ( ) . getUnitRowsMapping ( ) ) ; } else { break ; } } return rowsMappingList ; }


Input: Find item in collection . [CODESPLIT] @ SuppressWarnings ( "rawtypes" ) public static Object findItemInCollection ( final Collection collection , final int index ) { if ( index >= 0 ) { if ( collection instanceof List ) { List list = ( List ) collection ; return list . get ( index ) ; } int i = 0 ; for ( Object object : collection ) { if ( i == index ) { return object ; } i ++ ; } } return null ; }


Input: Builds the current range . [CODESPLIT] public static ConfigRange buildCurrentRange ( final ConfigRange sourceConfigRange , final Sheet sheet , final int insertPosition ) { ConfigRange current = new ConfigRange ( sourceConfigRange ) ; int shiftNum = insertPosition - sourceConfigRange . getFirstRowAddr ( ) . getRow ( ) ; current . shiftRowRef ( sheet , shiftNum ) ; return current ; }


Input: Whether the row is static . This only check rowIndex against original template . [CODESPLIT] public static boolean isStaticRow ( final ConfigRange sourceConfigRange , final int rowIndex ) { if ( sourceConfigRange . getCommandList ( ) != null ) { for ( int i = 0 ; i < sourceConfigRange . getCommandList ( ) . size ( ) ; i ++ ) { Command command = sourceConfigRange . getCommandList ( ) . get ( i ) ; if ( ( rowIndex >= command . getConfigRange ( ) . getFirstRowAddr ( ) . getRow ( ) ) && ( rowIndex < ( command . getConfigRange ( ) . getLastRowPlusAddr ( ) . getRow ( ) ) ) ) { return false ; } } } return true ; }


Input: Whether the row is static . This check row after shifted . [CODESPLIT] public static boolean isStaticRowRef ( final ConfigRange sourceConfigRange , final Row row ) { if ( sourceConfigRange . getCommandList ( ) != null ) { for ( int i = 0 ; i < sourceConfigRange . getCommandList ( ) . size ( ) ; i ++ ) { Command command = sourceConfigRange . getCommandList ( ) . get ( i ) ; int rowIndex = row . getRowNum ( ) ; if ( ( rowIndex >= command . getTopRow ( ) ) && ( rowIndex < ( command . getTopRow ( ) + command . getFinalLength ( ) ) ) ) { return false ; } } } return true ; }


Input: Remove last each command index from full name . e . g . for F . departments : E . department . 1 : E . employee . 2 will return F . departments : E . department . 1 : E . employee [CODESPLIT] public static String getFullDataCollectNameFromFullName ( final String fullName ) { if ( fullName == null ) { return "" ; } int lastEachCommandPos = fullName . lastIndexOf ( TieConstants . EACH_COMMAND_FULL_NAME_PREFIX ) ; if ( lastEachCommandPos < 0 ) { return "" ; } int lastEachCommandIndexPos = fullName . indexOf ( ' ' , lastEachCommandPos + TieConstants . EACH_COMMAND_FULL_NAME_PREFIX . length ( ) ) ; if ( lastEachCommandIndexPos < 0 ) { return fullName ; } return fullName . substring ( 0 , lastEachCommandIndexPos ) ; }


Input:
100 > = 80 [CODESPLIT] public static String replaceExpressionWithCellValue ( final String attrValue , final int rowIndex , final Sheet sheet ) { int ibegin = 0 ; int ifind ; int inameEnd ; String tempStr ; String findStr ; String replaceStr ; String returnStr = attrValue ; while ( ( ifind = attrValue . indexOf ( TieConstants . CELL_ADDR_PRE_FIX , ibegin ) ) > 0 ) { inameEnd = ParserUtility . findFirstNonCellNamePosition ( attrValue , ifind ) ; if ( inameEnd > 0 ) { findStr = attrValue . substring ( ifind , inameEnd ) ; } else { findStr = attrValue . substring ( ifind ) ; } if ( findStr . indexOf ( TieConstants . CELL_ADDR_PRE_FIX , 1 ) < 0 ) { // only $A
 tempStr = findStr + TieConstants . CELL_ADDR_PRE_FIX + ( rowIndex + 1 ) ; } else { tempStr = findStr ; } replaceStr = CellUtility . getCellValueWithoutFormat ( WebSheetUtility . getCellByReference ( tempStr , sheet ) ) ; if ( replaceStr == null ) { replaceStr = "" ; } returnStr = attrValue . replace ( findStr , replaceStr ) ; ibegin = ifind + 1 ; } return returnStr ; }


Input: Index merged region . [CODESPLIT] public static Map < String , CellRangeAddress > indexMergedRegion ( final Sheet sheet1 ) { int numRegions = sheet1 . getNumMergedRegions ( ) ; Map < String , CellRangeAddress > cellRangeMap = new HashMap <> ( ) ; for ( int i = 0 ; i < numRegions ; i ++ ) { CellRangeAddress caddress = sheet1 . getMergedRegion ( i ) ; if ( caddress != null ) { cellRangeMap . put ( CellUtility . getCellIndexNumberKey ( caddress . getFirstColumn ( ) , caddress . getFirstRow ( ) ) , caddress ) ; } } return cellRangeMap ; }


Input: Skipped region cells . [CODESPLIT] public static List < String > skippedRegionCells ( final Sheet sheet1 ) { int numRegions = sheet1 . getNumMergedRegions ( ) ; List < String > skipCellList = new ArrayList <> ( ) ; for ( int i = 0 ; i < numRegions ; i ++ ) { CellRangeAddress caddress = sheet1 . getMergedRegion ( i ) ; if ( caddress != null ) { addSkipCellToListInTheRegion ( skipCellList , caddress ) ; } } return skipCellList ; }


Input: Add skipped cell into the list of a region . [CODESPLIT] private static void addSkipCellToListInTheRegion ( final List < String > skipCellList , final CellRangeAddress caddress ) { for ( int col = caddress . getFirstColumn ( ) ; col <= caddress . getLastColumn ( ) ; col ++ ) { for ( int row = caddress . getFirstRow ( ) ; row <= caddress . getLastRow ( ) ; row ++ ) { if ( ( col == caddress . getFirstColumn ( ) ) && ( row == caddress . getFirstRow ( ) ) ) { continue ; } skipCellList . add ( CellUtility . getCellIndexNumberKey ( col , row ) ) ; } } }


Input: Build Sheet Comment From command alias . [CODESPLIT] public static void buildSheetCommentFromAlias ( Sheet sheet , List < TieCommandAlias > tieCommandAliasList ) { if ( ( tieCommandAliasList == null ) || ( tieCommandAliasList . isEmpty ( ) ) ) { return ; } for ( Row row : sheet ) { for ( Cell cell : row ) { buildCellCommentFromalias ( tieCommandAliasList , cell ) ; } } }


Input: Builds the cell comment fromalias . [CODESPLIT] private static void buildCellCommentFromalias ( List < TieCommandAlias > tieCommandAliasList , Cell cell ) { String value = CellUtility . getCellValueWithoutFormat ( cell ) ; if ( ( value != null ) && ( ! value . isEmpty ( ) ) ) { for ( TieCommandAlias alias : tieCommandAliasList ) { Matcher matcher = alias . getPattern ( ) . matcher ( value ) ; if ( matcher . find ( ) ) { CellUtility . createOrInsertComment ( cell , alias . getCommand ( ) ) ; if ( alias . isRemove ( ) ) { CellUtility . setCellValue ( cell , ParserUtility . removeCharsFromString ( value , matcher . start ( ) , matcher . end ( ) ) ) ; } } } } }


Input:
Builds the configuration . [CODESPLIT] public final Map < String , SheetConfiguration > buildConfiguration ( ) { Map < String , SheetConfiguration > sheetConfigMap = new LinkedHashMap <> ( ) ; // in buildsheet, it's possible to add sheets in workbook.
 // so cache the sheetname first here.
 List < String > sheetNames = new ArrayList <> ( ) ; String sname ; for ( int i = 0 ; i < parent . getWb ( ) . getNumberOfSheets ( ) ; i ++ ) { sname = parent . getWb ( ) . getSheetName ( i ) ; if ( ! sname . startsWith ( org . tiefaces . common . TieConstants . COPY_SHEET_PREFIX ) ) { sheetNames . add ( sname ) ; } } for ( String sheetName : sheetNames ) { Sheet sheet = parent . getWb ( ) . getSheet ( sheetName ) ; ConfigurationUtility . buildSheetCommentFromAlias ( sheet , parent . getTieCommandAliasList ( ) ) ; buildSheet ( sheet , sheetConfigMap , parent . getCellAttributesMap ( ) ) ; } return sheetConfigMap ; }


Input:
Gets the sheet configuration . [CODESPLIT] private SheetConfiguration getSheetConfiguration ( final Sheet sheet , final String formName , final int sheetRightCol ) { SheetConfiguration sheetConfig = new SheetConfiguration ( ) ; sheetConfig . setFormName ( formName ) ; sheetConfig . setSheetName ( sheet . getSheetName ( ) ) ; int leftCol = sheet . getLeftCol ( ) ; int lastRow = sheet . getLastRowNum ( ) ; int firstRow = sheet . getFirstRowNum ( ) ; int rightCol = 0 ; int maxRow = 0 ; for ( Row row : sheet ) { if ( row . getRowNum ( ) > TieConstants . TIE_WEB_SHEET_MAX_ROWS ) { break ; } maxRow = row . getRowNum ( ) ; int firstCellNum = row . getFirstCellNum ( ) ; if ( firstCellNum >= 0 && firstCellNum < leftCol ) { leftCol = firstCellNum ; } if ( ( row . getLastCellNum ( ) - 1 ) > rightCol ) { int verifiedcol = verifyLastCell ( row , rightCol , sheetRightCol ) ; if ( verifiedcol > rightCol ) { rightCol = verifiedcol ; } } } if ( maxRow < lastRow ) { lastRow = maxRow ; } // header range row set to 0 while column set to first column to
 // max
 // column (FF) e.g. $A$0 : $FF$0
 String tempStr = TieConstants . CELL_ADDR_PRE_FIX + WebSheetUtility . getExcelColumnName ( leftCol ) + TieConstants . CELL_ADDR_PRE_FIX + "0 : " + TieConstants . CELL_ADDR_PRE_FIX + WebSheetUtility . getExcelColumnName ( rightCol ) + TieConstants . CELL_ADDR_PRE_FIX + "0" ; sheetConfig . setFormHeaderRange ( tempStr ) ; sheetConfig . setHeaderCellRange ( new CellRange ( tempStr ) ) ; // body range row set to first row to last row while column set
 // to
 // first column to max column (FF) e.g. $A$1 : $FF$1000
 tempStr = TieConstants . CELL_ADDR_PRE_FIX + WebSheetUtility . getExcelColumnName ( leftCol ) + TieConstants . CELL_ADDR_PRE_FIX + ( firstRow + 1 ) + " : " + TieConstants . CELL_ADDR_PRE_FIX + WebSheetUtility . getExcelColumnName ( rightCol ) + TieConstants . CELL_ADDR_PRE_FIX + ( lastRow + 1 ) ; sheetConfig . setFormBodyRange ( tempStr ) ; sheetConfig . setBodyCellRange ( new CellRange ( tempStr ) ) ; sheetConfig . setFormBodyType ( org . tiefaces . common . TieConstants . FORM_TYPE_FREE ) ; sheetConfig . setCellFormAttributes ( new HashMap < String , List < CellFormAttributes > > ( ) ) ; // check it's a hidden sheet
 int sheetIndex = parent . getWb ( ) . getSheetIndex ( sheet ) ; if ( parent . getWb ( ) . isSheetHidden ( sheetIndex ) || parent . getWb ( ) . isSheetVeryHidden ( sheetIndex ) ) { sheetConfig . setHidden ( true ) ; } return sheetConfig ; }


Input: Builds the form command from sheet config . [CODESPLIT] private FormCommand buildFormCommandFromSheetConfig ( final SheetConfiguration sheetConfig , final Sheet sheet ) { int firstRow = sheetConfig . getBodyCellRange ( ) . getTopRow ( ) ; int leftCol = sheetConfig . getBodyCellRange ( ) . getLeftCol ( ) ; int rightCol = sheetConfig . getBodyCellRange ( ) . getRightCol ( ) ; int lastRow = sheetConfig . getBodyCellRange ( ) . getBottomRow ( ) ; Cell firstCell = sheet . getRow ( firstRow ) . getCell ( leftCol , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; FormCommand fcommand = new FormCommand ( ) ; fcommand . setCommandTypeName ( TieConstants . COMMAND_FORM ) ; if ( sheetConfig . isHidden ( ) ) { fcommand . setHidden ( TieConstants . TRUE_STRING ) ; } else { fcommand . setHidden ( TieConstants . FALSE_STRING ) ; } fcommand . setName ( sheetConfig . getFormName ( ) ) ; fcommand . getConfigRange ( ) . setFirstRowRef ( firstCell , true ) ; fcommand . getConfigRange ( ) . setLastRowPlusRef ( sheet , rightCol , lastRow , true ) ; fcommand . setHeaderLength ( "0" ) ; fcommand . setFooterLength ( "0" ) ; fcommand . setLength ( Integer . toString ( lastRow - firstRow + 1 ) ) ; return fcommand ; }


Input: check last column . if it s blank then treat it as null cell . [CODESPLIT] private int verifyLastCell ( final Row row , final int stoppoint , final int sheetRightCol ) { int lastCol = sheetRightCol ; int col ; for ( col = lastCol ; col >= stoppoint ; col -- ) { Cell cell = row . getCell ( col ) ; if ( ( cell != null ) && ( cell . getCellTypeEnum ( ) != CellType . BLANK ) ) { break ; } } return col ; }


Input:
build a sheet for configuration map . [CODESPLIT] public final void buildSheet ( final Sheet sheet , final Map < String , SheetConfiguration > sheetConfigMap , final CellAttributesMap cellAttributesMap ) { if ( ( sheet . getLastRowNum ( ) <= 0 ) && ( sheet . getRow ( 0 ) == null ) ) { // this is a empty sheet. skip it.
 return ; } checkAndRepairLastRow ( sheet ) ; int sheetRightCol = WebSheetUtility . getSheetRightCol ( sheet ) ; List < ConfigCommand > commandList = buildCommandListFromSheetComment ( ( XSSFSheet ) sheet , sheetRightCol , cellAttributesMap ) ; boolean hasEachCommand = hasEachCommandInTheList ( commandList ) ; List < String > formList = new ArrayList <> ( ) ; buildSheetConfigMapFromFormCommand ( sheet , sheetConfigMap , commandList , formList , sheetRightCol ) ; // match parent command
 matchParentCommand ( commandList ) ; // setup save attrs in hidden column in the sheet.
 // loop command list again to assemble other command list into sheet
 // configuration
 matchSheetConfigForm ( sheetConfigMap , commandList , formList ) ; initTemplateForCommand ( sheet , sheetConfigMap , formList , hasEachCommand ) ; }


Input:
check and repair the sheet s lastrow . If the row is blank then remove it . [CODESPLIT] private final void checkAndRepairLastRow ( final Sheet sheet ) { // repair last row if it's inserted in the configuration generation
 Row lastrow = sheet . getRow ( sheet . getLastRowNum ( ) ) ; // if it's lastrow and all the cells are blank. then remove the lastrow.
 if ( lastrow != null ) { for ( Cell cell : lastrow ) { if ( ( cell . getCellTypeEnum ( ) != CellType . _NONE ) && ( cell . getCellTypeEnum ( ) != CellType . BLANK ) ) { return ; } } sheet . removeRow ( lastrow ) ; } }


Input: Initialize template for command to use . e . g . set origin row number and copy template if there s each command . create missing row as row require sequenced . [CODESPLIT] private void initTemplateForCommand ( final Sheet sheet , final Map < String , SheetConfiguration > sheetConfigMap , final List < String > formList , final boolean hasEachCommand ) { for ( String formname : formList ) { SheetConfiguration sheetConfig = sheetConfigMap . get ( formname ) ; CellRange range = sheetConfig . getBodyCellRange ( ) ; for ( int index = range . getTopRow ( ) ; index <= range . getBottomRow ( ) ; index ++ ) { Row row = sheet . getRow ( index ) ; if ( row == null ) { row = sheet . createRow ( index ) ; } if ( hasEachCommand ) { ConfigurationUtility . setOriginalRowNumInHiddenColumn ( row , index ) ; } } } if ( hasEachCommand ) { copyTemplateForTieCommands ( sheet ) ; } }


Input:
build command list from comments . after transfer the comment to command remove it from comments . [CODESPLIT] private List < ConfigCommand > buildCommandListFromSheetComment ( final XSSFSheet sheet , final int sheetRightCol , final CellAttributesMap cellAttributesMap ) { List < ConfigCommand > commandList = new ArrayList <> ( ) ; // if skip then return empty list.
 if ( parent . isSkipConfiguration ( ) ) { return commandList ; } Map < CellAddress , ? extends Comment > comments = null ; try { // due to a poi bug. null exception throwed if no comments in the
 // sheet.
 comments = sheet . getCellComments ( ) ; } catch ( Exception ex ) { LOG . log ( Level . FINE , "Null exception throwed when no comment exists: " + ex . getLocalizedMessage ( ) , ex ) ; } if ( comments == null ) { return commandList ; } // not sure the map is sorted. So use tree map to sort it.
 SortedSet < CellAddress > keys = new TreeSet <> ( comments . keySet ( ) ) ; // go through each comments
 // if found tie command then transfer it to list also remove from
 // comments.
 for ( CellAddress key : keys ) { Cell cell = sheet . getRow ( key . getRow ( ) ) . getCell ( key . getColumn ( ) , MissingCellPolicy . CREATE_NULL_AS_BLANK ) ; buildCommandList ( sheet , sheetRightCol , cell , commandList , cellAttributesMap ) ; } return commandList ; }


Input:
build top level configuration map from command list . User can either put tie : form command in the comments ( which will transfer to sheetConfig ) Or just ignore it then use whole sheet as one form . [CODESPLIT] private void buildSheetConfigMapFromFormCommand ( final Sheet sheet , final Map < String , SheetConfiguration > sheetConfigMap , final List < ConfigCommand > commandList , final List < String > formList , final int sheetRightCol ) { boolean foundForm = false ; int minRowNum = sheet . getLastRowNum ( ) ; int maxRowNum = sheet . getFirstRowNum ( ) ; for ( Command command : commandList ) { // check whether is form command
 if ( command . getCommandTypeName ( ) . equalsIgnoreCase ( TieConstants . COMMAND_FORM ) ) { foundForm = true ; FormCommand fcommand = ( FormCommand ) command ; sheetConfigMap . put ( fcommand . getName ( ) , getSheetConfigurationFromConfigCommand ( sheet , fcommand , sheetRightCol ) ) ; formList . add ( fcommand . getName ( ) ) ; if ( fcommand . getTopRow ( ) < minRowNum ) { minRowNum = fcommand . getTopRow ( ) ; } if ( fcommand . getLastRow ( ) > maxRowNum ) { maxRowNum = fcommand . getLastRow ( ) ; } } } // if no form found, then use the whole sheet as form
 if ( ! foundForm ) { WebSheetUtility . clearHiddenColumns ( sheet ) ; String formName = sheet . getSheetName ( ) ; SheetConfiguration sheetConfig = getSheetConfiguration ( sheet , formName , sheetRightCol ) ; FormCommand fcommand = buildFormCommandFromSheetConfig ( sheetConfig , sheet ) ; commandList . add ( fcommand ) ; sheetConfig . setFormCommand ( fcommand ) ; sheetConfigMap . put ( formName , sheetConfig ) ; formList . add ( formName ) ; minRowNum = sheet . getFirstRowNum ( ) ; maxRowNum = sheet . getLastRowNum ( ) ; } // if skip config then return.
 if ( parent . isSkipConfiguration ( ) ) { return ; } SaveAttrsUtility . setSaveAttrsForSheet ( sheet , minRowNum , maxRowNum , parent . getCellAttributesMap ( ) . getTemplateCommentMap ( ) . get ( TieConstants . SAVE_COMMENT_KEY_IN_MAP ) ) ; }


Input: Set up parent attribute for each command ( exclude form command ) . The top level commands have no parent . [CODESPLIT] private void matchParentCommand ( final List < ConfigCommand > commandList ) { if ( commandList == null ) { return ; } for ( int i = 0 ; i < commandList . size ( ) ; i ++ ) { ConfigCommand child = commandList . get ( i ) ; if ( ! child . getCommandTypeName ( ) . equalsIgnoreCase ( TieConstants . COMMAND_FORM ) ) { setParentForChildCommand ( commandList , i , child ) ; } } }


Input: Sets the parent for child command . [CODESPLIT] private void setParentForChildCommand ( final List < ConfigCommand > commandList , final int i , final ConfigCommand child ) { int matchIndex = - 1 ; ConfigRange matchRange = null ; for ( int j = 0 ; j < commandList . size ( ) ; j ++ ) { if ( j != i ) { Command commandParent = commandList . get ( j ) ; if ( ! commandParent . getCommandTypeName ( ) . equalsIgnoreCase ( TieConstants . COMMAND_FORM ) && WebSheetUtility . insideRange ( child . getConfigRange ( ) , commandParent . getConfigRange ( ) ) && ( ( matchRange == null ) || ( WebSheetUtility . insideRange ( commandParent . getConfigRange ( ) , matchRange ) ) ) ) { matchRange = commandParent . getConfigRange ( ) ; matchIndex = j ; } } } if ( matchIndex >= 0 ) { commandList . get ( matchIndex ) . getConfigRange ( ) . addCommand ( child ) ; child . setParentFound ( true ) ; } }


Input: check whether contain each command in the list . [CODESPLIT] private boolean hasEachCommandInTheList ( final List < ConfigCommand > commandList ) { if ( commandList != null ) { for ( ConfigCommand command : commandList ) { if ( command . getCommandTypeName ( ) . equalsIgnoreCase ( TieConstants . COMMAND_EACH ) ) { return true ; } } } return false ; }


Input:
Assemble top level command to sheetConfiguration ( form ) . top level commands are those haven t matched from matchParentCommand function . [CODESPLIT] private void matchSheetConfigForm ( final Map < String , SheetConfiguration > sheetConfigMap , final List < ConfigCommand > commandList , final List < String > formList ) { for ( ConfigCommand command : commandList ) { // check weather it's form command
 if ( ! command . getCommandTypeName ( ) . equalsIgnoreCase ( TieConstants . COMMAND_FORM ) && ( ! command . isParentFound ( ) ) ) { matchCommandToSheetConfigForm ( sheetConfigMap , formList , command ) ; } } }


Input: Match command to sheet config form . [CODESPLIT] private void matchCommandToSheetConfigForm ( final Map < String , SheetConfiguration > sheetConfigMap , final List < String > formList , final ConfigCommand command ) { for ( String formname : formList ) { SheetConfiguration sheetConfig = sheetConfigMap . get ( formname ) ; if ( WebSheetUtility . insideRange ( command . getConfigRange ( ) , sheetConfig . getFormCommand ( ) . getConfigRange ( ) ) ) { sheetConfig . getFormCommand ( ) . getConfigRange ( ) . addCommand ( command ) ; break ; } } }


Input:
Copy the each command area to seperated sheet . As it will be used for iteration . [CODESPLIT] private void copyTemplateForTieCommands ( final Sheet sheet ) { // if skip configuration. then return.
 if ( parent . isSkipConfiguration ( ) ) { return ; } Workbook wb = sheet . getWorkbook ( ) ; String copyName = TieConstants . COPY_SHEET_PREFIX + sheet . getSheetName ( ) ; if ( wb . getSheet ( copyName ) == null ) { Sheet newSheet = wb . cloneSheet ( wb . getSheetIndex ( sheet ) ) ; int sheetIndex = wb . getSheetIndex ( newSheet ) ; wb . setSheetName ( sheetIndex , copyName ) ; wb . setSheetHidden ( sheetIndex , Workbook . SHEET_STATE_VERY_HIDDEN ) ; } }


Input:
build command list from comment . [CODESPLIT] private List < ConfigCommand > buildCommandList ( final Sheet sheet , final int sheetRightCol , final Cell cell , final List < ConfigCommand > cList , final CellAttributesMap cellAttributesMap ) { Comment comment = cell . getCellComment ( ) ; String text = comment . getString ( ) . getString ( ) ; String [ ] commentLines = text . split ( "\\n" ) ; StringBuilder newComment = new StringBuilder ( ) ; boolean changed = false ; for ( String commentLine : commentLines ) { String line = commentLine . trim ( ) ; if ( ParserUtility . isCommandString ( line ) ) { processCommandLine ( sheet , cell , line , cList , sheetRightCol ) ; changed = true ; } else if ( ParserUtility . isEmptyMethodString ( line ) || ParserUtility . isMethodString ( line ) ) { processMethodLine ( cell , line , cellAttributesMap ) ; changed = true ; } else { if ( newComment . length ( ) > 0 ) { newComment . append ( "\\n" + commentLine ) ; } else { newComment . append ( commentLine ) ; } } } if ( ! changed ) { moveCommentToMap ( cell , text , cellAttributesMap . getTemplateCommentMap ( ) , true ) ; } else { // reset comment string if changed
 if ( newComment . length ( ) > 0 ) { moveCommentToMap ( cell , newComment . toString ( ) , cellAttributesMap . getTemplateCommentMap ( ) , true ) ; CreationHelper factory = sheet . getWorkbook ( ) . getCreationHelper ( ) ; RichTextString str = factory . createRichTextString ( newComment . toString ( ) ) ; comment . setString ( str ) ; } else { // remove cell comment if new comment become empty.
 cell . removeCellComment ( ) ; } } return cList ; }


Input: Process method line . [CODESPLIT] private void processMethodLine ( final Cell cell , final String line , final CellAttributesMap cellAttributesMap ) { if ( ParserUtility . isWidgetMethodString ( line ) ) { ParserUtility . parseWidgetAttributes ( cell , line , cellAttributesMap ) ; } else if ( ParserUtility . isValidateMethodString ( line ) ) { ParserUtility . parseValidateAttributes ( cell , line , cellAttributesMap ) ; } else { moveCommentToMap ( cell , line , cellAttributesMap . getTemplateCommentMap ( ) , false ) ; } }


Input: Process command line . [CODESPLIT] private void processCommandLine ( final Sheet sheet , final Cell cell , final String line , final List < ConfigCommand > cList , final int sheetRightCol ) { int nameEndIndex = line . indexOf ( TieConstants . ATTR_PREFIX , TieConstants . COMMAND_PREFIX . length ( ) ) ; if ( nameEndIndex < 0 ) { String errMsg = "Failed to parse command line [" + line + "]. Expected '" + TieConstants . ATTR_PREFIX + "' symbol." ; LOG . severe ( errMsg ) ; throw new IllegalStateException ( errMsg ) ; } String commandName = line . substring ( TieConstants . COMMAND_PREFIX . length ( ) , nameEndIndex ) . trim ( ) ; Map < String , String > attrMap = buildAttrMap ( line , nameEndIndex ) ; ConfigCommand configCommand = createConfigCommand ( sheet , cell , sheetRightCol , commandName , attrMap ) ; if ( configCommand != null ) { cList . add ( configCommand ) ; } }


Input: change the comment . [CODESPLIT] private void moveCommentToMap ( final Cell cell , final String newComment , final Map < String , Map < String , String > > sheetCommentMap , final boolean normalComment ) { String cellKey = cell . getSheet ( ) . getSheetName ( ) + "!$" + cell . getColumnIndex ( ) + "$" + cell . getRowIndex ( ) ; ParserUtility . parseCommentToMap ( cellKey , newComment , sheetCommentMap , normalComment ) ; }


Input: create configuration command . [CODESPLIT] private ConfigCommand createConfigCommand ( final Sheet sheet , final Cell firstCell , final int sheetRightCol , final String commandName , final Map < String , String > attrMap ) { @ SuppressWarnings ( "rawtypes" ) Class clas = commandMap . get ( commandName ) ; if ( clas == null ) { LOG . log ( Level . WARNING , "Cannot find command class for {} " , commandName ) ; return null ; } try { ConfigCommand command = ( ConfigCommand ) clas . newInstance ( ) ; command . setCommandTypeName ( commandName ) ; for ( Map . Entry < String , String > attr : attrMap . entrySet ( ) ) { WebSheetUtility . setObjectProperty ( command , attr . getKey ( ) , attr . getValue ( ) , true ) ; } command . getConfigRange ( ) . setFirstRowRef ( firstCell , true ) ; command . getConfigRange ( ) . setLastRowPlusRef ( sheet , sheetRightCol , command . getLastRow ( ) , true ) ; return command ; } catch ( Exception e ) { LOG . log ( Level . WARNING , "Failed to initialize command class " + clas . getName ( ) + " for command" + commandName , e ) ; return null ; } }


Input: Build the attributes map . [CODESPLIT] private Map < String , String > buildAttrMap ( final String commandLine , final int nameEndIndex ) { int paramsEndIndex = commandLine . lastIndexOf ( TieConstants . ATTR_SUFFIX ) ; if ( paramsEndIndex < 0 ) { String errMsg = "Failed to parse command line [" + commandLine + "]. Expected '" + TieConstants . ATTR_SUFFIX + "' symbol." ; throw new IllegalArgumentException ( errMsg ) ; } String attrString = commandLine . substring ( nameEndIndex + 1 , paramsEndIndex ) . trim ( ) ; return ParserUtility . parseCommandAttributes ( attrString ) ; }


Input:
Create sheet configuration from form command . [CODESPLIT] private SheetConfiguration getSheetConfigurationFromConfigCommand ( final Sheet sheet , final FormCommand fcommand , final int sheetRightCol ) { SheetConfiguration sheetConfig = new SheetConfiguration ( ) ; sheetConfig . setFormName ( fcommand . getName ( ) ) ; sheetConfig . setSheetName ( sheet . getSheetName ( ) ) ; int leftCol = fcommand . getLeftCol ( ) ; int lastRow = fcommand . getLastRow ( ) ; int rightCol = 0 ; int maxRow = 0 ; for ( Row row : sheet ) { if ( row . getRowNum ( ) > TieConstants . TIE_WEB_SHEET_MAX_ROWS ) { break ; } maxRow = row . getRowNum ( ) ; if ( ( row . getLastCellNum ( ) - 1 ) > rightCol ) { int verifiedcol = verifyLastCell ( row , rightCol , sheetRightCol ) ; if ( verifiedcol > rightCol ) { rightCol = verifiedcol ; } } } if ( maxRow < lastRow ) { lastRow = maxRow ; } // header range row set to 0 while column set to first column to
 // max
 // column (FF) e.g. $A$0 : $FF$0
 setHeaderOfSheetConfiguration ( fcommand , sheetConfig , leftCol , rightCol ) ; // body range row set to first row to last row while column set
 // to
 // first column to max column (FF) e.g. $A$1 : $FF$1000
 setBodyOfSheetConfiguration ( fcommand , sheetConfig , leftCol , lastRow , rightCol ) ; // footer range row set to 0 while column set to first column to
 // max
 // column (FF) e.g. $A$0 : $FF$0
 setFooterOfSheetConfiguration ( fcommand , sheetConfig , leftCol , rightCol ) ; String hidden = fcommand . getHidden ( ) ; if ( ( hidden != null ) && ( Boolean . parseBoolean ( hidden ) ) ) { sheetConfig . setHidden ( true ) ; } String fixedWidthStyle = fcommand . getFixedWidthStyle ( ) ; if ( ( fixedWidthStyle != null ) && ( Boolean . parseBoolean ( fixedWidthStyle ) ) ) { sheetConfig . setFixedWidthStyle ( true ) ; } sheetConfig . setFormCommand ( fcommand ) ; return sheetConfig ; }


Input: Sets the footer of sheet configuration . [CODESPLIT] private void setFooterOfSheetConfiguration ( final FormCommand fcommand , final SheetConfiguration sheetConfig , final int leftCol , final int rightCol ) { String tempStr ; if ( fcommand . calcFooterLength ( ) == 0 ) { tempStr = CellUtility . getCellIndexLetterKey ( leftCol , 0 ) + " : " + CellUtility . getCellIndexLetterKey ( rightCol , 0 ) ; } else { tempStr = CellUtility . getCellIndexLetterKey ( leftCol , fcommand . getTopRow ( ) + fcommand . calcHeaderLength ( ) + fcommand . calcBodyLength ( ) ) + " : " + CellUtility . getCellIndexLetterKey ( rightCol , fcommand . getTopRow ( ) + fcommand . calcHeaderLength ( ) ) ; } sheetConfig . setFormFooterRange ( tempStr ) ; sheetConfig . setFooterCellRange ( new CellRange ( tempStr ) ) ; }


Input: Sets the body of sheet configuration . [CODESPLIT] private void setBodyOfSheetConfiguration ( final FormCommand fcommand , final SheetConfiguration sheetConfig , final int leftCol , final int lastRow , final int rightCol ) { String tempStr ; tempStr = CellUtility . getCellIndexLetterKey ( leftCol , fcommand . getTopRow ( ) + fcommand . calcHeaderLength ( ) + 1 ) + " : " + CellUtility . getCellIndexLetterKey ( rightCol , lastRow + 1 ) ; sheetConfig . setFormBodyRange ( tempStr ) ; sheetConfig . setBodyCellRange ( new CellRange ( tempStr ) ) ; sheetConfig . setFormBodyType ( TieConstants . FORM_TYPE_FREE ) ; sheetConfig . setCellFormAttributes ( new HashMap < String , List < CellFormAttributes > > ( ) ) ; }


Input: Sets the header of sheet configuration . [CODESPLIT] private void setHeaderOfSheetConfiguration ( final FormCommand fcommand , final SheetConfiguration sheetConfig , final int leftCol , final int rightCol ) { String tempStr ; if ( fcommand . calcHeaderLength ( ) == 0 ) { tempStr = CellUtility . getCellIndexLetterKey ( leftCol , 0 ) + " : " + CellUtility . getCellIndexLetterKey ( rightCol , 0 ) ; } else { tempStr = CellUtility . getCellIndexLetterKey ( leftCol , fcommand . getTopRow ( ) + 1 ) + " : " + CellUtility . getCellIndexLetterKey ( rightCol , fcommand . getTopRow ( ) + fcommand . calcHeaderLength ( ) ) ; } sheetConfig . setFormHeaderRange ( tempStr ) ; sheetConfig . setHeaderCellRange ( new CellRange ( tempStr ) ) ; }


Input:
Adds the row . [CODESPLIT] @ SuppressWarnings ( { "rawtypes" } ) public static int addRow ( final ConfigBuildRef configBuildRef , final int rowIndex , final Map < String , Object > dataContext ) { // replace the lastCollection.
 // since here's add one row.
 // Then we should insert one empty object in the list.
 // The collection must be a list to support add/delete function.
 // and the object must support empty constructor.
 String fullName = ConfigurationUtility . getFullNameFromRow ( configBuildRef . getSheet ( ) . getRow ( rowIndex ) ) ; String [ ] parts = fullName . split ( ":" ) ; configBuildRef . getCellHelper ( ) . restoreDataContext ( fullName ) ; CollectionObject collect = configBuildRef . getCellHelper ( ) . getLastCollect ( fullName ) ; Collection lastCollection = collect . getLastCollection ( ) ; int lastCollectionIndex = collect . getLastCollectionIndex ( ) ; EachCommand eachCommand = collect . getEachCommand ( ) ; if ( lastCollectionIndex < 0 ) { // no each command in the loop.
 throw new AddRowException ( "No each command found." ) ; } String unitFullName = CommandUtility . insertEmptyObjectInContext ( fullName , lastCollection , eachCommand , lastCollectionIndex , dataContext ) ; RowsMapping unitRowsMapping = new RowsMapping ( ) ; ConfigRangeAttrs savedRangeAttrs = configBuildRef . getShiftMap ( ) . get ( fullName ) ; int insertPosition = savedRangeAttrs . getFirstRowRef ( ) . getRowIndex ( ) + savedRangeAttrs . getFinalLength ( ) ; configBuildRef . setInsertPosition ( insertPosition ) ; CommandUtility . insertEachTemplate ( eachCommand . getConfigRange ( ) , configBuildRef , lastCollectionIndex + 1 , insertPosition , unitRowsMapping ) ; ConfigRange currentRange = ConfigurationUtility . buildCurrentRange ( eachCommand . getConfigRange ( ) , configBuildRef . getSheet ( ) , insertPosition ) ; List < RowsMapping > currentRowsMappingList = ConfigurationUtility . findParentRowsMappingFromShiftMap ( parts , configBuildRef . getShiftMap ( ) ) ; currentRowsMappingList . add ( unitRowsMapping ) ; currentRange . getAttrs ( ) . setAllowAdd ( true ) ; configBuildRef . setBodyAllowAdd ( true ) ; // reverse order of changeMap.
 Map < String , String > changeMap = new TreeMap <> ( Collections . reverseOrder ( ) ) ; ConfigurationUtility . changeIndexNumberInHiddenColumn ( configBuildRef , currentRange . getAttrs ( ) . getLastRowPlusRef ( ) . getRowIndex ( ) , fullName , changeMap , 1 ) ; ConfigurationUtility . changeIndexNumberInShiftMap ( configBuildRef . getShiftMap ( ) , changeMap ) ; configBuildRef . putShiftAttrs ( unitFullName , currentRange . getAttrs ( ) , unitRowsMapping ) ; int length = currentRange . buildAt ( unitFullName , configBuildRef , insertPosition , dataContext , currentRowsMappingList ) ; currentRange . getAttrs ( ) . setFinalLength ( length ) ; ConfigurationUtility . reBuildUpperLevelFormula ( configBuildRef , fullName ) ; ConfigurationUtility . changeUpperLevelFinalLength ( configBuildRef . getShiftMap ( ) , fullName , length ) ; currentRowsMappingList . remove ( unitRowsMapping ) ; dataContext . remove ( eachCommand . getVar ( ) ) ; return length ; }


Input:
Delete row . [CODESPLIT] @ SuppressWarnings ( { "rawtypes" } ) public static int deleteRow ( final ConfigBuildRef configBuildRef , final int rowIndex , final Map < String , Object > dataContext , final SheetConfiguration sheetConfig , final List < FacesRow > bodyRows ) { String fullName = ConfigurationUtility . getFullNameFromRow ( configBuildRef . getSheet ( ) . getRow ( rowIndex ) ) ; configBuildRef . getCellHelper ( ) . restoreDataContext ( fullName ) ; CollectionObject collect = configBuildRef . getCellHelper ( ) . getLastCollect ( fullName ) ; Collection lastCollection = collect . getLastCollection ( ) ; int lastCollectionIndex = collect . getLastCollectionIndex ( ) ; EachCommand eachCommand = collect . getEachCommand ( ) ; if ( lastCollectionIndex < 0 ) { // no each command in the loop.
 throw new DeleteRowException ( "No each command found." ) ; } if ( lastCollection . size ( ) <= 1 ) { // this is the last record and no parent left.
 throw new DeleteRowException ( "Cannot delete the last record in the group." ) ; } CommandUtility . deleteObjectInContext ( lastCollection , eachCommand , lastCollectionIndex , dataContext ) ; // find range from shiftmap.
 ConfigRangeAttrs currentRangeAttrs = configBuildRef . getShiftMap ( ) . get ( fullName ) ; if ( currentRangeAttrs == null ) { throw new DeleteRowException ( "Cannot find delete range." ) ; } // The lastRowRef is wrong in rangeAttrs. So use length to recalc it.
 int startRow = currentRangeAttrs . getFirstRowIndex ( ) ; int length = currentRangeAttrs . getFinalLength ( ) ; int endRow = startRow + length - 1 ; List < String > removeFullNameList = findRemoveFullNameList ( configBuildRef . getSheet ( ) , startRow , endRow ) ; // remove range from shiftmap.
 removeRangesFromShiftMap ( configBuildRef . getShiftMap ( ) , removeFullNameList ) ; // 1. remove ranged rows from sheet
 String var = eachCommand . getVar ( ) ; CommandUtility . removeRowsInSheet ( configBuildRef . getSheet ( ) , startRow , endRow , configBuildRef . getCachedCells ( ) ) ; // 2. reset FacesRow row index.
 CommandUtility . removeRowsInBody ( sheetConfig , bodyRows , startRow , endRow ) ; // 3. decrease index number in hidden column
 Map < String , String > changeMap = new TreeMap <> ( ) ; ConfigurationUtility . changeIndexNumberInHiddenColumn ( configBuildRef , startRow , fullName , changeMap , - 1 ) ; // 4. decrease index number in shift map
 ConfigurationUtility . changeIndexNumberInShiftMap ( configBuildRef . getShiftMap ( ) , changeMap ) ; // 5. rebuild upper level formula
 ConfigurationUtility . reBuildUpperLevelFormula ( configBuildRef , fullName ) ; // 6. decrease upper level final length
 ConfigurationUtility . changeUpperLevelFinalLength ( configBuildRef . getShiftMap ( ) , fullName , - length ) ; dataContext . remove ( var ) ; return length ; }


Input: Removes the ranges from shift map . [CODESPLIT] private static void removeRangesFromShiftMap ( final NavigableMap < String , ConfigRangeAttrs > shiftMap , final List < String > removeFullNameList ) { for ( String fname : removeFullNameList ) { shiftMap . remove ( fname ) ; } }


Input: Find remove full name list . [CODESPLIT] private static List < String > findRemoveFullNameList ( final Sheet sheet , final int startRow , final int endRow ) { List < String > list = new ArrayList <> ( ) ; for ( int rowIndex = startRow ; rowIndex <= endRow ; rowIndex ++ ) { String fullName = ConfigurationUtility . getFullNameFromRow ( sheet . getRow ( rowIndex ) ) ; if ( ! list . contains ( fullName ) ) { list . add ( fullName ) ; } } return list ; }


Input: Gets the each command from parts name . [CODESPLIT] public static EachCommand getEachCommandFromPartsName ( final Map < String , Command > commandIndexMap , final String [ ] varparts ) { if ( varparts . length == TieConstants . DEFAULT_COMMAND_PART_LENGTH ) { return ( EachCommand ) commandIndexMap . get ( TieConstants . EACH_COMMAND_FULL_NAME_PREFIX + varparts [ 1 ] ) ; } return null ; }


Input:
Insert empty object in context . [CODESPLIT] @ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private static String insertEmptyObjectInContext ( final String fullName , final Collection lastCollection , final EachCommand eachCommand , final int lastCollectionIndex , final Map < String , Object > dataContext ) { if ( ! ( lastCollection instanceof List ) ) { throw new EvaluationException ( "Collection must be list in order to insert/delete." ) ; } List collectionList = ( List ) lastCollection ; // the object must support empty constructor.
 Object currentObj = collectionList . get ( lastCollectionIndex ) ; Object insertObj ; try { insertObj = currentObj . getClass ( ) . newInstance ( ) ; collectionList . add ( lastCollectionIndex + 1 , insertObj ) ; dataContext . put ( eachCommand . getVar ( ) , insertObj ) ; return fullName . substring ( 0 , fullName . lastIndexOf ( ' ' ) + 1 ) + ( lastCollectionIndex + 1 ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new EvaluationException ( e ) ; } }


Input:
Delete object in context . [CODESPLIT] @ SuppressWarnings ( { "rawtypes" } ) private static void deleteObjectInContext ( final Collection lastCollection , final EachCommand eachCommand , final int lastCollectionIndex , final Map < String , Object > dataContext ) { if ( ! ( lastCollection instanceof List ) ) { throw new EvaluationException ( eachCommand . getVar ( ) + TieConstants . EACH_COMMAND_INVALID_MSG ) ; } List collectionList = ( List ) lastCollection ; // the object must support empty constructor.
 collectionList . remove ( lastCollectionIndex ) ; dataContext . remove ( eachCommand . getVar ( ) ) ; }


Input: Prepare collection data in context . [CODESPLIT] @ SuppressWarnings ( "rawtypes" ) public static int prepareCollectionDataInContext ( final String [ ] varparts , final Collection collection , final Map < String , Object > dataContext ) { if ( varparts . length == TieConstants . DEFAULT_COMMAND_PART_LENGTH ) { int collectionIndex = Integer . parseInt ( varparts [ 2 ] ) ; Object obj = ConfigurationUtility . findItemInCollection ( collection , collectionIndex ) ; if ( obj != null ) { dataContext . put ( varparts [ 1 ] , obj ) ; return collectionIndex ; } } return - 1 ; }


Input: Index command range . [CODESPLIT] public static void indexCommandRange ( final ConfigRange sourceConfigRange , final Map < String , Command > indexMap ) { if ( sourceConfigRange . getCommandList ( ) != null ) { for ( int i = 0 ; i < sourceConfigRange . getCommandList ( ) . size ( ) ; i ++ ) { Command command = sourceConfigRange . getCommandList ( ) . get ( i ) ; indexMap . put ( command . getCommandName ( ) , command ) ; command . getConfigRange ( ) . indexCommandRange ( indexMap ) ; } } }


Input: Checks if is row allow add . [CODESPLIT] public static boolean isRowAllowAdd ( final Row row , final SheetConfiguration sheetConfig ) { String fullName = ConfigurationUtility . getFullNameFromRow ( row ) ; if ( fullName != null ) { ConfigRangeAttrs attrs = sheetConfig . getShiftMap ( ) . get ( fullName ) ; if ( ( attrs != null ) && ( attrs . isAllowAdd ( ) ) && ( row . getRowNum ( ) == attrs . getFirstRowRef ( ) . getRowIndex ( ) ) ) { return true ; } } return false ; }


Input:
Insert each template . [CODESPLIT] public static void insertEachTemplate ( final ConfigRange sourceConfigRange , final ConfigBuildRef configBuildRef , final int index , final int insertPosition , final RowsMapping unitRowsMapping ) { int srcStartRow = sourceConfigRange . getFirstRowAddr ( ) . getRow ( ) ; int srcEndRow = sourceConfigRange . getLastRowPlusAddr ( ) . getRow ( ) - 1 ; Sheet sheet = configBuildRef . getSheet ( ) ; Workbook wb = sheet . getWorkbook ( ) ; // excel sheet name has limit 31 chars
 String copyName = TieConstants . COPY_SHEET_PREFIX + sheet . getSheetName ( ) ; if ( copyName . length ( ) > TieConstants . EXCEL_SHEET_NAME_LIMIT ) { copyName = copyName . substring ( 0 , TieConstants . EXCEL_SHEET_NAME_LIMIT ) ; } Sheet srcSheet = wb . getSheet ( copyName ) ; if ( index > 0 ) { CellUtility . copyRows ( srcSheet , sheet , srcStartRow , srcEndRow , insertPosition , false , true ) ; } for ( int rowIndex = srcStartRow ; rowIndex <= srcEndRow ; rowIndex ++ ) { if ( configBuildRef . getWatchList ( ) . contains ( rowIndex ) && ( ConfigurationUtility . isStaticRow ( sourceConfigRange , rowIndex ) ) ) { unitRowsMapping . addRow ( rowIndex , sheet . getRow ( insertPosition + rowIndex - srcStartRow ) ) ; } } }


Input: Evaluate . [CODESPLIT] @ SuppressWarnings ( "deprecation" ) public static void evaluate ( final Map < String , Object > context , final Cell cell , final ExpressionEngine engine ) { if ( ( cell != null ) && ( cell . getCellTypeEnum ( ) == CellType . STRING ) ) { String strValue = cell . getStringCellValue ( ) ; if ( isUserFormula ( strValue ) ) { evaluateUserFormula ( cell , strValue ) ; } else { evaluateNormalCells ( cell , strValue , context , engine ) ; } } }


Input: Evaluate normal cells . [CODESPLIT] public static void evaluateNormalCells ( final Cell cell , final String strValue , final Map < String , Object > context , final ExpressionEngine engine ) { if ( strValue . contains ( TieConstants . METHOD_PREFIX ) ) { Object evaluationResult = evaluate ( strValue , context , engine ) ; if ( evaluationResult == null ) { evaluationResult = "" ; } CellUtility . setCellValue ( cell , evaluationResult . toString ( ) ) ; createTieCell ( cell , context , engine ) ; } }


Input: Evaluate user formula . [CODESPLIT] private static void evaluateUserFormula ( final Cell cell , final String strValue ) { String formulaStr = strValue . substring ( 2 , strValue . length ( ) - 1 ) ; if ( ( formulaStr != null ) && ( ! formulaStr . isEmpty ( ) ) ) { cell . setCellFormula ( formulaStr ) ; } }


Input: Checks if is user formula . [CODESPLIT] private static boolean isUserFormula ( final String str ) { return str . startsWith ( TieConstants . USER_FORMULA_PREFIX ) && str . endsWith ( TieConstants . USER_FORMULA_SUFFIX ) ; }


Input: Evaluate . [CODESPLIT] public static Object evaluate ( final String strValue , final Map < String , Object > context , final ExpressionEngine engine ) { StringBuffer sb = new StringBuffer ( ) ; int beginExpressionLength = TieConstants . METHOD_PREFIX . length ( ) ; int endExpressionLength = TieConstants . METHOD_END . length ( ) ; Matcher exprMatcher = TieConstants . EXPRESSION_NOTATION_PATTERN . matcher ( strValue ) ; String matchedString ; String expression ; Object lastMatchEvalResult = null ; int matchCount = 0 ; int endOffset = 0 ; while ( exprMatcher . find ( ) ) { endOffset = exprMatcher . end ( ) ; matchCount ++ ; matchedString = exprMatcher . group ( ) ; expression = matchedString . substring ( beginExpressionLength , matchedString . length ( ) - endExpressionLength ) ; lastMatchEvalResult = engine . evaluate ( expression , context ) ; exprMatcher . appendReplacement ( sb , Matcher . quoteReplacement ( lastMatchEvalResult != null ? lastMatchEvalResult . toString ( ) : "" ) ) ; } String lastStringResult = lastMatchEvalResult != null ? lastMatchEvalResult . toString ( ) : "" ; boolean isAppendTail = matchCount == 1 && endOffset < strValue . length ( ) ; Object evaluationResult = null ; if ( matchCount > 1 || isAppendTail ) { exprMatcher . appendTail ( sb ) ; evaluationResult = sb . toString ( ) ; } else if ( matchCount == 1 ) { if ( sb . length ( ) > lastStringResult . length ( ) ) { evaluationResult = sb . toString ( ) ; } else { evaluationResult = lastMatchEvalResult ; } } else if ( matchCount == 0 ) { evaluationResult = strValue ; } return evaluationResult ; }


Input:
Creates the cell comment . [CODESPLIT] public static void createCellComment ( final Cell cell , final String newComment , final Map < Cell , String > finalCommentMap ) { // due to poi's bug. the comment must be set in sorted order ( row first
 // then column),
 // otherwise poi will mess up.
 // workaround solution is to save all comments into a map,
 // and output them together when download workbook.
 if ( newComment != null ) { finalCommentMap . put ( cell , newComment ) ; } }


Input: evaluate boolean express . [CODESPLIT] public static boolean evalBoolExpression ( final ExpressionEngine expEngine , final String pscript ) { Object result = null ; String script = "( " + pscript + " )" ; script = script . toUpperCase ( ) . replace ( "AND" , "&&" ) ; script = script . toUpperCase ( ) . replace ( "OR" , "||" ) ; try { result = expEngine . evaluate ( script ) ; } catch ( Exception e ) { LOG . log ( Level . SEVERE , "WebForm WebFormHelper evalBoolExpression script = " + script + "; error = " + e . getLocalizedMessage ( ) , e ) ; } if ( result != null ) { return ( ( Boolean ) result ) . booleanValue ( ) ; } else { return false ; } }


Input:
Remove the rows . [CODESPLIT] public static void removeRowsInSheet ( final Sheet sheet , final int rowIndexStart , final int rowIndexEnd , final Map < Cell , String > cachedMap ) { for ( int irow = rowIndexStart ; irow <= rowIndexEnd ; irow ++ ) { removeCachedCellForRow ( sheet , irow , cachedMap ) ; } int irows = rowIndexEnd - rowIndexStart + 1 ; if ( ( irows < 1 ) || ( rowIndexStart < 0 ) ) { return ; } int lastRowNum = sheet . getLastRowNum ( ) ; if ( rowIndexEnd < lastRowNum ) { sheet . shiftRows ( rowIndexEnd + 1 , lastRowNum , - irows ) ; } if ( rowIndexEnd == lastRowNum ) { // reverse order to delete rows.
 for ( int i = rowIndexEnd ; i >= rowIndexStart ; i -- ) { removeSingleRowInSheet ( sheet , rowIndexStart ) ; } } }


Input: Removes the single row in sheet . [CODESPLIT] private static void removeSingleRowInSheet ( final Sheet sheet , final int rowIndexStart ) { Row removingRow = sheet . getRow ( rowIndexStart ) ; if ( removingRow != null ) { sheet . removeRow ( removingRow ) ; } }


Input:
Removes the cached cell for row . [CODESPLIT] private static void removeCachedCellForRow ( final Sheet sheet , final int rowIndexStart , final Map < Cell , String > cachedMap ) { Row removingRow = sheet . getRow ( rowIndexStart ) ; if ( removingRow != null ) { // remove cached cell.
 for ( Cell cell : removingRow ) { cachedMap . remove ( cell ) ; } } }


Input: Removes the rows in body . [CODESPLIT] public static void removeRowsInBody ( final SheetConfiguration sheetConfig , final List < FacesRow > bodyRows , final int rowIndexStart , final int rowIndexEnd ) { int top = sheetConfig . getBodyCellRange ( ) . getTopRow ( ) ; if ( ( rowIndexEnd < rowIndexStart ) || ( rowIndexStart < top ) ) { return ; } int irows = rowIndexEnd - rowIndexStart + 1 ; for ( int rowIndex = rowIndexEnd ; rowIndex >= rowIndexStart ; rowIndex -- ) { bodyRows . remove ( rowIndex - top ) ; } for ( int irow = rowIndexStart - top ; irow < bodyRows . size ( ) ; irow ++ ) { FacesRow facesrow = bodyRows . get ( irow ) ; facesrow . setRowIndex ( facesrow . getRowIndex ( ) - irows ) ; } }


Input: Put picture image to session map and return the key to web . [CODESPLIT] private String loadPicture ( final int rowIndex , final int colIndex ) { FacesCell facesCell = parent . getCellHelper ( ) . getFacesCellWithRowColFromCurrentPage ( rowIndex , colIndex ) ; if ( facesCell != null && facesCell . isContainPic ( ) ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; String pictureId = facesCell . getPictureId ( ) ; String pictureViewId = Integer . toHexString ( System . identityHashCode ( parent . getWb ( ) ) ) + pictureId ; Map < String , Object > sessionMap = context . getExternalContext ( ) . getSessionMap ( ) ; if ( sessionMap . get ( pictureViewId ) == null ) { sessionMap . put ( pictureViewId , parent . getPicturesMap ( ) . get ( pictureId ) . getPictureData ( ) ) ; } return pictureViewId ; } else { return null ; } }


Input: Put chart image to session map and return the key to web . [CODESPLIT] private String loadChart ( final int rowIndex , final int colIndex ) { FacesCell facesCell = parent . getCellHelper ( ) . getFacesCellWithRowColFromCurrentPage ( rowIndex , colIndex ) ; if ( facesCell != null && facesCell . isContainChart ( ) ) { FacesContext context = FacesContext . getCurrentInstance ( ) ; String chartId = facesCell . getChartId ( ) ; String chartViewId = Integer . toHexString ( System . identityHashCode ( parent . getWb ( ) ) ) + chartId ; if ( context != null ) { Map < String , Object > sessionMap = context . getExternalContext ( ) . getSessionMap ( ) ; if ( sessionMap . get ( chartViewId ) == null ) { sessionMap . put ( chartViewId , parent . getCharsData ( ) . getChartsMap ( ) . get ( chartId ) ) ; } } return chartViewId ; } else { return null ; } }


Input:
/ * ( non - Javadoc ) [CODESPLIT] @ Override public final Object get ( final Object key ) { Object result = "" ; try { CellMapKey mkey = new CellMapKey ( ( String ) key ) ; if ( ! mkey . isParseSuccess ( ) ) { return result ; } Cell poiCell = parent . getCellHelper ( ) . getPoiCellWithRowColFromCurrentPage ( mkey . getRowIndex ( ) , mkey . getColIndex ( ) ) ; if ( poiCell == null ) { return result ; } if ( mkey . isCharted ( ) ) { result = loadChart ( mkey . getRowIndex ( ) , mkey . getColIndex ( ) ) ; } else if ( mkey . isPictured ( ) ) { result = loadPicture ( mkey . getRowIndex ( ) , mkey . getColIndex ( ) ) ; } else if ( mkey . isFormatted ( ) ) { result = CellUtility . getCellValueWithFormat ( poiCell , parent . getFormulaEvaluator ( ) , parent . getDataFormatter ( ) ) ; } else { result = CellUtility . getCellValueWithoutFormat ( poiCell ) ; } } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "Web Form CellMap get value error=" + ex . getLocalizedMessage ( ) , ex ) ; } // return blank if null
 return result ; }


Input:
/ * ( non - Javadoc ) [CODESPLIT] @ Override public final Object put ( final Object key , final Object value ) { try { CellMapKey mkey = new CellMapKey ( ( String ) key ) ; if ( ! mkey . isParseSuccess ( ) ) { return null ; } Cell poiCell = parent . getCellHelper ( ) . getPoiCellWithRowColFromCurrentPage ( mkey . getRowIndex ( ) , mkey . getColIndex ( ) ) ; if ( poiCell == null ) { return null ; } String oldValue = CellUtility . getCellValueWithoutFormat ( poiCell ) ; FacesCell facesCell = parent . getCellHelper ( ) . getFacesCellWithRowColFromCurrentPage ( mkey . getRowIndex ( ) , mkey . getColIndex ( ) ) ; String newValue = assembleNewValue ( value , facesCell ) ; if ( newValue != null && ! newValue . equals ( oldValue ) ) { CellUtility . setCellValue ( poiCell , newValue ) ; if ( facesCell . isHasSaveAttr ( ) ) { parent . getCellHelper ( ) . saveDataInContext ( poiCell , newValue ) ; } // patch to avoid not updated downloaded file
 CellUtility . copyCell ( poiCell . getSheet ( ) , poiCell . getRow ( ) , poiCell . getRow ( ) , poiCell . getColumnIndex ( ) , false ) ; parent . getCellHelper ( ) . reCalc ( ) ; } return value ; } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "Save cell data error : " + ex . getLocalizedMessage ( ) , ex ) ; } return null ; }


Input:
Assemble new value . [CODESPLIT] private String assembleNewValue ( final Object value , final FacesCell facesCell ) { String newValue ; if ( value instanceof java . util . Date ) { String datePattern = facesCell . getDatePattern ( ) ; if ( datePattern == null || datePattern . isEmpty ( ) ) { datePattern = parent . getDefaultDatePattern ( ) ; } Format formatter = new SimpleDateFormat ( datePattern ) ; newValue = formatter . format ( value ) ; } else { newValue = ( String ) value ; } if ( "textarea" . equalsIgnoreCase ( facesCell . getInputType ( ) ) && ( newValue != null ) ) { // remove "\r" because excel issue
 newValue = newValue . replace ( "\r\n" , "\n" ) ; } return newValue ; }


Input: return cell value with format . [CODESPLIT] @ SuppressWarnings ( "deprecation" ) public static String getCellValueWithFormat ( final Cell poiCell , final FormulaEvaluator formulaEvaluator , final DataFormatter dataFormatter ) { if ( poiCell == null ) { return null ; } String result ; try { CellType cellType = poiCell . getCellTypeEnum ( ) ; if ( cellType == CellType . FORMULA ) { cellType = formulaEvaluator . evaluate ( poiCell ) . getCellTypeEnum ( ) ; } if ( cellType == CellType . ERROR ) { result = "" ; } else { result = dataFormatter . formatCellValue ( poiCell , formulaEvaluator ) ; } } catch ( Exception e ) { LOG . log ( Level . SEVERE , "Web Form WebFormHelper getCellValue Error row = " + poiCell . getRowIndex ( ) + " column = " + poiCell . getColumnIndex ( ) + " error = " + e . getLocalizedMessage ( ) + "; Change return result to blank" , e ) ; result = "" ; } return result ; }


Input: get input cell value . none input return blank [CODESPLIT] @ SuppressWarnings ( "deprecation" ) public static String getCellValueWithoutFormat ( final Cell poiCell ) { if ( poiCell == null ) { return null ; } if ( poiCell . getCellTypeEnum ( ) == CellType . FORMULA ) { return getCellStringValueWithType ( poiCell , poiCell . getCachedFormulaResultTypeEnum ( ) ) ; } else { return getCellStringValueWithType ( poiCell , poiCell . getCellTypeEnum ( ) ) ; } }


Input:
Get cell value as string but with giving type . [CODESPLIT] private static String getCellStringValueWithType ( final Cell poiCell , final CellType cellType ) { switch ( cellType ) { case BOOLEAN : return getCellStringValueWithBooleanType ( poiCell ) ; case NUMERIC : return getCellStringValueWithNumberType ( poiCell ) ; case STRING : return poiCell . getStringCellValue ( ) ; default : return "" ; } // switch
 }


Input:
Gets the cell string value with number type . [CODESPLIT] private static String getCellStringValueWithNumberType ( final Cell poiCell ) { String result ; if ( DateUtil . isCellDateFormatted ( poiCell ) ) { result = poiCell . getDateCellValue ( ) . toString ( ) ; } else { result = BigDecimal . valueOf ( poiCell . getNumericCellValue ( ) ) . toPlainString ( ) ; // remove .0 from end for int
 if ( result . endsWith ( ".0" ) ) { result = result . substring ( 0 , result . length ( ) - 2 ) ; } } return result ; }


Input: Set cell value with giving String value . [CODESPLIT] @ SuppressWarnings ( "deprecation" ) public static Cell setCellValue ( final Cell c , final String value ) { try { if ( value . length ( ) == 0 ) { c . setCellType ( CellType . BLANK ) ; } else if ( WebSheetUtility . isNumeric ( value ) ) { setCellValueNumber ( c , value ) ; } else if ( WebSheetUtility . isDate ( value ) ) { setCellValueDate ( c , value ) ; } else if ( c . getCellTypeEnum ( ) == CellType . BOOLEAN ) { setCellValueBoolean ( c , value ) ; } else { setCellValueString ( c , value ) ; } } catch ( Exception e ) { LOG . log ( Level . SEVERE , " error in setCellValue of CellUtility = " + e . getLocalizedMessage ( ) , e ) ; setCellValueString ( c , value ) ; } return c ; }


Input: Sets the cell value string . [CODESPLIT] private static void setCellValueString ( final Cell c , final String value ) { c . setCellType ( CellType . STRING ) ; c . setCellValue ( value ) ; }


Input: Sets the cell value boolean . [CODESPLIT] private static void setCellValueBoolean ( final Cell c , final String value ) { if ( "Y" . equalsIgnoreCase ( value ) || "Yes" . equalsIgnoreCase ( value ) || "True" . equalsIgnoreCase ( value ) ) { c . setCellValue ( true ) ; } else { c . setCellValue ( false ) ; } }


Input: Sets the cell value date . [CODESPLIT] private static void setCellValueDate ( final Cell c , final String value ) { String date = WebSheetUtility . parseDate ( value ) ; setCellValueString ( c , date ) ; }


Input: Sets the cell value number . [CODESPLIT] private static void setCellValueNumber ( final Cell c , final String value ) { double val = Double . parseDouble ( value . replace ( Character . toString ( ' ' ) , "" ) ) ; c . setCellType ( CellType . NUMERIC ) ; c . setCellValue ( val ) ; }


Input:
Copy rows . [CODESPLIT] public static void copyRows ( final Sheet srcSheet , final Sheet destSheet , final int srcRowStart , final int srcRowEnd , final int destRow , final boolean checkLock , final boolean setHiddenColumn ) { int length = srcRowEnd - srcRowStart + 1 ; if ( length <= 0 ) { return ; } destSheet . shiftRows ( destRow , destSheet . getLastRowNum ( ) , length , true , false ) ; for ( int i = 0 ; i < length ; i ++ ) { copySingleRow ( srcSheet , destSheet , srcRowStart + i , destRow + i , checkLock , setHiddenColumn ) ; } // If there are are any merged regions in the source row, copy to new
 // row
 for ( int i = 0 ; i < srcSheet . getNumMergedRegions ( ) ; i ++ ) { CellRangeAddress cellRangeAddress = srcSheet . getMergedRegion ( i ) ; if ( ( cellRangeAddress . getFirstRow ( ) >= srcRowStart ) && ( cellRangeAddress . getLastRow ( ) <= srcRowEnd ) ) { int targetRowFrom = cellRangeAddress . getFirstRow ( ) - srcRowStart + destRow ; int targetRowTo = cellRangeAddress . getLastRow ( ) - srcRowStart + destRow ; CellRangeAddress newCellRangeAddress = new CellRangeAddress ( targetRowFrom , targetRowTo , cellRangeAddress . getFirstColumn ( ) , cellRangeAddress . getLastColumn ( ) ) ; destSheet . addMergedRegion ( newCellRangeAddress ) ; } } }


Input:
Copy single row . [CODESPLIT] private static void copySingleRow ( final Sheet srcSheet , final Sheet destSheet , final int sourceRowNum , final int destinationRowNum , final boolean checkLock , final boolean setHiddenColumn ) { // Get the source / new row
 Row newRow = destSheet . getRow ( destinationRowNum ) ; Row sourceRow = srcSheet . getRow ( sourceRowNum ) ; if ( newRow == null ) { newRow = destSheet . createRow ( destinationRowNum ) ; } newRow . setHeight ( sourceRow . getHeight ( ) ) ; // Loop through source columns to add to new row
 for ( int i = 0 ; i < sourceRow . getLastCellNum ( ) ; i ++ ) { // Grab a copy of the old/new cell
 copyCell ( destSheet , sourceRow , newRow , i , checkLock ) ; } if ( setHiddenColumn ) { ConfigurationUtility . setOriginalRowNumInHiddenColumn ( newRow , sourceRow . getRowNum ( ) ) ; } return ; }


Input:
Copy cell . [CODESPLIT] public static Cell copyCell ( final Sheet destSheet , final Row sourceRow , final Row newRow , final int cellIndex , final boolean checkLock ) { // If the old cell is null jump to next cell
 Cell sourceCell = sourceRow . getCell ( cellIndex ) ; if ( sourceCell == null ) { return null ; } // If source cell is dest cell refresh it
 boolean refreshCell = false ; if ( sourceRow . equals ( newRow ) && ( sourceCell . getColumnIndex ( ) == cellIndex ) ) { sourceRow . removeCell ( sourceCell ) ; refreshCell = true ; } Cell newCell = newRow . createCell ( cellIndex ) ; try { if ( ! refreshCell && ( sourceCell . getCellComment ( ) != null ) ) { // If there is a cell comment, copy
 cloneComment ( sourceCell , newCell ) ; } copyCellSetStyle ( destSheet , sourceCell , newCell ) ; copyCellSetValue ( sourceCell , newCell , checkLock ) ; } catch ( Exception ex ) { LOG . log ( Level . SEVERE , "copy cell set error = " + ex . getLocalizedMessage ( ) , ex ) ; } return newCell ; }


Input: set cell value . [CODESPLIT] @ SuppressWarnings ( "deprecation" ) private static void copyCellSetValue ( final Cell sourceCell , final Cell newCell , final boolean checkLock ) { CellStyle newCellStyle = newCell . getCellStyle ( ) ; String name = sourceCell . getCellTypeEnum ( ) . toString ( ) ; CellValueType e = Enum . valueOf ( CellValueType . class , name ) ; e . setCellValue ( newCell , sourceCell , checkLock , newCellStyle ) ; }


Input:
set up cell style . [CODESPLIT] @ SuppressWarnings ( "deprecation" ) private static void copyCellSetStyle ( final Sheet destSheet , final Cell sourceCell , final Cell newCell ) { CellStyle newCellStyle = getCellStyleFromSourceCell ( destSheet , sourceCell ) ; newCell . setCellStyle ( newCellStyle ) ; // If there is a cell hyperlink, copy
 if ( sourceCell . getHyperlink ( ) != null ) { newCell . setHyperlink ( sourceCell . getHyperlink ( ) ) ; } // Set the cell data type
 newCell . setCellType ( sourceCell . getCellTypeEnum ( ) ) ; }


Input:
clone existing comments into new cell comment . [CODESPLIT] 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 ) ; }


Input: Creates the comment anchor . [CODESPLIT] 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 ; }


Input:
Creates the or insert comment . [CODESPLIT] 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 ( ) ) ; }


Input:
Use low level API to match the comments setting . [CODESPLIT] 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 ) ; } }


Input: Find vmldrawing part according to cell . [CODESPLIT] 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 ; }


Input:
Find CtShape from vml object . This class use reflection to invoke the protected method in POI . [CODESPLIT] @ 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 ( ) ) ; }


Input:
create cell style from source cell . [CODESPLIT] 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 ; }


Input: return cell index number key . e . g . $0$0 for A1 cell . [CODESPLIT] public static String getCellIndexNumberKey ( final Cell cell ) { if ( cell != null ) { return TieConstants . CELL_ADDR_PRE_FIX + cell . getColumnIndex ( ) + TieConstants . CELL_ADDR_PRE_FIX + cell . getRowIndex ( ) ; } return null ; }


Input: return cell index number key . e . g . $0$0 for A1 cell . [CODESPLIT] public static String getCellIndexNumberKey ( final int columnIndex , final int rowIndex ) { return TieConstants . CELL_ADDR_PRE_FIX + columnIndex + TieConstants . CELL_ADDR_PRE_FIX + rowIndex ; }


Input: return cell index key with column letter and row index . e . g . $A$0 for A1 cell . [CODESPLIT] public static String getCellIndexLetterKey ( final String columnLetter , final int rowIndex ) { return TieConstants . CELL_ADDR_PRE_FIX + columnLetter + TieConstants . CELL_ADDR_PRE_FIX + rowIndex ; }


Input: return cell index key with column and row index . e . g . $A$0 for A1 cell . [CODESPLIT] public static String getCellIndexLetterKey ( final int columnIndex , final int rowIndex ) { return TieConstants . CELL_ADDR_PRE_FIX + WebSheetUtility . getExcelColumnName ( columnIndex ) + TieConstants . CELL_ADDR_PRE_FIX + rowIndex ; }