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.glaf.activiti.mail.SendTodoMailTaskBean.java

public void sendRunningTasks(String actorId) {
    User user = IdentityFactory.getUser(actorId);
    ISysTodoService todoService = ContextFactory.getBean("sysTodoService");
    List<Todo> todoList = todoService.getTodoList();
    if (todoList != null && !todoList.isEmpty()) {
        if (StringUtils.isNotEmpty(user.getMail()) && StringUtils.contains(user.getMail(), "@")) {
            this.sendRunningTasks(user, todoList);
        }/*from  w w w. ja v a2s  .c o  m*/
    }
}

From source file:ch.cyberduck.ui.cocoa.FileController.java

@Override
protected boolean validateInput() {
    if (StringUtils.contains(inputField.stringValue(), Path.DELIMITER)) {
        return false;
    }/*from  w  w w  .ja  va 2s  .c  o m*/
    if (StringUtils.isNotBlank(inputField.stringValue())) {
        if (cache.get(this.getWorkdir())
                .contains(new Path(this.getWorkdir(), inputField.stringValue(), EnumSet.of(Path.Type.file)))) {
            return false;
        }
        if (cache.get(this.getWorkdir()).contains(
                new Path(this.getWorkdir(), inputField.stringValue(), EnumSet.of(Path.Type.directory)))) {
            return false;
        }
        return true;
    }
    return false;
}

From source file:Methods.ManageKey.java

/**
 * Mtodo que procesa el fichero obtenido en el metodo Open
 * @param keyFile//from   w w  w  .j a v a 2s  .c om
 * @return 
 */
private String[] processFile(File keyFile) {
    String[] keys = new String[4];
    String line;
    // dentro de las primeras 20 lineas han de estar todos los componentes necesarios
    int numLines = 0;

    try {
        Scanner file = new Scanner(keyFile);

        while (file.hasNextLine() && numLines < 20) {

            line = file.nextLine();
            numLines++;

            if (StringUtils.contains(line, "P generado")) {
                line = file.nextLine();
                //para dejar solo los nmeros
                keys[0] = StringUtils.replaceAll(line, "[^0-9]", "");

                numLines++;
            }

            if (StringUtils.contains(line, "Q generado")) {
                line = file.nextLine();

                keys[1] = StringUtils.replaceAll(line, "[^0-9]", "");

                numLines++;
            }

            if (StringUtils.contains(line, "e generada")) {
                line = file.nextLine();

                keys[2] = StringUtils.replaceAll(line, "[^0-9]", "");

                numLines++;
            }

            if (StringUtils.contains(line, "Unidades:")) {

                if (StringUtils.contains(line, "Decimal")) {
                    keys[3] = "Decimal";
                } else {
                    keys[3] = "Hexadecimal";
                }

                numLines++;
            }
        }

    } catch (FileNotFoundException e) {
        this.errorDialog.readingFile();
        return null;
    }

    if (this.keysNotOk(keys)) {
        this.errorDialog.missingComponents();
        keys = null;
    }

    return keys;

}

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

public static Principal checkLogin(SecurityRequestWrapper request, HttpServletResponse response,
        XWikiContext context) throws Exception {
    // Always verify authentication
    String authorizationHeader = request.getHeader("Authorization");
    if (authorizationHeader != null) {
        String decoded = decodeBasicAuthorizationString(authorizationHeader);
        String username = convertUsername(parseUsername(decoded), context);
        String password = parsePassword(decoded);

        Principal principal = authenticate(username, password, context);

        if (principal != null) {
            // login successful
            request.getSession().removeAttribute(LOGIN_ATTEMPTS);

            // make sure the Principal contains wiki name information
            if (!StringUtils.contains(principal.getName(), ':')) {
                principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName());
            }/*  w  w  w  .java 2  s  . c o  m*/

            request.setUserPrincipal(principal);

            return principal;
        }
    }

    return null;
}

From source file:hk.mcc.utils.applog2es.Main.java

private static void post2ES(List<AppLog> appLogs) {
    try {//from   w w w .  ja  va 2  s . com
        // on startup
        DateTimeFormatter sdf = ISODateTimeFormat.dateTime();
        Settings settings = Settings.settingsBuilder().put("cluster.name", "my-application").build();
        //Add transport addresses and do something with the client...
        Client client = TransportClient.builder().settings(settings).build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

        XContentBuilder mapping = jsonBuilder().startObject().startObject("applog").startObject("properties")
                .startObject("Url").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("Event").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("ClassName").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("UserId").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("Application").field("type", "string").field("index", "not_analyzed").endObject()
                .startObject("ecid").field("type", "string").field("index", "not_analyzed").endObject()
                .endObject().endObject().endObject();

        PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping("applog")
                .setType("applog").setSource(mapping).execute().actionGet();
        BulkRequestBuilder bulkRequest = client.prepareBulk();
        for (AppLog appLog : appLogs) {
            // either use client#prepare, or use Requests# to directly build index/delete requests
            if (appLog != null) {
                if (StringUtils.contains(appLog.getMessage(), "[CIMS_INFO] Filter Processing time")) {
                    String[] split = StringUtils.split(appLog.getMessage(), ",");
                    int elapsedTime = 0;
                    String url = "";
                    String event = "";
                    for (String token : split) {
                        if (StringUtils.contains(token, "elapsedTime")) {
                            elapsedTime = Integer.parseInt(StringUtils.substringAfter(token, "="));
                        } else if (StringUtils.contains(token, "with URL")) {
                            url = StringUtils.substringAfter(token, "=");
                        } else if (StringUtils.contains(token, "event")) {
                            event = StringUtils.substringAfter(token, "=");
                        }
                    }

                    bulkRequest.add(client.prepareIndex("applog", "applog").setSource(jsonBuilder()
                            .startObject().field("className", appLog.getClassName())
                            .field("logTime", appLog.getLogTime()).field("application", appLog.getApplication())
                            .field("code", appLog.getCode()).field("message", appLog.getMessage())
                            .field("ecid", appLog.getEcid()).field("application", appLog.getApplication())
                            .field("level", appLog.getLevel()).field("server", appLog.getServer())
                            .field("tid", appLog.getTid()).field("userId", appLog.getUserId())
                            .field("urls", url).field("elapsedTime", elapsedTime).field("events", event)
                            .endObject()));
                }
            }
        }
        BulkResponse bulkResponse = bulkRequest.get();
        if (bulkResponse.hasFailures()) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, bulkResponse.buildFailureMessage());
            // process failures by iterating through each bulk response item
        }

        // on shutdown
        client.close();
    } catch (UnknownHostException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.glaf.jbpm.business.SendPastDueMailTaskBean.java

public void sendPastDueTasks(String actorId) {
    User user = IdentityFactory.getUser(actorId);
    ISysTodoService todoService = ContextFactory.getBean("sysTodoService");
    List<Todo> todoList = todoService.getTodoList();
    if (todoList != null && !todoList.isEmpty()) {
        if (StringUtils.isNotEmpty(user.getMail()) && StringUtils.contains(user.getMail(), "@")) {
            this.sendPastDueTasks(user, todoList);
        }//ww  w  .  j  a  va  2  s .  co m
    }
}

From source file:com.anrisoftware.sscontrol.scripts.findusedport.FindUsedPort.java

private Map<Integer, String> findServices(ProcessTask task) {
    String out = task.getOut();/*w w  w.java  2s.c o m*/
    String[] lines = StringUtils.split(out, "\n");
    Map<Integer, String> services = new HashMap<Integer, String>();
    for (int i = 0; i < lines.length; i++) {
        for (Integer port : ports) {
            if (StringUtils.contains(lines[i], format(":%d ", port))) {
                parsePortService(services, port, lines[i]);
            }
        }
    }
    return services;
}

From source file:com.glaf.report.web.springmvc.MxReportTaskController.java

@RequestMapping("/chooseReport")
public ModelAndView chooseReport(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);
    request.removeAttribute("canSubmit");
    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String rowId = ParamUtils.getString(params, "rowId");
    ReportQuery query = new ReportQuery();
    List<Report> list = reportService.list(query);
    request.setAttribute("unselecteds", list);
    ReportTask reportTask = null;/*from  w  ww.  j av a2s .  c  om*/
    if (StringUtils.isNotEmpty(rowId)) {
        reportTask = reportTaskService.getReportTask(rowId);
        request.setAttribute("reportTask", reportTask);
        if (StringUtils.isNotEmpty(reportTask.getReportIds())) {
            StringBuffer sb01 = new StringBuffer();
            StringBuffer sb02 = new StringBuffer();
            List<String> selecteds = new java.util.ArrayList<String>();
            for (Report r : list) {
                if (StringUtils.contains(reportTask.getReportIds(), r.getId())) {
                    selecteds.add(r.getId());
                    sb01.append(r.getId()).append(",");
                    sb02.append(r.getSubject()).append(",");
                }
            }
            if (sb01.toString().endsWith(",")) {
                sb01.delete(sb01.length() - 1, sb01.length());
            }
            if (sb02.toString().endsWith(",")) {
                sb02.delete(sb02.length() - 1, sb02.length());
            }
            request.setAttribute("selecteds", selecteds);
            request.setAttribute("reportIds", sb01.toString());

            request.setAttribute("reportNames", sb02.toString());
        }
    }

    String x_view = ViewProperties.getString("reportTask.chooseReport");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    return new ModelAndView("/bi/reportTask/chooseReport", modelMap);
}

From source file:com.nesscomputing.event.NessEventTest.java

@Test
public void testFuckImmutability() throws Exception {
    final Map<String, Object> nullPayLoad = Collections.<String, Object>singletonMap("test", null);
    String serialized = mapper/*w ww  .  j a va  2s .  c  om*/
            .writeValueAsString(NessEvent.createEvent(null, NessEventType.getForName(null), nullPayLoad));
    Assert.assertTrue(StringUtils.contains(serialized, "\"test\":null"));
}

From source file:com.norconex.commons.lang.url.QueryString.java

/**
 * Constructor.  /*w  ww .  jav  a  2  s  . c o m*/
 * It is possible to only supply a query string as opposed to an
 * entire URL.
 * Key and values making up a query string are assumed to be URL-encoded.
 * Will throw a {@link URLException} if the supplied encoding is 
 * unsupported or invalid.
 * @param urlWithQueryString a URL from which to extract a query string.
 * @param encoding character encoding
 */
public QueryString(String urlWithQueryString, String encoding) {
    super(new ListOrderedMap<String, List<String>>());
    if (StringUtils.isBlank(encoding)) {
        this.encoding = CharEncoding.UTF_8;
    } else {
        this.encoding = encoding;
    }
    String paramString = urlWithQueryString;
    if (StringUtils.contains(paramString, "?")) {
        paramString = paramString.replaceAll("(.*?)(\\?)(.*)", "$3");
    }
    String[] paramParts = paramString.split("\\&");
    for (int i = 0; i < paramParts.length; i++) {
        String paramPart = paramParts[i];
        if (StringUtils.contains(paramPart, "=")) {
            String key = StringUtils.substringBefore(paramPart, "=");
            String value = StringUtils.substringAfter(paramPart, "=");
            try {
                addString(URLDecoder.decode(key, this.encoding), URLDecoder.decode(value, this.encoding));
            } catch (UnsupportedEncodingException e) {
                throw new URLException("Cannot URL-decode query string (key=" + key + "; value=" + value + ").",
                        e);
            }
        }
    }
}