List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:mx.edu.um.mateo.activos.dao.impl.ActivoDaoHibernate.java
@Override @SuppressWarnings("unchecked") public void sube(byte[] datos, Usuario usuario, OutputStream out, Integer codigoInicial) { Date inicio = new Date(); int idx = 5;// w w w . ja v a 2 s . c o m int i = 0; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yy"); SimpleDateFormat sdf3 = new SimpleDateFormat("dd-MM-yy"); MathContext mc = new MathContext(16, RoundingMode.HALF_UP); NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(0); nf.setMinimumIntegerDigits(5); Transaction tx = null; try { String ejercicioId = "001-2012"; Map<String, CentroCosto> centrosDeCosto = new HashMap<>(); Map<String, TipoActivo> tipos = new HashMap<>(); Query tipoActivoQuery = currentSession() .createQuery("select ta from TipoActivo ta " + "where ta.empresa.id = :empresaId " + "and ta.cuenta.id.ejercicio.id.idEjercicio = :ejercicioId " + "and ta.cuenta.id.ejercicio.id.organizacion.id = :organizacionId"); log.debug("empresaId: {}", usuario.getEmpresa().getId()); log.debug("ejercicioId: {}", ejercicioId); log.debug("organizacionId: {}", usuario.getEmpresa().getOrganizacion().getId()); tipoActivoQuery.setLong("empresaId", usuario.getEmpresa().getId()); tipoActivoQuery.setString("ejercicioId", ejercicioId); tipoActivoQuery.setLong("organizacionId", usuario.getEmpresa().getOrganizacion().getId()); List<TipoActivo> listaTipos = tipoActivoQuery.list(); for (TipoActivo tipoActivo : listaTipos) { tipos.put(tipoActivo.getCuenta().getId().getIdCtaMayor(), tipoActivo); } log.debug("TIPOS: {}", tipos); Query proveedorQuery = currentSession().createQuery( "select p from Proveedor p where p.empresa.id = :empresaId and p.nombre = :nombreEmpresa"); proveedorQuery.setLong("empresaId", usuario.getEmpresa().getId()); proveedorQuery.setString("nombreEmpresa", usuario.getEmpresa().getNombre()); Proveedor proveedor = (Proveedor) proveedorQuery.uniqueResult(); Query codigoDuplicadoQuery = currentSession() .createQuery("select a from Activo a where a.empresa.id = :empresaId and a.codigo = :codigo"); XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(datos)); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ccostoFantasma = wb.createSheet("CCOSTO-FANTASMAS"); int ccostoFantasmaRow = 0; XSSFSheet sinCCosto = wb.createSheet("SIN-CCOSTO"); int sinCCostoRow = 0; XSSFSheet codigoAsignado = wb.createSheet("CODIGO-ASIGNADO"); int codigoAsignadoRow = 0; XSSFSheet fechaInvalida = wb.createSheet("FECHA-INVALIDA"); int fechaInvalidaRow = 0; XSSFSheet sinCosto = wb.createSheet("SIN-COSTO"); int sinCostoRow = 0; tx = currentSession().beginTransaction(); for (idx = 0; idx <= 5; idx++) { XSSFSheet sheet = workbook.getSheetAt(idx); int rows = sheet.getPhysicalNumberOfRows(); for (i = 2; i < rows; i++) { log.debug("Leyendo pagina {} renglon {}", idx, i); XSSFRow row = sheet.getRow(i); if (row.getCell(0) == null) { break; } String nombreGrupo = row.getCell(0).getStringCellValue().trim(); TipoActivo tipoActivo = tipos.get(nombreGrupo); if (tipoActivo != null) { String cuentaCCosto = row.getCell(2).toString().trim(); if (StringUtils.isNotBlank(cuentaCCosto)) { CentroCosto centroCosto = centrosDeCosto.get(cuentaCCosto); if (centroCosto == null) { Query ccostoQuery = currentSession().createQuery("select cc from CentroCosto cc " + "where cc.id.ejercicio.id.idEjercicio = :ejercicioId " + "and cc.id.ejercicio.id.organizacion.id = :organizacionId " + "and cc.id.idCosto like :idCosto"); ccostoQuery.setString("ejercicioId", ejercicioId); ccostoQuery.setLong("organizacionId", usuario.getEmpresa().getOrganizacion().getId()); ccostoQuery.setString("idCosto", "1.01." + cuentaCCosto); ccostoQuery.setMaxResults(1); List<CentroCosto> listaCCosto = ccostoQuery.list(); if (listaCCosto != null && listaCCosto.size() > 0) { centroCosto = listaCCosto.get(0); } if (centroCosto == null) { XSSFRow renglon = ccostoFantasma.createRow(ccostoFantasmaRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(row.getCell(8).toString()); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); continue; } centrosDeCosto.put(cuentaCCosto, centroCosto); } String poliza = null; switch (row.getCell(4).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: poliza = row.getCell(4).toString(); poliza = StringUtils.removeEnd(poliza, ".0"); log.debug("POLIZA-N: {}", poliza); break; case XSSFCell.CELL_TYPE_STRING: poliza = row.getCell(4).getStringCellValue().trim(); log.debug("POLIZA-S: {}", poliza); break; } Boolean seguro = false; if (row.getCell(5) != null && StringUtils.isNotBlank(row.getCell(5).toString())) { seguro = true; } Boolean garantia = false; if (row.getCell(6) != null && StringUtils.isNotBlank(row.getCell(6).toString())) { garantia = true; } Date fechaCompra = null; if (row.getCell(7) != null) { log.debug("VALIDANDO FECHA"); XSSFCell cell = row.getCell(7); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: log.debug("ES NUMERIC"); if (DateUtil.isCellDateFormatted(cell)) { log.debug("ES FECHA"); fechaCompra = cell.getDateCellValue(); } else if (DateUtil.isCellInternalDateFormatted(cell)) { log.debug("ES FECHA INTERNAL"); fechaCompra = cell.getDateCellValue(); } else { BigDecimal bd = new BigDecimal(cell.getNumericCellValue()); bd = stripTrailingZeros(bd); log.debug("CONVIRTIENDO DOUBLE {} - {}", DateUtil.isValidExcelDate(bd.doubleValue()), bd); fechaCompra = HSSFDateUtil.getJavaDate(bd.longValue(), true); log.debug("Cal: {}", fechaCompra); } break; case Cell.CELL_TYPE_FORMULA: log.debug("ES FORMULA"); CellValue cellValue = evaluator.evaluate(cell); switch (cellValue.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { fechaCompra = DateUtil.getJavaDate(cellValue.getNumberValue(), true); } } } } if (row.getCell(7) != null && fechaCompra == null) { String fechaCompraString; if (row.getCell(7).getCellType() == Cell.CELL_TYPE_STRING) { fechaCompraString = row.getCell(7).getStringCellValue(); } else { fechaCompraString = row.getCell(7).toString().trim(); } try { fechaCompra = sdf.parse(fechaCompraString); } catch (ParseException e) { try { fechaCompra = sdf2.parse(fechaCompraString); } catch (ParseException e2) { try { fechaCompra = sdf3.parse(fechaCompraString); } catch (ParseException e3) { // no se pudo convertir } } } } if (fechaCompra == null) { XSSFRow renglon = fechaInvalida.createRow(fechaInvalidaRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(row.getCell(8).toString()); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); continue; } String codigo = null; switch (row.getCell(8).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: codigo = row.getCell(8).toString(); break; case XSSFCell.CELL_TYPE_STRING: codigo = row.getCell(8).getStringCellValue().trim(); break; } if (StringUtils.isBlank(codigo)) { codigo = nf.format(codigoInicial); XSSFRow renglon = codigoAsignado.createRow(codigoAsignadoRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(codigoInicial); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); codigoInicial++; } else { // busca codigo duplicado if (codigo.contains(".")) { codigo = codigo.substring(0, codigo.lastIndexOf(".")); log.debug("CODIGO: {}", codigo); } codigoDuplicadoQuery.setLong("empresaId", usuario.getEmpresa().getId()); codigoDuplicadoQuery.setString("codigo", codigo); Activo activo = (Activo) codigoDuplicadoQuery.uniqueResult(); if (activo != null) { XSSFRow renglon = codigoAsignado.createRow(codigoAsignadoRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(codigo + "-" + nf.format(codigoInicial)); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); codigo = nf.format(codigoInicial); codigoInicial++; } } String descripcion = null; if (row.getCell(9) != null) { switch (row.getCell(9).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: descripcion = row.getCell(9).toString(); descripcion = StringUtils.removeEnd(descripcion, ".0"); break; case XSSFCell.CELL_TYPE_STRING: descripcion = row.getCell(9).getStringCellValue().trim(); break; default: descripcion = row.getCell(9).toString().trim(); } } String marca = null; if (row.getCell(10) != null) { switch (row.getCell(10).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: marca = row.getCell(10).toString(); marca = StringUtils.removeEnd(marca, ".0"); break; case XSSFCell.CELL_TYPE_STRING: marca = row.getCell(10).getStringCellValue().trim(); break; default: marca = row.getCell(10).toString().trim(); } } String modelo = null; if (row.getCell(11) != null) { switch (row.getCell(11).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: modelo = row.getCell(11).toString(); modelo = StringUtils.removeEnd(modelo, ".0"); break; case XSSFCell.CELL_TYPE_STRING: modelo = row.getCell(11).getStringCellValue().trim(); break; default: modelo = row.getCell(11).toString().trim(); } } String serie = null; if (row.getCell(12) != null) { switch (row.getCell(12).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: serie = row.getCell(12).toString(); serie = StringUtils.removeEnd(serie, ".0"); break; case XSSFCell.CELL_TYPE_STRING: serie = row.getCell(12).getStringCellValue().trim(); break; default: serie = row.getCell(12).toString().trim(); } } String responsable = null; if (row.getCell(13) != null) { switch (row.getCell(13).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: responsable = row.getCell(13).toString(); responsable = StringUtils.removeEnd(responsable, ".0"); break; case XSSFCell.CELL_TYPE_STRING: responsable = row.getCell(13).getStringCellValue().trim(); break; default: responsable = row.getCell(13).toString().trim(); } } String ubicacion = null; if (row.getCell(14) != null) { switch (row.getCell(14).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: ubicacion = row.getCell(14).toString(); ubicacion = StringUtils.removeEnd(ubicacion, ".0"); break; case XSSFCell.CELL_TYPE_STRING: ubicacion = row.getCell(14).getStringCellValue().trim(); break; default: ubicacion = row.getCell(14).toString().trim(); } } BigDecimal costo = null; switch (row.getCell(15).getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: costo = new BigDecimal(row.getCell(15).getNumericCellValue(), mc); log.debug("COSTO-N: {} - {}", costo, row.getCell(15).getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: costo = new BigDecimal(row.getCell(15).toString(), mc); log.debug("COSTO-S: {} - {}", costo, row.getCell(15).toString()); break; case XSSFCell.CELL_TYPE_FORMULA: costo = new BigDecimal( evaluator.evaluateInCell(row.getCell(15)).getNumericCellValue(), mc); log.debug("COSTO-F: {}", costo); } if (costo == null) { XSSFRow renglon = sinCosto.createRow(sinCostoRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(row.getCell(8).toString()); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); continue; } Activo activo = new Activo(fechaCompra, seguro, garantia, poliza, codigo, descripcion, marca, modelo, serie, responsable, ubicacion, costo, tipoActivo, centroCosto, proveedor, usuario.getEmpresa()); this.crea(activo, usuario); } else { XSSFRow renglon = sinCCosto.createRow(sinCCostoRow++); renglon.createCell(0).setCellValue(sheet.getSheetName() + ":" + (i + 1)); renglon.createCell(1).setCellValue(row.getCell(0).toString()); renglon.createCell(2).setCellValue(row.getCell(1).toString()); renglon.createCell(3).setCellValue(row.getCell(2).toString()); renglon.createCell(4).setCellValue(row.getCell(3).toString()); renglon.createCell(5).setCellValue(row.getCell(4).toString()); renglon.createCell(6).setCellValue(row.getCell(5).toString()); renglon.createCell(7).setCellValue(row.getCell(6).toString()); renglon.createCell(8).setCellValue(row.getCell(7).toString()); renglon.createCell(9).setCellValue(row.getCell(8).toString()); renglon.createCell(10).setCellValue(row.getCell(9).toString()); renglon.createCell(11).setCellValue(row.getCell(10).toString()); renglon.createCell(12).setCellValue(row.getCell(11).toString()); renglon.createCell(13).setCellValue(row.getCell(12).toString()); renglon.createCell(14).setCellValue(row.getCell(13).toString()); renglon.createCell(15).setCellValue(row.getCell(14).toString()); renglon.createCell(16).setCellValue(row.getCell(15).toString()); continue; } } else { throw new RuntimeException( "(" + idx + ":" + i + ") No se encontro el tipo de activo " + nombreGrupo); } } } tx.commit(); log.debug("################################################"); log.debug("################################################"); log.debug("TERMINO EN {} MINS", (new Date().getTime() - inicio.getTime()) / (1000 * 60)); log.debug("################################################"); log.debug("################################################"); wb.write(out); } catch (IOException | RuntimeException e) { if (tx != null && tx.isActive()) { tx.rollback(); } log.error("Hubo problemas al intentar pasar datos de archivo excel a BD (" + idx + ":" + i + ")", e); throw new RuntimeException( "Hubo problemas al intentar pasar datos de archivo excel a BD (" + idx + ":" + i + ")", e); } }
From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java
/** * Print debug information on status received from the server *///from w w w . ja v a2 s .c o m public void printServerStatus() { String statusMessageString = ""; if (this.isServerFlagSet(MySQLConstants.SERVER_STATUS_IN_TRANS)) statusMessageString = statusMessageString + "SERVER_STATUS_IN_TRANS | "; if (this.isServerFlagSet(MySQLConstants.SERVER_STATUS_AUTOCOMMIT)) statusMessageString = statusMessageString + "SERVER_STATUS_AUTOCOMMIT | "; if (this.isServerFlagSet(MySQLConstants.SERVER_MORE_RESULTS_EXISTS)) statusMessageString = statusMessageString + "SERVER_MORE_RESULTS_EXISTS | "; if (this.isServerFlagSet(MySQLConstants.SERVER_QUERY_NO_GOOD_INDEX_USED)) statusMessageString = statusMessageString + "SERVER_QUERY_NO_GOOD_INDEX_USED | "; if (this.isServerFlagSet(MySQLConstants.SERVER_QUERY_NO_INDEX_USED)) statusMessageString = statusMessageString + "SERVER_QUERY_NO_INDEX_USED | "; if (this.isServerFlagSet(MySQLConstants.SERVER_STATUS_CURSOR_EXISTS)) statusMessageString = statusMessageString + "SERVER_STATUS_CURSOR_EXISTS | "; if (this.isServerFlagSet(MySQLConstants.SERVER_STATUS_LAST_ROW_SENT)) statusMessageString = statusMessageString + "SERVER_STATUS_LAST_ROW_SENT | "; statusMessageString = StringUtils.removeEnd(statusMessageString, "| "); logger.debug(MessageFormat.format("Server Status= {0}", statusMessageString)); }
From source file:com.gemstone.gemfire.management.internal.cli.GfshParser.java
/** * *///from w ww . ja va 2 s . com public ParseResult parse(String userInput) { GfshParseResult parseResult = null; // First remove the trailing white spaces userInput = StringUtils.stripEnd(userInput, null); if ((ParserUtils.contains(userInput, SyntaxConstants.COMMAND_DELIMITER) && StringUtils.endsWithIgnoreCase(userInput, SyntaxConstants.COMMAND_DELIMITER))) { userInput = StringUtils.removeEnd(userInput, SyntaxConstants.COMMAND_DELIMITER); } try { boolean error = false; CliCommandOptionException coe = null; List<CommandTarget> targets = locateTargets(ParserUtils.trimBeginning(userInput), false); if (targets.size() > 1) { if (userInput.length() > 0) { handleCondition(CliStrings.format( CliStrings.GFSHPARSER__MSG__AMBIGIOUS_COMMAND_0_FOR_ASSISTANCE_USE_1_OR_HINT_HELP, new Object[] { userInput, AbstractShell.completionKeys }), CommandProcessingException.COMMAND_NAME_AMBIGUOUS, userInput); } } else { if (targets.size() == 1) { OptionSet parse = null; List<MethodParameter> parameters = new ArrayList<MethodParameter>(); Map<String, String> paramValMap = new HashMap<String, String>(); CommandTarget commandTarget = targets.get(0); GfshMethodTarget gfshMethodTarget = commandTarget.getGfshMethodTarget(); preConfigureConverters(commandTarget); try { parse = commandTarget.getOptionParser().parse(gfshMethodTarget.getRemainingBuffer()); } catch (CliException ce) { if (ce instanceof CliCommandOptionException) { coe = (CliCommandOptionException) ce; coe.setCommandTarget(commandTarget); parse = coe.getOptionSet(); error = true; } } try { checkOptionSetForValidCommandModes(parse, commandTarget); } catch (CliCommandMultiModeOptionException ce) { error = true; coe = ce; } error = processArguments(parse, commandTarget, paramValMap, parameters, error); error = processOptions(parse, commandTarget, paramValMap, parameters, error); if (!error) { Object[] methodParameters = new Object[parameters.size()]; for (MethodParameter parameter : parameters) { methodParameters[parameter.getParameterNo()] = parameter.getParameter(); } parseResult = new GfshParseResult(gfshMethodTarget.getMethod(), gfshMethodTarget.getTarget(), methodParameters, userInput, commandTarget.getCommandName(), paramValMap); } else { if (coe != null) { logWrapper.fine("Handling exception: " + coe.getMessage()); ExceptionHandler.handleException(coe); // ExceptionHandler.handleException() only logs it on console. // When on member, we need to handle this. if (!CliUtil.isGfshVM()) { handleCondition( CliStrings.format(CliStrings.GFSHPARSER__MSG__INVALID_COMMAND_STRING_0, userInput), coe, CommandProcessingException.COMMAND_INVALID, userInput); } } } } else { String message = CliStrings.format(CliStrings.GFSHPARSER__MSG__COMMAND_0_IS_NOT_VALID, userInput); CommandTarget commandTarget = locateExactMatchingTarget(userInput); if (commandTarget != null) { String commandName = commandTarget.getCommandName(); AvailabilityTarget availabilityIndicator = commandTarget.getAvailabilityIndicator(); message = CliStrings.format(CliStrings.GFSHPARSER__MSG__0_IS_NOT_AVAILABLE_REASON_1, new Object[] { commandName, availabilityIndicator.getAvailabilityDescription() }); } handleCondition(message, CommandProcessingException.COMMAND_INVALID_OR_UNAVAILABLE, userInput); } } } catch (IllegalArgumentException e1) { logWrapper.warning(CliUtil.stackTraceAsString(e1)); } catch (IllegalAccessException e1) { logWrapper.warning(CliUtil.stackTraceAsString(e1)); } catch (InvocationTargetException e1) { logWrapper.warning(CliUtil.stackTraceAsString(e1)); } return parseResult; }
From source file:adalid.commons.velocity.Writer.java
private String getTemplate(File propertiesFile) { String slashedPath;//from w w w . j ava 2 s . c om String shortestPath = null; String propertiesFilePath = propertiesFile.getPath().replace(FILE_SEPARATOR, SLASH); String[] velocityFileResourceLoaderPathArray = VelocityEngineer.getFileResourceLoaderPathArray(); if (velocityFileResourceLoaderPathArray != null && velocityFileResourceLoaderPathArray.length > 0) { for (String path : velocityFileResourceLoaderPathArray) { // slashedPath = path.replace(FILE_SEPARATOR, SLASH); slashedPath = StringUtils.removeEnd(path.replace(FILE_SEPARATOR, SLASH), SLASH) + SLASH; if (StringUtils.startsWithIgnoreCase(propertiesFilePath, slashedPath)) { if (shortestPath == null || slashedPath.length() < shortestPath.length()) { shortestPath = slashedPath; } } } } if (shortestPath == null) { return propertiesFile.getName(); } String template = StringUtils.removeStartIgnoreCase(propertiesFilePath, shortestPath); // return StringUtils.removeStartIgnoreCase(template, SLASH); return template; }
From source file:adalid.commons.util.StrUtils.java
public static String removeWholeWord(String string, String remove, char affixType, String separator) { if (separator == null) { separator = " "; }//from ww w . j a va2s. c o m return string == null || remove == null ? string : affixType == 'p' ? StringUtils.removeStart(string, remove + separator) : affixType == 's' ? StringUtils.removeEnd(string, separator + remove) : StringUtils.replace(string, separator + remove + separator, separator); }
From source file:de.bangl.lm.LotManagerPlugin.java
public String formatPrice(Double price) { String result = ""; result = String.format(Locale.GERMANY, "%.2f", price); result = StringUtils.removeEnd(result, ".00"); result = StringUtils.removeEnd(result, ",00"); result = result + " " + eco.currencyNamePlural(); return result; }
From source file:adalid.core.programmers.AbstractSqlProgrammer.java
private String getSelectColumns(QueryTable queryTable, List<Property> referencedColumns, boolean indent) { String string = EMPTY;//from ww w .j a v a 2s . com String tab = indent ? StringUtils.repeat(TAB$, queryTable.getDepth()) : EMPTY; String name, alias; for (Property p : queryTable.getColumns()) { if (referencedColumns == null || referencedColumns.isEmpty() || referencedColumns.contains(p)) { name = getPropertySqlName(p); alias = getPropertySqlAlias(p, queryTable); string += EOL$ + tab + queryTable.getAlias() + DOT$ + name; if (name.equals(alias)) { } else { string += SPC$ + getAs() + SPC$ + alias; } string += SEP$; } } String s; for (QueryJoin j : queryTable.getJoins()) { s = getSelectColumns(j.getRightTable(), referencedColumns, indent); if (StringUtils.isNotBlank(s)) { string += s + SEP$; } } return StringUtils.removeEnd(string, SEP$); }
From source file:com.bluexml.xforms.controller.alfresco.AlfrescoController.java
/** * Gets the actual data type for a form. Added because read only forms are * distinguished from/*from www . jav a 2 s. co m*/ * R/W forms using a suffix. Hence the form name in itself cannot be used to * designate the * datatype (or "form id" to be more precise). * * @param formName * @return the id of the read-write version of the form */ public String getDataTypeFromFormName(String formName) { String underlyingDataType = formName; String readOnlyFormsSuffix = getReadOnlyFormsSuffix(); if (StringUtils.endsWith(formName, readOnlyFormsSuffix)) { underlyingDataType = StringUtils.removeEnd(formName, readOnlyFormsSuffix); } return underlyingDataType; }
From source file:net.sourceforge.sqlexplorer.plugin.editors.SQLTextEditor.java
/** * DOC qzhang Comment method "createIFile". * // w w w . j av a 2 s. c om * @param monitor * @param file * @param content * @throws CoreException */ private IFile createIFile(IFile file, String content) throws CoreException { // MOD qiongli 2011-4-21.bug 20205 .should create sql file and property.use extension of service mechanism. if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) { ITDQRepositoryService service = (ITDQRepositoryService) GlobalServiceRegister.getDefault() .getService(ITDQRepositoryService.class); if (service != null) { String fName = StringUtils.removeEnd(StringUtils.removeEnd(file.getName(), DEFAULT_FILE_EXTENSION), DEFAULT_VERSION_STRING); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IPath rootPath = new Path("TDQ_Libraries/Source Files"); Item item = service.createFile(content, file.getProjectRelativePath().removeLastSegments(1).makeRelativeTo(rootPath), fName, file.getFileExtension()); // get the correct path(contain version info) for newInput file in editor. IPath location = file.getLocation(); if (item != null && item.getProperty() != null && location != null) { location = location.removeLastSegments(1); StringBuffer strb = new StringBuffer(); strb.append(location.toString()); String version = item.getProperty().getVersion() == null ? "" : "_" + item.getProperty().getVersion(); strb.append(Path.SEPARATOR).append(fName).append(version).append(DEFAULT_FILE_EXTENSION); location = Path.fromOSString(strb.toString()); file = workspace.getRoot().getFileForLocation(location); } } } return file; }
From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String redirectFrom = getRedirectFrom(request); if (RESERVED_REDIRECTS.containsKey(redirectFrom)) { LOG.info("Reserved redirection: " + redirectFrom); return new ModelAndView(new RedirectView(RESERVED_REDIRECTS.get(redirectFrom))); }//from w ww. j av a2 s . c o m Redirection redirection = redirectFrom == null ? null : redirectionDao.getRedirection(redirectFrom); if (redirection == null) { LOG.info("No redirection found: " + redirectFrom); return new ModelAndView(new RedirectView("http://subsonic.org/pages")); } redirection.setLastRead(new Date()); redirection.setReadCount(redirection.getReadCount() + 1); redirectionDao.updateRedirection(redirection); // Check for trial expiration (unless called from REST client for which the Subsonic server manages trial expiry). if (isTrialExpired(redirection) && !isREST(request)) { LOG.info("Expired redirection: " + redirectFrom); return new ModelAndView(new RedirectView("http://subsonic.org/pages/redirect-expired.jsp?redirectFrom=" + redirectFrom + "&expired=" + redirection.getTrialExpires().getTime())); } String requestUrl = getFullRequestURL(request); String to = StringUtils.removeEnd(getRedirectTo(request, redirection), "/"); String redirectTo = requestUrl.replaceFirst("http://" + redirectFrom + "\\.subsonic\\.org", to); LOG.info("Redirecting from " + requestUrl + " to " + redirectTo); return new ModelAndView(new RedirectView(redirectTo)); }