List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.xwiki.validator.HTML5DutchWebGuidelinesValidator.java
/** * Links to e-mail addresses: the e-mail address to which the message is addressed must be visible in the link text. *//*w ww . j a v a 2s .c o m*/ public void validateRpd8s16() { for (Element link : getElements(ELEM_LINK)) { String href = getAttributeValue(link, ATTR_HREF); if (href != null && href.startsWith(MAILTO)) { String email = StringUtils.substringAfter(href, MAILTO); if (email.contains(QUERY_STRING_SEPARATOR)) { email = StringUtils.substringBefore(email, QUERY_STRING_SEPARATOR); } assertTrue(Type.ERROR, "rpd8s16.email", link.text().contains(email)); } } }
From source file:org.xwiki.vfs.VfsResourceReference.java
/** * @param fullURI the full opaque URI containing both the reference to the archive and the path to the entry inside * it, e.g. {@code attach:space.page@attachment/path/to/file}. Note that this constructor requires that any * "/" character inside the reference to the archive be URL-encoded *//* ww w . j ava 2 s .co m*/ public VfsResourceReference(URI fullURI) { // Find the first "/" and consider that everything after is the path this(URI.create(StringUtils.substringBefore(fullURI.toString(), RESOURCE_PATH_SEPARATOR)), StringUtils.substringAfter(fullURI.toString(), RESOURCE_PATH_SEPARATOR)); }
From source file:org.xwiki.watchlist.internal.job.WatchListJob.java
/** * Method called from the scheduler./*from w w w . j a v a2 s .co m*/ * * @param jobContext Context of the request * @throws JobExecutionException if the job execution fails. */ @Override public void executeJob(JobExecutionContext jobContext) throws JobExecutionException { try { init(jobContext); if (this.watchListJobObject == null) { return; } Collection<String> subscribers = getSubscribers(); // Stop here if nobody is interested. if (!hasSubscribers()) { return; } // Determine what happened since the last execution for everybody. Date previousFireTime = getPreviousFireTime(); WatchListEventMatcher eventMatcher = Utils.getComponent(WatchListEventMatcher.class); List<WatchListEvent> events = eventMatcher.getEventsSince(previousFireTime); setPreviousFireTime(); // Stop here if nothing happened in the meantime. if (events.size() == 0) { return; } // Notify all interested subscribers, one at a time. for (String subscriber : subscribers) { try { // Determine what happened since the last execution on the watched elements of the current // subscriber only. List<WatchListEvent> matchingEvents = eventMatcher.getMatchingVisibleEvents(events, subscriber); String userWiki = StringUtils.substringBefore(subscriber, DefaultWatchListStore.WIKI_SPACE_SEP); // If events have occurred on at least one element watched by the user, send the email if (matchingEvents.size() > 0) { this.watchlist.getNotifier().sendNotification(subscriber, matchingEvents, getEmailTemplate(userWiki), previousFireTime); } } catch (Exception e) { LOGGER.error("Failed to send watchlist notification to user [{}]", subscriber, e); } } } catch (Exception e) { // We're in a job, we don't throw exceptions LOGGER.error("Exception while running job", e); } finally { this.context.getWiki().getStore().cleanUp(this.context); cleanupComponents(); } }
From source file:org.xwiki.webjars.internal.FilesystemResourceReferenceCopier.java
private void processCSSfile(String resourcePrefix, String targetPrefix, JarEntry entry, JarFile jar, FilesystemExportContext exportContext) throws Exception { // Limitation: we only support url() constructs located on a single line try (BufferedReader br = new BufferedReader(new InputStreamReader(jar.getInputStream(entry), "UTF-8"))) { String line;/* ww w . j ava 2 s . c o m*/ while ((line = br.readLine()) != null) { Matcher matcher = URL_PATTERN.matcher(line); while (matcher.find()) { String url = matcher.group(1); // Determine if URL is relative if (isRelativeURL(url)) { // Remove any query string part and any fragment part too url = StringUtils.substringBefore(url, "?"); url = StringUtils.substringBefore(url, "#"); // Normalize paths String resourceName = String.format(CONCAT_PATH_FORMAT, StringUtils.substringBeforeLast(entry.getName(), "/"), url); resourceName = new URI(resourceName).normalize().getPath(); resourceName = resourceName.substring(resourcePrefix.length() + 1); // Copy to filesystem copyResourceFromJAR(resourcePrefix, resourceName, targetPrefix, exportContext); } } } } }
From source file:org.zht.framework.zhtdao.base.impl.BaseDaoImpl.java
public DataSet loadDataSet(String queryStr, ParamObject paramObject) throws DaoException { if (paramObject == null) { throw new DaoException("?"); }/*from w w w.j ava 2 s .c om*/ if (paramObject.getIsNeedCount() == null) { throw new DaoException("[NeedCount]?"); } if (paramObject.getIsSql() == null) { throw new DaoException("[isSql]?"); } if (paramObject.getIsOffset() == null) { throw new DaoException("[isOffset]?"); } if (queryStr == null || !(queryStr.contains("@from") || queryStr.contains("@FROM"))) { throw new DaoException("?,[@from]"); } String queryCountStr = " select count(*) from " + StringUtils.substringAfter(queryStr, "@from"); //?grouby ? String countTemp = queryCountStr.replaceAll("\\((.*)\\)", "").replaceAll("[\\s]+", " ").toLowerCase(); if (countTemp.contains("group by")) { queryCountStr = "SELECT count(*) from ( " + queryCountStr + " )"; } queryStr = queryStr.replace("@from", "from").replace("@FROM", "FROM"); Query queryData, queryCount; if (paramObject.getIsSql()) { queryData = this.getCurrentSession().createSQLQuery(queryStr) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); queryCount = this.getCurrentSession().createSQLQuery(queryCountStr); } else { queryData = this.getCurrentSession().createQuery(queryStr) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); queryCount = this.getCurrentSession().createQuery(queryCountStr); } String tempSql = new String(queryStr); Map<String, Object> parmeterSet = paramObject.getQueryParams(); if (parmeterSet != null && parmeterSet.size() > 0) { while (tempSql.contains(":")) { tempSql = StringUtils.substringAfter(tempSql, ":"); String key = StringUtils.substringBefore(tempSql, " "); if (key != null && key.trim().endsWith(")")) { key = key.replace(")", ""); } if (parmeterSet.keySet().contains(key)) { Object paramValue = parmeterSet.get(key); //?null//// if (paramValue == null) { queryData.setParameter(key, paramValue); queryCount.setParameter(key, paramValue); } else { if (paramValue instanceof Collection) { queryData.setParameterList(key, (Collection<?>) paramValue); queryCount.setParameterList(key, (Collection<?>) paramValue); } else if (paramValue.getClass().isArray()) { queryData.setParameterList(key, (Object[]) paramValue); queryCount.setParameterList(key, (Object[]) paramValue); } else if ("true".equalsIgnoreCase("" + paramValue) || "false".equalsIgnoreCase("" + paramValue)) { queryData.setParameter(key, Boolean.valueOf("" + paramValue)); } else { queryData.setParameter(key, paramValue); queryCount.setParameter(key, paramValue); } } } } } if (paramObject.getIsOffset()) { queryData.setMaxResults(paramObject.getRows()); queryData.setFirstResult((paramObject.getPage() - 1) * paramObject.getRows()); } @SuppressWarnings("unchecked") List<Map<String, Object>> entityList = queryData.list(); Long total = 0L; if (paramObject.getIsNeedCount()) { total = (Long) queryCount.uniqueResult(); } return new DataSet(total, entityList); }
From source file:org.zht.framework.zhtdao.base.impl.BaseDaoImpl.java
@Override public List<?> findJustList(String queryStr, ParamObject paramObject) throws DaoException { if (paramObject == null) { throw new DaoException("?"); }/* w ww . j a v a 2s . com*/ if (paramObject.getIsNeedCount() == null) { throw new DaoException("[NeedCount]?"); } if (paramObject.getIsSql() == null) { throw new DaoException("[isSql]?"); } if (paramObject.getIsOffset() == null) { throw new DaoException("[isOffset]?"); } // if(queryStr==null||!(queryStr.contains("@from")||queryStr.contains("@FROM"))){ // throw new DaoException("?,[@from]"); // } queryStr = queryStr.replace("@from", "from").replace("@FROM", "FROM"); Query queryData; if (paramObject.getIsSql()) { queryData = this.getCurrentSession().createSQLQuery(queryStr); } else { queryData = this.getCurrentSession().createQuery(queryStr); } Map<String, Object> parmeterSet = paramObject.getQueryParams(); String tempSql = new String(queryStr); if (parmeterSet != null && parmeterSet.size() > 0) { while (tempSql.contains(":")) { tempSql = StringUtils.substringAfter(tempSql, ":"); String key = StringUtils.substringBefore(tempSql, " "); if (key != null && key.trim().endsWith(")")) { key = key.replace(")", ""); } if (parmeterSet.keySet().contains(key)) { Object paramValue = parmeterSet.get(key); //?null//// if (paramValue == null) { queryData.setParameter(key, paramValue); } else { if (paramValue instanceof Collection) { queryData.setParameterList(key, (Collection<?>) paramValue); } else if (paramValue.getClass().isArray()) { queryData.setParameterList(key, (Object[]) paramValue); } else if ("true".equalsIgnoreCase("" + paramValue) || "false".equalsIgnoreCase("" + paramValue)) { queryData.setParameter(key, Boolean.valueOf("" + paramValue)); } else { queryData.setParameter(key, paramValue); } } } } } List<?> entityList = queryData.list(); if (entityList != null && entityList.size() > 0) { return entityList; } return null; }
From source file:org.zht.framework.zhtdao.hibernate.impl.HibernateBaseDaoImpl.java
public int executeUpdate(String queryStr, ParamObject paramObject) throws DaoException { Query query = null;/* ww w. j a v a 2 s . c om*/ if (paramObject.getIsSql()) { query = this.getCurrentSession().createSQLQuery(queryStr); } else { query = this.getCurrentSession().createQuery(queryStr); } Map<String, Object> parmeterSet = paramObject.getQueryParams(); String tempSql = new String(queryStr); if (parmeterSet != null && parmeterSet.size() > 0) { while (tempSql.contains(":")) { tempSql = StringUtils.substringAfter(tempSql, ":"); String key = StringUtils.substringBefore(tempSql, " "); if (key != null && key.trim().endsWith(")")) { key = key.replace(")", ""); } if (parmeterSet.keySet().contains(key)) { Object paramValue = parmeterSet.get(key); //?null//// if (paramValue == null) { query.setParameter(key, paramValue); } else { if (paramValue instanceof Collection) { query.setParameterList(key, (Collection<?>) paramValue); } else if (paramValue.getClass().isArray()) { query.setParameterList(key, (Object[]) paramValue); } else { query.setParameter(key, paramValue); } } } } } return query.executeUpdate(); }
From source file:pl.madshai.rjmock.mocks.MocksHelper.java
/** * Get category/* w w w . j a v a2s.c o m*/ * @param url * @return */ public static String getPackageFromUrl(String url) { String removeFirstSlash = StringUtils.substringAfter(url, RJMOCK); return StringUtils.substringBefore(removeFirstSlash, "/"); }
From source file:pl.madshai.rjmock.mocks.MocksHelper.java
/** * Get subpath/*from w ww .j a v a 2s . c om*/ * @param url * @return */ public static String getSubpathFromUrl(String url) { String removeFirstSlash = StringUtils.substringAfter(url, RJMOCK); String subpath = StringUtils.substringAfter(removeFirstSlash, "/"); if (subpath.contains("?")) { subpath = StringUtils.substringBefore(subpath, "?"); } return subpath; }
From source file:rs.metropolitan.data_changer.base.ToDouble.java
@Override public Double changeString(String data) { try {//from w w w . ja v a2 s .c om String dot = "."; String beforeDot = StringUtils.substringBefore(data, dot); String afterDot = StringUtils.substringBefore(data, dot); if (StringUtils.isNumeric(beforeDot) && StringUtils.isNumeric(afterDot) && StringUtils.countMatches(data, dot) == 1) { return new Double(data); } return null; } catch (NumberFormatException ex) { System.err.print(ex.getLocalizedMessage()); return null; } catch (Exception ex) { System.err.print(ex.getLocalizedMessage()); return null; } }