List of usage examples for org.apache.commons.beanutils PropertyUtils describe
public static Map describe(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the entire set of properties for which the specified bean provides a read method.
For more details see PropertyUtilsBean
.
From source file:org.apache.struts.scaffold.BaseForm.java
/** * // :FIXME: Needs testing. Works OK without a profile bean =:o) * Merge a profile bean with this bean to provide a unified map * of the combined parameters. Will on add properties to the map * from the profile bean if matching property on this bean is * blank or null (which includes absent). * The result is a union of the properties, with the this * bean's non-blank properties having precedence over the * profile's properties. The profile is a base that this bean * can override on the fly -- If this bean does not supply a * property, then the profile property is used. But any * property named on the userProfile is included (even if * it has no match on this bean).//from ww w . j ava2s . co m * <p> * If profile is null, a map of this bean's properties is returned. * <p> * The profile can be any JavaBean. * <p> * This method is forwardly-compatible with BaseMapForm. * For an instance of BaseMapForm, getMap() is used; otherwise * describe() or PropertyUtils.describe() is used. * * :FIXME: Needs testing. Works OK without a profile bean =:o) * @param profile The profile bean, if any * @throws Exception if error transfering data to map */ protected Map merge(Object profile) throws Exception { Map formMap = null; if (this instanceof BaseMapForm) { BaseMapForm form = (BaseMapForm) this; formMap = form.getMap(); } else { formMap = describe(); } if (profile != null) { Map userMap = null; if (profile instanceof BaseMapForm) { BaseMapForm form = (BaseMapForm) profile; userMap = form.getMap(); } else if (profile instanceof BaseForm) { BaseForm form = (BaseForm) profile; userMap = form.describe(); } else { userMap = PropertyUtils.describe(this); } // Add user element to formMap if form element is null or blank // Starting with the formMap, for every element in the userMap, // see if the formMap element is non-existant, null, or an empty String. // If it is (our formMap doesn't override), add the userMap value // to the formMap. Iterator i = userMap.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); String formValue = (String) formMap.get(key); if (isBlank(formValue)) { formMap.put(key, userMap.get(key)); } } } return formMap; }
From source file:org.apache.struts.scaffold.ProcessAction.java
/** * Assume that helpers are ProcessBeans, execute each, and * process outcome./*w w w . j av a 2 s . com*/ * * @param mapping The ActionMapping used to select this instance * @param form The ActionForm * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @param helpers The object instantiated from type given as parameter. * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ protected void executeLogic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, Object[] helpers) throws Exception { // Retrieve user profile, if any BaseForm userBean = getUserProfile(mapping, form, request, response); servlet.log(Log.HELPER_PROCESSING, Log.DEBUG); Map properties = null; for (int i = 0; i < helpers.length; i++) { // Get helper instantiated by ancestor ProcessBean dataBean = (ProcessBean) helpers[i]; properties = null; if (null != form) { if (form instanceof BaseForm) { BaseForm formBean = (BaseForm) form; // Merge user profile (if found) // and our form into a single map servlet.log(Log.HELPER_POPULATE, Log.DEBUG); properties = formBean.merge(userBean); // Pass up the Locale, RemoteNode, and RemoteServer (if any) dataBean.setLocale(formBean.getSessionLocale()); dataBean.setRemoteNode(getRemoteNode(request)); dataBean.setRemoteServer(getRemoteServer()); } else { properties = PropertyUtils.describe(form); } } // end null form else if (null != userBean) { // if no form, but is profile, still use profile properties = PropertyUtils.describe(userBean); } // Execute business logic, using values from map servlet.log(Log.HELPER_EXECUTING, Log.DEBUG); ProcessResult result = (ProcessResult) dataBean.execute(properties); // Analyze result of business logic checkOutcome(mapping, request, response, result); } // end for }
From source file:org.apache.struts.scaffold.ProcessDispatchAction.java
/** * Instantiate helper object from the type given as the * first ActionMapping parameter and execute the method given * as the second parameter (delimited with semicolons). * <p>/* w w w.j av a 2 s . c o m*/ * Otherwise operates as a ProcessAction. * * @param mapping The ActionMapping used to select this instance * @param form The ActionForm * @param request The HTTP request we are processing * @param response The HTTP response we are creating * <p> * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs * @todo Refactor so both Process*Actions can call core logic * @todo Add support for mutliple object/methods */ public void executeLogic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Retrieve user profile, if any BaseForm userBean = getUserProfile(mapping, form, request, response); servlet.log(Log.HELPER_PROCESSING, Log.DEBUG); Map properties = null; // Munge the parameter property servlet.log(Log.TOKENS_PARSING, Log.DEBUG); String[] tokens = tokenize(mapping.getParameter()); // Create our ProcessBean helper Object helper = createHelperObject(request, tokens[0]); servlet.log(Log.HELPER_EXECUTING, Log.DEBUG); ProcessBean dataBean = (ProcessBean) helper; // Pass along the helper's parameter, if any if (tokens.length > 2) { dataBean.setParameter(tokens[2]); } properties = null; if (null != form) { if (form instanceof BaseForm) { BaseForm formBean = (BaseForm) form; // Merge user profile (if found) // and our form into a single map servlet.log(Log.HELPER_POPULATE, Log.DEBUG); properties = formBean.merge(userBean); // Pass up the Locale and RemoteServer (if any) dataBean.setLocale(formBean.getSessionLocale()); dataBean.setRemoteServer(getRemoteServer()); } else { properties = PropertyUtils.describe(form); } } // end null form else if (null != userBean) { // if no form, but is profile, still use profile properties = PropertyUtils.describe(userBean); } // Execute business logic, using values from map servlet.log(Log.HELPER_EXECUTING, Log.DEBUG); Method method = dataBean.getClass().getMethod(tokens[1], types); Object args[] = { properties }; ProcessResult result = null; try { result = (ProcessResult) method.invoke(dataBean, args); } catch (ClassCastException e) { processError(result, Tokens.ERROR_DISPATCH_RETURN, mapping); } catch (IllegalAccessException e) { processError(result, Tokens.ERROR_DISPATCH_RETURN, mapping); } catch (InvocationTargetException e) { // Rethrow the target exception if possible so that the // exception handling machinery can deal with it Throwable t = e.getTargetException(); if (t instanceof Exception) { throw ((Exception) t); } else { processError(result, Tokens.ERROR_DISPATCH, mapping); } } // Execute business logic, using map checkOutcome(mapping, request, response, result); }
From source file:org.bbreak.excella.reports.tag.BlockColRepeatParamParser.java
@Override public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException { try {/*from w ww . j a v a2s . co m*/ // ?? Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue()); // ? checkParam(paramDef, tagCell); ReportsParserInfo info = (ReportsParserInfo) data; ParamInfo paramInfo = info.getParamInfo(); // ParsedReportInfo parsedReportInfo = new ParsedReportInfo(); List<Object> resultList = new ArrayList<Object>(); // BC????? String bcTagname = paramDef.get(PARAM_VALUE); if (log.isDebugEnabled()) { log.debug("BC?? : " + bcTagname); } // ????? Object[] paramInfos = getParamData(paramInfo, bcTagname); if (paramInfos == null) { return parsedReportInfo; } // ???? List<SingleParamParser> singleParsers = getSingleReplaceParsers(info); // POJOParamInfo??? List<ParamInfo> paramInfoList = new ArrayList<ParamInfo>(); for (Object obj : paramInfos) { if (obj instanceof ParamInfo) { paramInfoList.add((ParamInfo) obj); continue; } ParamInfo childParamInfo = new ParamInfo(); Map<String, Object> map = PropertyUtils.describe(obj); for (Map.Entry<String, Object> entry : map.entrySet()) { for (ReportsTagParser<?> parser : singleParsers) { childParamInfo.addParam(parser.getTag(), entry.getKey(), entry.getValue()); } } paramInfoList.add(childParamInfo); } // ?? if (paramDef.containsKey(PARAM_MIN_REPEAT_NUM)) { Integer minRepeatNum = Integer.valueOf(paramDef.get(PARAM_MIN_REPEAT_NUM)); if (minRepeatNum > paramInfoList.size()) { int addEmptyRowNum = minRepeatNum - paramInfoList.size(); for (int num = 0; num < addEmptyRowNum; num++) { ParamInfo childParamInfo = new ParamInfo(); paramInfoList.add(childParamInfo); } } } paramInfos = paramInfoList.toArray(new ParamInfo[paramInfoList.size()]); // ? Integer repeatNum = paramInfos.length; if (paramDef.containsKey(PARAM_REPEAT)) { if (Integer.valueOf(paramDef.get(PARAM_REPEAT)) < repeatNum) { repeatNum = Integer.valueOf(paramDef.get(PARAM_REPEAT)); } } // ? // TODO ? /* * Integer turnNum = null; if (paramDef.containsKey( PARAM_TURN)) { turnNum = Integer.valueOf( paramDef.get( PARAM_TURN)); } */ // ?????????? Map<String, Object> beforeBlockSingleDataMap = new HashMap<String, Object>(); // ??? if (paramDef.containsKey(PARAM_DUPLICATE)) { String[] tmp = paramDef.get(PARAM_DUPLICATE).split(";"); // single??? for (String str : tmp) { for (ReportsTagParser<?> parser : singleParsers) { str = parser.getTag() + TAG_PARAM_PREFIX + str + TAG_PARAM_SUFFIX; // ??key??? beforeBlockSingleDataMap.put(str, ""); } } } // removeTag boolean removeTag = false; if (paramDef.containsKey(PARAM_REMOVE_TAG)) { removeTag = Boolean.valueOf(paramDef.get(PARAM_REMOVE_TAG)); } // fromCell int[] fromCellPosition = ReportsUtil.getCellIndex(paramDef.get(PARAM_FROM), PARAM_FROM); int defaultFromCellRowIndex = tagCell.getRow().getRowNum() + fromCellPosition[0]; int defaultFromCellColIndex = tagCell.getColumnIndex() + fromCellPosition[1]; // toCell int[] toCellIndex = ReportsUtil.getCellIndex(paramDef.get(PARAM_TO), PARAM_TO); int defaultToCellRowIndex = tagCell.getRow().getRowNum() + toCellIndex[0]; int defaultToCellColIndex = tagCell.getColumnIndex() + toCellIndex[1]; // ?(??) int blockEndRowIndex = defaultToCellRowIndex; int blockEndColIndex = defaultToCellColIndex; int blockStartRowIndex = defaultFromCellRowIndex; int blockStartColIndex = defaultFromCellColIndex; // BC??Cell[row][col] Object[][] blockCellsValue = ReportsUtil.getBlockCellValue(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellStyle[][] blockCellsStyle = ReportsUtil.getBlockCellStyle(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellType[][] blockCellTypes = ReportsUtil.getBlockCellType(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); // ????? int[] columnWidths = ReportsUtil.getColumnWidth(sheet, defaultFromCellColIndex, defaultToCellColIndex); // ? int rowlen = defaultToCellRowIndex - defaultFromCellRowIndex + 1; int collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // ??? CellRangeAddress[] margedCells = ReportsUtil.getMargedCells(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); // ???? int turnCount = 0; int maxblockEndRowIndex = blockEndRowIndex; TagParser<?> parser = null; ParsedReportInfo result = null; // for (int repeatCount = 0; repeatCount < repeatNum; repeatCount++) { collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // ??????blockStartRowIndex??blockEndColIndex? // TODO ? /* * if (turnNum != null && turnNum <= turnCount) { blockStartRowIndex = blockEndRowIndex + 1; blockEndColIndex = 0; turnCount = 0; } */ // if (turnCount > 0) { blockStartColIndex = blockEndColIndex + 1; blockEndColIndex = blockStartColIndex + collen - 1; } else { // ??????? 2009/11/16 // blockStartColIndex = tagCell.getColumnIndex(); } turnCount++; // ???BC if (repeatCount > 0) { CellRangeAddress rangeAddress = new CellRangeAddress(blockStartRowIndex, sheet.getLastRowNum(), blockStartColIndex, blockStartColIndex + collen - 1); PoiUtil.insertRangeRight(sheet, rangeAddress); if (log.isDebugEnabled()) { log.debug(""); log.debug(blockStartRowIndex + ":" + sheet.getLastRowNum() + ":" + blockStartColIndex + ":" + (blockStartColIndex + collen - 1)); } // ??? // ??????????? // ?????? int targetColNum = blockEndColIndex - defaultToCellColIndex; for (CellRangeAddress address : margedCells) { // ???(BC????????) // ???(BC????????) // ??? + BC?? - BC? // ??? + BC?? - BC? int firstRowNum = address.getFirstRow(); int lastRowNum = address.getLastRow(); int firstColumnNum = address.getFirstColumn() + targetColNum; int lastColumnNum = address.getLastColumn() + targetColNum; CellRangeAddress copyAddress = new CellRangeAddress(firstRowNum, lastRowNum, firstColumnNum, lastColumnNum); sheet.addMergedRegion(copyAddress); } } // ? if (log.isDebugEnabled()) { log.debug("?????? =" + repeatCount); } for (int rowIdx = 0; rowIdx < blockCellsValue.length; rowIdx++) { // ? // int copyToRowIndex = blockStartRowIndex + rowIdx; Row row = sheet.getRow(copyToRowIndex); // ??null??????????????? if (row == null && !ReportsUtil.isEmptyRow(blockCellTypes[rowIdx], blockCellsValue[rowIdx], blockCellsStyle[rowIdx])) { // ???? // ? // (??)?????????? // ??null???(RowCreate?)??????????? row = sheet.createRow(copyToRowIndex); } if (row != null) { // ? for (int colIdx = 0; colIdx < blockCellsValue[rowIdx].length; colIdx++) { // int copyToColIndex = blockStartColIndex + colIdx; // ? sheet.setColumnWidth(copyToColIndex, columnWidths[colIdx]); // ? Cell cell = row.getCell(copyToColIndex); // ?? CellType cellType = blockCellTypes[rowIdx][colIdx]; // ?? Object cellValue = blockCellsValue[rowIdx][colIdx]; // ?? CellStyle cellStyle = blockCellsStyle[rowIdx][colIdx]; // ????????????????? if (cell == null && !ReportsUtil.isEmptyCell(cellType, cellValue, cellStyle)) { cell = row.createCell(copyToColIndex); } // if (cell != null) { // ? cell.setCellType(cellType); // ?? PoiUtil.setCellValue(cell, cellValue); // ?? if (cellStyle != null) { cell.setCellStyle(cellStyle); } if (log.isDebugEnabled()) { log.debug("row=" + (copyToRowIndex) + " col" + (copyToColIndex) + ">>>>>>" + blockCellsValue[rowIdx][colIdx]); } } } } } // ????????? int plusRowNum = 0; // ????????? int plusColNum = 0; collen = defaultToCellColIndex - defaultFromCellColIndex + 1; // for (int targetRow = blockStartRowIndex; targetRow < blockStartRowIndex + rowlen + plusRowNum; targetRow++) { if (sheet.getRow(targetRow) == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " : row is not available. continued..."); } continue; } // ? Cell chgTargetCell = null; // for (int targetCol = blockStartColIndex; targetCol <= blockStartColIndex + collen + plusColNum - 1; targetCol++) { // ???? chgTargetCell = sheet.getRow(targetRow).getCell(targetCol); if (chgTargetCell == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " : cell is not available. continued..."); } continue; } parser = info.getMatchTagParser(sheet, chgTargetCell); if (parser == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " parser is not available. continued..."); } continue; } String chgTargetCellString = chgTargetCell.getStringCellValue(); if (log.isDebugEnabled()) { log.debug("########## row=" + targetRow + " col=" + targetCol + " =" + chgTargetCellString + " ##########"); } // ? result = (ParsedReportInfo) parser.parse(sheet, chgTargetCell, info.createChildParserInfo((ParamInfo) paramInfos[repeatCount])); // ??? plusRowNum += result.getRowIndex() - result.getDefaultRowIndex(); // ??? plusColNum += result.getColumnIndex() - result.getDefaultColumnIndex(); // ?single??????????? // ??????????? if (parser instanceof SingleParamParser && beforeBlockSingleDataMap.containsKey(chgTargetCellString)) { if (beforeBlockSingleDataMap.get(chgTargetCellString) .equals(result.getParsedObject())) { // PoiUtil.setCellValue(chgTargetCell, ""); } else { // ???? beforeBlockSingleDataMap.put(chgTargetCellString, result.getParsedObject()); } } // ?????????????? if (blockStartColIndex != result.getDefaultColumnIndex() && maxblockEndRowIndex <= blockEndRowIndex && result.getRowIndex() > result.getDefaultRowIndex()) { CellRangeAddress preRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), blockStartColIndex, targetCol - 1); PoiUtil.insertRangeDown(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + blockStartColIndex + ":" + (targetCol - 1)); } } // R?????? if (parser instanceof RowRepeatParamParser && maxblockEndRowIndex <= blockEndRowIndex && result.getRowIndex() > result.getDefaultRowIndex()) { CellRangeAddress rearRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), result.getDefaultColumnIndex() + 1, blockEndColIndex); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + (result.getDefaultColumnIndex() + 1) + ":" + blockEndColIndex); } } blockEndRowIndex = defaultToCellRowIndex + plusRowNum; resultList.add(result.getParsedObject()); if (parser instanceof BlockColRepeatParamParser || parser instanceof BlockRowRepeatParamParser) { collen += result.getColumnIndex() - result.getDefaultColumnIndex(); plusColNum -= result.getColumnIndex() - result.getDefaultColumnIndex(); } // ???????? if (blockStartColIndex + collen + plusColNum - 1 > blockEndColIndex) { int beforeLastColIndex = blockEndColIndex; blockEndColIndex = blockStartColIndex + collen + plusColNum - 1; // ??????????? CellRangeAddress preRangeAddress = new CellRangeAddress(tagCell.getRowIndex(), targetRow - 1, beforeLastColIndex + 1, blockEndColIndex); PoiUtil.insertRangeRight(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + tagCell.getRowIndex() + ":" + (targetRow - 1) + ":" + (beforeLastColIndex + 1) + ":" + blockEndColIndex); } // ?????? int lastRowNum = sheet.getLastRowNum(); if ((blockEndRowIndex + 1) <= lastRowNum && (beforeLastColIndex + 1) <= blockEndColIndex) { CellRangeAddress rangeAddress = new CellRangeAddress(blockEndRowIndex + 1, lastRowNum, beforeLastColIndex + 1, blockEndColIndex); PoiUtil.insertRangeRight(sheet, rangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("3 : " + (blockEndRowIndex + 1) + ":" + lastRowNum + ":" + (beforeLastColIndex + 1) + ":" + blockEndColIndex); } } } // ? } // ?????? if (blockStartColIndex + collen + plusColNum - 1 < blockEndColIndex) { CellRangeAddress rearRangeAddress = new CellRangeAddress(targetRow, targetRow, blockStartColIndex + collen + plusColNum, blockEndColIndex); PoiUtil.insertRangeRight(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + targetRow + ":" + targetRow + ":" + (blockStartColIndex + collen + plusColNum) + ":" + blockEndColIndex); } } plusColNum = 0; // ? } // ??????? if (maxblockEndRowIndex < blockEndRowIndex) { if (log.isDebugEnabled()) { log.debug("******"); } if (repeatCount != 0) { CellRangeAddress preRangeAddress = new CellRangeAddress(maxblockEndRowIndex + 1, blockEndRowIndex, defaultFromCellColIndex, blockStartColIndex - 1); PoiUtil.insertRangeDown(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("1 : " + (maxblockEndRowIndex + 1) + ":" + blockEndRowIndex + ":" + defaultFromCellColIndex + ":" + (blockStartColIndex - 1)); } } // ??????? CellRangeAddress rearRangeAddress = new CellRangeAddress(maxblockEndRowIndex + 1, blockEndRowIndex, blockEndColIndex + 1, PoiUtil.getLastColNum(sheet)); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("2 : " + (maxblockEndRowIndex + 1) + ":" + blockEndRowIndex + ":" + (blockEndColIndex + 1) + ":" + PoiUtil.getLastColNum(sheet)); } maxblockEndRowIndex = blockEndRowIndex; } } // if (removeTag) { tagCell.setCellType(CellType.BLANK); } // parsedReportInfo.setDefaultRowIndex(defaultToCellRowIndex); parsedReportInfo.setDefaultColumnIndex(defaultToCellColIndex); parsedReportInfo.setColumnIndex(blockEndColIndex); parsedReportInfo.setParsedObject(resultList); parsedReportInfo.setRowIndex(maxblockEndRowIndex); if (log.isDebugEnabled()) { log.debug("finalBlockRowIndex= " + maxblockEndRowIndex); log.debug("finalBlockColIndex=" + blockEndColIndex); } return parsedReportInfo; } catch (Exception e) { throw new ParseException(tagCell, e); } }
From source file:org.bbreak.excella.reports.tag.BlockRowRepeatParamParser.java
@Override public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException { try {/*w ww.ja va 2 s . c om*/ // ?? Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue()); // ? checkParam(sheet, paramDef, tagCell); ReportsParserInfo reportsParserInfo = (ReportsParserInfo) data; ParamInfo paramInfo = reportsParserInfo.getParamInfo(); // parse? ParsedReportInfo parsedReportInfo = new ParsedReportInfo(); List<Object> resultList = new ArrayList<Object>(); // ? int finalBlockRowIndex = 0; int finalBlockColIndex = 0; String brTagName = paramDef.get(PARAM_VALUE); if (log.isDebugEnabled()) { log.debug("BR??: " + brTagName); } // ????? Object[] paramInfos = getParamData(paramInfo, brTagName); if (paramInfos == null) { return parsedReportInfo; } // ???? List<SingleParamParser> singleParsers = getSingleReplaceParsers(reportsParserInfo); // POJOParamInfo??? List<ParamInfo> paramInfoList = new ArrayList<ParamInfo>(); for (Object obj : paramInfos) { if (obj instanceof ParamInfo) { paramInfoList.add((ParamInfo) obj); continue; } ParamInfo childParamInfo = new ParamInfo(); Map<String, Object> map = PropertyUtils.describe(obj); for (Map.Entry<String, Object> entry : map.entrySet()) { for (ReportsTagParser<?> parser : singleParsers) { childParamInfo.addParam(parser.getTag(), entry.getKey(), entry.getValue()); } } paramInfoList.add(childParamInfo); } // ?? if (paramDef.containsKey(PARAM_MIN_REPEAT_NUM)) { Integer minRepeatNum = Integer.valueOf(paramDef.get(PARAM_MIN_REPEAT_NUM)); if (minRepeatNum > paramInfoList.size()) { int addEmptyRowNum = minRepeatNum - paramInfoList.size(); for (int num = 0; num < addEmptyRowNum; num++) { ParamInfo childParamInfo = new ParamInfo(); paramInfoList.add(childParamInfo); } } } paramInfos = paramInfoList.toArray(new ParamInfo[paramInfoList.size()]); // repeatNum Integer repeatNum = paramInfos.length; if (paramDef.containsKey(PARAM_REPEAT_NUM)) { if (Integer.valueOf(paramDef.get(PARAM_REPEAT_NUM)) < repeatNum) { repeatNum = Integer.valueOf(paramDef.get(PARAM_REPEAT_NUM)); } } // duplicateParams ???????? Map<String, Object> unduplicableParamMap = new HashMap<String, Object>(); if (paramDef.containsKey(PARAM_DUPLICATE)) { String[] params = paramDef.get(PARAM_DUPLICATE).split(";"); for (String param : params) { for (ReportsTagParser<?> parser : singleParsers) { param = parser.getTag() + TAG_PARAM_PREFIX + param + TAG_PARAM_SUFFIX; unduplicableParamMap.put(param, ""); } } } // removeTag boolean removeTag = false; if (paramDef.containsKey(PARAM_REMOVE_TAG)) { removeTag = Boolean.valueOf(paramDef.get(PARAM_REMOVE_TAG)); } // int tagCellRowIndex = tagCell.getRowIndex(); int tagCellColIndex = tagCell.getColumnIndex(); // fromCell String fromCellParamDef = paramDef.get(PARAM_FROM_CELL); int[] fromCellPosition = ReportsUtil.getCellIndex(fromCellParamDef, PARAM_FROM_CELL); int defaultFromCellRowIndex = tagCellRowIndex + fromCellPosition[0]; int defaultFromCellColIndex = tagCellColIndex + fromCellPosition[1]; // toCell String toCellParamDef = paramDef.get(PARAM_TO_CELL); int[] toCellPosition = ReportsUtil.getCellIndex(toCellParamDef, PARAM_TO_CELL); int defaultToCellRowIndex = tagCellRowIndex + toCellPosition[0]; int defaultToCellColIndex = tagCellColIndex + toCellPosition[1]; // Object[][] blockCellValues = ReportsUtil.getBlockCellValue(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellStyle[][] blockCellStyles = ReportsUtil.getBlockCellStyle(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); CellType[][] blockCellTypes = ReportsUtil.getBlockCellType(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); float[] rowHeight = ReportsUtil.getRowHeight(sheet, defaultFromCellRowIndex, defaultToCellRowIndex); // ??? CellRangeAddress[] margedCells = ReportsUtil.getMargedCells(sheet, defaultFromCellRowIndex, defaultToCellRowIndex, defaultFromCellColIndex, defaultToCellColIndex); // ? final int defaultBlockHeight = defaultToCellRowIndex - defaultFromCellRowIndex + 1; final int defaultBlockWidth = defaultToCellColIndex - defaultFromCellColIndex + 1; int rowlen = defaultBlockHeight; int collen = defaultBlockWidth; // ??(fromCell??, 1?????) int blockStartRowIndex = defaultFromCellRowIndex; int blockStartColIndex = defaultFromCellColIndex; int blockEndRowIndex = defaultToCellRowIndex; int blockEndColIndex = defaultToCellColIndex; int maxblockEndRowIndex = blockEndRowIndex; parsedReportInfo.setDefaultRowIndex(defaultToCellRowIndex); parsedReportInfo.setDefaultColumnIndex(defaultToCellColIndex); for (int repeatCount = 0; repeatCount < repeatNum; repeatCount++) { // ???? if (repeatCount > 0) { blockStartRowIndex = blockEndRowIndex + 1; blockEndRowIndex = blockStartRowIndex + rowlen - 1; CellRangeAddress rangeAddress = new CellRangeAddress(blockStartRowIndex, blockEndRowIndex, blockStartColIndex, PoiUtil.getLastColNum(sheet)); PoiUtil.insertRangeDown(sheet, rangeAddress); if (log.isDebugEnabled()) { log.debug(""); log.debug(" : " + blockStartRowIndex + ":" + (blockStartRowIndex + rowlen - 1) + ":" + blockStartColIndex + ":" + PoiUtil.getLastColNum(sheet)); } // ??? // ??????????? // ?????? int targetRowNum = maxblockEndRowIndex - (defaultFromCellRowIndex - 1); for (CellRangeAddress address : margedCells) { // ??? + BR?? - BR? // ??? + BR?? - BR? // ???(BR????????) // ???(BR????????) int firstRowNum = address.getFirstRow() + targetRowNum; int lastRowNum = address.getLastRow() + targetRowNum; int firstColumnNum = address.getFirstColumn(); int lastColumnNum = address.getLastColumn(); CellRangeAddress copyAddress = new CellRangeAddress(firstRowNum, lastRowNum, firstColumnNum, lastColumnNum); sheet.addMergedRegion(copyAddress); } } if (log.isDebugEnabled()) { log.debug("repeatCount = " + repeatCount); log.debug("blockStartRowIndex = " + blockStartRowIndex); log.debug("blockStartColIndex = " + blockStartColIndex); } // ?? if (log.isDebugEnabled()) { log.debug("?????? =" + repeatCount); } for (int rowIdx = 0; rowIdx < defaultBlockHeight; rowIdx++) { // ? Row row = sheet.getRow(blockStartRowIndex + rowIdx); // ??null??????????????? if (row == null && !ReportsUtil.isEmptyRow(blockCellTypes[rowIdx], blockCellValues[rowIdx], blockCellStyles[rowIdx])) { row = sheet.createRow(blockStartRowIndex + rowIdx); } if (row != null) { // ??? row.setHeightInPoints(rowHeight[rowIdx]); // ? for (int colIdx = 0; colIdx < defaultBlockWidth; colIdx++) { // ? Cell cell = row.getCell(blockStartColIndex + colIdx); // ?? CellType cellType = blockCellTypes[rowIdx][colIdx]; // ?? Object cellValue = blockCellValues[rowIdx][colIdx]; // ?? CellStyle cellStyle = blockCellStyles[rowIdx][colIdx]; // ????????????????? if (cell == null && !ReportsUtil.isEmptyCell(cellType, cellValue, cellStyle)) { cell = row.createCell(blockStartColIndex + colIdx); } // if (cell != null) { // ? cell.setCellType(cellType); // ?? PoiUtil.setCellValue(cell, cellValue); // ?? if (cellStyle == null) { log.info("Cell Style at [" + rowIdx + "," + colIdx + "] is not available. Skipping setCellValue()"); } else { cell.setCellStyle(cellStyle); } log.debug("row=" + (blockStartRowIndex + rowIdx) + " col" + (blockStartColIndex + colIdx) + ">>>>>>" + blockCellValues[rowIdx][colIdx]); } } } } int currentBlockHeight = rowlen; int currentBlockWidth = collen; // ????????? int plusRowNum = 0; // ????????? int plusColNum = 0; collen = defaultBlockWidth; // // ??? for (int targetRow = blockStartRowIndex; targetRow < blockStartRowIndex + rowlen + plusRowNum; targetRow++) { if (finalBlockRowIndex < targetRow) { finalBlockRowIndex = targetRow; } if (sheet.getRow(targetRow) == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " : row is not available. continued..."); } continue; } for (int targetCol = blockStartColIndex; targetCol <= blockStartColIndex + collen + plusColNum - 1; targetCol++) { if (finalBlockColIndex < targetCol) { finalBlockColIndex = targetCol; } Cell targetCell = sheet.getRow(targetRow).getCell(targetCol); if (targetCell == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " : cell is not available. continued..."); } continue; } // ?? TagParser<?> parser = reportsParserInfo.getMatchTagParser(sheet, targetCell); if (parser == null) { if (log.isDebugEnabled()) { log.debug("row=" + targetRow + " col=" + targetCol + " parser is not available. continued..."); } continue; } String targetCellTag = targetCell.getStringCellValue(); if (log.isDebugEnabled()) { log.debug("########## row=" + targetRow + " col=" + targetCol + " =" + targetCellTag + " ##########"); } // ParsedReportInfo result = (ParsedReportInfo) parser.parse(sheet, targetCell, reportsParserInfo.createChildParserInfo((ParamInfo) paramInfos[repeatCount])); resultList.add(result.getParsedObject()); // ??? plusRowNum += result.getRowIndex() - result.getDefaultRowIndex(); // ??? plusColNum += result.getColumnIndex() - result.getDefaultColumnIndex(); int additionalHeight = result.getRowIndex() - result.getDefaultRowIndex(); int additionalWidth = result.getColumnIndex() - result.getDefaultColumnIndex(); // ?????????? currentBlockHeight = currentBlockHeight + additionalHeight; currentBlockWidth = currentBlockWidth + additionalWidth; // ??? if (parser instanceof SingleParamParser) { if (unduplicableParamMap.containsKey(targetCellTag)) { if (unduplicableParamMap.get(targetCellTag).equals(result.getParsedObject())) { PoiUtil.setCellValue(targetCell, ""); } else { unduplicableParamMap.put(targetCellTag, result.getParsedObject()); } } } // ?????????????? if (defaultFromCellColIndex != result.getDefaultColumnIndex() && result.getRowIndex() > result.getDefaultRowIndex() && blockStartColIndex < targetCol) { CellRangeAddress preRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), blockStartColIndex, targetCol - 1); PoiUtil.insertRangeDown(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + blockStartColIndex + ":" + (targetCol - 1)); } } // R?????? if (parser instanceof RowRepeatParamParser && result.getRowIndex() > result.getDefaultRowIndex()) { CellRangeAddress rearRangeAddress = new CellRangeAddress(blockEndRowIndex + 1, blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex()), result.getDefaultColumnIndex() + 1, PoiUtil.getLastColNum(sheet)); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + (blockEndRowIndex + 1) + ":" + (blockEndRowIndex + (result.getRowIndex() - result.getDefaultRowIndex())) + ":" + (result.getDefaultColumnIndex() + 1) + ":" + PoiUtil.getLastColNum(sheet)); } } blockEndRowIndex += result.getRowIndex() - result.getDefaultRowIndex(); if (parser instanceof BlockColRepeatParamParser || parser instanceof BlockRowRepeatParamParser) { collen += result.getColumnIndex() - result.getDefaultColumnIndex(); plusColNum -= result.getColumnIndex() - result.getDefaultColumnIndex(); } // ???????? if (blockStartColIndex + collen + plusColNum - 1 > blockEndColIndex) { int beforeLastColIndex = blockEndColIndex; blockEndColIndex = blockStartColIndex + collen + plusColNum - 1; // ??????????? CellRangeAddress preRangeAddress = new CellRangeAddress(tagCell.getRowIndex(), targetRow - 1, beforeLastColIndex + 1, blockEndColIndex); PoiUtil.insertRangeRight(sheet, preRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("1 : " + tagCell.getRowIndex() + ":" + (targetRow - 1) + ":" + (beforeLastColIndex + 1) + ":" + blockEndColIndex); } } // ? } // ?????? if (blockStartColIndex + collen + plusColNum - 1 < blockEndColIndex) { CellRangeAddress rearRangeAddress = new CellRangeAddress(targetRow, targetRow, blockStartColIndex + collen + plusColNum, blockEndColIndex); PoiUtil.insertRangeRight(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("******"); log.debug("2 : " + targetRow + ":" + targetRow + ":" + (blockStartColIndex + collen + plusColNum) + ":" + blockEndColIndex); } } plusColNum = 0; // ? } // ??????? int lastColNum = PoiUtil.getLastColNum(sheet); if ((maxblockEndRowIndex + 1) <= blockEndRowIndex && (blockEndColIndex + 1) <= lastColNum) { CellRangeAddress rearRangeAddress = new CellRangeAddress(maxblockEndRowIndex + 1, blockEndRowIndex, blockEndColIndex + 1, lastColNum); PoiUtil.insertRangeDown(sheet, rearRangeAddress); if (log.isDebugEnabled()) { log.debug("2 : " + (maxblockEndRowIndex + 1) + ":" + blockEndRowIndex + ":" + (blockEndColIndex + 1) + ":" + lastColNum); } } maxblockEndRowIndex = blockEndRowIndex; } // if (removeTag) { tagCell.setCellType(CellType.BLANK); } // ?? parsedReportInfo.setColumnIndex(finalBlockColIndex); parsedReportInfo.setRowIndex(finalBlockRowIndex); parsedReportInfo.setParsedObject(resultList); parsedReportInfo.setDefaultRowIndex(defaultToCellRowIndex); parsedReportInfo.setDefaultColumnIndex(defaultToCellColIndex); if (log.isDebugEnabled()) { log.debug("finalBlockRowIndex= " + finalBlockRowIndex); log.debug("finalBlockColIndex=" + finalBlockColIndex); } return parsedReportInfo; } catch (Exception e) { throw new ParseException(tagCell, e); } }
From source file:org.bbreak.excella.reports.util.ReportsUtil.java
/** * ?????????????<BR>/*www. j a v a 2s.com*/ * * <pre> * ? * ??:??? * * $R[]:? * $C: * $:??? * ??????????:????$:??? * * ($BR[]?$BC[])?.???? * ????? * ??:???.??:???.??:??? * * $BR[]:.$R[]: * $BR[]:.?? * </pre> * * @param info * @param propertyNameString ? * @param parsers ? * @return ???? */ public static List<Object> getParamValues(ParamInfo info, String propertyNameString, List<ReportsTagParser<?>> parsers) { String[] levels = propertyNameString.split("\\."); List<Object> paramValues = new ArrayList<Object>(); ParamInfo[] paramInfos = new ParamInfo[] { info }; for (String level : levels) { String tagName = null; String propertyName = null; if (level.indexOf(":") != -1) { // ? String[] values = level.split(":"); tagName = values[0]; propertyName = values[1]; } else { // ?????? tagName = SingleParamParser.DEFAULT_TAG; propertyName = level; } List<SingleParamParser> singleParsers = new ArrayList<SingleParamParser>(); for (ReportsTagParser<?> reportsParser : parsers) { if (reportsParser instanceof SingleParamParser) { singleParsers.add((SingleParamParser) reportsParser); } } // ???? ReportsTagParser<?> targetParser = null; for (ReportsTagParser<?> tagParser : parsers) { if (tagParser.getTag().equals(tagName)) { targetParser = tagParser; } } if (targetParser == null) { // ?? break; } // ?? Object object = null; for (ParamInfo paramInfo : paramInfos) { object = targetParser.getParamData(paramInfo, propertyName); if (object != null) { break; } } if (object != null) { if (object instanceof ParamInfo[]) { // $BR[],$BC[] List<ParamInfo> newParamInfos = new ArrayList<ParamInfo>(); for (ParamInfo paramInfo : paramInfos) { ParamInfo[] params = (ParamInfo[]) targetParser.getParamData(paramInfo, propertyName); if (params != null) { newParamInfos.addAll(Arrays.asList(params)); } } paramInfos = newParamInfos.toArray(new ParamInfo[newParamInfos.size()]); } else if (object.getClass().isArray()) { if (Array.getLength(object) == 0) { continue; } if (Array.get(object, 0) instanceof String || Array.get(object, 0) instanceof Number || Array.get(object, 0) instanceof Date || Array.get(object, 0) instanceof Boolean) { // $R[],$C[] for (ParamInfo paramInfo : paramInfos) { Object arrayObj = targetParser.getParamData(paramInfo, propertyName); if (arrayObj != null) { for (int i = 0; i < Array.getLength(arrayObj); i++) { paramValues.add(Array.get(arrayObj, i)); } } } } else { // $BR[],$BC[] List<ParamInfo> newParamInfos = new ArrayList<ParamInfo>(); for (ParamInfo paramInfo : paramInfos) { Object[] params = (Object[]) targetParser.getParamData(paramInfo, propertyName); // POJOParamInfo??? for (Object obj : params) { if (obj instanceof ParamInfo) { newParamInfos.add((ParamInfo) obj); continue; } ParamInfo childParamInfo = new ParamInfo(); Map<String, Object> map = null; try { map = PropertyUtils.describe(obj); } catch (Exception e) { throw new RuntimeException( "????????", e); } for (Map.Entry<String, Object> entry : map.entrySet()) { for (ReportsTagParser<?> parser : singleParsers) { childParamInfo.addParam(parser.getTag(), entry.getKey(), entry.getValue()); } } newParamInfos.add(childParamInfo); } } paramInfos = newParamInfos.toArray(new ParamInfo[newParamInfos.size()]); } } else if (object instanceof Collection<?>) { for (ParamInfo paramInfo : paramInfos) { Collection<?> collection = (Collection<?>) targetParser.getParamData(paramInfo, propertyName); if (collection != null) { paramValues.addAll(collection); } } } else { // $,$I for (ParamInfo paramInfo : paramInfos) { Object value = targetParser.getParamData(paramInfo, propertyName); if (value != null) { paramValues.add(value); } } } } } return paramValues; }
From source file:org.beanfuse.model.EntityUtils.java
/** * <pre>// w ww .j av a 2 s .c o m * merge???(orig)????.? * ?????.?component ?entity? * ?id?0,???null. * * ?????.???(Set)? * ?????(hibernate)? * orig??dest added at * ? * </pre> * * @deprecated * @see EntityUtil#evictEmptyProperty * @param dest * @param orig * ?dest */ public static void merge(Object dest, Object orig) { String attr = ""; try { Set attrs = PropertyUtils.describe(orig).keySet(); attrs.remove("class"); for (Iterator it = attrs.iterator(); it.hasNext();) { attr = (String) it.next(); if (!PropertyUtils.isWriteable(orig, attr)) { continue; } Object value = PropertyUtils.getProperty(orig, attr); if (null != value) { if (value instanceof Component) { Object savedValue = PropertyUtils.getProperty(dest, attr); if (null == savedValue) { PropertyUtils.setProperty(dest, attr, value); } else { merge(savedValue, value); } } else if (value instanceof Collection) { continue; } else if (value instanceof Entity) { Serializable key = (Serializable) PropertyUtils.getProperty(value, ((Entity) value).key()); if (null == key) { continue; } else if (new EmptyKeyPredicate().evaluate(key)) { PropertyUtils.setProperty(dest, attr, null); } else { PropertyUtils.setProperty(dest, attr, value); } } else { PropertyUtils.setProperty(dest, attr, value); } } } } catch (Exception e) { logger.error("meger error", e); if (logger.isDebugEnabled()) { logger.debug( "error occur in reflection of attr:" + attr + " of entity " + dest.getClass().getName()); } return; } }
From source file:org.beanfuse.query.ConditionUtils.java
/** * ????<br>//from w w w.j a v a 2 s . co m * ????"?"(?component)<br> * :null,Collection * * @param alias * @param entity * @param mode * @return */ public static List extractConditions(String alias, final Entity entity) { if (null == entity) { return Collections.EMPTY_LIST; } final List conditions = new ArrayList(); StringBuilder aliasBuilder = new StringBuilder(alias == null ? "" : alias); if (aliasBuilder.length() > 0 && !alias.endsWith(".")) { aliasBuilder.append("."); } String attr = ""; try { final Map beanMap = PropertyUtils.describe(entity); for (final Iterator iter = beanMap.keySet().iterator(); iter.hasNext();) { attr = (String) iter.next(); // ??? if (!PropertyUtils.isWriteable(entity, attr)) { continue; } final Object value = PropertyUtils.getProperty(entity, attr); if (null == value) { continue; } if (!(value instanceof Collection)) { addAttrCondition(conditions, alias + attr, value); } } } catch (Exception e) { logger.debug("error occur in extractConditions for bean {} with attr named {}", entity, attr); } return conditions; }
From source file:org.beanfuse.query.ConditionUtils.java
private static List extractComponent(final String prefix, final Component component) { if (null == component) { return Collections.EMPTY_LIST; }//from ww w . j av a 2 s . co m final List conditions = new ArrayList(); String attr = ""; try { final Map beanMap = PropertyUtils.describe(component); for (final Iterator iter = beanMap.keySet().iterator(); iter.hasNext();) { attr = (String) iter.next(); if ("class".equals(attr)) { continue; } if (!PropertyUtils.isWriteable(component, attr)) { continue; } final Object value = PropertyUtils.getProperty(component, attr); if (value == null) { continue; } else if (value instanceof Collection) { if (((Collection) value).isEmpty()) { continue; } } else { addAttrCondition(conditions, prefix + "." + attr, value); } } } catch (Exception e) { logger.warn("error occur in extractComponent of component:" + component + "with attr named :" + attr); } return conditions; }
From source file:org.beangle.model.persist.hibernate.CriterionUtils.java
/** * ??.<br>//from w ww. ja va 2 s . co m * component???<br> * componentmap??component.attr?. * * @param entity * ,null,map. * @param mode * ??like * @return */ public static Map<String, Object> getParamsMap(Entity<?> entity, MatchMode mode) { if (null == entity) { return Collections.EMPTY_MAP; } Map<String, Object> datas = CollectUtils.newHashMap(); String attr = ""; try { Map<String, Object> beanMap = PropertyUtils.describe(entity); for (Iterator<String> iter = beanMap.keySet().iterator(); iter.hasNext();) { attr = iter.next(); Object value = PropertyUtils.getProperty(entity, attr); if (value == null) { continue; } else { addTrivialAttr(datas, attr, value, mode); if (value instanceof Entity) { String key = "id"; value = PropertyUtils.getProperty(entity, attr + "." + key); if (ValidEntityKeyPredicate.getInstance().evaluate(value)) { datas.put(attr + "." + key, value); } } } } return datas; } catch (Exception e) { logger.error("[converToMap]:error occur in converToMap of bean" + entity + "with attr named " + attr, e); } return Collections.emptyMap(); }