List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty
public static String trimToEmpty(final String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .
From source file:com.widowcrawler.terminator.parse.Parser.java
private String sitemapRefIdentifier() { //System.out.println("sitemapRefIdentifier()"); int start = dataPtr; while (!isEndOfFile() && !isCommentStart() && !isEndline() && !isWhitespace()) { next();/*w w w. jav a2s . c o m*/ } String url = StringUtils.trimToEmpty(data.substring(start, dataPtr)); whitespace(); return url; }
From source file:de.micromata.genome.gwiki.controls.GWikiLoginActionBean.java
public Object onResetPassword() { checkPublicRegister();//from w w w .j a v a 2 s.c om if (allowPasswortForgotten == false) { return null; } passwordForgottenUser = StringUtils.trimToEmpty(passwordForgottenUser); if (StringUtils.isEmpty(passwordForgottenUser) == true) { wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.userneeded"); return null; } String userId = "admin/user/" + passwordForgottenUser; GWikiElement el = wikiContext.getWikiWeb().findElement(userId); if (el == null) { GLog.note(GWikiLogCategory.Wiki, "Passwort reset requested for unknown user: " + passwordForgottenUser); wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.emailsent"); // wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.unkownuser"); return null; } GWikiArtefakt<?> art = el.getPart(""); if ((art instanceof GWikiPropsArtefakt) == false) { GWikiLog.warn("No Valid user, cann not determine email. User: " + passwordForgottenUser); wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.noemail"); return null; } GWikiPropsArtefakt userP = (GWikiPropsArtefakt) art; String email = userP.getStorageData().get("email"); if (StringUtils.isBlank(email) == true) { return null; } String newPass = genPassword(); String crypedPass = GWikiSimpleUserAuthorization.encrypt(newPass); userP.getStorageData().put("password", crypedPass); wikiContext.getWikiWeb().saveElement(wikiContext, el, false); try { sendPasswordToUser(wikiContext, passwordForgottenUser, email, newPass); wikiContext.addValidationError("gwiki.page.admin.Login.message.resetpassw.emailsent"); } catch (Exception ex) { GWikiLog.warn("Cannot send reset password: " + ex.getMessage(), ex); wikiContext.addValidationError("gwiki.page.admin.RegisterUser.message.unabletosend"); } return null; }
From source file:kenh.expl.Environment.java
/** * Remove a function package.//from w ww . j a v a 2s . c o m * @param key The key of function package * @param funcPackage * @return true, if both key and function package are matching. */ public boolean removeFunctionPackage(String key, String funcPackage) { if (StringUtils.isBlank(key)) return false; if (StringUtils.isBlank(funcPackage)) return false; key = StringUtils.trimToEmpty(key); funcPackage = StringUtils.trimToEmpty(funcPackage); if (functionPackages.containsKey(key)) { String p = functionPackages.get(key); if (p.equals(funcPackage)) { functionPackages.remove(key); return true; } else return false; } else { return true; } }
From source file:com.moviejukebox.tools.PropertiesUtil.java
/** * Convert the value to a Long//from w ww . ja v a2s . c o m * * @param key * @param valueToConvert * @param defaultValue * @return */ private static long convertLongProperty(String valueToConvert, long defaultValue) { return NumberUtils.toLong(StringUtils.trimToEmpty(valueToConvert), defaultValue); }
From source file:gov.ca.cwds.data.persistence.cms.BaseSubstituteCareProvider.java
/** * @return the lisPersonId */ public String getLisPersonId() { return StringUtils.trimToEmpty(lisPersonId); }
From source file:com.norconex.collector.http.crawler.event.impl.URLStatusCrawlerEventListener.java
private void writeLine(String referrer, String url, String status, String cause, boolean append) { try (FileWriter out = new FileWriter(outputFile, append)) { out.write(StringUtils.trimToEmpty(referrer)); out.write('\t'); out.write(StringUtils.trimToEmpty(url)); out.write('\t'); out.write(StringUtils.trimToEmpty(status)); out.write('\t'); out.write(StringUtils.trimToEmpty(cause)); out.write('\n'); } catch (IOException e) { throw new CollectorException("Cannot write link report to file: " + outputFile, e); }/*from ww w . ja v a 2 s.com*/ }
From source file:gov.ca.cwds.data.persistence.cms.BaseSubstituteCareProvider.java
/** * @return the middleInitialName */ public String getMiddleInitialName() { return StringUtils.trimToEmpty(middleInitialName); }
From source file:com.moviejukebox.tools.PropertiesUtil.java
/** * Convert the value to a Integer//from w w w . jav a 2 s . com * * @param key * @param valueToConvert * @param defaultValue * @return */ private static int convertIntegerProperty(String valueToConvert, int defaultValue) { return NumberUtils.toInt(StringUtils.trimToEmpty(valueToConvert), defaultValue); }
From source file:com.erudika.scoold.controllers.QuestionsController.java
@PostMapping({ "/questions/space/{space}", "/questions/space" }) public String setSpace(@PathVariable(required = false) String space, HttpServletRequest req, HttpServletResponse res) {//from www . ja v a 2 s . co m Profile authUser = utils.getAuthUser(req); if (authUser != null) { if (StringUtils.isBlank(space) || pc.read(utils.getSpaceId(space)) == null) { if (utils.canAccessSpace(authUser, space)) { authUser.getSpaces().remove(space); authUser.update(); } } space = StringUtils.trimToEmpty(space); setRawCookie(SPACE_COOKIE, space, req, res, false, StringUtils.isBlank(space) ? 0 : 365 * 24 * 60 * 60); } res.setStatus(200); return "base"; }
From source file:com.jiangyifen.ec2.ui.mgr.system.tabsheet.SystemLicence.java
/** * added by chb 20140520/*from w ww .j a v a2 s. co m*/ * @return */ private VerticalLayout updateLicenseComponent() { VerticalLayout licenseUpdateLayout = new VerticalLayout(); final VerticalLayout textAreaPlaceHolder = new VerticalLayout(); final HorizontalLayout buttonPlaceHolder = new HorizontalLayout(); buttonPlaceHolder.setSpacing(true); // final Button updateButton = new Button("License"); updateButton.setData("show"); // final Button cancelButton = new Button("?"); // final TextArea licenseTextArea = new TextArea(); licenseTextArea.setColumns(30); licenseTextArea.setRows(5); licenseTextArea.setWordwrap(true); licenseTextArea.setInputPrompt("??"); //Layout buttonPlaceHolder.addComponent(updateButton); licenseUpdateLayout.addComponent(textAreaPlaceHolder); licenseUpdateLayout.addComponent(buttonPlaceHolder); // cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { textAreaPlaceHolder.removeAllComponents(); buttonPlaceHolder.removeComponent(cancelButton); updateButton.setData("show"); updateButton.setCaption("License"); } }); updateButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (((String) event.getButton().getData()).equals("show")) { textAreaPlaceHolder.removeAllComponents(); textAreaPlaceHolder.addComponent(licenseTextArea); buttonPlaceHolder.addComponent(cancelButton); event.getButton().setData("updateAndHide"); event.getButton().setCaption("??"); } else if (((String) event.getButton().getData()).equals("updateAndHide")) { StringReader stringReader = new StringReader( StringUtils.trimToEmpty((String) licenseTextArea.getValue())); Properties props = new Properties(); try { props.load(stringReader); } catch (IOException e) { e.printStackTrace(); } stringReader.close(); // Boolean isValidvalidateLicense(licenseTextArea.getValue()); String license_date = props.getProperty(LicenseManager.LICENSE_DATE); String license_count = props.getProperty(LicenseManager.LICENSE_COUNT); String license_localmd5 = props.getProperty(LicenseManager.LICENSE_LOCALMD5); // Boolean isMatch = regexMatchCheck(license_date, license_count, license_localmd5); if (isMatch) { Map<String, String> licenseMap = new HashMap<String, String>(); //?? // String license_count = (String)props.get(LicenseManager.LICENSE_COUNT); license_count = license_count == null ? "" : license_count; licenseMap.put(LicenseManager.LICENSE_COUNT, license_count); //? // String license_date = (String)props.get(LicenseManager.LICENSE_DATE); license_date = license_date == null ? "" : license_date; licenseMap.put(LicenseManager.LICENSE_DATE, license_date); //??? // String license_localmd5 = (String)props.get(LicenseManager.LICENSE_LOCALMD5); license_localmd5 = license_localmd5 == null ? "" : license_localmd5; licenseMap.put(LicenseManager.LICENSE_LOCALMD5, license_localmd5); //?License Map<String, String> resultMap = LicenseManager.licenseValidate(licenseMap); String validateResult = resultMap.get(LicenseManager.LICENSE_VALIDATE_RESULT); if (LicenseManager.LICENSE_VALID.equals(validateResult)) { //continue } else { NotificationUtil.showWarningNotification(SystemLicence.this, "License ?License"); return; } try { URL resourceurl = SystemLicence.class.getResource(LicenseManager.LICENSE_FILE); //System.err.println("chb: SystemLicense"+resourceurl.getPath()); OutputStream fos = new FileOutputStream(resourceurl.getPath()); props.store(fos, "license"); } catch (Exception e) { e.printStackTrace(); NotificationUtil.showWarningNotification(SystemLicence.this, "License "); return; } textAreaPlaceHolder.removeAllComponents(); buttonPlaceHolder.removeComponent(cancelButton); updateButton.setData("show"); updateButton.setCaption("License"); LicenseManager.loadLicenseFile(LicenseManager.LICENSE_FILE.substring(1)); // LicenseManager.loadLicenseFile(licenseFilename) refreshLicenseInfo(); NotificationUtil.showWarningNotification(SystemLicence.this, "License ?,?"); } else { NotificationUtil.showWarningNotification(SystemLicence.this, "License ??"); } } } /** * license ? * @param license_date * @param license_count * @param license_localmd5 * @return */ private Boolean regexMatchCheck(String license_date, String license_count, String license_localmd5) { if (StringUtils.isEmpty(license_date) || StringUtils.isEmpty(license_count) || StringUtils.isEmpty(license_localmd5)) { return false; } String date_regex = "^\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2}$"; //? String count_regex = "^\\d+$"; //? String md5_32_regex = "^\\w{32}$"; //? return license_localmd5.matches(md5_32_regex) && license_date.matches(date_regex) && license_count.matches(count_regex); } }); return licenseUpdateLayout; }