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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:ddf.mime.custom.CustomMimeTypeResolver.java

public void setCustomMimeTypes(String[] customMimeTypes) {
    LOGGER.trace("ENTERING: setCustomMimeTypes");

    this.customMimeTypes = customMimeTypes.clone();
    this.customFileExtensionsToMimeTypesMap = new HashMap<String, String>();
    this.customMimeTypesToFileExtensionsMap = new HashMap<String, List<String>>();

    for (String mimeTypeMapping : this.customMimeTypes) {
        LOGGER.trace(mimeTypeMapping);//from ww w . j a  va 2s.c  om

        // mimeTypeMapping is of the form <file extension>=<mime type>
        // Examples:
        // nitf=image/nitf

        String fileExtension = StringUtils.substringBefore(mimeTypeMapping, "=");
        String mimeType = StringUtils.substringAfter(mimeTypeMapping, "=");

        customFileExtensionsToMimeTypesMap.put(fileExtension, mimeType);
        List<String> fileExtensions = (List<String>) customMimeTypesToFileExtensionsMap.get(mimeType);
        if (fileExtensions == null) {
            LOGGER.debug("Creating fileExtensions array for mime type: {}", mimeType);
            fileExtensions = new ArrayList<String>();
        }
        LOGGER.debug("Adding file extension: {} for mime type: {}", fileExtensions, mimeType);
        fileExtensions.add(fileExtension);
        customMimeTypesToFileExtensionsMap.put(mimeType, fileExtensions);
    }

    LOGGER.debug("customFileExtensionsToMimeTypesMap = {} ", customFileExtensionsToMimeTypesMap);
    LOGGER.debug("customMimeTypesToFileExtensionsMap = {}", customMimeTypesToFileExtensionsMap);

    LOGGER.trace("EXITING: setCustomMimeTypes");
}

From source file:eionet.cr.util.FolderUtil.java

/**
 * Returns the path after the user home folder. For example if uri is
 * "http://127.0.0.1:8080/cr/home/heinlja/newFolder/newFile.txt" the result is "newFolder/newFile.txt".
 *
 * @param uri// ww w .  j  a va2  s . c om
 * @return
 */
public static String extractPathInUserHome(String uri) {
    if (!startsWithUserHome(uri)) {
        if (isProjectFolder(uri)) {
            return StringUtils.substringAfter(uri,
                    GeneralConfig.getRequiredProperty(GeneralConfig.APPLICATION_HOME_URL) + "/project/");
        }
        return null;
    }

    String userName = extractUserName(uri);

    String result = StringUtils.substringAfter(uri,
            GeneralConfig.getRequiredProperty(GeneralConfig.APPLICATION_HOME_URL) + "/home/" + userName + "/");
    return result;
}

From source file:mitm.application.djigzo.james.matchers.MailVariableResolver.java

/**
 * Returns the mail value of the mail variable. Returns null if the mail does not support a variable with the given name.
 *///from w  w w.  j a va  2  s. com
@Override
public String resolveVariable(String variable) throws FunctionException {
    /*
     * Note: non numbers must be single quoted (ie. 'value')
     */
    try {
        /*
         * Mail vars should start with mail.
         */
        if (StringUtils.startsWithIgnoreCase(variable, MAIL_VAR_PREFIX)) {
            if (SIZE.equalsIgnoreCase(variable)) {
                return Long.toString(mail.getMessageSize());
            } else if (RECIPIENTS_SIZE.equalsIgnoreCase(variable)) {
                return Integer.toString(mail.getRecipients().size());
            } else if (CONTENT_TYPE.equalsIgnoreCase(variable)) {
                MimeMessage message = mail.getMessage();

                return message != null ? message.getContentType() : "";
            } else if (StringUtils.startsWithIgnoreCase(variable, MAIL_ATTRIBUTE_PREFIX)) {
                /*
                 * Check to see whether Mail has an attribute with the name
                 */
                String attrName = StringUtils.substringAfter(variable, MAIL_ATTRIBUTE_PREFIX);

                if (StringUtils.isNotEmpty(variable)) {
                    Object attr = mail.getAttribute(attrName);

                    if (attr != null) {
                        return "'" + attr.toString() + "'";
                    }
                }
            }

            return NULL_STRING;
        }

        return null;
    } catch (MessagingException e) {
        throw new FunctionException(e);
    }
}

From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java

public List<ScriptResource> getScripts(ScriptType scriptType, @Nullable String moduleName) {
    try {/*  w w w. ja va 2s  .  c  om*/
        ResourcePatternResolver resourceResolver = createAppropriateResourceResolver();
        String urlPattern = String.format("%s/%s/%s/%s/**/*%s.*", dbScriptsDirectoryForSearch(),
                moduleName != null ? moduleName : "**", scriptType, dbmsType,
                scriptType == ScriptType.INIT ? "create-db" : "");
        String urlPatternWithDbmsVersion = null;
        if (StringUtils.isNotBlank(dbmsVersion)) {
            urlPatternWithDbmsVersion = String.format("%s/%s/%s/%s-%s/**/*%s.*", dbScriptsDirectoryForSearch(),
                    moduleName != null ? moduleName : "**", scriptType, dbmsType, dbmsVersion,
                    scriptType == ScriptType.INIT ? "create-db" : "");
        }

        Map<String, ScriptResource> scriptResources = findResourcesByUrlPattern(resourceResolver, urlPattern);
        if (StringUtils.isNotBlank(urlPatternWithDbmsVersion)) {
            Map<String, ScriptResource> additionalResources = findResourcesByUrlPattern(resourceResolver,
                    urlPatternWithDbmsVersion);
            scriptResources.putAll(additionalResources);
        }

        List<ScriptResource> results = new ArrayList<>(scriptResources.values());
        Collections.sort(results, (ScriptResource r1, ScriptResource r2) -> {
            if (r1.getDir().equals(r2.getDir())) {
                return r1.getName().compareTo(r2.getName());
            } else {
                String dbmsTypeAndVersion = dbmsType + "-" + dbmsVersion;
                String separator1 = r1.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;
                String separator2 = r2.getPath().contains(dbmsTypeAndVersion) ? dbmsTypeAndVersion : dbmsType;

                String pathAfterDbms1 = StringUtils.substringAfter(r1.getPath(), separator1);
                String pathBeforeDbms1 = StringUtils.substringBefore(r1.getPath(), separator1);

                String pathAfterDbms2 = StringUtils.substringAfter(r2.getPath(), separator2);
                String pathBeforeDbms2 = StringUtils.substringBefore(r2.getPath(), separator2);

                return pathBeforeDbms1.equals(pathBeforeDbms2) ? pathAfterDbms1.compareTo(pathAfterDbms2)
                        : pathBeforeDbms1.compareTo(pathBeforeDbms2);
            }
        });

        return results;
    } catch (IOException e) {
        throw new RuntimeException("An error occurred while loading scripts", e);
    }
}

From source file:com.safetys.framework.jmesa.limit.LimitActionFactory.java

public SortSet getSortSet() {
    SortSet sortSet = new SortSet();

    for (Object param : parameters.keySet()) {
        String parameter = (String) param;
        if (parameter.startsWith(prefixId + Action.SORT.toParam())) {
            String value = LimitUtils.getValue(parameters.get(parameter));
            if (StringUtils.isNotBlank(value)) {
                String position = StringUtils.substringBetween(parameter, prefixId + Action.SORT.toParam(),
                        "_");
                String property = StringUtils.substringAfter(parameter,
                        prefixId + Action.SORT.toParam() + position + "_");
                Order order = Order.valueOfParam(value);
                Sort sort = new Sort(new Integer(position), property, order);
                sortSet.addSort(sort);//from  www. ja va  2s  .  com
            }
        }
    }

    return sortSet;
}

From source file:de.hybris.platform.chinesepaymentaddon.controllers.pages.ChineseOrderConfirmationController.java

@Override
protected String processOrderCode(final String orderCode, final Model model, final HttpServletRequest request)
        throws CMSItemNotFoundException {
    final OrderData orderDetails = orderFacade.getOrderDetailsForCode(orderCode);

    if (orderDetails.isGuestCustomer() && !StringUtils.substringBefore(orderDetails.getUser().getUid(), "|")
            .equals(getSessionService().getAttribute(WebConstants.ANONYMOUS_CHECKOUT_GUID))) {
        return getCheckoutRedirectUrl();
    }/*from  w w  w .  j ava 2s.c o  m*/

    if (orderDetails.getEntries() != null && !orderDetails.getEntries().isEmpty()) {
        for (final OrderEntryData entry : orderDetails.getEntries()) {
            final String productCode = entry.getProduct().getCode();
            final ProductData product = productFacade.getProductForCodeAndOptions(productCode,
                    Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.CATEGORIES));
            entry.setProduct(product);
        }
    }

    model.addAttribute("orderCode", orderCode);
    model.addAttribute("orderData", orderDetails);
    model.addAttribute("allItems", orderDetails.getEntries());
    model.addAttribute("deliveryAddress", orderDetails.getDeliveryAddress());
    model.addAttribute("deliveryMode", orderDetails.getDeliveryMode());
    model.addAttribute("paymentInfo", orderDetails.getPaymentInfo());
    model.addAttribute("pageType", PageType.ORDERCONFIRMATION.name());

    final String uid;

    if (orderDetails.isGuestCustomer() && !model.containsAttribute("guestRegisterForm")) {
        final GuestRegisterForm guestRegisterForm = new GuestRegisterForm();
        guestRegisterForm.setOrderCode(orderDetails.getGuid());
        uid = StringUtils.substringAfter(orderDetails.getUser().getUid(), "|");
        guestRegisterForm.setUid(uid);
        model.addAttribute(guestRegisterForm);
    } else {
        uid = orderDetails.getUser().getUid();
    }
    model.addAttribute("email", uid);

    final String continueUrl = (String) getSessionService().getAttribute(WebConstants.CONTINUE_URL);
    model.addAttribute(CONTINUE_URL_KEY, (continueUrl != null && !continueUrl.isEmpty()) ? continueUrl : ROOT);

    final AbstractPageModel cmsPage = getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL);
    storeCmsPageInModel(model, cmsPage);
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(CHECKOUT_ORDER_CONFIRMATION_CMS_PAGE_LABEL));
    model.addAttribute(ThirdPartyConstants.SeoRobots.META_ROBOTS,
            ThirdPartyConstants.SeoRobots.NOINDEX_NOFOLLOW);

    if (ResponsiveUtils.isResponsive()) {
        return getViewForPage(model);
    }

    return ControllerConstants.Views.Pages.Checkout.CheckoutConfirmationPage;
}

From source file:com.marvelution.bamboo.plugins.sonar.tasks.upgrade.TimeMachineMetricsUpgradeTask.java

/**
 * {@inheritDoc}//from   www  .j a  va 2s  .  com
 */
@SuppressWarnings("unchecked")
@Override
public Collection<Message> doUpgrade() throws Exception {
    for (Plan plan : planManager.getAllPlansUnrestricted()) {
        PlanAwareBandanaContext context = PlanAwareBandanaContext.forPlan(plan);
        for (String key : bandanaManager.getKeys(context)) {
            if (key.startsWith(TIME_MACHINE_BASE_BANDANA_KEY)) {
                LOGGER.info("Migrating Time Machine Metrics under key " + key + " to the PluginSettigns");
                List<String> metrics = (List<String>) bandanaManager.getValue(context, key);
                User user = null;
                if (!GLOBAL_TIME_MACHINE_BANDANA_KEY.equals(key)) {
                    user = userManager.getUser(StringUtils.substringAfter(key, TIME_MACHINE_BASE_BANDANA_KEY));
                }
                metricsManager.setTimeMachineMetrics(plan, user, metrics);
                bandanaManager.removeValue(context, key);
            }
        }
    }
    return null;
}

From source file:managedBeans.informes.InformeMovimientoInventarioMB.java

private int determinarNumMovimiento() {
    int num;/*from   w  w w  .  j  a  va2s.c o m*/
    if (!numMovimiento.trim().isEmpty()) {
        try {
            num = Integer.parseInt(numMovimiento);
        } catch (Exception e) {
            if (numMovimiento.contains("0")) {
                String aux = StringUtils.substringAfter(numMovimiento, "0");
                try {
                    num = Integer.parseInt(aux);
                } catch (Exception ex) {
                    num = 0;
                }
                //                    }
            } else {
                num = 0;
            }
            if (num == 0) {
                CfgDocumento documento;
                if (movimientoSeleccionado != null) {
                    if (movimientoSeleccionado.getCodMovInvetario().equals("1")) {
                        documento = documentoFacade.buscarDocumentoInventarioEntradaBySede(sedeActual);
                    } else {
                        documento = documentoFacade.buscarDocumentoInventarioSalidaBySede(sedeActual);
                    }
                } else {//si no se escoge el tipo de movimiento. No se tendra en cuenta el numMovimiento entrado
                    return 0;
                }
                String aux = documento.getPrefijoDoc();
                int init = aux.length();
                if (init < numMovimiento.length()) {
                    aux = numMovimiento.substring(init);
                    try {
                        num = Integer.parseInt(aux);
                    } catch (Exception ex) {
                        num = 0;
                    }
                } else {
                    num = 0;
                }
            }
        }
    } else {
        num = 0;
    }
    return num;
}

From source file:info.magnolia.cms.core.Path.java

/**
 * Returns the decoded URI of the current request, without the context path.
 * @param req request/* w ww. jav a  2 s . c om*/
 * @return request URI without servlet context
 */
private static String getDecodedURI(HttpServletRequest req) {
    String encoding = StringUtils.defaultString(req.getCharacterEncoding(), ENCODING_DEFAULT);
    String decodedURL = null;
    try {
        decodedURL = URLDecoder.decode(req.getRequestURI(), encoding);
    } catch (UnsupportedEncodingException e) {
        decodedURL = req.getRequestURI();
    }
    return StringUtils.substringAfter(decodedURL, req.getContextPath());
}

From source file:info.magnolia.cms.filters.InstallFilter.java

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    // this isn't the cleanest thing, but we're basically tricking FreemarkerHelper into using a Context, while avoiding using WebContextImpl and its depedencies on the repository
    final Context originalContext = MgnlContext.hasInstance() ? MgnlContext.getInstance() : null;
    final InstallWebContext ctx = new InstallWebContext();
    ctx.init(request, response, servletContext);
    MgnlContext.setInstance(ctx);/* w w w.jav  a 2  s  . co  m*/

    try {
        final String contextPath = request.getContextPath();
        // TODO : this will be invalid the day we allow other resources (css, images) to be served through the installer
        response.setContentType("text/html");
        final Writer out = response.getWriter();
        final String uri = request.getRequestURI();
        final ModuleManagerUI ui = moduleManager.getUI();

        final String prefix = contextPath + ModuleManagerWebUI.INSTALLER_PATH;
        if (uri.startsWith(prefix)) {
            final String command = StringUtils.defaultIfEmpty(StringUtils.substringAfter(uri, prefix + "/"),
                    null);
            final boolean installDone = ui.execute(out, command);
            if (installDone) {
                filterManager.startUsingConfiguredFilters();
                // invalidate session: MAGNOLIA-2611
                request.getSession().invalidate();
                // redirect to root
                response.sendRedirect(contextPath + "/");
            }
        } else {
            // redirect to /.magnolia/installer - even if it has no concrete effect, the change in the browser's url bar makes this more explicit
            response.sendRedirect(prefix);
        }
    } catch (ModuleManagementException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e); // TODO
    } finally {
        MgnlContext.release();
        MgnlContext.setInstance(originalContext);
    }
}