List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n characters from the end of the String.
The returned substring starts with the character in the start position and ends before the end position.
From source file:io.manasobi.license.LicenseController.java
private String convertISODateToDate(Date isoDate) { DateTime dateTime = new DateTime(isoDate); String simpleDate = DateUtils.convertDateToString(dateTime.minusHours(9).toDate(), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z"); simpleDate = StringUtils.replace(simpleDate, "T", " "); simpleDate = StringUtils.remove(simpleDate, "Z"); return StringUtils.substring(simpleDate, 0, 19); }
From source file:com.dominion.salud.nomenclator.negocio.service.impl.farmatools.PpiosTeratoServiceImpl.java
@Override public void autoload() { logger.info("INICIANDO la carga de TERATOGENIAS automatizadas"); Set<String> mensajes = new HashSet<>(); List<AtcTeratogenias> listaAtcTeratogenias = atcTeratogeniasService.findAll(); if (listaAtcTeratogenias != null && !listaAtcTeratogenias.isEmpty()) { logger.debug(" Se han obtenido: " + listaAtcTeratogenias.size() + " TERATOGENIAS"); Iterator<AtcTeratogenias> iteradorAtcTeratogenias = listaAtcTeratogenias.iterator(); int contador = 1; while (iteradorAtcTeratogenias.hasNext()) { logger.debug(/*w w w .jav a2 s. c om*/ " Cargando TERATOGENIA (" + contador + " de " + listaAtcTeratogenias.size() + ")"); AtcTeratogenias atcTeratogenias = iteradorAtcTeratogenias.next(); try { PpiosTerato ppiosTerato = new PpiosTerato(); Practivo practivo = new Practivo(); try { practivo.setCodigo(atcTeratogenias.getAtc().getCodAtc()); practivo = practivoService.findByCodAtc(practivo); ppiosTerato.setIdPpiosTerato(findNextId()); ppiosTerato.setPrActivo(practivo); ppiosTerato.setCategoriaFda(StringUtils.substring(atcTeratogenias.getTxtTeratogenia(), 0, StringUtils.indexOf(atcTeratogenias.getTxtTeratogenia(), "-"))); ppiosTerato.setTrimestre(0); ppiosTerato.setObservaciones(StringUtils.substring(atcTeratogenias.getTxtTeratogenia(), StringUtils.indexOf(atcTeratogenias.getTxtTeratogenia(), "-") + 2)); ppiosTeratoRepository.save(ppiosTerato); logger.debug(" TERATOGENIA creada correctamente: " + ppiosTerato.toString()); } catch (NoResultException nre) { logger.warn(" No se ha encontrado PRACTIVO para el ATC: " + atcTeratogenias.getAtc().toString()); } } catch (Exception e) { logger.error(" No se ha podido generar la TERATOGENIA: " + e.toString()); mensajes.add("No se ha podido generar la INTERACCION: " + e.toString()); } contador++; } } if (!mensajes.isEmpty()) { logger.warn(" Se han producido los siguientes errores en la carga de registros: "); Iterator<String> iteradorMensajes = mensajes.iterator(); while (iteradorMensajes.hasNext()) { logger.warn(" - " + iteradorMensajes.next()); } } logger.info("FINALIZANDO la carga de TERATOGENIAS automatizadas"); }
From source file:de.micromata.genome.db.jpa.logging.entities.BaseLogMasterDO.java
/** * Sets the message.// w ww .j a v a 2 s. co m * * @param message the new message */ public void setMessage(String message) { this.message = StringUtils.substring(message, 0, MAX_LOG_MESSAGE_SIZE); }
From source file:com.norconex.collector.http.data.store.impl.jdbc.JDBCCrawlDataSerializer.java
@Override public Object[] getInsertCrawlDataValues(String table, ICrawlData crawlData) { HttpCrawlData data = (HttpCrawlData) crawlData; return new Object[] { data.getReference(), data.getParentRootReference(), data.isRootParentReference(), data.getState().toString(), data.getMetaChecksum(), data.getContentChecksum(), data.getDepth(), data.getSitemapLastMod(), data.getSitemapChangeFreq(), data.getSitemapPriority(), data.getReferrerReference(), StringUtils.substring(data.getReferrerLinkTag(), 0, TAG_MAX_LENGTH), StringUtils.substring(data.getReferrerLinkText(), 0, TEXT_MAX_LENGTH), StringUtils.substring(data.getReferrerLinkTitle(), 0, TITLE_MAX_LENGTH), }; }
From source file:com.pinterest.teletraan.resource.Builds.java
@GET public List<BuildBean> get(@QueryParam("commit") String scmCommit, @QueryParam("name") String buildName, @QueryParam("branch") String scmBranch, @QueryParam("pageIndex") Optional<Integer> pageIndex, @QueryParam("pageSize") Optional<Integer> pageSize, @QueryParam("before") Long before, @QueryParam("after") Long after) throws Exception { if (!StringUtils.isEmpty(scmCommit)) { return buildDAO.getByCommit7(StringUtils.substring(scmCommit, 0, 7), pageIndex.or(1), pageSize.or(DEFAULT_SIZE)); }// w ww. ja v a 2 s. c o m if (!StringUtils.isEmpty(buildName)) { if (before != null && after != null) { return buildDAO.getByNameDate(buildName, scmBranch, before, after); } else { return buildDAO.getByName(buildName, scmBranch, pageIndex.or(1), pageSize.or(DEFAULT_SIZE)); } } throw new TeletaanInternalException(Response.Status.BAD_REQUEST, "Require either commit id or build name in the request."); }
From source file:com.dominion.salud.nomenclator.negocio.service.impl.farmatools.InteracServiceImpl.java
@Override public void autoload() { logger.info("INICIANDO la carga de INTERACCIONES automatizadas"); Set<String> mensajes = new HashSet<>(); List<AtcInteracciones> listaAtcInteracciones = atcInteraccionesService.findAll(); if (listaAtcInteracciones != null && !listaAtcInteracciones.isEmpty()) { logger.debug(" Se han obtenido: " + listaAtcInteracciones.size() + " INTERACCIONES"); Iterator<AtcInteracciones> iteradorAtcInteracciones = listaAtcInteracciones.iterator(); int contador = 1; while (iteradorAtcInteracciones.hasNext()) { logger.debug(" Cargando INTERACCION (" + contador + " de " + listaAtcInteracciones.size() + ")"); AtcInteracciones atcInteracciones = iteradorAtcInteracciones.next(); try { Interac interac = new Interac(); InteracPK interacPK = new InteracPK(); Practivo practivo1 = new Practivo(); Practivo practivo2 = new Practivo(); try { practivo1.setCodigo(atcInteracciones.getAtc().getCodAtc()); interacPK.setPrActivo1(practivoService.findByCodAtc(practivo1)); practivo2.setCodigo(atcInteracciones.getInteraccion().getCodAtc()); interacPK.setPrActivo2(practivoService.findByCodAtc(practivo2)); interac.setInteracPK(interacPK); interac.setDesNaturaleza(atcInteracciones.getOrientacion()); interac.setDesInterac(atcInteracciones.getEfecto()); interac.setObservacion(StringUtils.substring(atcInteracciones.getDescripcion(), 0, 60)); try { interac = interacRepository.findOne(interac); logger.debug(" Ya existe la INTERACCION: " + interac.toString()); } catch (NoResultException nre) { interacRepository.save(interac); }//from w ww . j ava 2 s. c o m } catch (NoResultException nre) { logger.warn(" No se ha encontrado ATC para el PRINCIPIO ACTIVO " + practivo1.toString() + ": " + nre.toString()); } logger.debug(" INTERACCION creada correctamente"); contador++; } catch (Exception e) { logger.error(" No se ha podido generar la INTERACCION: " + e.toString()); mensajes.add("No se ha podido generar la INTERACCION: " + e.toString()); } } } if (!mensajes.isEmpty()) { logger.warn(" Se han producido los siguientes errores en la carga de registros: "); Iterator<String> iteradorMensajes = mensajes.iterator(); while (iteradorMensajes.hasNext()) { logger.warn(" - " + iteradorMensajes.next()); } } logger.info("FINALIZANDO la carga de INTERACCIONES automatizadas"); }
From source file:com.webbfontaine.valuewebb.action.tt.AttDocFileHandler.java
public String downloadAttachedFile() { TtGen ttGen = TtGenHome.getComponentInstance(true).getInstance(); List<TtDoc> ttDocs = ttGen.getTtDocs(); int itmNumInt = Integer.parseInt(itmNum); if (itmNumInt < ttDocs.size()) { TtDoc ttDoc = ttDocs.get(itmNumInt); String filename = StringUtils.isEmpty(ttDoc.getName()) ? "" : StringUtils.substring(PATTERN.matcher(ttDoc.getName()).replaceAll("_"), 0, 60); Utils.sendBytes(ttDoc.getBytes(), filename + '.' + ttDoc.getContentType(), ttDoc.getContentType()); } else {/*from w w w . j a v a 2 s . c o m*/ InfoHandling.getInstance().setInfoList(Utils.translate("File does not exist")); } return ""; }
From source file:controllers.WidgetAdmin.java
/** * * this method will reset the user's password. * the parameters are cryptic on purpose. * * @param p - the hmac/* www . j a v a 2 s . c o m*/ * @param pi - the user id * @return - */ public static Result resetPasswordAction(String p, Long pi) { User user = User.findById(pi); // validate p if (!ApplicationContext.get().getHmac().compare(p, user.getEmail(), user.getId(), user.getPassword())) { return badRequest(linkExpired.render()); } // if p is valid lets reset the password String newPasswordStr = StringUtils.substring(p, 0, 7); user.encryptAndSetPassword(newPasswordStr); user.save(); return ok(newPassword.render(newPasswordStr)); }
From source file:ca.uhn.fhir.jpa.term.TerminologyLoaderSvc.java
private void dropCircularRefs(TermConcept theConcept, ArrayList<String> theChain, Map<String, TermConcept> theCode2concept, Counter theCircularCounter) { theChain.add(theConcept.getCode());/*from www .jav a 2 s .com*/ for (Iterator<TermConceptParentChildLink> childIter = theConcept.getChildren().iterator(); childIter .hasNext();) { TermConceptParentChildLink next = childIter.next(); TermConcept nextChild = next.getChild(); if (theChain.contains(nextChild.getCode())) { StringBuilder b = new StringBuilder(); b.append("Removing circular reference code "); b.append(nextChild.getCode()); b.append(" from parent "); b.append(next.getParent().getCode()); b.append(". Chain was: "); for (String nextInChain : theChain) { TermConcept nextCode = theCode2concept.get(nextInChain); b.append(nextCode.getCode()); b.append('['); b.append(StringUtils.substring(nextCode.getDisplay(), 0, 20).replace("[", "").replace("]", "") .trim()); b.append("] "); } ourLog.info(b.toString(), theConcept.getCode()); childIter.remove(); nextChild.getParents().remove(next); } else { dropCircularRefs(nextChild, theChain, theCode2concept, theCircularCounter); } } theChain.remove(theChain.size() - 1); }
From source file:com.nhncorp.lucy.security.xss.listener.SecurityUtils.java
/** * @param element//from w ww .ja v a2 s. c o m * @param srcUrl * @param isWhiteUrl * @return */ public static boolean checkVulnerableWithHttp(Element element, String srcUrl, boolean isWhiteUrl, ContentTypeCacheRepo contentTypeCacheRepo) { boolean isVulnerable = false; // embed/object ? (XSSFILTERSUS-109) if (isWhiteUrl) { } else { String type = element.getAttributeValue("type").trim(); type = StringUtils.strip(type, "'\""); if (type != null && !"".equals(type)) { //? type ?? if (!(isAllowedType(type) || props.values().contains(type))) { isVulnerable = true; } } else { //? ? String url = StringUtils.strip(srcUrl, "'\""); String extension = getExtension(url); if (StringUtils.containsAny(extension, specialCharArray)) { int pos = StringUtils.indexOfAny(extension, specialCharArray); if (pos != -1) { extension = StringUtils.substring(extension, 0, pos); } } if (StringUtils.isEmpty(extension)) { // ? MIME TYPE ? ? , url ? head HTTP Method ? content-type ? type = getContentTypeFromUrlConnection(url, contentTypeCacheRepo); //? type ?? if (!isAllowedType(type)) { isVulnerable = true; } else { element.putAttribute("type", "\"" + type + "\""); } } else { type = getTypeFromExtension(extension); if (StringUtils.isEmpty(type)) { type = props.getProperty(extension); if (type != null) { type = type.trim(); } } //? type ?? if (StringUtils.isEmpty(type)) { isVulnerable = true; } else { element.putAttribute("type", "\"" + type + "\""); } } } } return isVulnerable; }