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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:com.dell.asm.asmcore.asmmanager.util.discovery.providers.CServer.java

private Map<String, String> parseBMCOutput(String serverMsg) {
    Map<String, String> firmwareVersions = new HashMap<String, String>();
    String[] tokens = serverMsg.split("\n");
    String model = null;/*from   w  w w  .  j ava 2  s  . c  o  m*/
    String serviceTag = null;
    String vendor = null;
    String biosVersion = "BIOS version";
    String bmcVersion = "BMC version";
    String fcbVersion = "FCB version";
    if (tokens != null && tokens.length > 0) {
        for (int i = 0; i < tokens.length; i++) {
            String[] strings = tokens[i].split(":");
            if (strings != null && strings.length == 2) {
                if (StringUtils.contains(strings[0], "Product Name"))
                    model = strings[1];
                if (StringUtils.contains(strings[0], "Product Serial"))
                    serviceTag = strings[1];
                if (StringUtils.contains(strings[0], "Product Manufacturer"))
                    vendor = strings[1];
                if (StringUtils.contains(strings[0], biosVersion))
                    firmwareVersions.put("BIOS", StringUtils.trim(strings[1]));
                if (StringUtils.contains(strings[0], bmcVersion))
                    firmwareVersions.put("BMC", StringUtils.trim(strings[1]));
                if (StringUtils.contains(strings[0], fcbVersion))
                    firmwareVersions.put("FCB", StringUtils.trim(strings[1]));

            }
        }

    }
    if (model != null) {
        result.setModel(StringUtils.trim(model));
        result.setServiceTag(StringUtils.trim(serviceTag));
        result.setVendor(StringUtils.trim(vendor));
        result.setDisplayName(result.getServiceTag());
    }

    return firmwareVersions;
}

From source file:com.glaf.activiti.container.ProcessContainer.java

/**
 * //from   w  w  w .  ja  v  a 2  s . c  o m
 * 
 * @param actorId
 * @param rows
 * @return
 */
public TaskItem filterOne(String actorId, TaskItem item) {
    List<Agent> agents = this.getAgents(actorId);
    // logger.debug(agents);
    // logger.debug(item.getProcessDescription() + "\t"
    // + item.getTaskDescription() + "\t" + item.getActorId());
    TaskItem taskItem = null;
    /**
     * ?
     */
    if (StringUtils.equals(actorId, item.getActorId())) {
        taskItem = item;
    } else if (StringUtils.contains(item.getActorId(), actorId)) {
        List<String> actorIds = StringTools.split(item.getActorId());
        if (actorIds != null && actorIds.contains(actorId)) {
            taskItem = item;
        }
    } else {
        if (agents != null && agents.size() > 0) {
            Iterator<Agent> it = agents.iterator();
            while (it.hasNext()) {
                Agent agent = it.next();
                if (!agent.isValid()) {
                    continue;
                }
                /**
                 * ???
                 */
                if (!StringUtils.equals(item.getActorId(), agent.getAssignFrom())) {
                    continue;
                }
                switch (agent.getAgentType()) {
                case 0:// ?
                    taskItem = item;
                    break;
                case 1:// ??
                    if (StringUtils.equalsIgnoreCase(agent.getProcessName(), item.getProcessName())) {
                        taskItem = item;
                    }
                    break;
                case 2:// ??
                    if (StringUtils.equalsIgnoreCase(agent.getProcessName(), item.getProcessName())
                            && StringUtils.equalsIgnoreCase(agent.getTaskName(), item.getTaskName())) {
                        taskItem = item;
                    }
                    break;
                default:
                    break;
                }
            }
        }
    }

    return taskItem;
}

From source file:com.dell.asm.asmcore.asmmanager.client.servicetemplate.ServiceTemplate.java

public void removeUnrelatedValues() {
    for (ServiceTemplateComponent component : this.getComponents()) {
        for (ServiceTemplateCategory category : component.getResources()) {

            for (Iterator<ServiceTemplateSetting> iter = category.getParameters().iterator(); iter.hasNext();) {
                ServiceTemplateSetting setting = iter.next();
                if (StringUtils.isNotEmpty(setting.dependencyTarget)) {

                    ServiceTemplateSetting depTarget = getTemplateSetting(component, setting.dependencyTarget);
                    if (depTarget == null
                            || !StringUtils.contains(setting.dependencyValue, depTarget.getValue())) {
                        // not used in deployment, remove it
                        iter.remove();//from w  w w . j  a  va2 s .com
                    }
                }
            }
        }
    }
}

From source file:com.thoughtworks.go.matchers.ConsoleOutMatcher.java

public static TypeSafeMatcher<String> printedAppsMissingInfoOnWindows(final String app) {
    return new TypeSafeMatcher<String>() {
        public String consoleOut;
        public String message;

        public boolean matchesSafely(String consoleOut) {
            this.consoleOut = consoleOut;
            message = format("'%s' is not recognized as an internal or external command", app);
            return StringUtils.contains(consoleOut, message);
        }/*from  w  ww  .  j  a  va2s  .c om*/

        public void describeTo(Description description) {
            description.appendText("Expected console to contain [" + message + "] but was " + consoleOut);
        }
    };
}

From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java

private static <T> T readJsonValue(String name, Class<T> type, String json) {
    try {//from  ww  w.  j  av a 2s. c  o m
        return reader.forType(type).readValue(json);
    } catch (IOException e) {
        if (ExceptionUtils.getRootCause(e) instanceof ClassNotFoundException) {
            //attempt to find the old class name and replace it with the new one
            ClassNotFoundException classNotFoundException = (ClassNotFoundException) ExceptionUtils
                    .getRootCause(e);
            String msg = classNotFoundException.getMessage();
            msg = StringUtils.remove(msg, "java.lang.ClassNotFound:");
            String oldName = StringUtils.trim(msg);
            try {
                Class newName = ClassNameChangeRegistry.findClass(oldName);
                String newNameString = newName.getName();
                if (StringUtils.contains(json, oldName)) {
                    //replace and try again
                    json = StringUtils.replace(json, oldName, newNameString);
                    return readJsonValue(name, type, json);
                }
            } catch (ClassNotFoundException c) {

            }

        }
        throw new MetadataRepositoryException("Failed to deserialize JSON property: " + name, e);
    }
}

From source file:de.micromata.genome.junittools.wicket.WicketTestBuilder.java

/**
 * @deprecated validateMatchingLastRenderedResponse(matcher);
 * @param searchString the string to look for
 * @return the builder//from   w  ww. jav  a  2s  . c o  m
 */
@Deprecated
public T _validateLastRenderedResponseContains(String searchString) {

    validateTrue(StringUtils.contains(_getLastResponseAsString(), searchString),
            "The given search string was not found, but should. s=" + searchString);
    return (T) this;
}

From source file:com.xpn.xwiki.user.impl.xwiki.MyFormAuthenticator.java

/**
 * Process any login information passed in parameter (username, password). Returns true if SecurityFilter should
 * abort further processing after the method completes (for example, if a redirect was sent as part of the login
 * processing).//  w ww .j  a va  2 s  . c  om
 * 
 * @param request
 * @param response
 * @return true if the filter should return after this method ends, false otherwise
 */
public boolean processLogin(String username, String password, String rememberme, SecurityRequestWrapper request,
        HttpServletResponse response, XWikiContext context) throws Exception {
    Principal principal = authenticate(username, password, context);
    if (principal != null) {
        // login successful
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("User " + principal.getName() + " has been logged-in");
        }

        // invalidate old session if the user was already authenticated, and they logged in as a different user
        if (request.getUserPrincipal() != null && !username.equals(request.getRemoteUser())) {
            request.getSession().invalidate();
        }

        // manage persistent login info, if persistent login management is enabled
        if (this.persistentLoginManager != null) {
            // did the user request that their login be persistent?
            if (rememberme != null) {
                // remember login
                this.persistentLoginManager.rememberLogin(request, response, username, password);
            } else {
                // forget login
                this.persistentLoginManager.forgetLogin(request, response);
            }
        }

        // make sure the Principal contains wiki name information
        if (!StringUtils.contains(principal.getName(), ':')) {
            principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName());
        }

        request.setUserPrincipal(principal);
        Boolean bAjax = (Boolean) context.get("ajax");
        if ((bAjax == null) || (!bAjax.booleanValue())) {
            String continueToURL = getContinueToURL(request);
            // This is the url that the user was initially accessing before being prompted for login.
            response.sendRedirect(response.encodeRedirectURL(continueToURL));
        }
    } else {
        // login failed
        // set response status and forward to error page
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("User " + username + " login has failed");
        }

        String returnCode = context.getWiki().Param("xwiki.authentication.unauthorized_code");
        int rCode = HttpServletResponse.SC_UNAUTHORIZED;
        if ((returnCode != null) && (!returnCode.equals(""))) {
            try {
                rCode = Integer.parseInt(returnCode);
            } catch (Exception e) {
                rCode = HttpServletResponse.SC_UNAUTHORIZED;
            }
        }
        response.setStatus(rCode); // TODO: Does this work? (200 in case of error)
    }

    return true;
}

From source file:in.mycp.workers.IpAddressWorker.java

@Async
public void associateAddress(final Infra infra, final AddressInfoP addressInfoP) {
    try {/* w  w  w.  ja  va2 s  . co  m*/
        Jec2 ec2 = getNewJce2(infra);

        try {
            logger.info("associateAddress address " + addressInfoP.getPublicIp() + " to instance "
                    + addressInfoP.getInstanceId());
            ec2.associateAddress(addressInfoP.getInstanceId(), addressInfoP.getPublicIp());
        } catch (Exception e) {
            logger.error(e);//e.printStackTrace();
            if (e.getMessage().indexOf("Permission denied while") > -1) {
                throw new Exception("Permission denied.");
            } else if (e.getMessage().indexOf("Number of retries exceeded") > -1) {
                throw new Exception("No Connectivity to Cloud");
            }
        }
        String instanceIdOrig = addressInfoP.getInstanceId();
        if (StringUtils.contains(instanceIdOrig, " ")) {
            instanceIdOrig = StringUtils.substringBefore(instanceIdOrig, " ");
        }

        InstanceP orig_compute = null;
        try {
            orig_compute = InstanceP.findInstancePsByInstanceIdEquals(instanceIdOrig).getSingleResult();
        } catch (Exception e) {
            logger.error(e);//e.printStackTrace();
        }

        AddressInfoP addressInfoP4PublicIp = null;
        try {
            addressInfoP4PublicIp = AddressInfoP.findAddressInfoPsByPublicIpEquals(addressInfoP.getPublicIp())
                    .getSingleResult();
        } catch (Exception e) {
            logger.error(e);//e.printStackTrace();
        }

        AddressInfoP addressInfoP4InstanceId = null;
        try {
            addressInfoP4InstanceId = AddressInfoP.findAddressInfoPsByInstanceIdLike(instanceIdOrig)
                    .getSingleResult();
        } catch (Exception e) {
            logger.error(e);//e.printStackTrace();
        }

        boolean match = false;
        int START_SLEEP_TIME = 5000;
        int waitformaxcap = START_SLEEP_TIME * 10;
        long now = 0;
        outer: while (!match) {
            if (now > waitformaxcap) {
                throw new Exception("Got bored, Quitting.");
            }
            now = now + START_SLEEP_TIME;

            try {

                List<String> params = new ArrayList<String>();
                List<ReservationDescription> instances = ec2.describeInstances(params);
                for (ReservationDescription res : instances) {
                    if (res.getInstances() != null) {
                        HashSet<InstanceP> instancesP = new HashSet<InstanceP>();
                        for (Instance inst : res.getInstances()) {
                            logger.info(inst.getInstanceId() + " " + orig_compute.getInstanceId() + " "
                                    + inst.getDnsName() + " " + addressInfoP.getPublicIp());
                            if (inst.getInstanceId().equals(orig_compute.getInstanceId())
                                    && inst.getDnsName().equals(addressInfoP.getPublicIp())) {
                                match = true;
                                break outer;
                            }

                        } //for (Instance inst : res.getInstances()) {
                    } //if (res.getInstances() != null) {
                } //for (ReservationDescription res : instances) {

                logger.info("Ipaddress " + addressInfoP.getPublicIp() + " getting associated; sleeping "
                        + START_SLEEP_TIME + "ms");
                Thread.sleep(START_SLEEP_TIME);

            } catch (Exception e) {
                logger.error(e);//e.printStackTrace();
                //addressInfoLocal=null;
                if (e.getMessage().indexOf("Number of retries exceeded") > -1) {
                    throw new Exception("No Connectivity to Cloud");
                }
            }
        }
        if (match == true) {
            try {
                orig_compute.setDnsName(addressInfoP.getPublicIp());
                orig_compute.merge();
            } catch (Exception e) {
                logger.error(e);//e.printStackTrace();
            }

            try {
                addressInfoP4PublicIp.setAssociated(true);
                addressInfoP4PublicIp.setInstanceId(orig_compute.getInstanceId());
                addressInfoP4PublicIp.setStatus(Commons.ipaddress_STATUS.associated + "");
                addressInfoP4PublicIp.merge();
            } catch (Exception e) {
                logger.error(e);//e.printStackTrace();
            }

            try {
                addressInfoP4InstanceId.setAssociated(false);
                addressInfoP4InstanceId.setInstanceId("somebody");
                addressInfoP4InstanceId.setStatus(Commons.ipaddress_STATUS.associated + "");
                addressInfoP4InstanceId.merge();
            } catch (Exception e) {
                logger.error(e);//e.printStackTrace();
            }
        }

    } catch (Exception e) {
        logger.error(e);//e.printStackTrace();
        try {
            AddressInfoP a = AddressInfoP.findAddressInfoP(addressInfoP.getId());
            a.setStatus(Commons.ipaddress_STATUS.failed + "");
            a = a.merge();
            setAssetEndTime(a.getAsset());
        } catch (Exception e2) {
            // TODO: handle exception
        }
    }

}

From source file:com.glaf.base.modules.sys.springmvc.MxLoginController.java

/**
 * //ww  w .  ja v  a 2 s  .co m
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping("/login")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {
    String ip = RequestUtils.getIPAddress(request);
    /**
     * ????
     */
    if (StringUtils.contains(conf.get("login.allow.ip", "127.0.0.1"), ip)
            || StringUtils.contains(SystemConfig.getString("login.allow.ip", "127.0.0.1"), ip)) {
        String actorId = request.getParameter("x");
        String password = request.getParameter("y");
        HttpSession session = request.getSession(true);
        java.util.Random random = new java.util.Random();
        String rand = Math.abs(random.nextInt(999999)) + com.glaf.core.util.UUID32.getUUID()
                + Math.abs(random.nextInt(999999));
        String rand2 = Math.abs(random.nextInt(9999)) + com.glaf.core.util.UUID32.getUUID()
                + Math.abs(random.nextInt(9999)) + SystemConfig.getToken();
        session = request.getSession(true);
        if (session != null) {
            session.setAttribute("x_y", rand);
            session.setAttribute("x_z", rand2);
        }
        String url = request.getContextPath() + "/mx/login/doLogin?x=" + actorId + "&y=" + rand + password
                + rand2;
        try {
            response.sendRedirect(url);
            return null;
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    return new ModelAndView("/modules/login");
}

From source file:alfio.controller.api.support.TicketHelper.java

public static List<Pair<String, String>> getLocalizedEUCountries(Locale locale, String euCountries) {
    return mapISOCountries(
            Stream.of(Locale.getISOCountries()).filter(isoCode -> StringUtils.contains(euCountries, isoCode)),
            locale);/*ww  w .j  av a 2  s. co  m*/
}