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

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

Introduction

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

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

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

/**
 * Get the path to the executable/* w  w w  .  jav  a 2  s.  co  m*/
 * 
 * @param homePath the home directory of the Sonar Runner
 * @return the path to the Sonar Runner executable
 */
private String getSonarRunnerExecutable(String homePath) {
    String pathToExecutable = StringUtils.join(new String[] { homePath, "bin", SONAR_RUNNER_EXECUTABLE },
            File.separator);
    if (StringUtils.contains(pathToExecutable, " ")) {
        try {
            File f = new File(pathToExecutable);
            pathToExecutable = f.getCanonicalPath();
        } catch (IOException e) {
            LOGGER.warn("IO Exception trying to get executable", e);
        }
    }
    return pathToExecutable;
}

From source file:com.mmj.app.common.pipeline.value.BaseWebUserBuilderValve.java

protected PipelineResult getToLogin(HttpServletRequest request, HttpServletResponse response, String uri)
        throws Exception {
    String url = loginUrl;/*from w  w w  . j  a  v  a 2  s  . c  o  m*/
    // ????returnurl
    if (request.getParameterMap().isEmpty() && !StringUtils.contains("/login", uri)) {
        url = loginUrl + "?returnurl=" + uri;
    }
    return PipelineResult.gotoAfterCompletion("gotoLogin", url);
}

From source file:com.commerce4j.storefront.controllers.CartController.java

@SuppressWarnings("unchecked")
public void update(HttpServletRequest request, HttpServletResponse response) {

    Gson gson = new GsonBuilder().create();
    List<Message> errors = new ArrayList<Message>();
    Map<String, Object> responseModel = new HashMap<String, Object>();

    List<CartDTO> cartEntries = getCart(request);
    Iterator inputSet = request.getParameterMap().keySet().iterator();
    while (inputSet.hasNext()) {
        String paramName = (String) inputSet.next();
        if (StringUtils.contains(paramName, "qty")) {
            String paramValue = request.getParameter(paramName);
            String paramId = StringUtils.substring(paramName, 4, paramName.length());
            if (paramId != null && StringUtils.isNumeric(paramId)) {
                for (CartDTO cartEntry : cartEntries) {
                    int entryId = cartEntry.getItem().getItemId().intValue();
                    int itemId = new Integer(paramId).intValue();
                    int cartQuantity = new Integer(paramValue).intValue();
                    if (entryId == itemId) {
                        cartEntry.setCartQuantity(cartQuantity);
                        cartEntry.setCartSubTotal(cartEntry.getItem().getItemPrice() * cartQuantity);
                        break;
                    }//from w  w w  . j  a  v a 2s.  co  m
                }
            }
        }
    }

    // fill response model
    if (errors.isEmpty()) {
        responseModel.put("responseCode", SUCCESS);
        responseModel.put("responseMessage", "Cart succesfully updated");
    } else {
        responseModel.put("responseCode", FAILURE);
        responseModel.put("responseMessage", "Error, Cart was not updated");
        responseModel.put("errors", errors);
    }

    // serialize output
    try {
        response.setContentType("application/json");
        OutputStreamWriter os = new OutputStreamWriter(response.getOutputStream());
        String data = gson.toJson(responseModel);
        os.write(data);
        os.flush();
        os.close();
    } catch (IOException e) {
        logger.fatal(e);
    }

}

From source file:com.amalto.core.server.routing.DefaultRoutingEngine.java

/**
 * Check that a rule actually matches a document
 * //  www  .  ja  va 2s  .c  om
 * @return true if it matches
 * @throws XtentisException
 */
private static boolean ruleExpressionMatches(ItemPOJO itemPOJO, RoutingRuleExpressionPOJO exp)
        throws XtentisException {
    Integer contentInt, expInt;
    String expXpath = exp.getXpath();
    if (expXpath.startsWith(itemPOJO.getConceptName())) {
        expXpath = StringUtils.substringAfter(expXpath, itemPOJO.getConceptName() + '/');
    }
    try {
        String[] contents = Util.getTextNodes(itemPOJO.getProjection(), expXpath);
        if (contents.length == 0 && exp.getOperator() == RoutingRuleExpressionPOJO.IS_NULL) {
            return true;
        }
        boolean match = false;
        for (String content : contents) {
            if (match) {
                break;
            }
            switch (exp.getOperator()) {
            case RoutingRuleExpressionPOJO.CONTAINS:
                match = StringUtils.contains(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.EQUALS:
                match = StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt > expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.GREATER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt >= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.IS_NOT_NULL:
                match = content != null;
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt < expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.LOWER_THAN_OR_EQUAL:
                expInt = safeParse(exp.getValue());
                contentInt = safeParse(content);
                if (expInt == null || contentInt == null) {
                    continue;
                }
                if (contentInt <= expInt) {
                    match = true;
                }
                break;
            case RoutingRuleExpressionPOJO.MATCHES:
                match = StringUtils.countMatches(content, exp.getValue()) > 0;
                break;
            case RoutingRuleExpressionPOJO.NOT_EQUALS:
                match = !StringUtils.equals(content, exp.getValue());
                break;
            case RoutingRuleExpressionPOJO.STARTSWITH:
                if (content != null) {
                    match = content.startsWith(exp.getValue());
                }
                break;
            }
        }
        return match;
    } catch (TransformerException e) {
        String err = "Subscription rule expression match: unable extract xpath '" + exp.getXpath()
                + "' from Item '" + itemPOJO.getItemPOJOPK().getUniqueID() + "': " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjDataFieldFormat.java

@Override
public String getSingleField() {
    if (fields.length == 1 && !StringUtils.contains(fields[0].getName(), ".")
            && fields[0].getUiFieldFormatter() == null) {
        return fields[0].getName();
    }//  www . ja v  a  2s  .c o m
    return null;
}

From source file:de.awtools.basic.file.AWToolsFileUtils.java

/**
 * Erzeugt die ntigen Verzeichnisse unterhalb von <code>basePath</code>
 * um eine Datei <code>relativeFileName</code> anlegen zu knnen. Die Datei
 * selbst wird nicht angelegt, es wird aber dafr gesorgt, dass alle
 * notwendigen Verzeichnisse fr diese Datei angelegt werden.<br>
 * Im Gegensatz zu der Methode <code>FileUtils#forceMkdir(File)</code> in
 * <code>IOUtils</code> aus jakarta-commons wird der letzte Pfadeintrag,
 * z.B. C:/tmp/www/web.xml nicht als Verzeichnis angelegt. Im Beispiel
 * wre <code>web.xml</code> tatschlich als Verzeichnis angelegt worden.
 *
 * @param basePath Ein Basisverzeichnis.
 * @param relativeFileName Ein relativer Filename (ab Basis).
 *//*w ww .j a v  a 2  s . c  om*/
public static void createFilePath(final String basePath, final String relativeFileName) {

    if (StringUtils.contains(relativeFileName, '\\')) {
        createFilePath(basePath, relativeFileName, '\\');
    } else if (StringUtils.contains(relativeFileName, '/')) {
        createFilePath(basePath, relativeFileName, '/');
    } else {
        log.debug("Directory creation not necessary!");
    }
}

From source file:com.adobe.acs.commons.http.injectors.AbstractHtmlRequestInjector.java

@SuppressWarnings("squid:S3923")
protected boolean accepts(final ServletRequest servletRequest, final ServletResponse servletResponse) {

    if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) {
        return false;
    }//from   w w  w. j  ava2  s.c om

    final HttpServletRequest request = (HttpServletRequest) servletRequest;

    if (!StringUtils.equalsIgnoreCase("get", request.getMethod())) {
        // Only inject on GET requests
        return false;
    } else if (StringUtils.equals(request.getHeader("X-Requested-With"), "XMLHttpRequest")) {
        // Do not inject into XHR requests
        return false;
    } else if (StringUtils.contains(request.getPathInfo(), ".")
            && !StringUtils.contains(request.getPathInfo(), ".html")) {
        // If extension is provided it must be .html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/editor.html" + request.getRequestURI())) {
        // Do not apply to pages loaded in the TouchUI editor.html
        return false;
    } else if (StringUtils.endsWith(request.getHeader("Referer"), "/cf")) {
        // Do not apply to pages loaded in the Classic Content Finder
        return false;
    }

    // Add HTML check
    if (log.isTraceEnabled()) {
        log.trace("Injecting HTML via AbstractHTMLRequestInjector");
    }
    return true;
}

From source file:com.hangum.tadpole.engine.security.DBPasswordAndOTPDialog.java

@Override
protected void okPressed() {
    String strOTPCode = textOTP.getText();

    if ("".equals(strOTPCode)) {
        MessageDialog.openError(getShell(), CommonMessages.get().Error, Messages.get().OTPEmpty);
        textOTP.setFocus();//from  w  w w.  ja v  a 2s .com
        return;
    }
    try {
        GetOTPCode.isValidate(SessionManager.getEMAIL(), SessionManager.getOTPSecretKey(), strOTPCode);
    } catch (Exception e) {
        logger.error("OTP check", e);
        MessageDialog.openError(getShell(), CommonMessages.get().Error, e.getMessage());
        textOTP.setFocus();

        return;
    }

    //  ? ? .
    try {
        userDB.setPasswd(StringUtils.trim(textPassword.getText()));
        TadpoleSQLManager.getInstance(userDB);
    } catch (Exception e) {
        logger.error("Test Passwd+opt Connection error ");

        String msg = e.getMessage();
        if (StringUtils.contains(msg, "No more data to read from socket")) {
            MessageDialog.openWarning(getShell(), CommonMessages.get().Warning,
                    msg + CommonMessages.get().Check_DBAccessSystem);
        } else {
            MessageDialog.openWarning(getShell(), CommonMessages.get().Warning, msg);
        }
        textPassword.setFocus();

        return;
    }

    super.okPressed();
}

From source file:com.enonic.cms.core.preference.PreferenceKey.java

private void initScope(String scopePart) {

    this.scopePart = scopePart;

    String scopeName;/* ww w.j a va 2 s . c  o  m*/
    String scopeKeyStr = null;
    if (StringUtils.contains(scopePart, ':')) {
        scopeName = StringUtils.substringBefore(scopePart, ":");
        scopeKeyStr = StringUtils.substringAfter(scopePart, ":");
    } else {
        scopeName = scopePart;
    }

    this.scopeType = PreferenceScopeType.parse(scopeName);
    if (this.scopeType == null) {
        throw new InvalidKeyException(rawKey, this.getClass(), "invalid scope");
    }

    if (scopeType != PreferenceScopeType.GLOBAL) {
        this.scopeKey = new PreferenceScopeKey(scopeKeyStr);
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.home.page.ApplicationPageBase.java

@SuppressWarnings({ "serial" })
private void commonInit() {
    getSession().setLocale(Locale.ENGLISH);

    logoutPanel = new LogoutPanel("logoutPanel");
    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.add(new AttributeModifier("class", "error"));
    feedbackPanel.setFilter(new IFeedbackMessageFilter() {
        @Override//www  .ja v a  2  s . co  m
        public boolean accept(FeedbackMessage aMessage) {
            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            if (aMessage.isFatal()) {
                LOG.fatal(username + ": " + aMessage.getMessage());
            } else if (aMessage.isError()) {
                LOG.error(username + ": " + aMessage.getMessage());
            } else if (aMessage.isWarning()) {
                LOG.warn(username + ": " + aMessage.getMessage());
            } else if (aMessage.isInfo()) {
                LOG.info(username + ": " + aMessage.getMessage());
            } else if (aMessage.isDebug()) {
                LOG.debug(username + ": " + aMessage.getMessage());
            }
            return true;
        }
    });

    versionLabel = new Label("version", SettingsUtil.getVersionString());

    embeddedDbWarning = new Label("embeddedDbWarning", "USE THIS INSTALLATION FOR TESTING ONLY -- "
            + "AN EMBEDDED DATABASE IS NOT RECOMMENDED FOR PRODUCTION USE");
    embeddedDbWarning.setVisible(false);
    try {
        String driver = repository.getDatabaseDriverName();
        embeddedDbWarning.setVisible(StringUtils.contains(driver.toLowerCase(Locale.US), "hsql"));
    } catch (Throwable e) {
        LOG.warn("Unable to determine which database is being used", e);
    }

    // Override warning about embedded database.
    Properties settings = SettingsUtil.getSettings();
    if ("false".equals(settings.getProperty("warnings.embeddedDatabase"))) {
        embeddedDbWarning.setVisible(false);
    }

    // Display a warning when using an unsupported browser
    RequestCycle requestCycle = RequestCycle.get();
    WebClientInfo clientInfo;
    if (Session.exists()) {
        WebSession session = WebSession.get();
        clientInfo = session.getClientInfo();
    } else {
        clientInfo = new WebClientInfo(requestCycle);
    }
    ClientProperties clientProperties = clientInfo.getProperties();

    browserWarning = new Label("browserWarning",
            "THIS BROWSER IS NOT SUPPORTED -- " + "PLEASE USE CHROME OR SAFARI");
    browserWarning.setVisible(!clientProperties.isBrowserSafari() && !clientProperties.isBrowserChrome());

    // Override warning about browser.
    if ("false".equals(settings.getProperty("warnings.unsupportedBrowser"))) {
        browserWarning.setVisible(false);
    }

    add(logoutPanel);
    add(feedbackPanel);
    add(versionLabel);
    add(embeddedDbWarning);
    add(browserWarning);
}