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:com.cognifide.cq.cqsm.foundation.actions.deny.Deny.java
private ActionResult process(final Context context, boolean simulate) { ActionResult actionResult = new ActionResult(); try {/*from w ww . j a v a 2s .c om*/ 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("Denying 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(), false); } actionResult.logMessage("Added deny privilege for " + authorizable.getID() + " on " + path); if (permissions.contains("MODIFY")) { List<String> globModifyPermission = new ArrayList<>(); globModifyPermission.add("MODIFY_PAGE"); String preparedGlob = ""; if (!StringUtils.isBlank(glob)) { preparedGlob = glob; if (StringUtils.endsWith(glob, "*")) { preparedGlob = StringUtils.substring(glob, 0, StringUtils.lastIndexOf(glob, '*')); } } new Deny(path, preparedGlob + "*/jcr:content*", ignoreUnexistingPaths, globModifyPermission) .process(context, simulate); } } catch (final PathNotFoundException e) { if (ignoreUnexistingPaths) { actionResult.logWarning("Path " + path + " not found"); } else { actionResult.logError("Path " + path + " not found"); } } catch (final RepositoryException | PermissionException | ActionExecutionException e) { actionResult.logError(MessagingUtils.createMessage(e)); } return actionResult; }
From source file:eionet.web.util.JstlFunctions.java
/** * Cuts the given String if exceeds the length. Finds the first whitespace after the position to be cut. Adds an ellipsis in the * end if the length is exceeded.//from w w w.j a v a 2 s . c o m * * @param str given string value * @param cutAtLength max len of string * * @return cut string */ public static java.lang.String cutAtSpace(java.lang.String str, int cutAtLength) { char c = (char) Integer.parseInt(String.valueOf(2026), 16); final String ellipsis = String.valueOf(c); if (str == null) { return ""; } if (str.length() <= cutAtLength) { return str; } String stringStart = str.substring(0, cutAtLength); // if the Nth char is space ther is not need to split the string if (str.charAt(cutAtLength) == ' ') { stringStart = stringStart + " "; } int prevSpace = StringUtils.lastIndexOf(stringStart, " "); str = prevSpace == -1 ? stringStart : str.substring(0, prevSpace + 1); return str + ellipsis; }
From source file:com.edgenius.wiki.render.filter.UserFilter.java
@Override protected void replaceHTML(HTMLNode node, ListIterator<HTMLNode> nodeIter, RenderContext context) { if (node.getPair() == null) { AuditLogger.error("Unexpected case: Unable to find close </a> tag"); return;/* w w w. j a v a 2 s. com*/ } LinkModel link = new LinkModel(); //we don't need view info,so just skip it link.fillToObject(node.getText(), null); //We put username into last part of anchor: /$CPAGE/up/admin String linkURL = link.getAnchor(); if (StringUtils.endsWith(linkURL, "/")) { linkURL = StringUtils.removeEnd(linkURL, "/"); } int idx = StringUtils.lastIndexOf(linkURL, "/"); if (idx != -1) { String username = linkURL.substring(idx + 1); HTMLNode subnode = node.next(); while (subnode != null && subnode != node.getPair()) { if (subnode.isTextNode()) subnode.reset("", true); subnode = subnode.next(); } node.getPair().reset("", true); String markupBorder = getSeparatorFilter(node); StringBuffer markup = new StringBuffer(markupBorder).append("@"); markup.append(username); markup.append("@").append(markupBorder); node.reset(markup.toString(), true); } }
From source file:gemlite.core.webapp.tools.ClusterController.java
/** * hoemDir//from w w w . j av a 2 s . co m U * /home/gemfire/order * @param homeDir * @return */ private String getParentDir(String homeDir) { if (StringUtils.endsWith(homeDir, "/")) homeDir = StringUtils.substring(homeDir, 0, homeDir.length() - 1); int index = StringUtils.lastIndexOf(homeDir, "/"); String left = StringUtils.substring(homeDir, 0, index); return left; }
From source file:edu.monash.merc.system.version.TLVersionTrack.java
public int[] separateTokenAsTwo() { String tokenStr = String.valueOf(this.trackToken); int last1Index = StringUtils.lastIndexOf(tokenStr, "1"); int last1Gap = tokenStr.length() - last1Index; if (last1Gap == tokenStr.length()) { return new int[] { this.trackToken }; } else {//from w w w .j a v a 2 s. c o m int secondToken = createSecondToken(last1Gap); int firstToken = this.trackToken - secondToken; return new int[] { firstToken, secondToken }; } }
From source file:hydrograph.ui.dataviewer.adapters.DataViewerAdapter.java
private String getType(String databaseName) throws IOException { StringBuffer typeString = new StringBuffer(); String debugFileName = debugDataViewer.getDebugFileName(); String debugFileLocation = debugDataViewer.getDebugFileLocation(); if (ViewDataSchemaHelper.INSTANCE.getFieldsFromSchema( debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION) == null) { return ""; }/* w w w . ja v a2 s . c o m*/ Map<String, String> fieldAndTypes = new HashMap<String, String>(); for (Field field : ViewDataSchemaHelper.INSTANCE .getFieldsFromSchema(debugFileLocation + debugFileName + AdapterConstants.SCHEMA_FILE_EXTENTION) .getField()) { fieldAndTypes.put(StringUtils.lowerCase(field.getName()), field.getType().value()); } try (BufferedReader bufferedReader = new BufferedReader( new FileReader(new File(databaseName + tableName + AdapterConstants.CSV)))) { String firstLine = bufferedReader.readLine(); StringTokenizer stringTokenizer = new StringTokenizer(firstLine, ","); int countTokens = stringTokenizer.countTokens(); for (int i = 0; i < countTokens; i++) { String columnName = stringTokenizer.nextToken(); String typeName = fieldAndTypes.get(StringUtils.lowerCase(columnName)); typeString.append(StringUtils.substring(typeName, StringUtils.lastIndexOf(typeName, ".") + 1)); if (i != countTokens - 1) { typeString.append(","); } } } catch (IOException ioException) { logger.error("Failed to read view data file column headers", ioException); throw ioException; } return typeString.toString(); }
From source file:crawl.SphinxWrapper.java
private static String shortenUrl(String url) { String result = url.replaceAll("//+", "/"); int s0 = StringUtils.lastIndexOf(url, '/'); int s1 = StringUtils.lastIndexOf(url, '/', s0 - 1); if (s1 > 0) { result = url.substring(s1 + 1);// ww w . j av a 2 s. co m } return result; }
From source file:com.egt.core.aplicacion.Bitacora.java
private static String getSimpleClassName(String className) { int i = StringUtils.lastIndexOf(className, '.'); return i < 0 ? className : className.substring(i + 1); }
From source file:biz.netcentric.cq.tools.actool.dumpservice.impl.DumpserviceImpl.java
/** removes the name of the group node itself (groupID) from the intermediate path * * @param intermediatePath//w w w. j a v a2 s . c o m * @param groupID * @return corrected path if groupID was found at the end of the intermediatePath, otherwise original path */ private String getIntermediatePath(String intermediatePath, final String groupID) { int index = StringUtils.lastIndexOf(intermediatePath, "/" + groupID); if (index != -1) { intermediatePath = intermediatePath.replace(intermediatePath.substring(index), ""); } return intermediatePath; }
From source file:com.bluexml.xforms.controller.alfresco.agents.MappingAgent.java
/** * Finds a new name for an uploaded content. The name includes the content type, the random path * and the original file name./*from w ww.java2s . c o m*/ * <p/> * NOTE: uploadDir must have been set. * * @param type * the type * @param fileName * the file name * * @return the file */ private File findNewName(int depth, String type, String fileName) { String lFileName = fileName; if (lFileName.contains("\\")) { int lastIndexOf = StringUtils.lastIndexOf(lFileName, '\\'); lFileName = StringUtils.substring(lFileName, lastIndexOf + 1); } String rootPath = currentUploadDir.getAbsolutePath() + File.separator + type; String randomPath = RandomStringUtils.randomNumeric(depth); for (int i = 0; i < depth; i++) { rootPath = rootPath + File.separator + randomPath.charAt(i); } File root = new File(rootPath); File result = new File(root, lFileName); if (result.exists()) { int dotPos = lFileName.lastIndexOf("."); String fileNameWihoutExtension = null; String fileNameExtension = null; if (dotPos == -1) { fileNameWihoutExtension = lFileName; } else { fileNameWihoutExtension = lFileName.substring(0, dotPos); fileNameExtension = lFileName.substring(dotPos + 1); } int i = 0; do { String newFileName = fileNameWihoutExtension + "-" + i; if (fileNameExtension != null) { newFileName = newFileName + "." + fileNameExtension; } result = new File(root, newFileName); i++; } while (result.exists()); } result.getParentFile().mkdirs(); return result; }