List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:com.adobe.acs.commons.data.Spreadsheet.java
/** * Look for type hints in the name of a column to extract a usable type. Also look for array hints as well. <br> * Possible formats: // w w w. jav a 2s .c o m * <ul> * <li>column-name - A column named "column-name" </li> * <li>col@int - An integer column named "col" </li> * <li>col2@int[] - An integer array colum named "col2", assumes standard delimiter (,) </li> * <li>col3@string[] or col3@[] - A String array named "col3", assumes standard delimiter (,)</li> * <li>col4@string[||] - A string array where values are using a custom delimiter (||)</li> * </ul> * * @param name * @return */ private Class detectTypeFromName(String name) { boolean isArray = false; Class detectedClass = String.class; if (name.contains("@")) { String typeStr = StringUtils.substringAfter(name, "@"); if (name.endsWith("]")) { String colName = convertHeaderName(name); isArray = true; String delimiter = StringUtils.substringBetween(name, "[", "]"); typeStr = StringUtils.substringBefore("[", delimiter); if (!StringUtils.isEmpty(delimiter)) { delimiters.put(colName, delimiter); } } detectedClass = getClassFromName(typeStr); } if (isArray) { return getArrayType(detectedClass); } else { return detectedClass; } }
From source file:de.crowdcode.kissmda.core.jdt.JdtHelper.java
/** * Get JDT ParameterizedType for the given type name. * /*from www . j ava 2 s . c o m*/ * @param ast * JDT AST tree * @param typeName * input type name * @return JDT ParameterizedType */ @SuppressWarnings("unchecked") public ParameterizedType getAstParameterizedType(AST ast, String typeName) { // Get the component type and parameters <Type, Type, ...> String componentTypeName = StringUtils.substringBefore(typeName, "<"); Type componentType = getAstSimpleType(ast, componentTypeName); ParameterizedType parameterizedType = ast.newParameterizedType(componentType); String paramTypeNames = StringUtils.substringAfter(typeName, "<"); paramTypeNames = StringUtils.removeEnd(paramTypeNames, ">"); // Result: String, Integer, List<Boolean>, de.test.Company String[] parametersAsString = StringUtils.split(paramTypeNames, ","); for (int index = 0; index < parametersAsString.length; index++) { String paramTypeName = parametersAsString[index]; paramTypeName = StringUtils.remove(paramTypeName, ","); paramTypeName = StringUtils.trim(paramTypeName); Type paramType = getChosenType(ast, paramTypeName, paramTypeName, ""); // Add the type arguments parameterizedType.typeArguments().add(paramType); } return parameterizedType; }
From source file:com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver.java
private String getMetadataPropertyValue(FeedMetadata metadata, String variableName) throws Exception { String fieldPathName = StringUtils.substringAfter(variableName, metadataPropertyPrefix); Object obj = null;//from w ww .j ava 2s .c om try { obj = BeanUtils.getProperty(metadata, fieldPathName); } catch (Exception e) { // throw new RuntimeException(e); } //check to see if the path has a Metadata annotation with a matching field String matchingProperty = MetadataFields.getInstance().getMatchingPropertyDescriptor(metadata, variableName); if (obj == null && matchingProperty != null) { matchingProperty = StringUtils.substringAfter(matchingProperty, metadataPropertyPrefix); obj = BeanUtils.getProperty(metadata, matchingProperty); } if (obj != null) { return obj.toString(); } else { return null; } }
From source file:com.cognifide.qa.bb.aem.touch.siteadmin.aem62.SiteadminPage.java
private void navigateInteractively(String destination) { String currentUrl = StringUtils.substringAfter(driver.getCurrentUrl(), "sites.html"); if (!currentUrl.endsWith(destination)) { boolean isGoBackNeeded = !destination.startsWith(currentUrl); if (isGoBackNeeded) { goBackUsingNavigator(destination, currentUrl); } else {/*from w ww . j a va 2 s . c o m*/ goForwardToDestination(currentUrl, destination); } wait.withTimeout(Timeouts.SMALL) .until((ExpectedCondition<Object>) input -> ((JavascriptExecutor) driver) .executeScript("return $.active").toString().equals("0")); navigateInteractively(destination); } }
From source file:com.wso2.code.quality.matrices.ChangesFinder.java
/** * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of * * @param fileNames Arraylist of files names that are being affected by the relevant commit * @param patchString Array list having the patch string value for each of the file being changed *//* ww w . j ava 2s . c o m*/ public void saveRelaventEditLineNumbers(ArrayList<String> fileNames, ArrayList<String> patchString) { //filtering only the line ranges that are modified and saving to a string array // cannot ues parallel streams here as the order of the line changes must be preserved patchString.stream().map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@")) .forEach(lineChanges -> { //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array IntStream.range(0, lineChanges.length).forEach(j -> { //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28 String tempString = lineChanges[j]; String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-", " +"); // for taking the authors and commit hashes of the previous lines String lineRangeInTheNewFileResultedFromModification = StringUtils .substringAfter(tempString, "+"); // for taking the parent commit int intialLineNoInOldFile = Integer .parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ",")); int tempEndLineNoInOldFile = Integer .parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ",")); int endLineNoOfOldFile; if (intialLineNoInOldFile != 0) { // to filterout the newly created files endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1); } else { endLineNoOfOldFile = tempEndLineNoInOldFile; } int intialLineNoInNewFile = Integer.parseInt( StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ",")); int tempEndLineNoInNewFile = Integer.parseInt( StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ",")); int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1); // storing the line ranges that are being modified in the same array by replacing values lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/" + intialLineNoInNewFile + "," + endLineNoOfNewFile; }); ArrayList<String> tempArrayList = new ArrayList<>(Arrays.asList(lineChanges)); //adding to the array list which keep track of the line ranges being changed lineRangesChanged.add(tempArrayList); }); System.out.println("done saving file names and their relevant modification line ranges"); System.out.println(fileNames); System.out.println(lineRangesChanged + "\n"); }
From source file:eionet.webq.xforms.XFormsHTTPRequestAuthHandlerImpl.java
@Override public void addAuthToHttpRequest(HttpRequestBase httpRequestBase, Map<Object, Object> context) { String uri = httpRequestBase.getURI().toString(); String instance = null;/* w ww . j a va 2 s .c om*/ String envelope = null; String requestURLHost = null; Integer fileId = null; String authentication = null; String sessionId = null; if (uri == null) { return; } // load bf context attributes if (context.get("instance") != null) { instance = (String) context.get("instance"); } if (context.get("envelope") != null) { envelope = (String) context.get("envelope"); } if (context.get(BF_REQUEST_URL_ATTRIBUTE) != null) { try { URI requestURI = new URI((String) context.get(BF_REQUEST_URL_ATTRIBUTE)); requestURLHost = StringUtils.substringBefore(requestURI.toString(), requestURI.getHost()) + requestURI.getHost(); LOGGER.info("bF requestURLHost= " + requestURLHost); } catch (URISyntaxException e) { LOGGER.warn("requestURL is not valid URL: " + context.get(BF_REQUEST_URL_ATTRIBUTE)); } } if (context.get("fileId") != null) { fileId = Integer.valueOf((String) context.get("fileId")); } // http session attribute stored in betterform context if (context.get(BF_HTTP_SESSION_ATTRIBUTE) != null) { sessionId = (String) context.get(BF_HTTP_SESSION_ATTRIBUTE); } LOGGER.info("Get resource from XForm: " + uri); if (uri.startsWith(requestURLHost)) { // check if the request on the same (webq) host is done in the same session. Fix session id if required. if (sessionId != null) { validateSessionIdInRequestHeader(context, sessionId); LOGGER.info("Get resource from: " + uri); } } else { // add auth info only for URIs that are not on the same host. if (fileId != null && sessionId != null) { LOGGER.debug("Check if user is logged in to get resource for fileId=" + fileId); if (!context.containsKey(WEBQ_AUTH_ATTRIBUTE)) { // check if user is logged in - ask auth info from user_xml file table UserFile userFile = userFileService.getById(fileId); if (userFile.isAuthorized()) { String authorizationInfo = userFile.getAuthorization(); String cookiesInfo = userFile.getCookies(); if (StringUtils.isNotEmpty(authorizationInfo)) { authentication = "Authorization=" + authorizationInfo; } else if (StringUtils.isNotEmpty(cookiesInfo)) { authentication = "Cookie=" + cookiesInfo; } } context.put(WEBQ_AUTH_ATTRIBUTE, authentication); LOGGER.debug("Store basic auth info in context for fileId=" + fileId); } else { // auth info stored in context authentication = context.get(WEBQ_AUTH_ATTRIBUTE) != null ? (String) context.get(WEBQ_AUTH_ATTRIBUTE) : null; } // add auth info only if user is logged in if (StringUtils.isNotEmpty(authentication)) { LOGGER.debug("User is logged in to get resource for fileId=" + fileId); String authAttribute = StringUtils.substringBefore(authentication, "="); // if the URI starts with instance or envelope URI, then we can use the basic auth retrieved from CDR. if (!"Cookie".equals(authAttribute) && ((StringUtils.isNotBlank(instance) && uri.startsWith(instance)) || (StringUtils.isNotBlank(envelope) && uri.startsWith(envelope)))) { String authAttributeValues = StringUtils.substringAfter(authentication, "="); // prevent betterForm to overwrite cookies /* Fall back to KnownHosts authorisation (qaaccount) if cookie auth mode is used. // cookie mode does not work on test server. if ("Cookie".equals(authAttribute)) { if (context.containsKey(AbstractHTTPConnector.REQUEST_COOKIE)) { context.remove(AbstractHTTPConnector.REQUEST_COOKIE); } } */ httpRequestBase.addHeader(authAttribute, authAttributeValues); LOGGER.info("Add " + authAttribute + " from session to URL: " + uri); } else { // check if we have known host in db KnownHost knownHost = knownHostsService.getKnownHost(uri); if (knownHost != null) { // add ticket parameter to request URI if needed if (knownHost .getAuthenticationMethod() == KnownHostAuthenticationMethod.REQUEST_PARAMETER) { LOGGER.info("Add ticket parameter from known hosts to URL: " + uri); uri = getUrlWithAuthParam(uri, knownHost); if (!uri.equals(httpRequestBase.getURI().toString())) { try { httpRequestBase.setURI(new URI(uri)); } catch (URISyntaxException e) { LOGGER.error("Unable to add known host ticket parameter for URI:" + uri); e.printStackTrace(); } } } else if (knownHost.getAuthenticationMethod() == KnownHostAuthenticationMethod.BASIC) { // Add basic authorisation if needed try { LOGGER.info("Add basic auth from known hosts to URL: " + uri); httpRequestBase.addHeader("Authorization", "Basic " + Base64.encodeBase64String( (knownHost.getKey() + ":" + knownHost.getTicket()).getBytes("utf-8")) .replaceAll("\n", "")); } catch (UnsupportedEncodingException e) { LOGGER.warn("UnsupportedEncodingException: utf-8"); } } } } } } } }
From source file:com.erudika.scoold.utils.ScooldUtils.java
public boolean isEmailDomainApproved(String email) { if (StringUtils.isBlank(email)) { return false; }//from w ww.j a va 2 s.c o m if (!APPROVED_DOMAINS.isEmpty()) { return APPROVED_DOMAINS.contains(StringUtils.substringAfter(email, "@")); } return true; }
From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java
public static String getPackageName(String code) { String packageName = StringUtils.substringBefore(StringUtils.substringAfter(code, "package "), ";").trim(); return packageName; }
From source file:fusion.FuseLinkServlet.java
private void metadataKeepFlatLeft(int idx) throws SQLException { Connection virt_conn = vSet.getConnection(); StringBuilder concat_str = new StringBuilder(); for (String s : fs.predsA) { String[] pres = StringUtils.split(s, ","); StringBuilder q = new StringBuilder(); q.append("sparql SELECT * "); String prev_s = "<" + nodeA + ">"; q.append(" WHERE {\n GRAPH <" + tGraph + "metadataA> {"); if (pres.length == 1) { StringBuilder sq = new StringBuilder(); sq.append("INSERT { GRAPH <" + tGraph + "> { "); sq.append(prev_s + " <" + pres[0] + "> ?o" + 0 + " . } "); sq.append(" } WHERE {\n GRAPH <" + tGraph + "metadataA> { " + prev_s + " <" + pres[0] + "> ?o" + 0 + " . } }"); //System.out.println(sq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(sq.toString(), vSet); vur.exec();//from w w w. java 2 s. c o m return; } for (int i = 0; i < pres.length; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } q.append("} }"); //System.out.println(q.toString()); PreparedStatement stmt; stmt = virt_conn.prepareStatement(q.toString()); ResultSet rs = stmt.executeQuery(); while (rs.next()) { StringBuilder insq = new StringBuilder(); insq.append("INSERT { GRAPH <" + tGraph + "> { "); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length - 2; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } String o = rs.getString(pres.length); String simplified = StringUtils.substringAfter(pres[pres.length - 1], "#"); if (simplified.equals("")) { simplified = StringUtils.substring(pres[pres.length - 1], StringUtils.lastIndexOf(pres[pres.length - 1], "/") + 1); } String o2 = rs.getString(pres.length - 1); insq.append(prev_s + " <" + o2 + "_" + simplified + "> \"" + o + "\""); insq.append("} } WHERE {\n GRAPH <" + tGraph + "metadataA> {"); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } insq.append("} }"); //System.out.println(insq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(insq.toString(), vSet); vur.exec(); } //System.out.println(q.toString()); } }
From source file:com.xpn.xwiki.objects.classes.PropertyClass.java
public void displayCustom(StringBuffer buffer, String fieldName, String prefix, String type, BaseObject object, XWikiContext context) throws XWikiException { String content = ""; try {// w w w.j a va 2 s. c o m VelocityContext vcontext = Utils.getComponent(VelocityManager.class).getVelocityContext(); vcontext.put("name", fieldName); vcontext.put("prefix", prefix); // The PropertyClass instance can be used to access meta properties in the custom displayer (e.g. // dateFormat, multiSelect). It can be obtained from the XClass of the given object but only if the property // has been added to the XClass. We need to have it in the Velocity context for the use case when an XClass // property needs to be previewed before being added to the XClass. vcontext.put("field", new com.xpn.xwiki.api.PropertyClass(this, context)); vcontext.put("object", new com.xpn.xwiki.api.Object(object, context)); vcontext.put("type", type); vcontext.put("context", new com.xpn.xwiki.api.Context(context)); BaseProperty prop = (BaseProperty) object.safeget(fieldName); if (prop != null) { vcontext.put("value", prop.getValue()); } else { // The $value property can exist in the velocity context, we overwrite it to make sure we don't get a // wrong value in the displayer when the property does not exist yet. vcontext.put("value", null); } String customDisplayer = getCachedDefaultCustomDisplayer(context); if (StringUtils.isNotEmpty(customDisplayer)) { if (customDisplayer.equals(CLASS_DISPLAYER_IDENTIFIER)) { content = getCustomDisplay(); String classSyntax = context.getWiki().getDocument(getObject().getDocumentReference(), context) .getSyntax().toIdString(); content = context.getDoc().getRenderedContent(content, classSyntax, context); } else if (customDisplayer.startsWith(DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX)) { XWikiDocument displayerDoc = context.getWiki().getDocument( StringUtils.substringAfter(customDisplayer, DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX), context); content = displayerDoc.getContent(); String classSyntax = displayerDoc.getSyntax().toIdString(); content = context.getDoc().getRenderedContent(content, classSyntax, context); } else if (customDisplayer.startsWith(TEMPLATE_DISPLAYER_IDENTIFIER_PREFIX)) { content = context.getWiki().evaluateTemplate( StringUtils.substringAfter(customDisplayer, TEMPLATE_DISPLAYER_IDENTIFIER_PREFIX), context); } } } catch (Exception e) { throw new XWikiException(XWikiException.MODULE_XWIKI_CLASSES, XWikiException.ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY, "Exception while preparing the custom display of " + fieldName, e, null); } buffer.append(content); }