List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:ips1ap101.lib.core.db.util.DBUtils.java
public static String[] getConstraintMessageKeys(String message) { String trimmed = StringUtils// ww w .j a va2 s. c o m .trimToEmpty(StringUtils.substringAfter(StringUtils.substringBefore(message, WHERE), ERROR)); if (StringUtils.isNotBlank(trimmed)) { String[] tokens = StringUtils.split(trimmed, ';'); if (tokens != null && tokens.length > 1) { String key = tokens[0].trim(); if (key.matches("^[0-9]{1,3}$")) { int length = Integer.valueOf(key); if (length == tokens.length - 1) { String string; String[] keys = new String[length]; for (int i = 1; i < tokens.length; i++) { key = tokens[i].trim(); if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) { key = StringUtils.removeEnd(key, SUFIJO); string = BundleMensajes.getString(key); keys[i - 1] = isKey(string) ? string : "<" + key + ">"; } else { return null; } } return keys; } } } String key, string; String stripChars = BOMK + EOMK; List<String> list = new ArrayList<>(); Pattern pattern = Pattern.compile("\\" + BOMK + ".*\\" + EOMK); Matcher matcher = pattern.matcher(trimmed); while (matcher.find()) { key = StringUtils.strip(matcher.group(), stripChars); if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) { key = StringUtils.removeEnd(key, SUFIJO); string = BundleMensajes.getString(key); key = isKey(string) ? string : "<" + key + ">"; list.add(key); } } return (list.isEmpty()) ? null : list.toArray(new String[list.size()]); } return null; }
From source file:eionet.cr.dao.virtuoso.VirtuosoUrgentHarvestQueueDAO.java
@Override public void addPullHarvests(List<UrgentHarvestQueueItemDTO> queueItems) throws DAOException { String sql = "insert into URGENT_HARVEST_QUEUE (URL,\"TIMESTAMP\") VALUES (?,NOW())"; PreparedStatement ps = null;//from w w w .j ava 2s . c o m Connection conn = null; try { conn = getSQLConnection(); ps = conn.prepareStatement(sql); for (int i = 0; i < queueItems.size(); i++) { UrgentHarvestQueueItemDTO dto = queueItems.get(i); String url = dto.getUrl(); if (url != null) { url = StringUtils.substringBefore(url, "#"); } ps.setString(1, url); ps.addBatch(); } ps.executeBatch(); } catch (Exception e) { throw new DAOException(e.getMessage(), e); } finally { SQLUtil.close(ps); SQLUtil.close(conn); } }
From source file:eionet.cr.filestore.ScriptTemplateDaoImpl.java
/** * {@inheritDoc}//from ww w . j a v a 2 s . c om */ @Override public ScriptTemplateDTO getScriptTemplate(String id) { ScriptTemplateDTO result = new ScriptTemplateDTO(); result.setId(id); for (Object key : PROPERTIES.keySet()) { String currentId = StringUtils.substringBefore((String) key, "."); String property = StringUtils.substringAfterLast((String) key, "."); if (currentId.equals(id)) { if (property.equals("name")) { result.setName(PROPERTIES.getProperty((String) key).trim()); } if (property.equals("script")) { result.setScript(PROPERTIES.getProperty((String) key).trim()); } } } return result; }
From source file:com.comcast.cats.monitor.reboot.BarcelonaRebootMonitor.java
/** * Parse the snmp result to detect reboot. * /*from ww w.ja va 2s. c o m*/ * Examples of expected results : "18:54:41.36", "2 days, 18:54:41.36", * "1 day, 18:54:41.36" */ @Override protected void parseRebootInfo(String snmpQueryResult) { logger.debug("snmpQueryResult " + snmpQueryResult); long upTime = 0; String upTimeDays = null; String upTimehours; try { if (snmpQueryResult != null && !snmpQueryResult.isEmpty()) { Pattern pattern = Pattern.compile(REBOOT_DETECTION_REGEX_STRING); Matcher matcher = pattern.matcher(snmpQueryResult); if (matcher.find()) { // seperate the days information and the time information. upTimeDays = StringUtils.substringBefore(snmpQueryResult, matcher.group()).trim(); upTimehours = StringUtils.substringAfter(snmpQueryResult, matcher.group()).trim(); } else { upTimehours = snmpQueryResult.trim(); } upTime = calculateUptime(upTimeDays, upTimehours); long timeInterval = calculcateMonitorTimeIntervalInMillis(); logger.debug("timeInterval sec " + (timeInterval / (1000))); logger.debug("upTime sec " + (upTime) / 1000); if (timeInterval > upTime) { logger.debug("Reboot Happened"); RebootStatistics stats = new RebootStatistics(new Date()); stats.setMonitorType(REBOOT_TYPE); stats.setMessage("UP Time " + snmpQueryResult, settop.getHostMacAddress()); stats.setUptime(upTime / 1000); alarm(stats); } else { logger.trace("NO Reboot Happened"); } } else { logger.debug("SNMP detection failed : No response from settop " + snmpQueryResult); } } catch (ParseException e) { logger.trace("Result not in an expected format : " + e.getMessage()); } catch (NumberFormatException e) { logger.trace("Result not in an expected format : " + e.getMessage()); } ((Calendar) getState()).setTime(new Date()); }
From source file:info.magnolia.voting.voters.ResponseContentTypeVoter.java
@Override protected boolean boolVote(Object value) { final HttpServletResponse response; if (value instanceof HttpServletResponse) { response = (HttpServletResponse) value; } else {/*from w w w .j av a 2s . c om*/ if (MgnlContext.isWebContext()) { response = MgnlContext.getWebContext().getResponse(); } else { return false; } } // strip the encoding off of the content type: final String contentType = StringUtils.substringBefore(response.getContentType(), ";"); if (contentType == null) { log.warn("No content type set on the response, can't vote."); return false; } if (allowed.size() > 0 && !allowed.contains(contentType)) { return false; } if (rejected.size() > 0 && rejected.contains(contentType)) { return false; } return true; }
From source file:info.magnolia.cms.util.RequestFormUtil.java
/** * The url is not always properly decoded. This method does the job. * @param request//from w ww . ja v a2 s. c o m * @param charset * @return decoded map of all values */ public static Map getURLParametersDecoded(HttpServletRequest request, String charset) { Map map = new HashMap(); String queryString = request.getQueryString(); if (queryString != null) { String[] params = request.getQueryString().split("&"); for (int i = 0; i < params.length; i++) { String name = StringUtils.substringBefore(params[i], "="); String value = StringUtils.substringAfter(params[i], "="); try { value = URLDecoder.decode(value, charset); } catch (UnsupportedEncodingException e) { // nothing: return value as is } map.put(name, value); } } return map; }
From source file:com.justinmobile.core.dao.support.PropertyFilter.java
private void buildFilterName(String filterName) { // ????/*from w w w. ja v a2s . c om*/ String aliasPart = StringUtils.substringBefore(filterName, "_"); if (ALIAS.equals(aliasPart)) { String allPart = StringUtils.substringAfter(filterName, "_"); String firstPart = StringUtils.substringBefore(allPart, "_"); this.aliasName = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String joinTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); this.joinType = Enum.valueOf(JoinType.class, joinTypeCode).getValue(); filterName = StringUtils.substringAfter(allPart, "_"); } // ?????matchTypepropertyTypeCode String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } // ??OR String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); }
From source file:eionet.cr.util.URLUtil.java
/** * Connect to the URL and check if it is modified since the timestamp argument. Returns null, if it cannot be determined for * sure.//from w w w . ja v a2 s . c o m * * @param urlString * @param timestamp * @return true if it is modified. */ public static Boolean isModifiedSince(String urlString, long timestamp) { if (!URLUtil.isURL(urlString)) { return Boolean.FALSE; } if (timestamp == 0) { return Boolean.TRUE; } URLConnection urlConnection = null; try { URL url = new URL(StringUtils.substringBefore(urlString, "#")); urlConnection = escapeIRI(url).openConnection(); urlConnection.setRequestProperty("Connection", "close"); urlConnection.setRequestProperty("User-Agent", userAgentHeader()); urlConnection.setIfModifiedSince(timestamp); int responseCode = ((HttpURLConnection) urlConnection).getResponseCode(); System.out.println(responseCode); if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) { return Boolean.FALSE; } else if (responseCode == HttpURLConnection.HTTP_OK) { return Boolean.TRUE; } else { // Return null to indicate if it's unclear whether the source has // been modified or not. return null; } } catch (IOException ioe) { return null; } finally { URLUtil.disconnect(urlConnection); } }
From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java
private void logProfileCall(final ProceedingJoinPoint call, final Object model, final long duration) { // model is null on login if (model != null && model.getClass().isAnnotationPresent(HibernateProfiled.class)) { try {/*from w w w . ja v a2 s .co m*/ LOGGER.trace(new StringBuilder( StringUtils.substringBefore(call.getSignature().getDeclaringType().getSimpleName(), "$")) .append("|").append(call.getSignature().getName()).append("|") .append(getClassNameAndPersistentId(model)).append("|").append(duration)); } catch (final Exception e) { LOGGER.error("unable to profile class: " + model.getClass()); } } }
From source file:com.github.bluetiger9.nosql.benchmarking.clients.document.mongodb.MongoDBClient.java
private static ServerAddress getServerAddress(String server) throws UnknownHostException { final String host = StringUtils.substringBefore(server, ":"); final String port = StringUtils.substringAfter(server, ":"); if (!StringUtils.isBlank(port)) { return new ServerAddress(host, Integer.parseInt(port)); } else {/*from w ww. ja v a 2s . c om*/ return new ServerAddress(host); } }