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:de.willuhn.jameica.hbci.gui.dialogs.CSVProfileStoreDialog.java
/** * Liefert einen Namensvorschlag fuer das Profil. * @return Namensvorschlag fuer das Profil. *///from w w w .j a va 2 s .c o m private String suggestName() { // Wir versuchen einen Namensvorschlag fr das Profil zu ermitteln // Hierzu checken wir, ob es mit einer Zahl endet. Wenn ja, erhoehen // wir sie um 1. Wenn nicht, haengen wir "2" hinten dran. String template = this.profile.getName(); int space = template.lastIndexOf(" "); // Checken, ob wir schon eine Nummer im Namen haben if (space > 0) { String s1 = StringUtils.trimToNull(template.substring(0, space)); String s2 = StringUtils.trimToNull(template.substring(space)); if (s1 != null && s2 != null && s2.matches("[0-9]{1,4}")) template = s1; } // Erste freie Nummer suchen for (int i = 2; i < 100; ++i) { boolean found = false; String name = template + " " + i; for (Profile p : this.profiles) { if (name.equals(p.getName())) { found = true; break; } } // wir haben einen passenden Namen gefunden if (!found) return name; } // Ne, dann muss der User selbst einen neuen Namen vergeben return template; }
From source file:ch.entwine.weblounge.test.site.GreeterHTMLAction.java
/** * {@inheritDoc}// w w w . j a v a2 s . c o m * * @see ch.entwine.weblounge.common.impl.site.HTMLActionSupport#configure(ch.entwine.weblounge.common.request.WebloungeRequest, * ch.entwine.weblounge.common.request.WebloungeResponse, * ch.entwine.weblounge.common.request.RequestFlavor) */ @Override public void configure(WebloungeRequest request, WebloungeResponse response, RequestFlavor flavor) throws ActionException { super.configure(request, response, flavor); // Load the greetings Map<String, String> allGreetings = TestSiteUtils.loadGreetings(); try { language = getLanguage(request); greeting = allGreetings.get(language); } catch (IllegalStateException e) { throw new ActionException("Language parameter '" + LANGUAGE_PARAM + "' was not specified"); } // Load the template String codeTemplate = StringUtils.trimToNull(request.getParameter(CODE_TEMPLATE)); if (codeTemplate != null) { PageTemplate t = site.getTemplate(codeTemplate); if (t == null) { logger.warn("Template '{}' does not exist", codeTemplate); } else { logger.info("Setting template to '{}'", codeTemplate); setTemplate(t); } } }
From source file:com.bluexml.xforms.controller.alfresco.AlfrescoTransaction.java
private void initializeBatch() { this.batch = objectFactory.createBatch(); // ** #1365/*from www.j a v a 2s. c o m*/ ServiceRequestSource requesterId = objectFactory.createServiceRequestSource(); requesterId.setId("XFormsController"); batch.getCreateOrUpdateOrDelete().add(requesterId); // ** #1365 String saveToPath; Map<String, String> params = getInitParams(); if (params != null) { // this should always be true saveToPath = params.get(MsgId.PARAM_SAVE_DATA_TO.getText()); if (StringUtils.trimToNull(saveToPath) != null) { batch.setSaveTo(saveToPath); } } }
From source file:mitm.djigzo.web.services.security.InvalidateUserSpringSecurityFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException("HttpServletRequest expected."); }/*from w w w.j a va 2 s. c o m*/ if (!(response instanceof HttpServletResponse)) { throw new ServletException("HttpServletResponse expected."); } HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; String loggedInUserName = null; Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication(); if (loggedInUser != null) { loggedInUserName = loggedInUser.getName(); } if (loggedInUserName != null) { String email = StringUtils.trimToNull(request.getParameter(usernameRequestParameter)); if (email != null) { email = EmailAddressUtils.canonicalize(email); if (!email.equals(loggedInUserName)) { /* * The user has changed, so invalidate session */ HttpSession session = httpServletRequest.getSession(false); if (session != null) { session.invalidate(); } SecurityContextHolder.clearContext(); /* * We need to 'reload' the complete request to make sure the user need to login */ StringBuffer redirectURL = httpServletRequest.getRequestURL(); if (httpServletRequest.getQueryString() != null) { redirectURL.append("?").append(httpServletRequest.getQueryString()); } httpServletResponse.sendRedirect(httpServletResponse.encodeRedirectURL(redirectURL.toString())); return; } } } chain.doFilter(request, response); }
From source file:com.opengamma.web.portfolio.WebPortfolioResource.java
@PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON)// w w w . j av a 2 s . c o m public Response putJSON(@FormParam("name") String name, @FormParam("hidden") Boolean isHidden) { PortfolioDocument doc = data().getPortfolio(); if (doc.isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } name = StringUtils.trimToNull(name); DocumentVisibility visibility = BooleanUtils.isTrue(isHidden) ? DocumentVisibility.HIDDEN : DocumentVisibility.VISIBLE; updatePortfolio(name, visibility, doc); return Response.ok().build(); }
From source file:de.willuhn.jameica.hbci.passports.pintan.ChipTANDialog.java
/** * @see de.willuhn.jameica.hbci.passports.pintan.TANDialog#setText(java.lang.String) *//*from w w w . j av a2 s . com*/ @Override public void setText(String text) { // Ueberschrieben, um den im Fliesstext am Anfang enthaltenen Flicker-Code rauszuschneiden. text = StringUtils.trimToNull(text); if (text != null) { final String token2 = "CHLGTEXT"; // Jetzt checken, ob die beiden Tokens enthalten sind int t1Start = text.indexOf("CHLGUC"); int t2Start = text.indexOf(token2); if (t1Start == -1 || t2Start == -1 || t2Start <= t1Start) { // Ne, nicht enthalten super.setText(text); return; } // Alles bis zum Ende des zweiten Tocken abschneiden text = text.substring(t2Start + token2.length()); // Jetzt noch diese 4-stellige Ziffer abschneiden, die auch noch hinten dran steht. // Aber nur, wenn auch noch relevant Text uebrig ist if (text.length() > 4) { String nums = text.substring(0, 4); if (nums.matches("[0-9]{4}")) text = text.substring(4); } } super.setText(text); return; }
From source file:com.bluexml.xforms.generator.forms.modelelement.ModelElementInstanceList.java
/** * @param bean/*from w w w .ja va 2 s. co m*/ */ private void initFields(AssociationBean bean) { this.formatPattern = bean.getFormatPattern(); this.maxLength = bean.getLabelLength(); this.filterAssoc = bean.getFilterAssoc(); this.isComposition = bean.isComposition(); this.isForSearch = bean.isInFeatureSearchMode(); this.luceneQuery = bean.getLuceneQuery(); this.dataSourceUri = StringUtils.trimToNull(bean.getDataSourceUri()); }
From source file:com.opengamma.web.region.WebRegionResource.java
@POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML)// w w w.j a va 2 s. c o m public Response postHTML(@FormParam("name") String name, @FormParam("fullname") String fullName, @FormParam("classification") String classification, @FormParam("country") String countryISO, @FormParam("currency") String currencyISO, @FormParam("timezone") String timeZoneId) { if (data().getRegion().isLatest() == false) { return Response.status(Status.FORBIDDEN).entity(getHTML()).build(); } name = StringUtils.trimToNull(name); fullName = StringUtils.trimToNull(fullName); countryISO = StringUtils.trimToNull(countryISO); currencyISO = StringUtils.trimToNull(currencyISO); timeZoneId = StringUtils.trimToNull(timeZoneId); RegionClassification regionClassification = safeValueOf(RegionClassification.class, classification); if (name == null || regionClassification == null) { FlexiBean out = createRootData(); if (name == null) { out.put("err_nameMissing", true); } if (regionClassification == null) { out.put("err_classificationMissing", true); } String html = getFreemarker().build(HTML_DIR + "region-add.ftl", out); return Response.ok(html).build(); } if (fullName == null) { fullName = name; } URI uri = addRegion(name, fullName, regionClassification, countryISO, currencyISO, timeZoneId); return Response.seeOther(uri).build(); }
From source file:com.bluexml.xforms.controller.navigation.NavigationPath.java
/** * @param statusMsg/*from ww w.j a va2 s.co m*/ * the status message to set */ public void setStatusMsg(String statusMsg) { String emptyMSG = MsgPool.getMsg(MsgId.MSG_STATUS_EMPTY); if ((StringUtils.trimToNull(statusMsg) == null) || StringUtils.equals(emptyMSG, statusMsg)) { statusIteration = ITERATION_START; } else { if (StringUtils.equals(this.statusMsg, statusMsg)) { statusIteration++; } else { statusIteration = ITERATION_START; } } this.statusMsg = statusMsg; }
From source file:com.github.restdriver.serverdriver.http.Url.java
/** * You can pass this object to all the get/post/put/delete etc methods. * //from w ww .jav a2 s .c om * @return The textual representation of the Url, correctly formatted. */ public final String toString() { String[] baseParts; if (url.toString().contains("://")) { baseParts = url.toString().split("://"); } else { baseParts = new String[] { "http", url.toString() }; } String scheme, ssp, path, query; scheme = baseParts[0]; if (baseParts[1].contains("/")) { ssp = baseParts[1].substring(0, baseParts[1].indexOf("/")); path = baseParts[1].substring(baseParts[1].indexOf("/")); } else { ssp = baseParts[1]; path = ""; } query = StringUtils.trimToNull(StringUtils.join(queryParams, "&")); try { return new URI(scheme, ssp, path, query, null).toASCIIString(); } catch (URISyntaxException use) { // NB not sure how this could get caused... throw new RuntimeUriSyntaxException("Cannot create URL", use); } }