List of usage examples for org.springframework.web.context WebApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
/** * ? ?? .</br>? ??//from w w w . j a va2s . com * org.codelabor.system.file.FileConstants.FILE_LIST_KEY? attribute? * ??. Map Id? ? Map Id * org.codelabor.system.file.FileConstants.MAP_ID? attribute? ??. * * @param mapping * * @param form * ? * @param request * * @param response * ? * @return ? * @throws Exception * */ public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); IdGenService mapIdGenService = (IdGenService) ctx.getBean("sequenceMapIdGenService"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String mapId = (String) paramMap.get("mapId"); String repositoryType = (String) paramMap.get("repositoryType"); List<FileDTO> fileDTOList = null; if (StringUtils.isEmpty(repositoryType)) { if (StringUtils.isEmpty(mapId)) { fileDTOList = fileManager.selectFileAll(); } else { fileDTOList = fileManager.selectFileByMapId(mapId); } } else { switch (RepositoryType.valueOf(repositoryType)) { case DATABASE: fileDTOList = fileManager.selectFileByRepositoryType(RepositoryType.DATABASE); break; case FILE_SYSTEM: fileDTOList = fileManager.selectFileByRepositoryType(RepositoryType.FILE_SYSTEM); break; default: logger.error("Invalid repository type: {}", repositoryType); throw new InvalidRepositoryTypeException(repositoryType); } } request.setAttribute(FileConstants.MAP_ID, mapIdGenService.getNextStringId()); request.setAttribute(FileConstants.FILE_LIST_KEY, fileDTOList); return mapping.findForward("list"); }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
/** * ? .</br>? ?? ? Id ? fileID ?? DTO * org.codelabor.system.file.FileConstants.FILE_KEY? attribute? ??. * /* w w w .j a v a 2 s. c o m*/ * @param mapping * * @param form * ? * @param request * * @param response * ? * @return ? * @throws Exception * */ public ActionForward read(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); String fileId = request.getParameter("fileId"); FileDTO fileDTO = fileManager.selectFileByFileId(fileId); request.setAttribute(FileConstants.FILE_KEY, fileDTO); return mapping.findForward("read"); }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
/** * ?? .</br> ? ? ?? ? , (: ?) ? mapId . ? * ?? ? repositoryType , ?//from w w w . j a va2 s .c o m * org.codelabor.system.file.RepositoryType . * * @param mapping * * @param form * ? * @param request * * @param response * ? * @return ? * @throws Exception * */ public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); PropertiesService propertiesService = (PropertiesService) ctx.getBean("propertiesService"); // get parameter String repositoryType = request.getParameter("repositoryType"); if (repositoryType == null) { repositoryType = propertiesService.getString("file.default.real.repository.type", "FILE_SYSTEM"); } RepositoryType.valueOf(repositoryType); logger.debug("repositoryType: {}", repositoryType); // get form FileUploadForm uploadForm = (FileUploadForm) form; List<FormFile> formFileList = uploadForm.getFormFileList(); String mapId = uploadForm.getMapId(); logger.debug("formFileList: {}", formFileList); logger.debug("mapId: {}", mapId); // upload List<FileDTO> fileDTOList = this.saveFile(RepositoryType.valueOf(repositoryType), mapId, formFileList); // invoke manager int affectedRowCount = fileManager.insertFile(fileDTOList); request.setAttribute(AFFECTED_ROW_COUNT, affectedRowCount); // forward return mapping.findForward("upload"); }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
/** * ?? ./* w w w. j a v a 2 s. c om*/ * * @param repositoryType * ? ? * @param mapId * Map Id * @param formFile * ? ? * @return ? DTO * @throws Exception * */ protected FileDTO saveFile(RepositoryType repositoryType, String mapId, FormFile formFile) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); PropertiesService propertiesService = (PropertiesService) ctx.getBean("propertiesService"); IdGenService uniqueFilenameGenerationService = (IdGenService) ctx .getBean("uniqueFilenameGenerationService"); // set file properties String realFilename = formFile.getFileName(); int fileSize = formFile.getFileSize(); String contentType = formFile.getContentType(); InputStream inputStream = formFile.getInputStream(); String uniqueFilename = uniqueFilenameGenerationService.getNextStringId(); // set configuration String repositoryPath = propertiesService.getString("file.default.real.repository.path", System.getProperty("user.dir")); // set dto FileDTO fileDTO = new FileDTO(); fileDTO.setMapId(mapId); fileDTO.setRealFilename(realFilename); fileDTO.setUniqueFilename(uniqueFilename); fileDTO.setFileSize(fileSize); fileDTO.setContentType(contentType); fileDTO.setRepositoryPath(repositoryPath); logger.debug(fileDTO.toString()); UploadUtils.processFile(repositoryType, inputStream, fileDTO); return fileDTO; }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
/** * ?? .</br> ?? ? Id ? fileId . * org.codelabor.system.daos.AFFECTED_ROW_COUNT? attribute? ??. * /* www . j a v a 2 s. co m*/ * @param mapping * * @param form * ? * @param request * * @param args * ? * @return ? * @throws Exception * */ public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse args) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); int affectedRowCount = 0; if (form != null) { FileUploadForm uploadForm = (FileUploadForm) form; String[] fileIdList = uploadForm.getFileId(); affectedRowCount = fileManager.deleteFileByFileId(fileIdList); request.setAttribute(AFFECTED_ROW_COUNT, affectedRowCount); } return mapping.findForward("delete"); }
From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java
public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServlet().getServletContext()); FileManager fileManager = (FileManager) ctx.getBean("fileManager"); Map<String, Object> paramMap = RequestUtils.getParameterMap(request); logger.debug("paramMap: {}", paramMap.toString()); String fileId = (String) paramMap.get("fileId"); StringBuilder sb = new StringBuilder(); FileDTO fileDTO;// ww w. j av a2s . c o m fileDTO = fileManager.selectFileByFileId(fileId); logger.debug("fileDTO: {}", fileDTO); String repositoryPath = fileDTO.getRepositoryPath(); String uniqueFilename = fileDTO.getUniqueFilename(); String realFilename = fileDTO.getRealFilename(); InputStream inputStream = null; if (StringUtils.isNotEmpty(repositoryPath)) { // FILE_SYSTEM sb.setLength(0); sb.append(repositoryPath); if (!repositoryPath.endsWith(File.separator)) { sb.append(File.separator); } sb.append(uniqueFilename); File file = new File(sb.toString()); inputStream = new FileInputStream(file); } else { // DATABASE byte[] bytes = new byte[] {}; if (fileDTO.getFileSize() > 0) { bytes = fileDTO.getBytes(); } inputStream = new ByteArrayInputStream(bytes); } response.setContentType(fileDTO.getContentType()); // set response contenttype, header String encodedRealFilename = URLEncoder.encode(realFilename, "UTF-8"); logger.debug("realFilename: {}", realFilename); logger.debug("encodedRealFilename: {}", encodedRealFilename); logger.debug("character encoding: {}", response.getCharacterEncoding()); logger.debug("content type: {}", response.getContentType()); logger.debug("bufferSize: {}", response.getBufferSize()); logger.debug("locale: {}", response.getLocale()); BufferedInputStream bufferdInputStream = new BufferedInputStream(inputStream); ServletOutputStream servletOutputStream = response.getOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(servletOutputStream); int bytesRead; byte buffer[] = new byte[2048]; while ((bytesRead = bufferdInputStream.read(buffer)) != -1) { bufferedOutputStream.write(buffer, 0, bytesRead); } // flush stream bufferedOutputStream.flush(); // close stream inputStream.close(); bufferdInputStream.close(); servletOutputStream.close(); bufferedOutputStream.close(); return null; }
From source file:org.egov.collection.web.actions.receipts.AjaxReceiptCreateAction.java
/** * This method is accessed from challan.js and MiscReceipts.js * * @return//from w w w .j a va 2s . com * @throws Exception */ @Action(value = "/receipts/ajaxReceiptCreate-ajaxValidateDetailCodeNew") public String ajaxValidateDetailCodeNew() throws Exception { final String code = parameters.get("code")[0]; final String index = parameters.get(INDEX)[0]; final String codeorname = parameters.get("codeorname")[0]; final Accountdetailtype adt = (Accountdetailtype) getPersistenceService().find(accountDetailTypeQuery, Integer.valueOf(parameters.get(DETAILTYPEID)[0])); if (adt == null) { value = index + "~" + ERROR + "#"; return RESULT; } final String table = adt.getFullQualifiedName(); final Class<?> service = Class.forName(table); String simpleName = service.getSimpleName(); simpleName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1) + "Service"; final WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(ServletActionContext.getServletContext()); final EntityTypeService entityService = (EntityTypeService) wac.getBean(simpleName); entityList = (List<EntityType>) entityService.filterActiveEntities(code, 10, adt.getId()); if (entityList == null || entityList.isEmpty()) value = index + "~" + ERROR + "#"; else { if (entityList.size() > 1) {// To Check with same code/name if more than one entity is returned value = index + "~" + ERROR + "#"; return RESULT; } for (final EntityType entity : entityList) if (entity == null) { value = index + "~" + ERROR + "#"; break; } else if (codeorname.equalsIgnoreCase("both")) {// To Check if // both name // and code has // to be // compared if (entity.getName().equals(code) || entity.getCode().equals(code)) { value = index + "~" + entity.getEntityId() + "~" + entity.getName() + "~" + entity.getCode(); break; } else value = index + "~" + ERROR + "#"; } else if (entity.getCode().equals(code)) {// In case of view // mode, to get the // details from the // code value = index + "~" + entity.getEntityId() + "~" + entity.getName() + "~" + entity.getCode(); break; } else value = index + "~" + ERROR + "#"; } return RESULT; }
From source file:org.egov.collection.web.actions.receipts.AjaxReceiptCreateAction.java
@Action(value = "/receipts/ajaxReceiptCreate-getCodeNew") public String getCodeNew() throws Exception { value = "";/*from w w w. j a v a 2 s. c o m*/ final String detailTypeId = parameters.get("detailTypeId")[0]; final String filterKey = parameters.get("filterKey")[0]; final Integer accountDetailTypeId = Integer.valueOf(detailTypeId); final Accountdetailtype adt = (Accountdetailtype) getPersistenceService().find(accountDetailTypeQuery, accountDetailTypeId); if (adt == null) return RESULT; final String table = adt.getFullQualifiedName(); final Class<?> service = Class.forName(table); String simpleName = service.getSimpleName(); simpleName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1) + "Service"; final WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(ServletActionContext.getServletContext()); final EntityTypeService entityService = (EntityTypeService) wac.getBean(simpleName); final List<EntityType> tempEntityList = (List<EntityType>) entityService.filterActiveEntities(filterKey, -1, adt.getId()); entityList = new ArrayList<EntityType>(); for (final EntityType e : tempEntityList) { if (e.getName().contains("@") || e.getName().contains("#") || e.getName().contains("$") || e.getName().contains("%") || e.getName().contains("^") || e.getName().contains("&") || e.getName().contains("*")) e.getName().replace("@", " ").replace("#", " ").replace("$", " ").replace("%", " ") .replace("^", " ").replace("&", " ").replace("*", " "); entityList.add(e); } return "entities"; }
From source file:org.egov.egf.web.actions.payment.DirectBankPaymentAction.java
@ValidationErrorPage(value = NEW) @SkipValidation//from w ww . j a v a2 s. c om public String nonBillPayment() { voucherHeader = persistenceService.getSession().load(CVoucherHeader.class, voucherHeader.getId()); final String vName = voucherHeader.getName(); String appconfigKey = ""; if (vName.equalsIgnoreCase(FinancialConstants.JOURNALVOUCHER_NAME_CONTRACTORJOURNAL)) appconfigKey = "worksBillPurposeIds"; else if (vName.equalsIgnoreCase(FinancialConstants.JOURNALVOUCHER_NAME_SUPPLIERJOURNAL)) appconfigKey = "purchaseBillPurposeIds"; else if (vName.equalsIgnoreCase(FinancialConstants.JOURNALVOUCHER_NAME_SALARYJOURNAL)) appconfigKey = "salaryBillPurposeIds"; final AppConfigValues appConfigValues = appConfigValuesService .getConfigValuesByModuleAndKey(FinancialConstants.MODULE_NAME_APPCONFIG, appconfigKey).get(0); final String purposeValue = appConfigValues.getValue(); final CGeneralLedger netPay = (CGeneralLedger) persistenceService.find( "from CGeneralLedger where voucherHeaderId.id=? and glcodeId.purposeId=?", voucherHeader.getId(), purposeValue); if (netPay == null) throw new ValidationException(Arrays.asList(new ValidationError( "net.payable.not.selected.or.selected.wrongly", "Either Net payable code is not selected or wrongly selected in voucher .Payment creation Failed"))); billDetailslist = new ArrayList<VoucherDetails>(); subLedgerlist = new ArrayList<VoucherDetails>(); final VoucherDetails vd = new VoucherDetails(); vd.setGlcodeDetail(netPay.getGlcode()); vd.setGlcodeIdDetail(netPay.getGlcodeId().getId()); vd.setAccounthead(netPay.getGlcodeId().getName()); vd.setDebitAmountDetail(BigDecimal.valueOf(netPay.getCreditAmount())); if (netPay.getFunctionId() != null) { vd.setFunctionIdDetail(Long.valueOf(netPay.getFunctionId())); final CFunction function = persistenceService.getSession().load(CFunction.class, Long.valueOf(netPay.getFunctionId())); vd.setFunctionDetail(function.getId().toString()); } commonBean.setAmount(BigDecimal.valueOf(netPay.getCreditAmount())); billDetailslist.add(vd); final Set<CGeneralLedgerDetail> generalLedgerDetails = netPay.getGeneralLedgerDetails(); final int i = 0; for (final CGeneralLedgerDetail gldetail : generalLedgerDetails) { final VoucherDetails vdetails = new VoucherDetails(); vdetails.setSubledgerCode(netPay.getGlcode()); vdetails.setAmount(gldetail.getAmount()); // vdetails.setDebitAmountDetail(vdetails.getAmount()); vdetails.setGlcodeDetail(netPay.getGlcode()); vdetails.setGlcode(netPay.getGlcodeId()); vdetails.setSubledgerCode(netPay.getGlcode()); vdetails.setAccounthead(netPay.getGlcodeId().getName()); final Accountdetailtype detailType = persistenceService.getSession().load(Accountdetailtype.class, gldetail.getDetailTypeId()); vdetails.setDetailTypeName(detailType.getName()); vdetails.setDetailType(detailType); vdetails.setDetailKey(gldetail.getDetailKeyId().toString()); vdetails.setDetailKeyId(gldetail.getDetailKeyId()); final String table = detailType.getFullQualifiedName(); Class<?> service; try { service = Class.forName(table); } catch (final ClassNotFoundException e1) { LOGGER.error(e1.getMessage(), e1); throw new ValidationException( Arrays.asList(new ValidationError("application.error", "application.error"))); } String simpleName = service.getSimpleName(); // simpleName=simpleName.toLowerCase()+"Service"; simpleName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1) + "Service"; final WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(ServletActionContext.getServletContext()); final PersistenceService entityPersistenceService = (PersistenceService) wac.getBean(simpleName); String dataType = ""; try { final Class aClass = Class.forName(table); final java.lang.reflect.Method method = aClass.getMethod("getId"); dataType = method.getReturnType().getSimpleName(); } catch (final Exception e) { throw new ApplicationRuntimeException(e.getMessage()); } EntityType entity = null; if (dataType.equals("Long")) entity = (EntityType) entityPersistenceService .findById(Long.valueOf(gldetail.getDetailKeyId().toString()), false); else entity = (EntityType) entityPersistenceService.findById(gldetail.getDetailKeyId(), false); vdetails.setDetailCode(entity.getCode()); vdetails.setDetailName(entity.getName()); vdetails.setDetailKey(entity.getName()); if (i == 0) commonBean.setPaidTo(entity.getName()); subLedgerlist.add(vdetails); } if (subLedgerlist.size() == 0) subLedgerlist.add(new VoucherDetails()); loadAjaxedDropDowns(); return NEW; }
From source file:org.egov.egf.web.actions.voucher.CommonAction.java
@SuppressWarnings("unchecked") @Action(value = "/voucher/common-ajaxLoadEntites") public String ajaxLoadEntites() throws ClassNotFoundException { if (LOGGER.isDebugEnabled()) LOGGER.debug("Starting ajaxLoadEntites..."); if (accountDetailType == null) entitiesList = new ArrayList<EntityType>(); else {//w w w . j av a 2s .c om final Accountdetailtype detailType = (Accountdetailtype) persistenceService .find("from Accountdetailtype where id=? order by name", accountDetailType); final String table = detailType.getFullQualifiedName(); final Class<?> service = Class.forName(table); String simpleName = service.getSimpleName(); simpleName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1) + "Service"; final WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(ServletActionContext.getServletContext()); final EntityTypeService entityService = (EntityTypeService) wac.getBean(simpleName); entitiesList = (List<EntityType>) entityService.getAllActiveEntities(accountDetailType); } if (LOGGER.isDebugEnabled()) LOGGER.debug("Completed ajaxLoadEntites."); return "entities"; }