_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q178700
ConfigurationHandler.buildCommandList
test
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; }
java
{ "resource": "" }
q178701
ConfigurationHandler.processMethodLine
test
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); } }
java
{ "resource": "" }
q178702
ConfigurationHandler.processCommandLine
test
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); } }
java
{ "resource": "" }
q178703
ConfigurationHandler.moveCommentToMap
test
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); }
java
{ "resource": "" }
q178704
ConfigurationHandler.createConfigCommand
test
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; } }
java
{ "resource": "" }
q178705
ConfigurationHandler.buildAttrMap
test
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); }
java
{ "resource": "" }
q178706
ConfigurationHandler.getSheetConfigurationFromConfigCommand
test
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; }
java
{ "resource": "" }
q178707
ConfigurationHandler.setFooterOfSheetConfiguration
test
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)); }
java
{ "resource": "" }
q178708
ConfigurationHandler.setBodyOfSheetConfiguration
test
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>>()); }
java
{ "resource": "" }
q178709
ConfigurationHandler.setHeaderOfSheetConfiguration
test
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)); }
java
{ "resource": "" }
q178710
CommandUtility.deleteRow
test
@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; }
java
{ "resource": "" }
q178711
CommandUtility.removeRangesFromShiftMap
test
private static void removeRangesFromShiftMap( final NavigableMap<String, ConfigRangeAttrs> shiftMap, final List<String> removeFullNameList) { for (String fname : removeFullNameList) { shiftMap.remove(fname); } }
java
{ "resource": "" }
q178712
CommandUtility.findRemoveFullNameList
test
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; }
java
{ "resource": "" }
q178713
CommandUtility.getEachCommandFromPartsName
test
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; }
java
{ "resource": "" }
q178714
CommandUtility.insertEmptyObjectInContext
test
@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); } }
java
{ "resource": "" }
q178715
CommandUtility.deleteObjectInContext
test
@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()); }
java
{ "resource": "" }
q178716
CommandUtility.prepareCollectionDataInContext
test
@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; }
java
{ "resource": "" }
q178717
CommandUtility.indexCommandRange
test
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); } } }
java
{ "resource": "" }
q178718
CommandUtility.isRowAllowAdd
test
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; }
java
{ "resource": "" }
q178719
CommandUtility.insertEachTemplate
test
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)); } } }
java
{ "resource": "" }
q178720
CommandUtility.evaluateNormalCells
test
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); } }
java
{ "resource": "" }
q178721
CommandUtility.evaluateUserFormula
test
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); } }
java
{ "resource": "" }
q178722
CommandUtility.isUserFormula
test
private static boolean isUserFormula(final String str) { return str.startsWith(TieConstants.USER_FORMULA_PREFIX) && str.endsWith(TieConstants.USER_FORMULA_SUFFIX); }
java
{ "resource": "" }
q178723
CommandUtility.createCellComment
test
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); } }
java
{ "resource": "" }
q178724
CommandUtility.evalBoolExpression
test
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; } }
java
{ "resource": "" }
q178725
CommandUtility.removeRowsInSheet
test
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); } } }
java
{ "resource": "" }
q178726
CommandUtility.removeSingleRowInSheet
test
private static void removeSingleRowInSheet(final Sheet sheet, final int rowIndexStart) { Row removingRow = sheet.getRow(rowIndexStart); if (removingRow != null) { sheet.removeRow(removingRow); } }
java
{ "resource": "" }
q178727
CommandUtility.removeCachedCellForRow
test
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); } } }
java
{ "resource": "" }
q178728
CommandUtility.removeRowsInBody
test
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); } }
java
{ "resource": "" }
q178729
CellMap.loadPicture
test
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; } }
java
{ "resource": "" }
q178730
CellMap.loadChart
test
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; } }
java
{ "resource": "" }
q178731
CellMap.assembleNewValue
test
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; }
java
{ "resource": "" }
q178732
CellUtility.getCellValueWithFormat
test
@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; }
java
{ "resource": "" }
q178733
CellUtility.getCellValueWithoutFormat
test
@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()); } }
java
{ "resource": "" }
q178734
CellUtility.getCellStringValueWithType
test
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 }
java
{ "resource": "" }
q178735
CellUtility.getCellStringValueWithNumberType
test
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; }
java
{ "resource": "" }
q178736
CellUtility.setCellValue
test
@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; }
java
{ "resource": "" }
q178737
CellUtility.setCellValueString
test
private static void setCellValueString(final Cell c, final String value) { c.setCellType(CellType.STRING); c.setCellValue(value); }
java
{ "resource": "" }
q178738
CellUtility.setCellValueBoolean
test
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); } }
java
{ "resource": "" }
q178739
CellUtility.setCellValueDate
test
private static void setCellValueDate(final Cell c, final String value) { String date = WebSheetUtility.parseDate(value); setCellValueString(c, date); }
java
{ "resource": "" }
q178740
CellUtility.setCellValueNumber
test
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); }
java
{ "resource": "" }
q178741
CellUtility.copyRows
test
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); } } }
java
{ "resource": "" }
q178742
CellUtility.copySingleRow
test
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; }
java
{ "resource": "" }
q178743
CellUtility.copyCell
test
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; }
java
{ "resource": "" }
q178744
CellUtility.copyCellSetValue
test
@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); }
java
{ "resource": "" }
q178745
CellUtility.copyCellSetStyle
test
@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()); }
java
{ "resource": "" }
q178746
CellUtility.cloneComment
test
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); }
java
{ "resource": "" }
q178747
CellUtility.createCommentAnchor
test
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; }
java
{ "resource": "" }
q178748
CellUtility.createOrInsertComment
test
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()); }
java
{ "resource": "" }
q178749
CellUtility.matchCommentSettings
test
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); } }
java
{ "resource": "" }
q178750
CellUtility.getVmlDrawingFromCell
test
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; }
java
{ "resource": "" }
q178751
CellUtility.getCtShapeFromVml
test
@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()); }
java
{ "resource": "" }
q178752
CellUtility.getCellStyleFromSourceCell
test
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; }
java
{ "resource": "" }
q178753
CellUtility.convertCell
test
public static void convertCell(final SheetConfiguration sheetConfig, final FacesCell fcell, final Cell poiCell, final Map<String, CellRangeAddress> cellRangeMap, final int originRowIndex, final CellAttributesMap cellAttributesMap, final String saveAttrs) { CellRangeAddress caddress; String key = getCellIndexNumberKey(poiCell); caddress = cellRangeMap.get(key); if (caddress != null) { // has col or row span fcell.setColspan(caddress.getLastColumn() - caddress.getFirstColumn() + 1); fcell.setRowspan(caddress.getLastRow() - caddress.getFirstRow() + 1); } CellControlsUtility.setupControlAttributes(originRowIndex, fcell, poiCell, sheetConfig, cellAttributesMap); fcell.setHasSaveAttr(SaveAttrsUtility.isHasSaveAttr(poiCell, saveAttrs)); }
java
{ "resource": "" }
q178754
CellUtility.getRowColFromComponentAttributes
test
public static int[] getRowColFromComponentAttributes(final UIComponent target) { int rowIndex = (Integer) target.getAttributes().get("data-row"); int colIndex = (Integer) target.getAttributes().get("data-column"); int[] list = new int[2]; list[0] = rowIndex; list[1] = colIndex; return list; }
java
{ "resource": "" }
q178755
CellUtility.getInitRowsFromConfig
test
public static int getInitRowsFromConfig(final SheetConfiguration sheetConfig) { int initRows = 1; if ("Repeat".equalsIgnoreCase(sheetConfig.getFormBodyType())) { initRows = sheetConfig.getBodyInitialRows(); if (initRows < 1) { initRows = 1; } } return initRows; }
java
{ "resource": "" }
q178756
CellUtility.getFacesRowFromBodyRow
test
public static FacesRow getFacesRowFromBodyRow(final int row, final List<FacesRow> bodyRows, final int topRow) { FacesRow frow = null; try { frow = bodyRows.get(row - topRow); } catch (Exception e) { LOG.log(Level.SEVERE, "getFacesRowFromBodyRow Error row = " + row + "top row = " + topRow + " ; error = " + e.getLocalizedMessage(), e); } return frow; }
java
{ "resource": "" }
q178757
CellUtility.getFacesCellFromBodyRow
test
public static FacesCell getFacesCellFromBodyRow(final int row, final int col, final List<FacesRow> bodyRows, final int topRow, final int leftCol) { FacesCell cell = null; try { cell = bodyRows.get(row - topRow).getCells().get(col - leftCol); } catch (Exception e) { LOG.log(Level.SEVERE, "getFacesCellFromBodyRow Error row = " + row + " col = " + col + "top row = " + topRow + " leftCol = " + leftCol + " ; error = " + e.getLocalizedMessage(), e); } return cell; }
java
{ "resource": "" }
q178758
CellUtility.getPoiCellFromSheet
test
public static Cell getPoiCellFromSheet(final int rowIndex, final int colIndex, final Sheet sheet1) { if ((sheet1 != null) && (sheet1.getRow(rowIndex) != null)) { return sheet1.getRow(rowIndex).getCell(colIndex); } return null; }
java
{ "resource": "" }
q178759
CellUtility.getSkeyFromPoiCell
test
public static String getSkeyFromPoiCell(final Cell poiCell) { return poiCell.getSheet().getSheetName() + "!" + CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), poiCell.getRowIndex()); }
java
{ "resource": "" }
q178760
CellUtility.getOrAddTieCellInMap
test
public static TieCell getOrAddTieCellInMap(final Cell poiCell, HashMap<String, TieCell> tieCells) { String skey = CellUtility.getSkeyFromPoiCell(poiCell); TieCell tieCell = tieCells.get(skey); if (tieCell == null) { tieCell = new TieCell(); tieCell.setSkey(skey); tieCells.put(skey, tieCell); } return tieCell; }
java
{ "resource": "" }
q178761
TieWebSheetBeanCurrent.getCurrentDataContextName
test
public final String getCurrentDataContextName() { if (currentDataContextName == null) { StringBuilder sb = new StringBuilder(); List<String> list = this.getCurrentDataContextNameList(); for (int i = 0; i < list.size(); i++) { if (i > 0) { sb.append(":" + list.get(i)); } else { sb.append(list.get(i)); } } this.setCurrentDataContextName(sb.toString()); } return currentDataContextName; }
java
{ "resource": "" }
q178762
ExpressionEngine.evaluate
test
public final Object evaluate(final String expression, final Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { JexlEngine jexl = JEXL_LOCAL.get(); Map<String, Expression> expMap = JEXL_MAP_LOCAL.get(); Expression jexlExpression = expMap.get(expression); if (jexlExpression == null) { jexlExpression = jexl.createExpression(expression); expMap.put(expression, jexlExpression); } return jexlExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException(e); } }
java
{ "resource": "" }
q178763
ExpressionEngine.evaluate
test
public final Object evaluate(final Map<String, Object> context) { JexlContext jexlContext = new MapContext(context); try { return jExpression.evaluate(jexlContext); } catch (Exception e) { throw new EvaluationException( "An error occurred when evaluating expression " + jExpression.getExpression(), e); } }
java
{ "resource": "" }
q178764
SerialRow.writeObject
test
private void writeObject(final java.io.ObjectOutputStream out) throws IOException { this.rowIndex = this.getRow().getRowNum(); out.defaultWriteObject(); }
java
{ "resource": "" }
q178765
RowsMapping.removeRow
test
public final void removeRow(final Integer sourceRowNum, final Row targetRow) { List<SerialRow> mapRowList = rowsMap.get(sourceRowNum); if (mapRowList != null) { mapRowList.remove(new SerialRow(targetRow, -1)); rowsMap.put(sourceRowNum, mapRowList); } }
java
{ "resource": "" }
q178766
RowsMapping.mergeMap
test
public final void mergeMap(final RowsMapping addMap) { Map<Integer, List<SerialRow>> map = addMap.getRowsMap(); for (Map.Entry<Integer, List<SerialRow>> entry : map.entrySet()) { List<SerialRow> entryRowList = entry.getValue(); if ((entryRowList != null) && (!entryRowList.isEmpty())) { for (SerialRow row : entryRowList) { this.addRow(entry.getKey(), row.getRow()); } } } }
java
{ "resource": "" }
q178767
RowsMapping.recover
test
public final void recover(final Sheet sheet) { for (Map.Entry<Integer, List<SerialRow>> entry : this.getRowsMap() .entrySet()) { List<SerialRow> listRow = entry.getValue(); for (SerialRow serialRow : listRow) { serialRow.recover(sheet); } } }
java
{ "resource": "" }
q178768
ChartUtility.getChartType
test
public static ChartType getChartType(final CTChart ctChart) { CTPlotArea plotArea = ctChart.getPlotArea(); for (ChartType chartType : ChartType.values()) { if (chartType.isThisType(plotArea)) { return chartType; } } return null; }
java
{ "resource": "" }
q178769
ChartUtility.toStroke
test
public static BasicStroke toStroke(final String style) { BasicStroke result = null; if (style != null) { float lineWidth = STROKE_DEFAULT_LINE_WIDTH; float[] dash = { STROKE_DEFAULT_DASH_WIDTH }; float[] dot = { lineWidth }; if (style.equalsIgnoreCase(STYLE_LINE)) { result = new BasicStroke(lineWidth); } else if (style.equalsIgnoreCase(STYLE_DASH)) { result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, STROKE_MITER_LIMIT_STYLE_DASH, dash, STROKE_DEFAULT_DASHPHASE); } else if (style.equalsIgnoreCase(STYLE_DOT)) { result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, STROKE_MITER_LIMIT_STYLE_DOT, dot, STROKE_DEFAULT_DASHPHASE); } } return result; }
java
{ "resource": "" }
q178770
ChartUtility.initChartDataFromXSSFChart
test
public static ChartData initChartDataFromXSSFChart(final String chartId, final XSSFChart chart, final XSSFWorkbook wb) { ThemesTable themeTable = wb.getStylesSource().getTheme(); ChartData chartData = new ChartData(); XSSFRichTextString chartTitle = chart.getTitle(); if (chartTitle != null) { chartData.setTitle(chartTitle.toString()); } CTChart ctChart = chart.getCTChart(); ChartType chartType = ChartUtility.getChartType(ctChart); if (chartType == null) { throw new IllegalChartException("Unknown chart type"); } chartData.setBgColor( ColorUtility.getBgColor(ctChart.getPlotArea(), themeTable)); chartData.setId(chartId); chartData.setType(chartType); List<CTCatAx> ctCatAxList = ctChart.getPlotArea().getCatAxList(); if ((ctCatAxList != null) && (!ctCatAxList.isEmpty())) { chartData.setCatAx(new ChartAxis(ctCatAxList.get(0))); } List<CTValAx> ctValAxList = ctChart.getPlotArea().getValAxList(); if ((ctValAxList != null) && (!ctValAxList.isEmpty())) { chartData.setValAx(new ChartAxis(ctValAxList.get(0))); } ChartObject ctObj = chartType.createChartObject(); if (ctObj == null) { throw new IllegalChartException("Cannot create chart object."); } setUpChartData(chartData, ctChart, themeTable, ctObj); return chartData; }
java
{ "resource": "" }
q178771
ChartUtility.setUpChartData
test
public static void setUpChartData(final ChartData chartData, final CTChart ctChart, final ThemesTable themeTable, final ChartObject ctObj) { Object chartObj = null; @SuppressWarnings("rawtypes") List plotCharts = ctObj.getChartListFromCtChart(ctChart); // chart object if (plotCharts != null && (!plotCharts.isEmpty())) { chartObj = plotCharts.get(0); } if (chartObj != null) { @SuppressWarnings("rawtypes") List bsers = ctObj.getSerListFromCtObjChart(chartObj); if (!AppUtils.emptyList(bsers)) { chartData.buildCategoryList( ctObj.getCtAxDataSourceFromSerList(bsers)); chartData.buildSeriesList(bsers, themeTable, ctObj); } } }
java
{ "resource": "" }
q178772
ChartUtility.initXSSFAnchorsMap
test
public static void initXSSFAnchorsMap(final XSSFWorkbook wb, final ChartsData charsData) { Map<String, ClientAnchor> anchortMap = charsData .getChartAnchorsMap(); Map<String, String> positionMap = charsData.getChartPositionMap(); anchortMap.clear(); positionMap.clear(); for (int i = 0; i < wb.getNumberOfSheets(); i++) { initXSSFAnchorsMapForSheet(anchortMap, positionMap, wb.getSheetAt(i)); } }
java
{ "resource": "" }
q178773
ChartUtility.initXSSFAnchorsMapForSheet
test
private static void initXSSFAnchorsMapForSheet( final Map<String, ClientAnchor> anchortMap, final Map<String, String> positionMap, final XSSFSheet sheet) { XSSFDrawing drawing = sheet.createDrawingPatriarch(); CTDrawing ctDrawing = drawing.getCTDrawing(); if (ctDrawing.sizeOfTwoCellAnchorArray() <= 0) { return; } List<CTTwoCellAnchor> alist = ctDrawing.getTwoCellAnchorList(); for (int j = 0; j < alist.size(); j++) { CTTwoCellAnchor ctanchor = alist.get(j); String singleChartId = getAnchorAssociateChartId(ctanchor); if (singleChartId != null) { String chartId = sheet.getSheetName() + "!" + singleChartId; int dx1 = (int) ctanchor.getFrom().getColOff(); int dy1 = (int) ctanchor.getFrom().getRowOff(); int dx2 = (int) ctanchor.getTo().getColOff(); int dy2 = (int) ctanchor.getTo().getRowOff(); int col1 = ctanchor.getFrom().getCol(); int row1 = ctanchor.getFrom().getRow(); int col2 = ctanchor.getTo().getCol(); int row2 = ctanchor.getTo().getRow(); anchortMap.put(chartId, new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2)); positionMap.put(WebSheetUtility.getFullCellRefName( sheet.getSheetName(), row1, col1), chartId); } } }
java
{ "resource": "" }
q178774
ChartUtility.getAnchorAssociateChartId
test
private static String getAnchorAssociateChartId( final CTTwoCellAnchor ctanchor) { if (ctanchor.getGraphicFrame() == null) { return null; } Node parentNode = ctanchor.getGraphicFrame().getGraphic() .getGraphicData().getDomNode(); NodeList childNodes = parentNode.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); if ((childNode != null) && ("c:chart".equalsIgnoreCase(childNode.getNodeName())) && (childNode.hasAttributes())) { String rId = getChartIdFromChildNodeAttributes( childNode.getAttributes()); if (rId != null) { return rId; } } } return null; }
java
{ "resource": "" }
q178775
ChartUtility.getChartIdFromChildNodeAttributes
test
private static String getChartIdFromChildNodeAttributes( final NamedNodeMap attrs) { for (int j = 0; j < attrs.getLength(); j++) { Attr attribute = (Attr) attrs.item(j); if ("r:id".equalsIgnoreCase(attribute.getName())) { return attribute.getValue(); } } return null; }
java
{ "resource": "" }
q178776
EachCommand.buildEachObjects
test
@SuppressWarnings("rawtypes") private int buildEachObjects(String fullName, final ConfigBuildRef configBuildRef, final int atRow, final Map<String, Object> context, final List<RowsMapping> currentRowsMappingList, final Collection itemsCollection, final String objClassName) { int index = 0; int insertPosition = atRow; String thisObjClassName = objClassName; // loop through each object in the collection for (Object obj : itemsCollection) { // gather and cache object class name which used for add row if (thisObjClassName == null) { thisObjClassName = obj.getClass().getName(); configBuildRef.getCollectionObjNameMap().put(this.var, thisObjClassName); } RowsMapping unitRowsMapping = new RowsMapping(); context.put(var, obj); CommandUtility.insertEachTemplate(this.getConfigRange(), configBuildRef, index, insertPosition, unitRowsMapping); ConfigRange currentRange = ConfigurationUtility .buildCurrentRange(this.getConfigRange(), configBuildRef.getSheet(), insertPosition); currentRowsMappingList.add(unitRowsMapping); String unitFullName = fullName + "." + index; currentRange.getAttrs().setAllowAdd(false); if ((this.allowAdd != null) && ("true".equalsIgnoreCase(this.allowAdd.trim()))) { currentRange.getAttrs().setAllowAdd(true); configBuildRef.setBodyAllowAdd(true); } configBuildRef.putShiftAttrs(unitFullName, currentRange.getAttrs(), new RowsMapping(unitRowsMapping)); int length = currentRange.buildAt(unitFullName, configBuildRef, insertPosition, context, currentRowsMappingList); currentRange.getAttrs().setFinalLength(length); insertPosition += length; currentRowsMappingList.remove(unitRowsMapping); index++; context.remove(var); } return insertPosition; }
java
{ "resource": "" }
q178777
CellHelper.saveDataInContext
test
public final void saveDataInContext(final Cell poiCell, final String strValue) { String saveAttr = SaveAttrsUtility.prepareContextAndAttrsForCell(poiCell, ConfigurationUtility.getFullNameFromRow(poiCell.getRow()), this); if (saveAttr!= null) { SaveAttrsUtility.saveDataToObjectInContext( parent.getSerialDataContext().getDataContext(), saveAttr, strValue, parent.getExpEngine()); parent.getHelper().getWebSheetLoader().setUnsavedStatus( RequestContext.getCurrentInstance(), true); } }
java
{ "resource": "" }
q178778
CellHelper.reCalc
test
public final void reCalc() { parent.getFormulaEvaluator().clearAllCachedResultValues(); try { parent.getFormulaEvaluator().evaluateAll(); } catch (Exception ex) { // skip the formula exception when recalc but log it LOG.log(Level.SEVERE, " recalc formula error : " + ex.getLocalizedMessage(), ex); } }
java
{ "resource": "" }
q178779
CellHelper.getPoiCellWithRowColFromTab
test
public final Cell getPoiCellWithRowColFromTab(final int rowIndex, final int colIndex, final String tabName) { if (parent.getWb() != null) { return CellUtility.getPoiCellFromSheet(rowIndex, colIndex, parent.getWb().getSheet(parent.getSheetConfigMap() .get(tabName).getSheetName())); } return null; }
java
{ "resource": "" }
q178780
CellHelper.getFacesCellWithRowColFromCurrentPage
test
public final FacesCell getFacesCellWithRowColFromCurrentPage( final int rowIndex, final int colIndex) { if (parent.getBodyRows() != null) { int top = parent.getCurrent().getCurrentTopRow(); int left = parent.getCurrent().getCurrentLeftColumn(); return parent.getBodyRows().get(rowIndex - top).getCells() .get(colIndex - left); } return null; }
java
{ "resource": "" }
q178781
CellHelper.restoreDataContext
test
public final void restoreDataContext(final String fullName) { String[] parts = fullName.split(":"); if (!isNeedRestore(fullName, parts)) { return; } boolean stopSkip = false; List<String> list = parent.getCurrent() .getCurrentDataContextNameList(); int listSize = list.size(); // prepare collection data in context. // must loop through the full name which may have multiple // layer. // i.e. E.department.1:E.employee.0 // need prepare department.1 and employee.0 for (int i = 0; i < parts.length; i++) { String part = parts[i]; boolean skip = false; if ((!stopSkip) && (i < listSize)) { String listPart = list.get(i); if (part.equalsIgnoreCase(listPart)) { skip = true; } } if (!skip) { stopSkip = true; startRestoreDataContext(part); } } if (stopSkip) { parent.getCurrent().setCurrentDataContextName(fullName); } return; }
java
{ "resource": "" }
q178782
CellHelper.getLastCollect
test
public final CollectionObject getLastCollect(final String fullName) { String[] parts = fullName.split(":"); String part = parts[parts.length - 1]; return startRestoreDataContext(part); }
java
{ "resource": "" }
q178783
CellHelper.isNeedRestore
test
private boolean isNeedRestore(final String fullName, final String[] parts) { if (fullName == null) { return false; } if ((parent.getCurrent().getCurrentDataContextName() != null) && (parent.getCurrent().getCurrentDataContextName() .toLowerCase() .startsWith(fullName.toLowerCase()))) { return false; } return ((parts != null) && (parts.length > 1)); }
java
{ "resource": "" }
q178784
CellHelper.startRestoreDataContext
test
private CollectionObject startRestoreDataContext(final String part) { if (part.startsWith(TieConstants.EACH_COMMAND_FULL_NAME_PREFIX)) { String[] varparts = part.split("\\."); CollectionObject collect = new CollectionObject(); collect.setEachCommand( CommandUtility .getEachCommandFromPartsName( parent.getCurrentSheetConfig() .getCommandIndexMap(), varparts)); collect.setLastCollection(ConfigurationUtility .transformToCollectionObject(parent.getExpEngine(), collect.getEachCommand().getItems(), parent.getSerialDataContext() .getDataContext())); collect.setLastCollectionIndex( CommandUtility.prepareCollectionDataInContext(varparts, collect.getLastCollection(), parent.getSerialDataContext() .getDataContext())); return collect; } return null; }
java
{ "resource": "" }
q178785
ConfigRange.shiftRowRef
test
public final void shiftRowRef(final Sheet sheet, final int shiftnum) { try { this.setFirstRowRef(sheet .getRow(attrs.getFirstRowAddr().getRow() + shiftnum) .getCell(attrs.getFirstRowAddr().getColumn(), MissingCellPolicy.CREATE_NULL_AS_BLANK), false); this.setLastRowPlusRef(sheet, attrs.getLastRowPlusAddr().getColumn(), attrs.getLastRowPlusAddr().getRow() + shiftnum - 1, false); if (commandList != null) { for (ConfigCommand command : commandList) { command.shiftRowRef(sheet, shiftnum); } } } catch (Exception ex) { LOG.log(Level.SEVERE, "shiftRowRef error =" + ex.getLocalizedMessage(), ex); } }
java
{ "resource": "" }
q178786
ConfigRange.setFirstRowRef
test
public final void setFirstRowRef(final Cell pFirstRowRef, final boolean alsoCreateAddr) { this.attrs.setFirstRowRef(pFirstRowRef); if (alsoCreateAddr) { this.setFirstRowAddr(new SerialCellAddress(pFirstRowRef)); } }
java
{ "resource": "" }
q178787
ConfigRange.setLastRowPlusRef
test
public final void setLastRowPlusRef(final Sheet sheet, final int rightCol, final int lastRow, final boolean alsoSetAddr) { if ((lastRow >= 0) && (sheet != null) && (rightCol >= 0)) { Row row = sheet.getRow(lastRow + 1); if (row == null) { row = sheet.createRow(lastRow + 1); } Cell cell = row.getCell(rightCol); if (cell == null) { cell = row.getCell(rightCol, MissingCellPolicy.CREATE_NULL_AS_BLANK); this.attrs.setLastCellCreated(true); } else { this.attrs.setLastCellCreated(false); } this.attrs.setLastRowPlusRef(cell); if (alsoSetAddr) { this.setLastRowPlusAddr(new SerialCellAddress(cell)); } } else { this.attrs.setLastRowPlusRef(null); if (alsoSetAddr) { this.attrs.setLastRowPlusAddr(null); } } }
java
{ "resource": "" }
q178788
ConfigRange.buildCellsForRow
test
private void buildCellsForRow(final Row row, final String fullName, final Map<String, Object> context, final ConfigBuildRef configBuildRef, ShiftFormulaRef shiftFormulaRef) { if ((row == null) || !ConfigurationUtility.isStaticRowRef(this, row)) { return; } for (Cell cell : row) { buildSingleCell(cell, context, configBuildRef, shiftFormulaRef); } ConfigurationUtility.setFullNameInHiddenColumn(row, fullName); }
java
{ "resource": "" }
q178789
ConfigRange.buildSingleCell
test
private void buildSingleCell(final Cell cell, final Map<String, Object> context, final ConfigBuildRef configBuildRef, final ShiftFormulaRef shiftFormulaRef) { try { CommandUtility.evaluate(context, cell, configBuildRef.getEngine()); if (cell.getCellTypeEnum() == CellType.FORMULA) { // rebuild formula if necessary for dynamic row String originFormula = cell.getCellFormula(); shiftFormulaRef.setFormulaChanged(0); ConfigurationUtility.buildCellFormulaForShiftedRows( configBuildRef.getSheet(), configBuildRef.getWbWrapper(), shiftFormulaRef, cell, cell.getCellFormula()); if (shiftFormulaRef.getFormulaChanged() > 0) { configBuildRef.getCachedCells().put(cell, originFormula); } } } catch (Exception ex) { LOG.log(Level.SEVERE, "build cell ( row = " + cell.getRowIndex() + " column = " + cell.getColumnIndex() + " error = " + ex.getLocalizedMessage(), ex); } }
java
{ "resource": "" }
q178790
SerialDataContext.readObject
test
private void readObject(final java.io.ObjectInputStream in) throws IOException { try { in.defaultReadObject(); Gson objGson = new GsonBuilder().setPrettyPrinting().create(); Type listType = new TypeToken<Map<String, Object>>() { }.getType(); this.dataContext = objGson.fromJson(mapToJson, listType); } catch (EncryptedDocumentException | ClassNotFoundException e) { LOG.log(Level.SEVERE, " error in readObject of serialWorkbook : " + e.getLocalizedMessage(), e); } }
java
{ "resource": "" }
q178791
ChartData.buildCategoryList
test
public final void buildCategoryList(final CTAxDataSource ctAxDs) { List<ParsedCell> cells = new ArrayList<>(); try { String fullRangeName = ctAxDs.getStrRef().getF(); String sheetName = WebSheetUtility .getSheetNameFromFullCellRefName(fullRangeName); CellRangeAddress region = CellRangeAddress.valueOf( WebSheetUtility.removeSheetNameFromFullCellRefName( fullRangeName)); for (int row = region.getFirstRow(); row <= region .getLastRow(); row++) { for (int col = region.getFirstColumn(); col <= region .getLastColumn(); col++) { cells.add(new ParsedCell(sheetName, row, col)); } } } catch (Exception ex) { LOG.log(Level.FINE, "failed in buildCategoryList", ex); } this.setCategoryList(cells); }
java
{ "resource": "" }
q178792
ChartData.buildSeriesList
test
@SuppressWarnings("rawtypes") public final void buildSeriesList(final List bsers, final ThemesTable themeTable, final ChartObject ctObj) { List<ChartSeries> lseriesList = new ArrayList<>(); try { for (int index = 0; index < bsers.size(); index++) { Object ctObjSer = bsers.get(index); ChartSeries ctSer = buildChartSeriesInList(themeTable, ctObj, ctObjSer, index); lseriesList.add(ctSer); } } catch (Exception ex) { LOG.log(Level.FINE, "failed in buildSerialList", ex); } this.setSeriesList(lseriesList); }
java
{ "resource": "" }
q178793
ChartData.buildChartSeriesInList
test
private ChartSeries buildChartSeriesInList(final ThemesTable themeTable, final ChartObject ctObj, final Object ctObjSer, final int index) { ChartSeries ctSer = new ChartSeries(); ctSer.setSeriesLabel(new ParsedCell( ctObj.getSeriesLabelFromCTSer(ctObjSer))); ctSer.setSeriesColor(ColorUtility.geColorFromSpPr(index, ctObj.getShapePropertiesFromCTSer(ctObjSer), themeTable, ctObj.isLineColor())); List<ParsedCell> cells = new ArrayList<>(); String fullRangeName = (ctObj .getCTNumDataSourceFromCTSer(ctObjSer)).getNumRef() .getF(); String sheetName = WebSheetUtility .getSheetNameFromFullCellRefName(fullRangeName); CellRangeAddress region = CellRangeAddress .valueOf(WebSheetUtility .removeSheetNameFromFullCellRefName( fullRangeName)); for (int row = region.getFirstRow(); row <= region .getLastRow(); row++) { for (int col = region.getFirstColumn(); col <= region .getLastColumn(); col++) { cells.add(new ParsedCell(sheetName, row, col)); } } ctSer.setValueList(cells); ctSer.setValueColorList(getColorListFromDPTWithValueList( ctObj.getDPtListFromCTSer(ctObjSer), cells, themeTable, ctObj)); return ctSer; }
java
{ "resource": "" }
q178794
ChartData.getColorListFromDPTWithValueList
test
private List<XColor> getColorListFromDPTWithValueList( final List<CTDPt> dptList, final List<ParsedCell> cells, final ThemesTable themeTable, final ChartObject ctObj) { List<XColor> colors = new ArrayList<>(); if ((dptList != null) && (cells != null)) { for (int index = 0; index < cells.size(); index++) { CTDPt dpt = getDPtFromListWithIndex(dptList, index); CTShapeProperties ctSpPr = null; if (dpt != null) { ctSpPr = dpt.getSpPr(); } colors.add(ColorUtility.geColorFromSpPr(index, ctSpPr, themeTable, ctObj.isLineColor())); } } return colors; }
java
{ "resource": "" }
q178795
ChartData.getDPtFromListWithIndex
test
private CTDPt getDPtFromListWithIndex(final List<CTDPt> dptList, final int index) { if (dptList != null) { for (CTDPt dpt : dptList) { if (dpt.getIdx().getVal() == index) { return dpt; } } } return null; }
java
{ "resource": "" }
q178796
SheetConfiguration.setCommandIndexMap
test
public final void setCommandIndexMap( final Map<String, Command> pcommandIndexMap) { if (pcommandIndexMap instanceof HashMap) { this.commandIndexMap = (HashMap<String, Command>) pcommandIndexMap; } else { this.commandIndexMap = new HashMap<>(); this.commandIndexMap.putAll(pcommandIndexMap); } }
java
{ "resource": "" }
q178797
PicturesUtility.getPictruesMap
test
public static void getPictruesMap(final Workbook wb, final Map<String, Picture> picMap) { if (wb instanceof XSSFWorkbook) { getXSSFPictruesMap((XSSFWorkbook) wb, picMap); } return; }
java
{ "resource": "" }
q178798
PicturesUtility.getXSSFPictruesMap
test
private static void getXSSFPictruesMap(final XSSFWorkbook wb, final Map<String, Picture> picMap) { picMap.clear(); List<XSSFPictureData> pictures = wb.getAllPictures(); if (pictures.isEmpty()) { return; } for (int i = 0; i < wb.getNumberOfSheets(); i++) { XSSFSheet sheet = wb.getSheetAt(i); for (POIXMLDocumentPart dr : sheet.getRelations()) { try { indexPictureInMap(picMap, sheet, dr); } catch (Exception ex) { LOG.log(Level.SEVERE, "Load Picture error = " + ex.getLocalizedMessage(), ex); } } } return; }
java
{ "resource": "" }
q178799
PicturesUtility.indexPictureInMap
test
private static void indexPictureInMap(final Map<String, Picture> picMap, final XSSFSheet sheet, final POIXMLDocumentPart dr) { if (dr instanceof XSSFDrawing) { XSSFDrawing drawing = (XSSFDrawing) dr; List<XSSFShape> shapes = drawing.getShapes(); for (XSSFShape shape : shapes) { if (shape instanceof XSSFPicture) { XSSFPicture pic = (XSSFPicture) shape; XSSFClientAnchor anchor = pic.getPreferredSize(); CTMarker ctMarker = anchor.getFrom(); String picIndex = WebSheetUtility.getFullCellRefName( sheet.getSheetName(), ctMarker.getRow(), ctMarker.getCol()); picMap.put(picIndex, pic); } } } }
java
{ "resource": "" }