List of usage examples for org.apache.commons.lang3 StringUtils removeStartIgnoreCase
public static String removeStartIgnoreCase(final String str, final String remove)
Case insensitive removal of a substring if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.cryptomator.frontend.webdav.jackrabbitservlet.FilesystemResourceFactory.java
/** * Processes the given range header field, if it is supported. Only headers containing a single byte range are supported.<br/> * <code>/*from w w w . ja v a 2 s . c om*/ * bytes=100-200<br/> * bytes=-500<br/> * bytes=1000- * </code> * * @return Tuple of lower and upper range. * @throws DavException HTTP statuscode 400 for malformed requests. * @throws NotASingleByteRangeException Indicating a range that is not supported by this server, i.e. range header should be ignored. */ private Pair<String, String> parseSingleByteRange(String rangeHeader) throws DavException, NotASingleByteRangeException { assert rangeHeader != null; if (!rangeHeader.startsWith(RANGE_BYTE_PREFIX)) { throw new NotASingleByteRangeException(); } final String byteRangeSet = StringUtils.removeStartIgnoreCase(rangeHeader, RANGE_BYTE_PREFIX); final String[] byteRanges = StringUtils.split(byteRangeSet, RANGE_SET_SEP); if (byteRanges.length != 1) { throw new NotASingleByteRangeException(); } final String byteRange = byteRanges[0]; final String[] bytePos = StringUtils.splitPreserveAllTokens(byteRange, RANGE_SEP); if (bytePos.length != 2 || bytePos[0].isEmpty() && bytePos[1].isEmpty()) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "malformed range header: " + rangeHeader); } return new ImmutablePair<>(bytePos[0], bytePos[1]); }
From source file:org.cryptomator.frontend.webdav.servlet.ByteRange.java
private static String getSingleByteRange(String headerValue) throws UnsupportedRangeException, MalformedByteRangeException { final String byteRangeSet = StringUtils.removeStartIgnoreCase(headerValue, RANGE_BYTE_PREFIX); if (StringUtils.isBlank(byteRangeSet)) { throw new MalformedByteRangeException(); }//from ww w . j a v a 2 s . co m final String[] byteRanges = StringUtils.split(byteRangeSet, RANGE_SET_SEP); if (byteRanges.length != 1) { throw new UnsupportedRangeException(); } else { return byteRanges[0]; } }
From source file:org.cyk.ui.web.api.WebNavigationManager.java
public String url(String id, Object[] parameters, Boolean actionOutcome, Boolean partial, Boolean pretty) { FacesContext facesContext = FacesContext.getCurrentInstance(); StringBuilder url = new StringBuilder(); NavigationCase navigationCase = ((ConfigurableNavigationHandler) facesContext.getApplication() .getNavigationHandler()).getNavigationCase(facesContext, null, id); //System.out.println(id+" / "+navigationCase); if (navigationCase == null) { log.severe("No Navigation Case found for " + id); return url(OUTCOME_NOT_FOUND, new Object[] { "oc", id }, Boolean.FALSE, Boolean.FALSE); }/*from ww w . java2s . c o m*/ String s = navigationCase.getToViewId(facesContext); if (Boolean.TRUE.equals(actionOutcome)) url.append(s); else url.append(StringUtils.replace(s, FILE_STATIC_EXTENSION, FILE_PROCESSING_EXTENSION)); if (Boolean.TRUE.equals(actionOutcome)) navigationHelper.addParameter(url, QUERY_PARAMETER_FACES_REDIRECT_NAME, navigationCase.isRedirect()); if (parameters != null && parameters.length > 0) { for (int i = 0; i < parameters.length - 1; i = i + 2) if (parameters[i + 1] == null) ; else navigationHelper.addParameter(url, /*(String)*/ parameters[i], parameters[i + 1]); } if (Boolean.TRUE.equals(partial)) ; else { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); //FacesContext.getCurrentInstance().getExternalContext().encodeResourceURL() will trigger rewriting //int countContextPath = StringUtils.countMatches(url, request.getContextPath()); url = new StringBuilder(StringUtils.removeStartIgnoreCase(//TODO might not work always FacesContext.getCurrentInstance().getExternalContext().encodeResourceURL(url.toString()), request.getContextPath())); //if(StringUtils.countMatches(url, request.getContextPath())>countContextPath) url.insert(0, request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()); } return url.toString(); }
From source file:org.cyk.ui.web.api.WebNavigationManager.java
public String getPath(String outcome, Boolean actionOutcome, Boolean partial) { FacesContext facesContext = FacesContext.getCurrentInstance(); StringBuilder path = new StringBuilder(); NavigationCase navigationCase = ((ConfigurableNavigationHandler) facesContext.getApplication() .getNavigationHandler()).getNavigationCase(facesContext, null, outcome); if (navigationCase == null) { log.severe("No Navigation Case found for " + outcome); return url(OUTCOME_NOT_FOUND, new Object[] { "oc", outcome }, Boolean.FALSE, Boolean.FALSE); }/*from www .ja v a2s. c om*/ String s = navigationCase.getToViewId(facesContext); if (Boolean.TRUE.equals(actionOutcome)) path.append(s); else path.append(StringUtils.replace(s, FILE_STATIC_EXTENSION, FILE_PROCESSING_EXTENSION)); if (Boolean.TRUE.equals(partial)) ; else { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); path = new StringBuilder(StringUtils.removeStartIgnoreCase(//TODO might not work always FacesContext.getCurrentInstance().getExternalContext().encodeResourceURL(path.toString()), request.getContextPath())); path.insert(0, request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()); } return path.toString(); }
From source file:org.jtwig.loader.impl.ClasspathLoader.java
protected String normalizeName(String name) { if (StringUtils.startsWithIgnoreCase(name, "classpath:")) { name = StringUtils.removeStartIgnoreCase(name, "classpath:"); }//from w w w . ja v a 2 s . c om name = "/" + StringUtils.strip(name, "/\\"); String path = new File(name).toURI().normalize().getRawPath(); return StringUtils.stripStart(path, "/\\"); }
From source file:org.mrgeo.geometry.WktConverter.java
public static String toWkt(GeometryCollection gc) { StringBuffer result;/* w w w . j a v a 2 s.c o m*/ if (gc.isValid() == false) { result = new StringBuffer("GEOMETRYCOLLECTION EMPTY"); } else { // 1st figure out if all the collection is the same type Geometry type = null; for (Geometry g : gc.getGeometries()) { if (type == null) { type = g; } else if (!type.getClass().isInstance(g)) { type = null; break; } } if (type == null) { result = new StringBuffer("GEOMETRYCOLLECTION EMPTY"); } else { String strip = null; if (GeometryCollection.class.isInstance(type)) { result = new StringBuffer("GEOMETRYCOLLECTION("); } else if (Point.class.isInstance(type)) { result = new StringBuffer("MULTIPOINT("); strip = "POINT"; } else if (LineString.class.isInstance(type)) { result = new StringBuffer("MULTILINESTRING("); strip = "LINESTRING"; } else if (Polygon.class.isInstance(type)) { result = new StringBuffer("MULTIPOLYGON("); strip = "POLYGON"; } else { result = new StringBuffer("GEOMETRYCOLLECTION EMPTY"); } String sep = ""; for (Geometry g : gc.getGeometries()) { result.append(sep); // strip the name if it a multi... type result.append(StringUtils.removeStartIgnoreCase(toWkt(g), strip)); sep = ","; } result.append(")"); } } return result.toString(); }
From source file:org.xwiki.query.internal.TextQueryFilter.java
private List<String> getFilterableColumns(String statement) { List<String> columns = new ArrayList<>(); String selectClause = statement .substring("select ".length(), StringUtils.indexOfIgnoreCase(statement, " from ")).trim(); selectClause = StringUtils.removeStartIgnoreCase(selectClause, "distinct "); for (String column : COLUMN_SEPARATOR.split(selectClause)) { // Remove the column alias. String columnWithoutAlias = column; int aliasPosition = column.lastIndexOf(" as "); if (aliasPosition > 0) { columnWithoutAlias = column.substring(0, aliasPosition).trim(); String alias = column.substring(aliasPosition + 4).trim(); if (alias.startsWith("unfilterable")) { continue; }//from w w w . ja v a 2s .c o m } columns.add(columnWithoutAlias); } return columns; }