List of usage examples for org.apache.commons.lang3.math NumberUtils toLong
public static long toLong(final String str)
Convert a String
to a long
, returning zero
if the conversion fails.
If the string is null
, zero
is returned.
NumberUtils.toLong(null) = 0L NumberUtils.toLong("") = 0L NumberUtils.toLong("1") = 1L
From source file:com.tacitknowledge.flip.aspectj.converters.LongConverter.java
/** {@inheritDoc } */ public Object convert(String expression, Class outputClass) { return NumberUtils.toLong(expression); }
From source file:io.wcm.dam.assetservice.impl.AssetRequestParser.java
private static List<AssetRequest> getAssetRequestsFromSuffix(String assetPath, SlingHttpServletRequest request) { List<AssetRequest> requests = new ArrayList<>(); String suffixWithoutExtension = StringUtils.substringBefore(request.getRequestPathInfo().getSuffix(), "."); String[] suffixParts = StringUtils.split(suffixWithoutExtension, "/"); if (suffixParts != null) { for (String suffixPart : suffixParts) { Map<String, String> params = parseSuffixPart(suffixPart); String mediaFormat = params.get(RP_MEDIAFORMAT); long width = NumberUtils.toLong(params.get(RP_WIDTH)); long height = NumberUtils.toLong(params.get(RP_HEIGHT)); if (StringUtils.isNotEmpty(mediaFormat) || width > 0 || height > 0) { requests.add(new AssetRequest(assetPath, mediaFormat, width, height)); }/*w w w . ja v a2 s.c om*/ } } return requests; }
From source file:com.xpn.xwiki.web.DeleteAttachmentAction.java
/** * {@inheritDoc}// w ww . j a va 2 s .c o m * * @see com.xpn.xwiki.web.XWikiAction#action(com.xpn.xwiki.XWikiContext) */ @Override public boolean action(XWikiContext context) throws XWikiException { // CSRF prevention if (!csrfTokenCheck(context)) { return false; } XWikiRequest request = context.getRequest(); XWikiResponse response = context.getResponse(); XWikiDocument doc = context.getDoc(); XWikiAttachment attachment = null; XWiki xwiki = context.getWiki(); String filename; // Delete from the trash if (request.getParameter("trashId") != null) { long trashId = NumberUtils.toLong(request.getParameter("trashId")); DeletedAttachment da = xwiki.getAttachmentRecycleBinStore().getDeletedAttachment(trashId, context, true); // If the attachment hasn't been previously deleted (i.e. it's not in the deleted attachment store) then // don't try to delete it and instead redirect to the attachment list. if (da != null) { com.xpn.xwiki.api.DeletedAttachment daapi = new com.xpn.xwiki.api.DeletedAttachment(da, context); if (!daapi.canDelete()) { throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "You are not allowed to delete an attachment from the trash " + "immediately after it has been deleted from the wiki"); } if (!da.getDocName().equals(doc.getFullName())) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, "The specified trash entry does not match the current document"); } // TODO: Add a confirmation check xwiki.getAttachmentRecycleBinStore().deleteFromRecycleBin(trashId, context, true); } sendRedirect(response, Utils.getRedirect("attach", context)); return false; } if (context.getMode() == XWikiContext.MODE_PORTLET) { filename = request.getParameter("filename"); } else { // Note: We use getRequestURI() because the spec says the server doesn't decode it, as // we want to use our own decoding. String requestUri = request.getRequestURI(); filename = Util.decodeURI(requestUri.substring(requestUri.lastIndexOf("/") + 1), context); } XWikiDocument newdoc = doc.clone(); // An attachment can be indicated either using an id, or using the filename. if (request.getParameter("id") != null) { int id = NumberUtils.toInt(request.getParameter("id")); if (newdoc.getAttachmentList().size() > id) { attachment = newdoc.getAttachmentList().get(id); } } else { attachment = newdoc.getAttachment(filename); } // No such attachment if (attachment == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); VelocityContext vcontext = (VelocityContext) context.get("vcontext"); if (vcontext != null) { vcontext.put("message", context.getMessageTool().get("core.action.deleteAttachment.failed", filename)); vcontext.put("details", context.getMessageTool().get("platform.core.action.deleteAttachment.noAttachment")); } return true; } newdoc.setAuthor(context.getUser()); // Set "deleted attachment" as the version comment. ArrayList<String> params = new ArrayList<String>(); params.add(filename); if (attachment.isImage(context)) { newdoc.setComment(context.getMessageTool().get("core.comment.deleteImageComment", params)); } else { newdoc.setComment(context.getMessageTool().get("core.comment.deleteAttachmentComment", params)); } try { newdoc.deleteAttachment(attachment, context); // Needed to counter a side effect: the attachment is deleted from the newdoc.originalDoc as well newdoc.setOriginalDocument(doc); // Also save the document and attachment metadata context.getWiki().saveDocument(newdoc, context); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); VelocityContext vcontext = (VelocityContext) context.get("vcontext"); if (vcontext != null) { vcontext.put("message", context.getMessageTool().get("core.action.deleteAttachment.failed", filename)); vcontext.put("details", ExceptionUtils.getRootCauseMessage(ex)); } return true; } // forward to attach page String redirect = Utils.getRedirect("attach", context); sendRedirect(response, redirect); return false; }
From source file:io.wcm.handler.media.CropDimension.java
/** * Get crop dimension from crop string./*from ww w .j ava 2 s. c o m*/ * Please note: Crop string contains not width/height as 3rd/4th parameter but right, bottom. * @param cropString Cropping string from CQ5 smartimage widget * @return Crop dimension instance * @throws IllegalArgumentException if crop string syntax is invalid */ public static CropDimension fromCropString(String cropString) { if (StringUtils.isEmpty(cropString)) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } // strip off optional size parameter after "/" String crop = cropString; if (StringUtils.contains(crop, "/")) { crop = StringUtils.substringBefore(crop, "/"); } String[] parts = StringUtils.split(crop, ","); if (parts.length != 4) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } long x1 = NumberUtils.toLong(parts[0]); long y1 = NumberUtils.toLong(parts[1]); long x2 = NumberUtils.toLong(parts[2]); long y2 = NumberUtils.toLong(parts[3]); long width = x2 - x1; long height = y2 - y1; if (x1 < 0 || y1 < 0 || width <= 0 || height <= 0) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); } return new CropDimension(x1, y1, width, height); }
From source file:io.wcm.dam.assetservice.impl.AssetRequestParser.java
private static List<AssetRequest> getAssetRequestsFromUrlParams(String assetPath, SlingHttpServletRequest request) { String[] mediaFormats = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_MEDIAFORMAT), new String[0]); String[] widthStrings = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_WIDTH), new String[0]); String[] heightStrings = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_HEIGHT), new String[0]); int maxParamIndex = NumberUtils.max(mediaFormats.length, widthStrings.length, heightStrings.length); List<AssetRequest> requests = new ArrayList<>(); for (int i = 0; i < maxParamIndex; i++) { String mediaFormat = mediaFormats.length > i ? mediaFormats[i] : null; long width = widthStrings.length > i ? NumberUtils.toLong(widthStrings[i]) : 0; long height = heightStrings.length > i ? NumberUtils.toLong(heightStrings[i]) : 0; requests.add(new AssetRequest(assetPath, mediaFormat, width, height)); }/*from w ww .j a v a 2 s . c o m*/ return requests; }
From source file:com.dominion.salud.mpr.negocio.service.integracion.impl.BuzonErroresServiceImpl.java
@Override @Transactional//from ww w . j a v a 2 s .c om public BuzonErrores procesar(BuzonErrores buzonErrores) { logger.debug("PROCESANDO EL REGISTRO DE BUZON_ERRORES: " + buzonErrores.toString()); if (buzonErrores.getBuzonIn() != null) { BuzonIn buzonIn = buzonErrores.getBuzonIn(); logger.debug(" Procesando mensaje de BUZON_IN: " + buzonErrores.getBuzonIn().toString()); switch (buzonIn.getTipo()) { case "ZDS_O13": //Dispensacion buzonIn.setEstado(BuzonErrores.MENSAJE_NO_PROCESADO); buzonInService.save(buzonIn); delete(buzonErrores); break; case "ZFN_M13": //Evaluacion buzonIn.setEstado(BuzonErrores.MENSAJE_NO_PROCESADO); buzonInService.save(buzonIn); delete(buzonErrores); break; case "RAS_O17": //Administracion break; case "OMP_O09": //Prescripcion break; default: logger.error("No se reconoce el formato del mensaje: " + buzonIn.getTipo()); } } else if (buzonErrores.getBuzonOut() != null) { BuzonOut buzonOut = buzonErrores.getBuzonOut(); logger.debug(" Procesando mensaje de BUZON_OUT: " + buzonErrores.getBuzonOut().toString()); switch (buzonOut.getTipo()) { case "ZFN_O13": //Acuerdo if (StringUtils.isNotBlank(buzonErrores.getParametros())) { AcuCentros acuCentros = acuCentrosService .findOne(NumberUtils.toLong(buzonErrores.getParametros())); if (acuCentros != null) { buzonOutService.delete(buzonOut); delete(buzonErrores); acuCentrosService.toBuzonOut(acuCentros); } } else { buzonOut.setEstado(BuzonErrores.MENSAJE_NO_PROCESADO); buzonOutService.save(buzonOut); delete(buzonErrores); } break; default: logger.error("No se reconoce el formato del mensaje: " + buzonOut.getTipo()); } } else { logger.error("No se reconoce el formato del mensaje"); } logger.debug("FINALIZA EL PROCESADO DEL REGISTRO DE BUZON_ERRORES: " + buzonErrores.toString()); return buzonErrores; }
From source file:io.wcm.dam.assetservice.impl.AssetRequestServlet.java
private List<AssetRequest> getAssetRequests(String assetPath, SlingHttpServletRequest request) { String[] mediaFormats = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_MEDIAFORMAT), new String[0]); String[] widthStrings = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_WIDTH), new String[0]); String[] heightStrings = ObjectUtils.defaultIfNull(RequestParam.getMultiple(request, RP_HEIGHT), new String[0]); int maxParamIndex = NumberUtils.max(mediaFormats.length, widthStrings.length, heightStrings.length); List<AssetRequest> requests = new ArrayList<>(); if (maxParamIndex == 0) { requests.add(new AssetRequest(assetPath, null, 0, 0)); } else {/* www . ja va 2 s. c o m*/ for (int i = 0; i < maxParamIndex; i++) { String mediaFormat = mediaFormats.length > i ? mediaFormats[i] : null; long width = widthStrings.length > i ? NumberUtils.toLong(widthStrings[i]) : 0; long height = heightStrings.length > i ? NumberUtils.toLong(heightStrings[i]) : 0; requests.add(new AssetRequest(assetPath, mediaFormat, width, height)); } } return requests; }
From source file:com.dominion.salud.mpr.negocio.report.evaluaciones.impl.AcuEvalResReportImpl.java
/** * * @param parametros//from w ww . j a v a 2s .c o m * @return * @throws com.dominion.salud.mpr.negocio.service.exception.InformeSinDatosException * @throws com.dominion.salud.mpr.negocio.service.exception.InformeException */ @Override public String listadoAcuEvalResReport(Map<String, Object> parametros) throws InformeSinDatosException, InformeException { logger.debug("Generando el listado: " + MPR_LISTADO_RESULTADOS); logger.debug(" Parametros del listado: "); logger.debug(" idAcuerdo: " + parametros.get("idAcuerdo")); logger.debug(" txtAcuerdo: " + parametros.get("txtAcuerdo")); logger.debug(" idCentro: " + parametros.get("idCentro")); logger.debug(" txtCentro: " + parametros.get("txtCentro")); logger.debug(" fecIniEval: " + parametros.get("fecIniEval")); logger.debug(" fecFinEval: " + parametros.get("fecFinEval")); //CONVERSION DE PARAMETROS DE ENTRADA logger.debug(" Iniciando la conversion de parametros para el listado"); SimpleDateFormat ddmmyyyy = new SimpleDateFormat("dd/MM/yyyy"); Date fecIniEval = null; Date fecFinEval = null; try { if (StringUtils.isNoneBlank((String) parametros.get("fecIniEval"))) { logger.debug(" Iniciando la conversion de fecIniEval: " + (String) parametros.get("fecIniEval")); fecIniEval = ddmmyyyy.parse((String) parametros.get("fecIniEval")); logger.debug(" Conversion de fecIniEval: " + (String) parametros.get("fecIniEval") + " realizada correctamente: " + fecIniEval); } } catch (ParseException pe) { logger.warn("No se ha podido parsear fecIniEval: " + parametros.get("fecIniEval")); } try { if (StringUtils.isNoneBlank((String) parametros.get("fecFinEval"))) { logger.debug(" Iniciando la conversion de fecFinEval: " + (String) parametros.get("fecFinEval")); fecFinEval = ddmmyyyy.parse((String) parametros.get("fecFinEval")); logger.debug(" Conversion de fecFinEval: " + (String) parametros.get("fecFinEval") + " realizada correctamente: " + fecFinEval); } } catch (ParseException pe) { logger.warn("No se ha podido parsear fecFinEval: " + parametros.get("fecFinEval")); } Long idCentro = null; if (StringUtils.isNotBlank((String) parametros.get("idCentro"))) { logger.debug(" Iniciando la conversion de idCentro: " + (String) parametros.get("idCentro")); idCentro = NumberUtils.toLong((String) parametros.get("idCentro")); logger.debug(" Conversion de idCentro: " + (String) parametros.get("idCentro") + " realizada correctamente: " + idCentro); } Long idAcuerdo = null; if (StringUtils.isNotBlank((String) parametros.get("idAcuerdo"))) { logger.debug(" Iniciando la conversion de idAcuerdo: " + (String) parametros.get("idAcuerdo")); idAcuerdo = NumberUtils.toLong((String) parametros.get("idAcuerdo")); logger.debug(" Conversion de idAcuerdo: " + (String) parametros.get("idAcuerdo") + " realizada correctamente: " + idAcuerdo); } logger.debug(" Finaliza la conversion de parametros para el listado"); //OBTENCION DE DATOS PARA POBLAR EL LISTADO logger.debug(" Iniciando la obtencion de informacion para el listado"); List<AcuEvalRes> acuEvalReses = new ArrayList<>(); acuEvalReses = acuEvalResService.findListadoAcuEvalRes(idCentro, idAcuerdo, fecIniEval, fecFinEval); logger.debug(" Se han obtenido: " + acuEvalReses.size() + " resultados"); if (acuEvalReses.size() <= 0) { throw new InformeSinDatosException("No se han obtenido resultados"); } logger.debug(" Finaliza la obtencion de informacion para el listado"); //GENERACION DEL INFORME try { logger.debug(" Localizando la plantilla del listado: " + getClass().getClassLoader().getResource(MPR_LISTADO_RESULTADOS)); JasperReport reporte = (JasperReport) JRLoader .loadObject(getClass().getClassLoader().getResource(MPR_LISTADO_RESULTADOS)); logger.debug(" Plantilla del listado localizada correctamente"); logger.debug(" Completando los datos del listado"); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, new JRBeanCollectionDataSource(acuEvalReses)); logger.debug(" Datos del listado completados correctamente"); logger.debug(" Generando el listado en la ubicacion: " + MPRConstantes._MPR_RESOURCES + new Date().getTime() + ".pdf"); String ruta = reportPDFtoFile(jasperPrint, MPRConstantes._MPR_RESOURCES + new Date().getTime() + ".pdf"); logger.debug(" Listado generado correctamente en la ubicacion: " + ruta); logger.debug("Listado: " + MPR_LISTADO_RESULTADOS + " generado correctamente"); return ruta; } catch (Exception e) { throw new InformeException(e); } }
From source file:com.dominion.salud.mpr.negocio.report.tratamientos.impl.DispensacionesReportImpl.java
/** * * @param parametros//from w w w . j a v a 2 s . c o m * @return * @throws com.dominion.salud.mpr.negocio.service.exception.InformeSinDatosException * @throws com.dominion.salud.mpr.negocio.service.exception.InformeException */ @Override public String listadoDispensacionReport(Map<String, Object> parametros) throws InformeSinDatosException, InformeException { logger.debug("Generando el listado: " + MPR_LISTADO_DISPENSACIONES); logger.debug(" Parametros del listado: "); logger.debug(" idAcuerdo: " + parametros.get("idAcuerdo")); logger.debug(" txtAcuerdo: " + parametros.get("txtAcuerdo")); logger.debug(" idCentro: " + parametros.get("idCentro")); logger.debug(" txtCentro: " + parametros.get("txtCentro")); logger.debug(" fecIniDisp: " + parametros.get("fecIniDisp")); logger.debug(" fecFinDisp: " + parametros.get("fecFinDisp")); //CONVERSION DE PARAMETROS DE ENTRADA logger.debug(" Iniciando la conversion de parametros para el listado"); SimpleDateFormat ddmmyyyy = new SimpleDateFormat("dd/MM/yyyy"); Date fecIniDisp = null; Date fecFinDisp = null; try { if (StringUtils.isNoneBlank((String) parametros.get("fecIniDisp"))) { logger.debug(" Iniciando la conversion de fecIniDisp: " + (String) parametros.get("fecIniDisp")); fecIniDisp = ddmmyyyy.parse((String) parametros.get("fecIniDisp")); logger.debug(" Conversion de fecIniDisp: " + (String) parametros.get("fecIniDisp") + " realizada correctamente: " + fecIniDisp); } } catch (ParseException pe) { logger.warn("No se ha podido parsear fecIniDisp: " + parametros.get("fecIniDisp")); } try { if (StringUtils.isNoneBlank((String) parametros.get("fecFinDisp"))) { logger.debug(" Iniciando la conversion de fecFinDisp: " + (String) parametros.get("fecFinDisp")); fecFinDisp = ddmmyyyy.parse((String) parametros.get("fecFinDisp")); logger.debug(" Conversion de fecFinDisp: " + (String) parametros.get("fecFinDisp") + " realizada correctamente: " + fecFinDisp); } } catch (ParseException pe) { logger.warn("No se ha podido parsear fecFinDisp: " + parametros.get("fecFinDisp")); } Long idCentro = null; if (StringUtils.isNotBlank((String) parametros.get("idCentro"))) { logger.debug(" Iniciando la conversion de idCentro: " + (String) parametros.get("idCentro")); idCentro = NumberUtils.toLong((String) parametros.get("idCentro")); logger.debug(" Conversion de idCentro: " + (String) parametros.get("idCentro") + " realizada correctamente: " + idCentro); } Long idAcuerdo = null; if (StringUtils.isNotBlank((String) parametros.get("idAcuerdo"))) { logger.debug(" Iniciando la conversion de idAcuerdo: " + (String) parametros.get("idAcuerdo")); idAcuerdo = NumberUtils.toLong((String) parametros.get("idAcuerdo")); logger.debug(" Conversion de idAcuerdo: " + (String) parametros.get("idAcuerdo") + " realizada correctamente: " + idAcuerdo); } logger.debug(" Finaliza la conversion de parametros para el listado"); //OBTENCION DE DATOS PARA POBLAR EL LISTADO logger.debug(" Iniciando la obtencion de informacion para el listado"); List<Dispensaciones> dispensacioneses = new ArrayList<>(); dispensacioneses = dispensacionesService.findListadoDispensaciones(idCentro, idAcuerdo, fecIniDisp, fecFinDisp); logger.debug(" Se han obtenido: " + dispensacioneses.size() + " resultados"); if (dispensacioneses.size() <= 0) { throw new InformeSinDatosException("No se han obtenido resultados"); } logger.debug(" Finaliza la obtencion de informacion para el listado"); //GENERACION DEL INFORME try { logger.debug(" Localizando la plantilla del listado: " + getClass().getClassLoader().getResource(MPR_LISTADO_DISPENSACIONES)); JasperReport reporte = (JasperReport) JRLoader .loadObject(getClass().getClassLoader().getResource(MPR_LISTADO_DISPENSACIONES)); logger.debug(" Plantilla del listado localizada correctamente"); logger.debug(" Completando los datos del listado"); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, new JRBeanCollectionDataSource(dispensacioneses)); logger.debug(" Datos del listado completados correctamente"); logger.debug(" Generando el listado en la ubicacion: " + MPRConstantes._MPR_RESOURCES + new Date().getTime() + ".pdf"); String ruta = reportPDFtoFile(jasperPrint, MPRConstantes._MPR_RESOURCES + new Date().getTime() + ".pdf"); logger.debug(" Listado generado correctamente en la ubicacion: " + ruta); logger.debug("Listado: " + MPR_LISTADO_DISPENSACIONES + " generado correctamente"); return ruta; } catch (Exception e) { throw new InformeException(e); } }
From source file:com.galenframework.speclang2.pagespec.ForLoop.java
private static Object convertValueToIndex(String stringValue) { if (NumberUtils.isNumber(stringValue)) { return NumberUtils.toLong(stringValue); } else {/*w w w.j av a 2 s .c o m*/ return stringValue; } }