Java Code Examples for org.apache.commons.lang3.StringUtils#trimToNull()
The following examples show how to use
org.apache.commons.lang3.StringUtils#trimToNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrovitUtils.java From OpenEstate-IO with Apache License 2.0 | 6 votes |
/** * Read a {@link Calendar} value from XML. * * @param value XML string * @return parsed value or null, if the value is invalid */ public static Calendar parseDateValue(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; final String[] patterns = new String[]{ "dd/MM/yyyy", "dd/MM/yyyy hh:mm:ss", "dd-MM-yyyy", "dd-MM-yyyy hh:mm:ss", "yyyy/MM/dd", "yyyy/MM/dd hh:mm:ss", "yyyy-MM-dd", "yyyy-MM-dd hh:mm:ss" }; try { Date date = DateUtils.parseDateStrictly(value, Locale.ENGLISH, patterns); Calendar cal = Calendar.getInstance(Locale.getDefault()); cal.setTime(date); return cal; } catch (ParseException ex) { throw new IllegalArgumentException("Can't parse date value '" + value + "'!", ex); } }
Example 2
Source File: BaseUserDirectoryService.java From sakai with Educational Community License v2.0 | 5 votes |
/** * @inheritDoc */ public boolean checkPassword(String pw) { pw = StringUtils.trimToNull(pw); return m_pwdService.check(pw, m_pw); }
Example 3
Source File: AbstractOptions.java From RemoteSupportTool with Apache License 2.0 | 5 votes |
protected Integer getPropertyAsInteger(String key, Integer defaultValue) { String value = StringUtils.trimToNull(this.getProperty(key)); try { return (value != null) ? Integer.valueOf(value) : defaultValue; } catch (NumberFormatException ex) { LOGGER.warn("Can't read option '" + key + "'!", ex); return defaultValue; } }
Example 4
Source File: BackfillItemHashesJob.java From sakai with Educational Community License v2.0 | 5 votes |
private int getBatchSize() { String val = StringUtils.trimToNull(getConfiguredProperty(BATCH_SIZE)); if ( val == null ) { return DEFAULT_BATCH_SIZE; } int valInt = Integer.parseInt(val); return valInt <= 0 ? DEFAULT_BATCH_SIZE : valInt; }
Example 5
Source File: IdxRecord.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
@SuppressWarnings("Duplicates") public void setPicture11(Media value) { String file = (value != null) ? StringUtils.trimToNull(value.getFileName()) : null; this.set(FIELD_PICTURE_11_FILE, file); this.set(FIELD_PICTURE_11_TITLE, (value != null && file != null) ? IdxFormat.printString(value.getTitle(), 200) : null); this.set(FIELD_PICTURE_11_TEXT, (value != null && file != null) ? IdxFormat.printString(value.getDescription(), 1800) : null); this.set(FIELD_PICTURE_11_URL, (value != null && file != null) ? value.getUrl() : null); }
Example 6
Source File: CsvPrinter.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
/** * Helper function to replace line breaks in a string with a custom value * before printing. * <p> * This method may be used by inheriting classes, if the particular format * does not support line breaks. * * @param value value to replace * @param lineBreak value, that is used for replacement of line breaks - if null, <br/> * is used * @return value with replaced line breaks */ protected static String replaceLineBreaks(String value, String lineBreak) { value = StringUtils.trimToNull(value); if (value == null) return null; if (lineBreak == null) lineBreak = "<br/>"; Matcher m = LINES.matcher(value); StringBuilder out = new StringBuilder(); while (m.find()) { out.append(StringUtils.trimToEmpty(m.group())); if (!m.hitEnd()) out.append(lineBreak); } return out.toString(); }
Example 7
Source File: OpenImmo_1_2_7.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
/** * Downgrade <anhang> elements to OpenImmo 1.2.6. * <p> * The options "EPASS-SKALA", "ANBOBJURL" for the "gruppe" attribute of * <anhang> elements are not available in version 1.2.6 * * @param doc OpenImmo document in version 1.2.7 * @throws JaxenException if xpath evaluation failed */ protected void downgradeAnhangElements(Document doc) throws JaxenException { List nodes = XmlUtils.newXPath( "/io:openimmo/io:anbieter/io:anhang[@gruppe] | " + "/io:openimmo/io:anbieter/io:immobilie/io:anhaenge/io:anhang[@gruppe]", doc).selectNodes(doc); for (Object item : nodes) { Element node = (Element) item; String value = StringUtils.trimToNull(node.getAttribute("gruppe")); if ("EPASS-SKALA".equalsIgnoreCase(value)) node.removeAttribute("gruppe"); else if ("ANBOBJURL".equalsIgnoreCase(value)) node.removeAttribute("gruppe"); } }
Example 8
Source File: BaseUserDirectoryService.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Adjust the eid - trim it to null, and lower case IF we are case insensitive. * * @param eid * The eid to clean up. * @return A cleaned up eid. */ protected String cleanEid(String eid) { eid = StringUtils.lowerCase(eid); eid = StringUtils.trimToNull(eid); if (eid != null) { // remove all instances of these chars <>,;:\" eid = StringUtils.replaceChars(eid, "<>,;:\\/", ""); } // NOTE: length check is handled later on return eid; }
Example 9
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Generates partial JDOQL statement excluding suppressed vulnerabilities for this project/component * and for globally suppressed vulnerabilities against the specified component. * @param component the component to query on * @param project the project to query on * @return a partial where clause */ @SuppressWarnings("unchecked") private String generateExcludeSuppressed(Project project, Component component) { // Retrieve a list of all suppressed vulnerabilities final Query analysisQuery = pm.newQuery(Analysis.class, "(project == :project || project == null) && component == :component && suppressed == true"); final List<Analysis> analysisList = (List<Analysis>)analysisQuery.execute(project, component); // Construct exclude clause based on above results String excludeClause = analysisList.stream().map(analysis -> "id != " + analysis.getVulnerability().getId() + " && ").collect(Collectors.joining()); if (StringUtils.trimToNull(excludeClause) != null) { excludeClause = " && (" + excludeClause.substring(0, excludeClause.lastIndexOf(" && ")) + ")"; } return excludeClause; }
Example 10
Source File: ImmobiliareItUtils.java From OpenEstate-IO with Apache License 2.0 | 5 votes |
public static Category parseCategory(String value) { value = StringUtils.trimToNull(value); if (value == null) return null; Category cat = Category.fromXmlValue(value); if (cat == null) throw new IllegalArgumentException("Can't parse category value '" + value + "'!"); return cat; }
Example 11
Source File: UsersAction.java From sakai with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ protected List<User> readResourcesPage(SessionState state, int first, int last) { // search? String search = StringUtils.trimToNull((String) state.getAttribute(STATE_SEARCH)); if (search != null) { return userDirectoryService.searchUsers(search, first, last); } return userDirectoryService.getUsers(first, last); }
Example 12
Source File: HtmlSortHeaderRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException { // If this is a currently sorted sort header, always give it the "currentSort" CSS style class if (component instanceof HtmlCommandSortHeader) { HtmlCommandSortHeader sortHeader = (HtmlCommandSortHeader)component; String styleClass = StringUtils.trimToNull(getStyleClass(facesContext, component)); String newStyleClass; String unStyleClass; if (sortHeader.findParentDataTable().getSortColumn().equals(sortHeader.getColumnName())) { newStyleClass = CURRENT_SORT_STYLE; unStyleClass = NOT_CURRENT_SORT_STYLE; } else { newStyleClass = NOT_CURRENT_SORT_STYLE; unStyleClass = CURRENT_SORT_STYLE; } if (StringUtils.indexOf(styleClass, newStyleClass) == -1) { if (StringUtils.indexOf(styleClass, unStyleClass) != -1) { styleClass = StringUtils.replace(styleClass, unStyleClass, newStyleClass); } else if (styleClass != null) { styleClass = (new StringBuilder(styleClass)).append(' ').append(newStyleClass).toString(); } else { styleClass = newStyleClass; } sortHeader.setStyleClass(styleClass); } } super.encodeBegin(facesContext, component); //check for NP }
Example 13
Source File: SiteSetupQuestionFileParser.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Does the specified configuration/hierarchy resource exist? * @param resourceName Resource name * @return true If we can access this content */ protected static boolean exists(String resourceName) { String configFolderRef = getConfigFolderReference(); if (StringUtils.trimToNull(configFolderRef) != null && StringUtils.trimToNull(resourceName)!=null) { String referenceName = configFolderRef + resourceName; Reference reference = EntityManager.newReference(referenceName); if (reference == null) return false; enableSecurityAdvisor(); ContentResource resource= null; try { resource = contentHostingService.getResource(reference.getId()); // as a remind for newly added configuration file log.info("exists(): find new resource " + reference.getId()); } catch (Exception ee) { // the configuration xml file are added, and get read immediately and moved to the config backup folder afterwards. Its contents are stored into database // so it is normal to find the the configuration xml missing from the original config folder // this exception is as expected, don't put it into log file } popSecurityAdvisor(); return (resource != null); } return false; }
Example 14
Source File: LogonResetPasswordForm.java From openemm with GNU Affero General Public License v3.0 | 4 votes |
public void setEmail(String email) { this.email = StringUtils.trimToNull(StringUtils.lowerCase(email)); }
Example 15
Source File: SymmetricCryptograph.java From cassandra-reaper with Apache License 2.0 | 4 votes |
public SymmetricCryptograph.Builder withCipherType(String cipherType) { this.cipherType = StringUtils.trimToNull(cipherType); return this; }
Example 16
Source File: AdminSitesAction.java From sakai with Educational Community License v2.0 | 4 votes |
/** * {@inheritDoc} */ protected int sizeResources(SessionState state) { // search? String search = StringUtils.trimToNull((String) state.getAttribute(STATE_SEARCH)); String siteId = StringUtils.trimToNull((String) state.getAttribute(STATE_SEARCH_SITE_ID)); String userId = StringUtils.trimToNull((String) state.getAttribute(STATE_SEARCH_USER_ID)); // search for non-user sites, using the criteria if (siteId != null) { try { siteService.getSite(siteId); return 1; } catch (IdUnusedException e) { } return 0; } else if (userId != null) { Site userSite = findUserSiteByUserIdCriteria(userId); if ( userSite == null ) { return 0; } return 1; } else if (search != null) { return siteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.NON_USER, null, search, null); } else { return siteService.countSites(org.sakaiproject.site.api.SiteService.SelectionType.ANY, null, search, null); } }
Example 17
Source File: OpenImmoFeedbackDocument.java From OpenEstate-IO with Apache License 2.0 | 4 votes |
@Override public OpenImmoVersion getDocumentVersion() { String version; try { Document doc = this.getDocument(); Element node = (Element) XmlUtils .newXPath("/io:openimmo_feedback/io:version", doc) .selectSingleNode(doc); // versions older then 1.2.4 do not support the <version> element // - version 1.2.3 is assumed, when no <version> element is present and // an empty namespace is used // - version 1.2.0 is assumed, when no <version> element is present and // the old namespace is used if (node == null) { Element root = XmlUtils.getRootElement(doc); return (OpenImmoUtils.OLD_NAMESPACE.equalsIgnoreCase(root.getNamespaceURI())) ? OpenImmoVersion.V1_2_0 : OpenImmoVersion.V1_2_3; } version = StringUtils.trimToNull(node.getTextContent()); if (version == null) { LOGGER.warn("Can't find version information in the XML document!"); //System.out.println( "----------------------------" ); //try //{ // DocumentUtils.write( doc, System.out ); //} //catch (Exception ex) //{ // LOGGER.error( "Can't write XML document!" ); // LOGGER.error( "> " + ex.getLocalizedMessage(), ex ); //} //System.out.println( "----------------------------" ); return null; } } catch (JaxenException ex) { LOGGER.error("Can't evaluate XPath expression!"); LOGGER.error("> " + ex.getLocalizedMessage(), ex); return null; } OpenImmoVersion v = OpenImmoVersion.detectFromString(version); if (v != null) return v; LOGGER.warn("The provided version (" + version + ") is not supported!"); return null; }
Example 18
Source File: TrimPreProcess.java From word2vec with Apache License 2.0 | 4 votes |
@Override public String preProcess(String s) { return StringUtils.trimToNull(s); }
Example 19
Source File: ImmobiliareItUtils.java From OpenEstate-IO with Apache License 2.0 | 4 votes |
public static Integer parseRooms(String value) { value = StringUtils.trimToNull(value); return (value != null) ? DatatypeConverter.parseInt(value) : null; }
Example 20
Source File: DatabaseImpl.java From jackcess with Apache License 2.0 | 2 votes |
/** * Returns the given string trimmed, or {@code null} if the string is {@code * null} or empty. */ public static String trimToNull(String str) { return StringUtils.trimToNull(str); }