List of usage examples for org.apache.commons.lang StringUtils substring
public static String substring(String str, int start)
Gets a substring from the specified String avoiding exceptions.
From source file:org.sonar.batch.scan.filesystem.PathPattern.java
static PathPattern create(String s) { String trimmed = StringUtils.trim(s); if (StringUtils.startsWithIgnoreCase(trimmed, "file:")) { return new AbsolutePathPattern(StringUtils.substring(trimmed, "file:".length())); }//www .j av a 2 s . c o m return new RelativePathPattern(trimmed); }
From source file:org.sonar.core.resource.ResourceIndexerDao.java
void doIndex(ResourceDto resource, ResourceIndexerMapper mapper) { String key = nameToKey(resource.getName()); if (key.length() >= MINIMUM_KEY_SIZE) { ResourceIndexDto dto = new ResourceIndexDto().setResourceId(resource.getId()) .setQualifier(resource.getQualifier()).setRootProjectId(resource.getRootId()) .setNameSize(resource.getName().length()); for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) { dto.setPosition(position);/*from w ww . j a v a2 s. c o m*/ dto.setKey(StringUtils.substring(key, position)); mapper.insert(dto); } } }
From source file:org.sonar.core.resource.ResourceIndexerDao.java
private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexerMapper mapper) {//from w w w.j a va 2 s. c o m boolean indexed = false; String key = nameToKey(name); if (key.length() >= MINIMUM_KEY_SIZE) { indexed = true; boolean toBeIndexed = sanitizeIndex(id, key, mapper); if (toBeIndexed) { ResourceIndexDto dto = new ResourceIndexDto().setResourceId(id).setQualifier(qualifier) .setRootProjectId(rootId).setNameSize(name.length()); for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) { dto.setPosition(position); dto.setKey(StringUtils.substring(key, position)); mapper.insert(dto); } session.commit(); } } return indexed; }
From source file:org.sonar.plugins.web.checks.scripting.OGNLExpressionCheck.java
private void parseAndValidate(TagNode element, String text) { for (int i = 0; i + 1 < text.length(); i++) { if ((text.charAt(i) == '%' || text.charAt(i) == '#') && text.charAt(i + 1) == '{') { String expression = StringUtils.substringBefore(StringUtils.substring(text, i + 2), "}"); validateExpression(element, expression); }//from w w w .j a v a 2 s .c om } }
From source file:org.talend.metadata.managment.model.NetezzaConnectionFiller.java
/** * get the database name from the url./*from ww w. j a v a 2 s . c o m*/ * * @param url * @return */ private String getDatabaseNameFromUrl(String url) { if (StringUtils.isBlank(url)) { return StringUtils.EMPTY; } int lastIndexOf1 = StringUtils.lastIndexOf(url, "/"); //$NON-NLS-1$ if (lastIndexOf1 < 0 || lastIndexOf1 > url.length() - 1) { return StringUtils.EMPTY; } int lastIndexOf2 = StringUtils.lastIndexOf(url, "?"); //$NON-NLS-1$ if (lastIndexOf2 < 0) { return StringUtils.substring(url, lastIndexOf1 + 1); } else { if (lastIndexOf2 < lastIndexOf1) { return StringUtils.EMPTY; } return StringUtils.substring(url, lastIndexOf1 + 1, lastIndexOf2); } }
From source file:org.trancecode.xproc.step.AddXmlBaseStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { final XdmNode sourceDoc = input.readNode(XProcPorts.SOURCE); final boolean allOption = Boolean.valueOf(input.getOptionValue(XProcOptions.ALL, "false")); final boolean relativeOption = Boolean.valueOf(input.getOptionValue(XProcOptions.RELATIVE, "true")); final QName xmlBase = new QName("xml", XMLConstants.XML_NS_URI, "base"); if (allOption && relativeOption) { throw XProcExceptions.xc0058(input.getStep().getLocation()); }/*from w ww. j a va 2s . c om*/ final SaxonProcessorDelegate addXmlBaseDelegate = new CopyingSaxonProcessorDelegate() { @Override public EnumSet<NextSteps> startElement(final XdmNode node, final SaxonBuilder builder) { builder.startElement(node.getNodeName(), node); for (final XdmNode attribute : SaxonAxis.attributes(node)) { LOG.trace("copy existing attribute except xml base: {}", attribute); if (!xmlBase.equals(attribute.getNodeName())) { builder.attribute(attribute.getNodeName(), attribute.getStringValue()); } } if (allOption || XdmNodeKind.DOCUMENT.equals(node.getParent().getNodeKind())) { builder.attribute(xmlBase, node.getBaseURI().toString()); } else { if (!node.getBaseURI().equals(node.getParent().getBaseURI())) { if (relativeOption) { final String attrBase = node.getParent().getBaseURI().resolve(node.getBaseURI()) .toString(); final int lastIdx = StringUtils.lastIndexOf(attrBase, "/") + 1; builder.attribute(xmlBase, StringUtils.substring(attrBase, lastIdx)); } else { builder.attribute(xmlBase, node.getBaseURI().toString()); } } } return EnumSet.of(NextSteps.PROCESS_CHILDREN, NextSteps.START_CONTENT); } }; final SaxonProcessor addXmlBaseProcessor = new SaxonProcessor(input.getPipelineContext().getProcessor(), addXmlBaseDelegate); final XdmNode result = addXmlBaseProcessor.apply(sourceDoc); output.writeNodes(XProcPorts.RESULT, result); }
From source file:org.vulpe.fox.apt.strategies.ForAllDAOTemplateStrategy.java
private void putMethod(final DecoratedClassDeclaration clazz, final DecoratedDAO dao, final String query, final String queryName, final QueryHint[] hints) { if (queryName.equals(dao.getName().concat(".read"))) { return;/*from w ww. java 2s . c o m*/ } final DecoratedDAOMethod method = new DecoratedDAOMethod(); if (StringUtils.indexOf(queryName, dao.getName().concat(".")) > -1) { method.setName( StringUtils.substring(queryName, StringUtils.indexOf(queryName, dao.getName().concat(".")) + new String(dao.getName().concat(".")).length())); } else { throw new VulpeSystemException("Name of definition in the query is incorrect. Must be on format: " .concat(dao.getName()).concat(".").concat(queryName)); } boolean unique = false; String newQuery = StringUtils.replace(query, "\t", " "); final char dots = ':'; final char space = ' '; while (newQuery.indexOf(dots) > -1) { newQuery = newQuery.substring(newQuery.indexOf(dots)); String param = newQuery.substring(1); param = param.replace(")", "").replace("(", ""); if (newQuery.indexOf(space) > -1) { param = newQuery.substring(1, newQuery.indexOf(space)); } newQuery = newQuery.replace(":".concat(param), ""); // get parameter type in annotations @Params and @QueryParameter String type = getType(param, hints); if (type == null) { final FieldDeclaration field = getField(clazz, param); if (field == null) { throw new VulpeSystemException( "Parameter [".concat(param).concat("] not found on class: ").concat(dao.getName())); } else { if (param.equals("id")) { unique = true; } type = field.getType().toString(); // verified if is unique column or id if (!unique) { final Column column = field.getAnnotation(Column.class); if (column != null) { unique = column.unique(); } if (!unique) { final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class); if (field.getAnnotation(JoinColumn.class) != null) { unique = joinColumn.unique(); } } } } } final DecoratedDAOParameter parameter = new DecoratedDAOParameter(); parameter.setName(param); parameter.setType(type); method.getParameters().add(parameter); } for (final QueryHint queryHint : hints) { if (queryHint.name().equals("limit")) { final DecoratedDAOParameter parameter = new DecoratedDAOParameter(); parameter.setName("limit"); parameter.setType("java.lang.Integer"); parameter.setValue(Integer.valueOf(queryHint.value())); method.getParameters().add(0, parameter); } } setupReturn(dao, queryName, hints, method, unique); dao.getMethods().add(method); }
From source file:org.vulpe.fox.dao.DecoratedDAO.java
public String getSuperclassSimpleName() { return StringUtils.substring(superclassName, StringUtils.lastIndexOf(superclassName, ".") + 1); }
From source file:org.vulpe.fox.dao.DecoratedDAO.java
public String getDaoSuperclassSimpleName() { return StringUtils.substring(daoSuperclassName, StringUtils.lastIndexOf(daoSuperclassName, ".") + 1); }
From source file:org.wso2.carbon.identity.oauth.endpoint.authz.OAuth2AuthzEndpoint.java
/** * @param consent//from ww w .j a v a 2s . c om * @param sessionDataCacheEntry * @return * @throws OAuthSystemException */ private String handleUserConsent(HttpServletRequest request, String consent, OAuth2Parameters oauth2Params, SessionDataCacheEntry sessionDataCacheEntry, OIDCSessionState sessionState) throws OAuthSystemException { String applicationName = sessionDataCacheEntry.getoAuth2Parameters().getApplicationName(); AuthenticatedUser loggedInUser = sessionDataCacheEntry.getLoggedInUser(); String clientId = sessionDataCacheEntry.getoAuth2Parameters().getClientId(); boolean skipConsent = EndpointUtil.getOAuthServerConfiguration().getOpenIDConnectSkipeUserConsentConfig(); if (!skipConsent) { boolean approvedAlways = OAuthConstants.Consent.APPROVE_ALWAYS.equals(consent) ? true : false; if (approvedAlways) { OpenIDConnectUserRPStore.getInstance().putUserRPToStore(loggedInUser, applicationName, approvedAlways, clientId); } } OAuthResponse oauthResponse = null; String responseType = oauth2Params.getResponseType(); // authorizing the request OAuth2AuthorizeRespDTO authzRespDTO = authorize(oauth2Params, sessionDataCacheEntry); if (authzRespDTO != null && authzRespDTO.getErrorCode() == null) { OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse .authorizationResponse(request, HttpServletResponse.SC_FOUND); // all went okay if (StringUtils.isNotBlank(authzRespDTO.getAuthorizationCode())) { builder.setCode(authzRespDTO.getAuthorizationCode()); addUserAttributesToCache(sessionDataCacheEntry, authzRespDTO.getAuthorizationCode(), authzRespDTO.getCodeId()); } if (StringUtils.isNotBlank(authzRespDTO.getAccessToken()) && !OAuthConstants.ID_TOKEN.equalsIgnoreCase(responseType) && !OAuthConstants.NONE.equalsIgnoreCase(responseType)) { builder.setAccessToken(authzRespDTO.getAccessToken()); builder.setExpiresIn(authzRespDTO.getValidityPeriod()); builder.setParam(OAuth.OAUTH_TOKEN_TYPE, "Bearer"); } if (StringUtils.isNotBlank(authzRespDTO.getIdToken())) { builder.setParam("id_token", authzRespDTO.getIdToken()); } if (StringUtils.isNotBlank(oauth2Params.getState())) { builder.setParam(OAuth.OAUTH_STATE, oauth2Params.getState()); } String redirectURL = authzRespDTO.getCallbackURI(); if (RESPONSE_MODE_FORM_POST.equals(oauth2Params.getResponseMode())) { String authenticatedIdPs = sessionDataCacheEntry.getAuthenticatedIdPs(); if (authenticatedIdPs != null && !authenticatedIdPs.isEmpty()) { builder.setParam("AuthenticatedIdPs", sessionDataCacheEntry.getAuthenticatedIdPs()); } oauthResponse = builder.location(redirectURL).buildJSONMessage(); } else { oauthResponse = builder.location(redirectURL).buildQueryMessage(); } sessionState.setAuthenticated(true); } else if (authzRespDTO != null && authzRespDTO.getErrorCode() != null) { // Authorization failure due to various reasons sessionState.setAuthenticated(false); String errorMsg; if (authzRespDTO.getErrorMsg() != null) { errorMsg = authzRespDTO.getErrorMsg(); } else { errorMsg = "Error occurred while processing the request"; } OAuthProblemException oauthProblemException = OAuthProblemException.error(authzRespDTO.getErrorCode(), errorMsg); return EndpointUtil.getErrorRedirectURL(oauthProblemException, oauth2Params); } else { // Authorization failure due to various reasons sessionState.setAuthenticated(false); String errorCode = OAuth2ErrorCodes.SERVER_ERROR; String errorMsg = "Error occurred while processing the request"; OAuthProblemException oauthProblemException = OAuthProblemException.error(errorCode, errorMsg); return EndpointUtil.getErrorRedirectURL(oauthProblemException, oauth2Params); } //When response_mode equals to form_post, body parameter is passed back. if (RESPONSE_MODE_FORM_POST.equals(oauth2Params.getResponseMode()) && StringUtils.isNotEmpty(oauthResponse.getBody())) { return oauthResponse.getBody(); } else { //When responseType equal to "id_token" the resulting token is passed back as a query parameter //According to the specification it should pass as URL Fragment if (OAuthConstants.ID_TOKEN.equalsIgnoreCase(responseType)) { if (authzRespDTO.getCallbackURI().contains("?")) { return authzRespDTO.getCallbackURI() + "#" + StringUtils .substring(oauthResponse.getLocationUri(), authzRespDTO.getCallbackURI().length() + 1); } else { return oauthResponse.getLocationUri().replace("?", "#"); } } else { return appendAuthenticatedIDPs(sessionDataCacheEntry, oauthResponse.getLocationUri()); } } }