List of usage examples for org.apache.commons.lang StringUtils lastIndexOf
public static int lastIndexOf(String str, String searchStr)
Finds the last index within a String, handling null
.
From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.MappingParam.java
public static MappingParam parse(String aMapping) { int sep = StringUtils.lastIndexOf(aMapping, SEP); return new MappingParam(aMapping.substring(0, sep), aMapping.substring(sep + SEP.length())); }
From source file:com.hangum.tadpole.commons.utils.zip.util.ZipUtils.java
/** * //from ww w.j a v a 2s .c o m * @param base_dir * @param zipFile * @return * @throws Exception */ public static String pack(String base_dir, String zipFile) throws Exception { String zipFullPath = PublicTadpoleDefine.TEMP_DIR + zipFile + ".zip"; ZipUtil.pack(new File(base_dir), new File(zipFullPath), new NameMapper() { public String map(String name) { try { if (!StringUtils.equals(name, StringEscapeUtils.escapeJava(name))) { name = "download_files" + StringUtils.substring(name, StringUtils.lastIndexOf(name, '.')); } name = new String(name.getBytes(), "UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return name; } }); return zipFullPath; }
From source file:de.thischwa.pmcms.tool.connection.PathAnalyzer.java
public PathAnalyzer(final String targetPath) { if (StringUtils.isBlank(targetPath)) throw new IllegalArgumentException("TargetPath shouldn't be null!"); int pos = StringUtils.lastIndexOf(targetPath, '/'); if (pos == -1 || pos == 0) { dir = ""; if (pos == -1) name = targetPath;/* w w w.j a v a 2s.co m*/ else name = targetPath.substring(1); } else { dir = targetPath.substring(0, StringUtils.lastIndexOf(targetPath, '/')); name = targetPath.substring(StringUtils.lastIndexOf(targetPath, '/'), targetPath.length()); if (name.startsWith("/")) name = name.substring(1); if (dir.startsWith("/")) dir = dir.substring(1); } }
From source file:com.cyclopsgroup.waterview.core.DefaultPath.java
/** * Constructor//from w w w . ja v a2s.c o m * * @param packageName Package name * @param packageAlias Package alias * @param path Relative path without package alias */ DefaultPath(String packageName, String packageAlias, String path) { if (path.indexOf(0) == '/') { path = '/' + path; } this.packageName = packageName; this.packageAlias = packageAlias; this.path = path; pathWithoutExtension = path; int lastDot = StringUtils.lastIndexOf(path, '.'); if (lastDot > -1) { pathWithoutExtension = path.substring(0, lastDot); extension = path.substring(lastDot); } fullPath = '/' + packageAlias + path; }
From source file:eionet.meta.filters.DDCORSFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) resp; HttpServletRequest request = (HttpServletRequest) req; String requestUrl = request.getRequestURL().toString(); // filter only if request ends with /json int lastIndexOfSlash = StringUtils.lastIndexOf(requestUrl, "/"); String subString = StringUtils.substring(requestUrl, lastIndexOfSlash); if (StringUtils.startsWith(subString, "/json")) { response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); }/*from ww w.ja va 2 s. co m*/ chain.doFilter(req, resp); }
From source file:com.intel.cosbench.driver.generator.HistogramIntGenerator.java
private static HistogramIntGenerator tryParse(String pattern) { pattern = StringUtils.substringBetween(pattern, "(", ")"); String[] args = StringUtils.split(pattern, ','); ArrayList<Bucket> bucketsList = new ArrayList<Bucket>(); for (String arg : args) { int v1 = StringUtils.indexOf(arg, '|'); int v2 = StringUtils.lastIndexOf(arg, '|'); boolean isOpenRange = ((v2 - v1) == 1) ? true : false; String[] values = StringUtils.split(arg, '|'); int lower, upper, weight; if (isOpenRange) { lower = Integer.parseInt(values[0]); upper = UniformIntGenerator.getMAXupper(); weight = Integer.parseInt(values[1]); } else if (values.length != 3) { throw new IllegalArgumentException(); } else {//from w ww .j a va2 s . c om lower = Integer.parseInt(values[0]); upper = Integer.parseInt(values[1]); weight = Integer.parseInt(values[2]); } bucketsList.add(new Bucket(lower, upper, weight)); } if (bucketsList.isEmpty()) { throw new IllegalArgumentException(); } Collections.sort(bucketsList, new LowerComparator()); final Bucket[] buckets = bucketsList.toArray(new Bucket[0]); int cumulativeWeight = 0; for (Bucket bucket : buckets) { cumulativeWeight += bucket.weight; bucket.cumulativeWeight = cumulativeWeight; } return new HistogramIntGenerator(buckets); }
From source file:com.ewcms.content.resource.service.ResourceService.java
/** * Uri/*w ww .j ava 2s.com*/ * * @param uri ??? * @return */ String getThumbUri(String uri) { int index = StringUtils.lastIndexOf(uri, '.'); if (index == -1) { return uri + getThumbSuffix(); } else { return StringUtils.overlay(uri, getThumbSuffix(), index, index); } }
From source file:info.magnolia.cms.filters.RepositoryMappingFilter.java
@Override public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String uri = MgnlContext.getAggregationState().getCurrentURI(); int firstSelectorDelimiterPos = StringUtils.indexOf(uri, Path.SELECTOR_DELIMITER, StringUtils.lastIndexOf(uri, '/')); String path;/* w ww. ja v a 2s . c om*/ // TODO Warning - this might change in the future - see MAGNOLIA-2343 for details. String selector; if (firstSelectorDelimiterPos > -1) { int lastSelectorDelimiterPos = StringUtils.lastIndexOf(uri, Path.SELECTOR_DELIMITER); path = StringUtils.substring(uri, 0, firstSelectorDelimiterPos); selector = StringUtils.substring(uri, firstSelectorDelimiterPos + 1, lastSelectorDelimiterPos); } else { // no tilde (and no extension) path = uri; selector = ""; } URI2RepositoryMapping mapping = uri2RepositoryManager.getMapping(uri); // remove prefix if any path = mapping.getHandle(path); final AggregationState aggregationState = MgnlContext.getAggregationState(); aggregationState.setRepository(mapping.getRepository()); aggregationState.setHandle(path); // selector could potentially be set from some other place, but we have no better idea for now :) aggregationState.setSelector(selector); chain.doFilter(request, response); }
From source file:gov.nih.nci.cacis.ip.mirthconnect.CanonicalModelProcessor.java
/** * Method accepts canonical data for processing * /*from w w w . ja va 2 s.c o m*/ * @param request CaCISRequest * @return response CaCISResponse * @throws AcceptCanonicalFault Fault * @throws */ @WebResult(name = "caCISResponse", targetNamespace = CACIS_NS, partName = "parameter") @WebMethod public gov.nih.nci.cacis.CaCISResponse acceptCanonical( @WebParam(partName = "parameter", name = "caCISRequest", targetNamespace = CACIS_NS) CaCISRequest request) throws AcceptCanonicalFault { final CaCISResponse response = new CaCISResponse(); final StringWriter sw = new StringWriter(); try { final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final Marshaller m = jc.createMarshaller(); final PrintWriter pw = new PrintWriter(sw); m.marshal(request, pw); response.setStatus(ResponseStatusType.SUCCESS); } catch (JAXBException jaxE) { throw new AcceptCanonicalFault("Error Marshalling object", jaxE); } try { String mcResponse = webServiceMessageReceiver.processData(sw.toString()); if (mcResponse != null && (mcResponse.indexOf("Error") > -1 || mcResponse.indexOf("Exception") > -1 || mcResponse.indexOf("ERROR") > -1 || mcResponse.indexOf("error") > -1)) { mcResponse = StringUtils.remove(mcResponse, "SUCCESS:"); String channelUid = StringUtils.substringBetween(mcResponse, "(", ")"); if (channelUid != null) { mcResponse = StringUtils.remove(mcResponse, "(" + channelUid + ")"); } throw new AcceptCanonicalFault( StringUtils.substring(mcResponse, StringUtils.lastIndexOf(mcResponse, ':'))); } response.setStatus(ResponseStatusType.SUCCESS); return response; // CHECKSTYLE:OFF } catch (Exception e) { // CHECKSTYLE:ON //throw new AcceptCanonicalFault("Error processing message!" + e.getMessage(), e); throw new AcceptCanonicalFault(e.getMessage(), e); } }
From source file:com.cognifide.cq.cqsm.foundation.actions.allow.Allow.java
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = new ActionResult(); try {// w w w. j a v a 2s. c o m Authorizable authorizable = context.getCurrentAuthorizable(); actionResult.setAuthorizable(authorizable.getID()); context.getSession().getNode(path); final PermissionActionHelper permissionActionHelper = new PermissionActionHelper( context.getValueFactory(), path, glob, permissions); LOGGER.info(String.format("Adding permissions %s for authorizable with id = %s for path = %s %s", permissions.toString(), context.getCurrentAuthorizable().getID(), path, StringUtils.isEmpty(glob) ? "" : ("glob = " + glob))); if (simulate) { permissionActionHelper.checkPermissions(context.getAccessControlManager()); } else { permissionActionHelper.applyPermissions(context.getAccessControlManager(), authorizable.getPrincipal(), true); } actionResult.logMessage("Added allow privilege for " + authorizable.getID() + " on " + path); if (permissions.contains("MODIFY")) { String preparedGlob = ""; if (!StringUtils.isBlank(glob)) { preparedGlob = glob; if (StringUtils.endsWith(glob, "*")) { preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*')); } } new Allow(path, preparedGlob + "*/jcr:content*", ignoreInexistingPaths, Collections.singletonList("MODIFY_PAGE")).process(context, simulate); } } catch (final PathNotFoundException e) { if (ignoreInexistingPaths) { actionResult.logWarning("Path " + path + " not found"); } else { actionResult.logError("Path " + path + " not found"); return actionResult; } } catch (RepositoryException | PermissionException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }