List of usage examples for org.apache.commons.lang StringUtils trimToNull
public static String trimToNull(String str)
Removes control characters (char <= 32) from both ends of this String returning null
if the String is empty ("") after the trim or if it is null
.
From source file:com.zimbra.cs.servlet.ContextPathBasedThreadPoolBalancerFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { suspendMs = DEFAULT_SUSPEND_MS;//from w w w. j a va 2 s . c o m String str = StringUtils.trimToNull(filterConfig.getInitParameter(SUSPEND_INIT_PARAM)); if (str != null) { suspendMs = Integer.parseInt(str); } str = StringUtils.trimToNull(filterConfig.getInitParameter(RULES_INIT_PARAM)); parse(str); ZimbraLog.misc.info("Initialized with %s", str); ThreadPool threadPool = JettyMonitor.getThreadPool(); if (threadPool instanceof QueuedThreadPool) { queuedThreadPool = (QueuedThreadPool) threadPool; ZimbraLog.misc.info("Thread pool was configured to max=" + queuedThreadPool.getMaxThreads()); } }
From source file:ips1ap101.lib.base.util.ObjUtils.java
public static String toString(Object o) { if (o == null) { return null; } else if (invalidUIInput(o)) { return null; } else if (o instanceof Checkbox) { return trimToNull(((Checkbox) o).getSelected()); } else if (o instanceof DropDown) { return trimToNull(((DropDown) o).getSelected()); } else if (o instanceof TextField) { return trimToNull(((TextField) o).getText()); } else if (o instanceof PasswordField) { return trimToNull(((PasswordField) o).getPassword()); } else if (o instanceof CampoArchivo) { return StringUtils.trimToNull(((CampoArchivo) o).getServerFileName()); } else if (o instanceof CampoArchivoMultiPart) { return StringUtils.trimToNull(((CampoArchivoMultiPart) o).getServerFileName()); } else if (o instanceof RecursoCodificable) { return StringUtils.trimToNull(((RecursoCodificable) o).getCodigoRecurso()); } else if (o instanceof RecursoNombrable) { return StringUtils.trimToNull(((RecursoNombrable) o).getNombreRecurso()); } else if (o instanceof RecursoIdentificable) { Long id = ((RecursoIdentificable) o).getIdentificacionRecurso(); return id == null ? null : id.toString(); } else if (o instanceof RecursoEnumerable) { Integer numero = ((RecursoEnumerable) o).getNumeroRecurso(); return numero == null ? null : numero.toString(); }/*from w w w.ja v a 2s .co m*/ return o.toString(); }
From source file:mitm.common.util.URIUtils.java
/** * Tries to create a URI out of the string. It first tries to create a URI directly. If that fails * it tries to URI encode the string and then create the URI. * @param identifier/*from www. j a va 2 s . c om*/ * @return */ public static URI toURI(String identifier, boolean encode) throws URISyntaxException { identifier = StringUtils.trimToNull(identifier); if (identifier == null) { return null; } URI uri = null; try { uri = new URI(identifier); } catch (URISyntaxException e) { logger.debug("Not a valid URI. Trying encoded version. Identifier: " + identifier); if (!encode) { throw e; } /* * try to URI encode the string */ try { identifier = URIUtil.encodePathQuery(identifier); } catch (URIException urie) { throw new CausableURISyntaxException(identifier, urie.getMessage(), urie); } uri = new URI(identifier); } return uri; }
From source file:com.bluexml.side.util.deployer.war.WarDeployer.java
public String getWebappName() { if (webappName == null) { try {/*from w w w. ja v a 2s . com*/ webappName = getGenerationParameters().get(webappKeyName); if (StringUtils.trimToNull(webappName) == null) { webappName = webappDefaultName; } } catch (NullPointerException e) { new Exception("getWebappName() MUST be called after initialize() !", e); } } return webappName; }
From source file:com.hmsinc.epicenter.integrator.service.event.AdmitService.java
public Admit handleEvent(HL7Message message, PatientDetail details) throws Exception { Validate.notNull(message);//from w w w. j av a 2s . c om Validate.notNull(details); // Make sure we have a patientId if (details.getPatient().getPatientId() == null) { throw new IncompleteDataException("No patient ID in message.", IncompleteDataType.PATIENT_ID); } final Admit admit = new Admit(); configureInteraction(message, admit, details); Validate.isTrue(message.getMessage() instanceof ADT_A01); final ADT_A01 adt = (ADT_A01) message.getMessage(); // Visit number (PV1-19) - REQUIRED FOR ADMIT admit.setVisitNumber(StringUtils.trimToNull(adt.getPV1().getVisitNumber().getIDNumber().getValue())); if (admit.getVisitNumber() == null) { throw new IncompleteDataException("No visit number in message.", IncompleteDataType.VISIT_NUMBER); } // Check for an existing record final Long existingId = healthRepository.findExistingAdmit(admit); if (existingId != null) { throw new DuplicateDataException("Admit already exists.", existingId); } // Admit date admit.setInteractionDate(extractDate(adt.getPV1().getAdmitDateTime().getTime(), message)); // ICD9 Codes admit.setIcd9(extractICD9Codes(adt)); // Diagnosis - use DG1 first, and PV2-3 if blank. final String diagnosis = extractDiagnosis(adt); if (diagnosis != null && isValidComplaint(diagnosis)) { admit.setReason(diagnosis); } else { admit.setReason(extractReason(adt)); } if (admit.getReason() == null && admit.getIcd9() == null) { throw new IncompleteDataException("No admit reason or ICD9 code provided.", IncompleteDataType.REASON); } if (logger.isDebugEnabled()) { logger.debug(admit.toString()); } return admit; }
From source file:com.hmsinc.epicenter.integrator.service.event.RegistrationService.java
public Registration handleEvent(HL7Message message, PatientDetail details) throws Exception { Validate.notNull(message);/*from ww w . j a va2 s . co m*/ Validate.notNull(details); Validate.isTrue(message.getMessage() instanceof ADT_A01, "Message should be an ADT_A01 structure, but was: " + message.getMessage().getClass().getName()); final ADT_A01 adt = (ADT_A01) message.getMessage(); Registration registration = new Registration(); configureInteraction(message, registration, details); // Visit number registration.setVisitNumber(StringUtils.trimToNull(adt.getPV1().getVisitNumber().getIDNumber().getValue())); // Admit date registration.setInteractionDate(extractDate(adt.getPV1().getAdmitDateTime().getTime(), message)); // Admit reason (try both component 1 and 2) final String reason = extractReason(adt); if (reason != null && isValidComplaint(reason)) { registration.setReason(reason); } // ICD9 Codes registration.setIcd9(extractICD9Codes(adt)); // Use ICD9 Description if no registrationReason if (registration.getReason() == null) { registration.setReason(extractDiagnosis(adt)); } if (registration.getReason() == null && registration.getIcd9() == null) { throw new IncompleteDataException("No registration reason or ICD9 code provided.", IncompleteDataType.REASON); } if (logger.isDebugEnabled()) { logger.debug(registration.toString()); } return registration; }
From source file:mitm.common.mail.MessageIDCreator.java
private String getHostname() { String hostname = null;//www. ja v a2 s. c o m InetAddress localHost = null; try { localHost = InetAddress.getLocalHost(); if (localHost != null) { hostname = StringUtils.trimToNull(localHost.getHostName()); } } catch (Exception e) { /* * Can happen if the name of the host is invalid */ logger.debug("Error getting localhost", e); } if (hostname == null) { hostname = "localhost"; } return hostname; }
From source file:com.bluexml.xforms.actions.SubmitAction.java
@Override protected void afterSubmit() throws ServletException { String url = StringUtils.trimToNull(initParams.get(MsgId.PARAM_NEXT_PAGE_SUBMIT.getText())); if (url == null) { // #1656 // there may be something specified in the Xtension property of this form url = controller.getXtensionNextPageSubmit(currentPage.getFormName(), currentPage.getFormType()); }/*from ww w .j a v a2s .c o m*/ // if in search mode, a specific processing applies if (isSearching()) { if (logger.isDebugEnabled()) { logger.debug("Redirecting after search mode or search form"); logger.debug(" --> targetURL:'" + url + "'"); logger.debug(" --> search string:'" + transactionId + "'"); } if (StringUtils.trimToNull(url) == null) { throw new ServletException("No next page was provided for this search."); } String nextPageURL = url; nextPageURL += (url.indexOf('?') == -1) ? "?" : "&"; nextPageURL += "search=" + transactionId; super.redirectClient(nextPageURL); return; } String elementId = transaction.getIds().get(transactionId); String extActionResultURL = null; // persist data id Page currentPage = navigationPath.peekCurrentPage(); currentPage.setDataId(elementId); currentPage.setNode(null); // call external action if any if (initParams != null) { String className = StringUtils.trimToNull(initParams.get(MsgId.PARAM_ACTION_NAME.getText())); if ((className != null) && !(className.equals("null"))) { extActionResultURL = callExternalAction(className); } } if (StringUtils.trimToNull(extActionResultURL) != null) { super.redirectClient(extActionResultURL); } else { if (StringUtils.trimToNull(url) != null) { url = buildRedirectionUrlWithParams(url, currentPage); super.redirectClient(url); } else { // go to previous page restorePrevPage(navigationPath, elementId); setSubmissionDefaultLocation(getServletURL(), result); } } }
From source file:com.opengamma.web.position.WebPositionResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML)// w w w.j av a2s .c om public Response putHTML(@FormParam("quantity") String quantityStr) { PositionDocument doc = data().getPosition(); if (doc.isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", ""); BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr) : null; if (quantity == null) { FlexiBean out = createRootData(); if (quantityStr == null) { out.put("err_quantityMissing", true); } else { out.put("err_quantityNotNumeric", true); } String html = getFreemarker().build(HTML_DIR + "position-update.ftl", out); return Response.ok(html).build(); } URI uri = updatePosition(doc, quantity, null); return Response.seeOther(uri).build(); }
From source file:de.willuhn.jameica.hbci.server.KontoauszugPdfUtil.java
/** * Liefert das File-Objekt fuer diesen Kontoauszug. * Wenn er direkt im Filesystem gespeichert ist, wird dieses geliefert. * Wurde er jedoch per Messaging gespeichert, dann ruft die Funktion ihn * vom Archiv ab und erzeugt eine Temp-Datei mit dem Kontoauszug. * @param ka der Kontoauszug.// w w w. ja va 2s. co m * @return die Datei. * @throws ApplicationException */ public static File getFile(Kontoauszug ka) throws ApplicationException { if (ka == null) throw new ApplicationException(i18n.tr("Bitte whlen Sie den zu ffnenden Kontoauszug")); try { // Wenn ein Pfad und Dateiname angegeben ist, dann sollte die Datei // dort auch liegen final String path = StringUtils.trimToNull(ka.getPfad()); final String name = StringUtils.trimToNull(ka.getDateiname()); if (path != null && name != null) { File file = new File(path, name); Logger.info("trying to open pdf file from: " + file); if (!file.exists()) { Logger.error("file does not exist (anymore): " + file); throw new ApplicationException(i18n .tr("Datei \"{0}\" existiert nicht mehr. Wurde sie gelscht?", file.getAbsolutePath())); } if (!file.canRead()) { Logger.error("cannot read file: " + file); throw new ApplicationException(i18n.tr("Datei \"{0}\" nicht lesbar", file.getAbsolutePath())); } return file; } final String uuid = StringUtils.trimToNull(ka.getUUID()); Logger.info("trying to open pdf file using messaging, uuid: " + uuid); // Das kann eigentlich nicht sein. Dann wuerde ja alles fehlen if (uuid == null) throw new ApplicationException(i18n.tr("Ablageort des Kontoauszuges unbekannt")); QueryMessage qm = new QueryMessage(uuid, null); Application.getMessagingFactory().getMessagingQueue("jameica.messaging.get").sendSyncMessage(qm); byte[] data = (byte[]) qm.getData(); if (data == null) { Logger.error("got no data from messaging for uuid: " + uuid); throw new ApplicationException( i18n.tr("Datei existiert nicht mehr im Archiv. Wurde sie gelscht?")); } Logger.info("got " + data.length + " bytes from messaging for uuid: " + uuid); File file = File.createTempFile("kontoauszug-" + RandomStringUtils.randomAlphanumeric(5), ".pdf"); file.deleteOnExit(); OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(file)); IOUtil.copy(new ByteArrayInputStream(data), os); } finally { IOUtil.close(os); } Logger.info("copied messaging data into temp file: " + file); return file; } catch (ApplicationException ae) { throw ae; } catch (Exception e) { Logger.error("unable to open file", e); throw new ApplicationException(i18n.tr("Fehler beim ffnen des Kontoauszuges: {0}", e.getMessage())); } }