Example usage for org.apache.commons.lang StringUtils removeStart

List of usage examples for org.apache.commons.lang StringUtils removeStart

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils removeStart.

Prototype

public static String removeStart(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the begining of a source string, otherwise returns the source string.

Usage

From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Payload.java

public static String reference(String str) {
    return StringUtils.removeStart(str, "-");
}

From source file:it.TestCustomFields.java

@Test
public void importMultiselectCustomFields() {
    final String customFieldName = "Multi";
    final String cid = StringUtils.removeStart(
            administration.customFields().addCustomField(MULTISELECT_CF_TYPE, customFieldName),
            FieldManager.CUSTOM_FIELD_PREFIX);
    administration.customFields().addOptions(cid, "Core", "Subsystem", "API", "UX");

    assertMultiCustomFields(customFieldName);
}

From source file:com.github.ipaas.ideploy.agent.handler.UpdateCodeHandlerTest.java

/**
 * ??,???,//from   w  w  w.j av  a  2  s  . co  m
 * 
 * @throws Exception
 */
@Test
public void updateCodeTest() throws Exception {
    String usingRoot = "/www/apptemp/" + USING_VERSION;
    String doingRoot = "/www/apptemp/" + DOING_VERSION;
    DownloadCodeHandler downLoadHandler = new DownloadCodeHandler();
    File usingfile = new File(usingRoot);
    if (usingfile.exists()) {
        FileUtils.forceDelete(usingfile);
    }
    File doingFile = new File(doingRoot);
    if (doingFile.exists()) {
        FileUtils.forceDelete(doingFile);
    }

    String flowId = "flowIdNotNeed";
    String cmd = "cmdNotNeed";
    Integer hostStatus4New = 1;
    Integer updateAll = 1;
    Map<String, Object> firstDownLoadParams = new HashMap<String, Object>();
    firstDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION);
    firstDownLoadParams.put("hostStatus", hostStatus4New);
    firstDownLoadParams.put("savePath", usingRoot);// ??
    firstDownLoadParams.put("updateAll", updateAll);
    downLoadHandler.execute(flowId, cmd, firstDownLoadParams, null);

    Assert.assertTrue(new File(usingRoot + "/update.txt").exists());

    Integer notUpdateAll = 2;
    Integer hostStatus4Old = 2;
    Map<String, Object> secondDownLoadParams = new HashMap<String, Object>();
    secondDownLoadParams.put("doingCodeVerPath", TEST_GROUP + TAGS + "/" + DOING_VERSION);
    secondDownLoadParams.put("usingCodeVerPath", TEST_GROUP + TAGS + "/" + USING_VERSION);
    secondDownLoadParams.put("hostStatus", hostStatus4Old);
    secondDownLoadParams.put("savePath", doingRoot);// ??
    secondDownLoadParams.put("updateAll", notUpdateAll);
    downLoadHandler.execute(flowId, cmd, secondDownLoadParams, null);
    File updateFile = new File(doingRoot + "/update.txt");
    List<String> updateList = FileUtils.readLines(updateFile);
    UpdateCodeHandler updateHandler = new UpdateCodeHandler();
    Map<String, Object> updateParam = new HashMap<String, Object>();
    updateParam.put("targetPath", usingRoot + "/code");
    updateParam.put("srcPath", doingRoot);
    updateHandler.execute(null, null, updateParam, null);// ?doingRoot?usingRoot

    // ?
    // String do

    for (String str : updateList) {
        if (str.startsWith("+")) {
            Assert.assertTrue(
                    new File(usingRoot + "/code" + StringUtils.removeStart(str, "+").trim()).exists());
        } else if (str.startsWith("-")) {
            String f = usingRoot + "/code" + StringUtils.removeStart(str, "-").trim();
            Assert.assertFalse(new File(f).exists());
        }
    }

    if (usingfile.exists()) {
        FileUtils.forceDelete(usingfile);
    }

}

From source file:com.salesmanager.central.shipping.ShippingModuleAction.java

public void prepare() throws Exception {

    // SHP_RT_INDNM indicator and name [name coma delimited]
    // SHP_RT_INDNMCRED indicator, name & credentials, will have to remove
    // the credentials

    // SHP_ZONES_SHIPPING international or domestic

    Context ctx = (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    // Get everything related to shipping
    ConfigurationRequest requestvo = new ConfigurationRequest(merchantid.intValue(), true, "SHP_");
    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    ConfigurationResponse responsevo = mservice.getConfiguration(requestvo);
    List config = responsevo.getMerchantConfigurationList();

    if (config != null) {
        this.setConfigurationVo(responsevo);
        Iterator it = config.iterator();
        while (it.hasNext()) {

            MerchantConfiguration m = (MerchantConfiguration) it.next();

            String key = m.getConfigurationKey();
            if (key.equals(ShippingConstants.MODULE_SHIPPING_ZONES_SHIPPING)) {// national
                // or
                // international
                this.setShippingType(m.getConfigurationValue());
                super.getServletRequest().setAttribute("zonesshipping", m.getConfigurationValue());// this is for the
                // include shipping page
            } else if (key.equals(ShippingConstants.MODULE_SHIPPING_RT_MODULE_INDIC_NAME)) {// indicator
                // and
                // name
                // @TODO, parse token ?
                if (configurationModuleNames == null)
                    configurationModuleNames = new HashMap();
                configurationModuleNames.put(m.getConfigurationValue1(), m);
            }//  w w  w .ja va2  s .  c  o m

        }
    }

    // get module name
    String pathnocontext = StringUtils.removeStart(super.getServletRequest().getRequestURI(),
            super.getServletRequest().getContextPath() + "/shipping/");
    // pathnocontext is moduleid/dsiplay.action
    // retreive moduleid
    String moduleid = pathnocontext.substring(0, pathnocontext.indexOf("_"));

    this.setModuleName(moduleid);
    super.getServletRequest().setAttribute("shippingModule", moduleid);
    super.setPageTitle("module." + moduleid);

    if (this.getConfigurationModuleNames() != null
            && this.getConfigurationModuleNames().containsKey(moduleid)) {
        MerchantConfiguration conf = (MerchantConfiguration) this.getConfigurationModuleNames().get(moduleid);
        if (conf.getConfigurationValue1() != null && !conf.getConfigurationValue1().equals("")) {
            this.setCurrentModuleName(moduleid);
        }
        if (!StringUtils.isBlank(conf.getConfigurationValue()) && conf.getConfigurationValue().equals("true")) {
            this.setCurrentModuleEnabled("true");
        } else {
            this.setCurrentModuleEnabled("false");
        }
    }

    this.prepareModule();

}

From source file:net.sourceforge.fenixedu.webServices.jersey.api.FenixJerseyAPIConfig.java

private static String ends(String path) {
    return StringUtils.removeStart(StringUtils.removeEnd(path, "/"), "/");
}

From source file:com.adobe.acs.commons.wcm.impl.PropertyMergePostProcessor.java

/**
 * Gets the corresponding list of PropertyMerge directives from the
 * RequestParams./*from   ww  w. ja  va 2  s. c o m*/
 *
 * @param requestParameters the Request Param Map
 * @return a list of the PropertyMerge directives by Destination
 */
@SuppressWarnings("squid:S3776")
private List<PropertyMerge> getPropertyMerges(final SlingHttpServletRequest request) {
    final RequestParameterMap requestParameters = request.getRequestParameterMap();
    final HashMap<String, Set<String>> mapping = new HashMap<>();
    boolean isBulkUpdate = Boolean.valueOf(getParamValue(requestParameters, "dam:bulkUpdate"));

    // Collect the Destination / Source mappings
    requestParameters.forEach((key, values) -> {
        if (!StringUtils.endsWith(key, AT_SUFFIX)) {
            // Not a @PropertyMerge request param
            return;
        }

        Function<String, String> stripPrefix = (s -> StringUtils.removeStart(StringUtils.stripToNull(s),
                IGNORE_PREFIX));
        final String source = stripPrefix.apply(StringUtils.substringBefore(key, AT_SUFFIX));

        Stream.of(values).map(RequestParameter::getString).map(stripPrefix).filter(Objects::nonNull)
                .forEach(destination -> {
                    if (source.equalsIgnoreCase(OPERATION_ALL_TAGS)) {
                        // if this is a request for merging all tags, look at everyting that might be a tag
                        trackAllTagsMergeParameters(request, destination, mapping);
                    } else if (isBulkUpdate) {
                        // if this is a DAM bulk update, search all request params ending with this value
                        trackAssetMergeParameters(requestParameters, source, destination, mapping);
                    } else {
                        trackMergeParameters(mapping, source, destination);
                    }
                });
    });

    // Convert the Mappings into PropertyMerge objects
    return mapping.entrySet().stream()
            .map(entry -> new PropertyMerge(entry.getKey(), entry.getValue(),
                    areDuplicatesAllowed(requestParameters, entry.getKey()),
                    getFieldTypeHint(requestParameters, entry.getKey())))
            .collect(Collectors.toList());
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 *///from  w  w w .j  ava2  s  .  c  o  m
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.replace(keySuffix, ".", "/");
        path = StringUtils.removeStart(path, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + "@type")) {
                    cleaned.put(path + ".@type", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:com.atlassian.plugins.studio.storage.toolkit.impl.DefaultStorageFacadeImpl.java

private Collection<String> cleanKeys(Collection<String> keys) {
    if (keys == null)
        return keys;

    return ImmutableList.copyOf(Iterables.transform(keys, new Function<String, String>() {
        public String apply(String from) {
            return StringUtils.removeStart(from, instanceId.getKeyPrefix());
        }/*from w ww. ja va  2 s .com*/
    }));
}

From source file:com.netflix.spinnaker.echo.pipelinetriggers.monitor.GitEventMonitor.java

private boolean hasValidGitHubSecureSignature(TriggerEvent event, Trigger trigger) {
    val headers = event.getDetails().getRequestHeaders();
    if (!headers.containsKey(GITHUB_SECURE_SIGNATURE_HEADER)) {
        return true;
    }//  w  ww  . j a v  a 2 s. c o m

    String header = headers.getFirst(GITHUB_SECURE_SIGNATURE_HEADER);
    log.debug("GitHub Signature detected. " + GITHUB_SECURE_SIGNATURE_HEADER + ": " + header);
    String signature = StringUtils.removeStart(header, "sha1=");

    String triggerSecret = trigger.getSecret();
    if (StringUtils.isEmpty(triggerSecret)) {
        log.warn("Received GitEvent from Github with secure signature, but trigger did not contain the secret");
        return false;
    }

    String computedDigest = HmacUtils.hmacSha1Hex(triggerSecret, event.getRawContent());

    // TODO: Find constant time comparison algo?
    boolean digestsMatch = signature.equalsIgnoreCase(computedDigest);
    if (!digestsMatch) {
        log.warn("Github Digest mismatch! Pipeline NOT triggered: " + trigger);
        log.debug("computedDigest: " + computedDigest + ", from GitHub: " + signature);
    }

    return digestsMatch;
}

From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.JerseyOAuth2Filter.java

private Boolean checkAccessToken(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException, ServletException {

    //        final String uri =
    //                StringUtils.removeStart(request.getRequestURI(), request.getContextPath() + request.getServletPath() + "/fenix/");

    final String uri = StringUtils.removeStart(request.getRequestURI(), request.getContextPath() + "/api/");

    if (FenixJerseyAPIConfig.isPublicScope(uri)) {
        return true;
    }/*from  w  ww .ja v a 2s .  c  o m*/

    String accessToken = request.getHeader(ACCESS_TOKEN);

    if (StringUtils.isBlank(accessToken)) {
        accessToken = request.getParameter(ACCESS_TOKEN);
    }

    try {
        FenixOAuthToken fenixAccessToken = FenixOAuthToken.parse(accessToken);
        AppUserSession appUserSession = fenixAccessToken.getAppUserSession();
        ExternalApplication externalApplication = appUserSession.getAppUserAuthorization().getApplication();

        if (externalApplication.isDeleted()) {
            return sendError(response, "accessTokenInvalidFormat", "Access Token not recognized.");
        }

        if (externalApplication.isBanned()) {
            return sendError(response, "appBanned", "The application has been banned.");
        }

        if (!validScope(appUserSession, uri)) {
            return sendError(response, "invalidScope",
                    "Application doesn't have permissions to this endpoint.");
        }

        if (!appUserSession.matchesAccessToken(accessToken)) {
            return sendError(response, "accessTokenInvalid", "Access Token doesn't match.");
        }

        if (!appUserSession.isAccessTokenValid()) {
            return sendError(response, "accessTokenExpired",
                    "The access has expired. Please use the refresh token endpoint to generate a new one.");
        }

        User foundUser = appUserSession.getAppUserAuthorization().getUser();

        authenticateUser(request, foundUser);

        return true;

    } catch (FenixOAuthTokenException foate) {
        return sendError(response, "accessTokenInvalidFormat", "Access Token not recognized.");
    }
}