List of usage examples for org.apache.commons.lang3 StringUtils contains
public static boolean contains(final CharSequence seq, final CharSequence searchSeq)
Checks if CharSequence contains a search CharSequence, handling null .
From source file:com.greenpepper.maven.runner.CommandLineRunnerTest.java
@Test public void usingMavenCoordinatesWithClassifier() throws Exception { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); runner = new CommandLineRunner(new PrintStream(byteOut)); runner.run("--debug", "--pdd", "com.github.strator-dev.greenpepper:greenpepper-client:jar:complete:" + GreenPepperCore.VERSION, "src/test/resources/collection.html", "-o", "target/reports", "--xml"); String output = byteOut.toString(); assertThat(output,/*from www .j a v a 2 s. c o m*/ containsString("Artifact: com.github.strator-dev.greenpepper:greenpepper-client:jar:complete:")); assertFalse(StringUtils.contains(output, "Artifact: com.github.strator-dev.greenpepper:greenpepper-client:jar:" + GreenPepperCore.VERSION)); }
From source file:com.mirth.connect.util.MessageImporter.java
private void importMessagesFromInputStream(InputStream inputStream, MessageWriter messageWriter, int[] result) throws IOException, InterruptedException { BufferedReader reader = null; try {/*from w w w . java 2s . co m*/ reader = new BufferedReader(new InputStreamReader(inputStream)); String line; StringBuilder serializedMessage = new StringBuilder(); boolean enteredMessage = true; int depth = 0; while ((line = reader.readLine()) != null) { ThreadUtils.checkInterruptedStatus(); if (StringUtils.contains(line, OPEN_ELEMENT)) { depth++; enteredMessage = true; } if (enteredMessage) { serializedMessage.append(line); if (StringUtils.contains(line, CLOSE_ELEMENT)) { if (depth == 1) { Message message = serializer.deserialize(serializedMessage.toString(), Message.class); serializedMessage.delete(0, serializedMessage.length()); enteredMessage = false; result[0]++; try { if (messageWriter.write(message)) { result[1]++; } } catch (MessageWriterException e) { logger.error("Failed to write message", e); } } depth--; } } } } finally { IOUtils.closeQuietly(reader); } }
From source file:io.wcm.handler.mediasource.dam.DamMediaSource.java
@Override public void enableMediaDrop(HtmlElement element, MediaRequest mediaRequest) { if (wcmMode == WCMMode.DISABLED || wcmMode == null) { return;/*from w w w. ja v a2s .c o m*/ } String refProperty = getMediaRefProperty(mediaRequest); if (!StringUtils.startsWith(refProperty, "./")) { refProperty = "./" + refProperty; //NOPMD } String cropProperty = getMediaCropProperty(mediaRequest); if (!StringUtils.startsWith(cropProperty, "./")) { cropProperty = "./" + cropProperty; //NOPMD } String name = refProperty; if (StringUtils.contains(name, "/")) { name = Text.getName(name); } if (componentContext != null && componentContext.getEditContext() != null && MediaMarkupBuilderUtil.canApplyDragDropSupport(mediaRequest, componentContext)) { Component componentDefinition = WCMUtils.getComponent(resource); // set drop target - with path of current component as default resource type Map<String, String> params = new HashMap<String, String>(); if (componentDefinition != null) { params.put("./" + ResourceResolver.PROPERTY_RESOURCE_TYPE, componentDefinition.getPath()); // clear cropping parameters if a new image is inserted via drag&drop params.put(cropProperty, ""); } DropTarget dropTarget = new DropTargetImpl(name, refProperty).setAccept(new String[] { "image/.*" // allow all image mime types }).setGroups(new String[] { "media" // allow drop from DAM contentfinder tab }).setParameters(params); componentContext.getEditContext().getEditConfig().getDropTargets().put(dropTarget.getId(), dropTarget); if (element != null) { element.addCssClass(DropTarget.CSS_CLASS_PREFIX + name); } } }
From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.Media.java
public String getJpcId() { String imagePk = get(JPCID);/*from w ww. j a v a2 s.c o m*/ if (StringUtils.contains(imagePk, "e+") == true) { Double l = NumberUtils.toDouble(imagePk); imagePk = Long.toString(l.longValue()); } return imagePk; }
From source file:com.glaf.jbpm.action.MailAction.java
public void execute(ExecutionContext ctx) throws Exception { logger.debug("------------------------------------------------------"); logger.debug("-------------------MailAction-------------------------"); logger.debug("------------------------------------------------------"); Map<String, Object> context = new HashMap<String, Object>(); ContextInstance contextInstance = ctx.getContextInstance(); Map<String, Object> variables = contextInstance.getVariables(); if (variables != null && variables.size() > 0) { Iterator<String> iterator = variables.keySet().iterator(); while (iterator.hasNext()) { String variableName = iterator.next(); if (context.get(variableName) == null) { Object value = contextInstance.getVariable(variableName); context.put(variableName, value); }/*from w w w . ja va 2s .c o m*/ } } ProcessInstance processInstance = ctx.getProcessInstance(); ProcessDefinition processDefinition = processInstance.getProcessDefinition(); context.put("x_process_name", processDefinition.getName()); context.put("x_process_title", processDefinition.getDescription()); context.put("task_subject", subject); context.put("taskName", taskName); context.put("task_name", taskName); context.put("taskContent", taskContent); context.put("task_content", taskContent); if (StringUtils.isNotEmpty(templateId)) { Template template = TemplateContainer.getContainer().getTemplate(templateId); if (template != null) { logger.debug(template); if (StringUtils.isEmpty(subject)) { subject = template.getTitle(); } if (StringUtils.isEmpty(content)) { content = template.getContent(); } } } if (subject != null) { subject = ExpressionTools.evaluate(subject, context); } logger.debug("subject:" + subject); logger.debug("content:" + content); if (StringUtils.isEmpty(subject) || StringUtils.isEmpty(content)) { throw new RuntimeException("subject or content is empty"); } String process_starter = (String) contextInstance.getVariable(Constant.PROCESS_STARTERID); String value = null; String tmp = null; if (mailTo.equals(Constant.PROCESS_STARTER_EXPRESSION)) { value = process_starter; } else if (mailTo.equals("x_running")) { TaskMgmtInstance tmi = ctx.getTaskMgmtInstance(); Collection<TaskInstance> taskInstances = tmi.getTaskInstances(); if (taskInstances != null && taskInstances.size() > 0) { StringBuffer actBuffer = new StringBuffer(); Iterator<TaskInstance> iter = taskInstances.iterator(); while (iter.hasNext()) { TaskInstance ti = iter.next(); if ((!ti.isOpen()) || ti.isSuspended()) { continue; } if (taskName != null && (!StringUtils.contains(taskName, ti.getName()))) { continue; } if (ti.getActorId() != null) { actBuffer.append(ti.getActorId()).append(','); } else { Set<PooledActor> pas = ti.getPooledActors(); if (pas != null && pas.size() > 0) { Iterator<PooledActor> it = pas.iterator(); while (it.hasNext()) { PooledActor pa = it.next(); if (pa.getActorId() != null) { actBuffer.append(pa.getActorId()).append(','); } } } } } value = actBuffer.toString(); } } else if (mailTo.equals("x_finished")) { TaskMgmtInstance tmi = ctx.getTaskMgmtInstance(); Collection<TaskInstance> taskInstances = tmi.getTaskInstances(); if (taskInstances != null && taskInstances.size() > 0) { StringBuffer actBuffer = new StringBuffer(); Iterator<TaskInstance> iter = taskInstances.iterator(); while (iter.hasNext()) { TaskInstance ti = iter.next(); if (!ti.hasEnded()) { continue; } if (taskName != null && (!StringUtils.contains(taskName, ti.getName()))) { continue; } if (ti.getActorId() != null) { actBuffer.append(ti.getActorId()).append(','); } } value = actBuffer.toString(); } } else if (mailTo.startsWith("#P{") && mailTo.endsWith("}")) { tmp = StringTools.replaceIgnoreCase(mailTo, "#P{", ""); tmp = StringTools.replaceIgnoreCase(tmp, "}", ""); value = (String) contextInstance.getVariable(tmp); } else if (mailTo.startsWith("#{") && mailTo.endsWith("}")) { value = ExpressionTools.evaluate(mailTo, context); } logger.debug("send actors:" + value); if (StringUtils.isEmpty(value)) { return; } Map<String, String> mailsTo = new HashMap<String, String>(); Map<String, User> userMap = new HashMap<String, User>(); StringTokenizer st = new StringTokenizer(value, ","); while (st.hasMoreTokens()) { String actorId = st.nextToken(); User user = IdentityFactory.getUser(actorId); if (user != null && MailTools.isMailAddress(user.getMail())) { mailsTo.put(user.getActorId(), user.getMail()); userMap.put(user.getActorId(), user); userMap.put(user.getMail(), user); } } logger.debug("send mailsTo:" + mailsTo); if (mailsTo.size() == 0) { return; } Iterator<String> iterator = mailsTo.keySet().iterator(); while (iterator.hasNext()) { String actorId = iterator.next(); String mailAddress = mailsTo.get(actorId); logger.debug("??:" + mailAddress); logger.debug(subject); StringBuffer urlBuffer = new StringBuffer(); String messageId = UUID32.getUUID(); String link = ""; if (context.get("todo_url") != null) { link = (String) context.get("todo_url"); } else { String key = processDefinition.getName() + "_" + taskName; link = TodoConfig.getLink(key); if (StringUtils.isEmpty(link)) { key = processDefinition.getName(); link = TodoConfig.getLink(key); } } urlBuffer.append(link); urlBuffer.append("&messageId=").append(messageId); context.put("serviceUrl", SystemConfig.getServiceUrl()); context.put("appId", contextInstance.getVariable("appId")); context.put("app_name", contextInstance.getVariable("app_name")); context.put("rowId", contextInstance.getVariable(Constant.PROCESS_ROWID)); context.put("processName", processDefinition.getName()); context.put("processInstanceId", String.valueOf(processInstance.getId())); if (contextInstance.getVariable("appId") != null) { urlBuffer.append("&appId=").append(contextInstance.getVariable("appId")); } if (contextInstance.getVariable("app_name") != null) { urlBuffer.append("&app_name=").append(contextInstance.getVariable("app_name")); } urlBuffer.append("&rowId=").append(contextInstance.getVariable(Constant.PROCESS_ROWID)); urlBuffer.append("&processName=").append(processDefinition.getName()); urlBuffer.append("&processInstanceId=").append(String.valueOf(processInstance.getId())); User user = userMap.get(actorId); if (user != null) { urlBuffer.append("&xyz_activationCode=").append(RequestUtils.encodeString(user.getActorId())); } String gotopage = urlBuffer.toString(); String redirectUrl = RequestUtils.encodeURL(gotopage); context.put("gotopage", gotopage); context.put("callback", gotopage); context.put("redirectUrl", redirectUrl); if (user != null) { context.put("sid", RequestUtils.encodeString(user.getActorId())); context.put("xyz_activationCode", RequestUtils.encodeString(user.getActorId())); } context.put("user", userMap.get(actorId)); context.put("mailToUser", userMap.get(actorId)); content = TemplateUtils.process(context, content); logger.debug("content:" + content); MailMessage mailMessage = new MailMessage(); // mailMessage.setTemplateId(templateId); mailMessage.setMessageId(messageId); mailMessage.setTo(mailAddress); mailMessage.setSubject(subject); mailMessage.setContent(content); mailMessage.setDataMap(context); mailMessage.setSaveMessage(true); try { MailThread thread = new MailThread(mailMessage); com.glaf.core.util.threads.ThreadFactory.run(thread); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:info.magnolia.ui.framework.command.ImportZipCommand.java
protected void handleFileEntry(ZipFile zip, ZipArchiveEntry entry) throws IOException, RepositoryException { String fileName = entry.getName(); if (StringUtils.contains(fileName, "/")) { fileName = StringUtils.substringAfterLast(fileName, "/"); }/* w w w. j av a 2s .c o m*/ String extension = StringUtils.substringAfterLast(fileName, "."); InputStream stream = zip.getInputStream(entry); FileOutputStream os = null; try { UploadReceiver receiver = createReceiver(); String folderPath = extractEntryPath(entry); if (folderPath.startsWith("/")) { folderPath = folderPath.substring(1); } Node folder = getJCRNode(context); if (StringUtils.isNotBlank(folderPath)) { if (folder.hasNode(folderPath)) { folder = folder.getNode(folderPath); } else { folder = NodeUtil.createPath(folder, folderPath, NodeTypes.Folder.NAME, true); } } receiver.setFieldType(UploadField.FieldType.BYTE_ARRAY); receiver.receiveUpload(fileName, StringUtils.defaultIfEmpty(MIMEMapping.getMIMEType(extension), DEFAULT_MIME_TYPE)); receiver.setValue(IOUtils.toByteArray(stream)); doHandleEntryFromReceiver(folder, receiver); } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(stream); IOUtils.closeQuietly(os); } }
From source file:cn.mrdear.pay.util.WebUtils.java
/** * GET//from ww w .j a v a 2 s. co m * * @param url * URL * @param parameterMap * ? * @return */ public static String get(String url, Map<String, Object> parameterMap) { String result = null; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); if (parameterMap != null) { for (Map.Entry<String, Object> entry : parameterMap.entrySet()) { String name = entry.getKey(); String value = String.valueOf(entry.getValue()); if (StringUtils.isNotEmpty(name)) { nameValuePairs.add(new BasicNameValuePair(name, value)); } } } HttpGet httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"))); CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpGet); result = consumeResponse(httpResponse); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } catch (ParseException e) { throw new RuntimeException(e.getMessage(), e); } catch (ClientProtocolException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } return result; }
From source file:com.dchq.docker.volume.driver.controller.DockerVolumeDriverControllerIntegrationTests.java
@Test public void pathTest() { String name = RandomStringUtils.randomAlphabetic(6); CreateRequest request = new CreateRequest(); request.setName(name);/*from w ww . java 2s . c o m*/ String response = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.CREATE, request, String.class); Assert.assertNotNull(response); Assert.assertEquals(response, "{\"Err\":\"\"}"); PathRequest pathRequest = new PathRequest(); pathRequest.setName(name); String pathResponse = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.PATH, pathRequest, String.class); Assert.assertNotNull(pathResponse); Assert.assertTrue(StringUtils.contains(pathResponse, "\"Err\":\"\"")); logger.info("Response [{}]", pathResponse); }
From source file:com.thoughtworks.go.matchers.ConsoleOutMatcher.java
public static TypeSafeMatcher<String> printedUploadingFailure(final File file) { return new TypeSafeMatcher<String>() { public String consoleOut; public String message; public boolean matchesSafely(String consoleOut) { this.consoleOut = consoleOut; this.message = "Failed to upload " + file.getAbsolutePath(); return StringUtils.contains(consoleOut.toLowerCase(), message.toLowerCase()); }/*from w ww . java 2s .c o m*/ public void describeTo(Description description) { description.appendText("Expected console to contain [" + message + "] but was " + consoleOut); } }; }
From source file:net.eledge.android.europeana.search.SearchController.java
public List<FacetItem> getBreadcrumbs(Context context) { List<FacetItem> breadcrumbs = new ArrayList<>(); FacetItem crumb;// ww w . j a v a 2 s.c o m for (String term : terms) { crumb = new FacetItem(); crumb.itemType = FacetItemType.BREADCRUMB; crumb.facetType = FacetType.TEXT; crumb.description = term; crumb.facet = term; if (StringUtils.contains(term, ":")) { FacetType type = FacetType.safeValueOf(StringUtils.substringBefore(term, ":")); if (type != null) { crumb.facetType = type; crumb.description = StringUtils .capitalize(StringUtils.lowerCase(GuiUtils.getString(context, type.resId))) + ":" + type.createFacetLabel(context, StringUtils.substringAfter(term, ":")); } } breadcrumbs.add(crumb); } return breadcrumbs; }