Java Code Examples for org.apache.commons.lang3.StringUtils.substringAfterLast()

The following are Jave code examples for showing how to use substringAfterLast() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pprxmtr   File: Handler.java   View Source Code Vote up 7 votes
private void sendSlackImageResponse(ObjectNode json, String s3Key) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		ObjectNode message = mapper.createObjectNode();
		ArrayNode attachments = mapper.createArrayNode();
		ObjectNode attachment = mapper.createObjectNode();

		String emoji = json.get("text").asText();

		if (UrlValidator.getInstance().isValid(emoji)) {
			attachment.put("title_link", emoji);
			emoji = StringUtils.substringAfterLast(emoji, "/");
		}

		String username = json.get("user_name").asText();
		String responseUrl = json.get("response_url").asText();
		String slackChannelId = json.get("channel_id").asText();
		String imageUrl = String.format("https://s3.amazonaws.com/%s/%s", PROPERTIES.getProperty(S3_BUCKET_NAME), s3Key);

		message.put("response_type", "in_channel");
		message.put("channel_id", slackChannelId);
		attachment.put("title", resolveMessage("slackImageResponse", emoji, username));
		attachment.put("fallback", resolveMessage("approximated", emoji));
		attachment.put("image_url", imageUrl);
		attachments.add(attachment);
		message.set("attachments", attachments);

		HttpClient client = HttpClientBuilder.create().build();
		HttpPost slackResponseReq = new HttpPost(responseUrl);
		slackResponseReq.setEntity(new StringEntity(mapper.writeValueAsString(message), ContentType.APPLICATION_JSON));
		HttpResponse slackResponse = client.execute(slackResponseReq);
		int status = slackResponse.getStatusLine().getStatusCode();
		LOG.info("Got {} status from Slack API after sending approximation to response url.", status);
	} catch (UnsupportedOperationException | IOException e) {
		LOG.error("Exception occured when sending Slack response", e);
	}
}
 
Example 2
Project: solo-spring   File: Cron.java   View Source Code Vote up 6 votes
/**
 * Parses the specified schedule into {@link #period execution period}.
 *
 * @param schedule
 *            the specified schedule
 */
private void parse(final String schedule) {
	final int num = Integer.valueOf(StringUtils.substringBetween(schedule, " ", " "));
	final String timeUnit = StringUtils.substringAfterLast(schedule, " ");

	logger.trace("Parsed a cron job [schedule={}]: [num={}, timeUnit={}, description={}], ",
			new Object[] { schedule, num, timeUnit, description });

	if ("hours".equals(timeUnit)) {
		period = num * SIXTY * SIXTY * THOUSAND;
	} else if ("minutes".equals(timeUnit)) {
		period = num * SIXTY * THOUSAND;
	} else if ("seconds".equals(timeUnit)) {
		period = num * THOUSAND;
	}
}
 
Example 3
Project: gitplex-mit   File: TextHit.java   View Source Code Vote up 5 votes
@Override
public String getNamespace() {
	String fileName = getBlobPath();
	if (fileName.contains("/")) 
		fileName = StringUtils.substringAfterLast(fileName, "/");
	return fileName;
}
 
Example 4
Project: aceql-http   File: FrameworkDebug.java   View Source Code Vote up 5 votes
/**
    * Says if a class must be in debug mode
    * 
    * @param clazz
    *            the class to analyze if debug must be on
    * @return true if the class must be on debug mode, else false
    */
   public static boolean isSet(Class<?> clazz) {
load();

String className = clazz.getName();
String rawClassName = StringUtils.substringAfterLast(className, ".");

if (CLASSES_TO_DEBUG.contains(className)
	|| CLASSES_TO_DEBUG.contains(rawClassName)) {
    return true;
} else {
    return false;
}
   }
 
Example 5
Project: imagetozxspec   File: FileOutputListener.java   View Source Code Vote up 5 votes
/**
 * Java MacOS workaround to detect the duplicated entry at the end of the path
 * 
 * @param file the file to check
 * @return whether the directory at the end of the path is duplicated
 */
private boolean isDuplicatedDirectory(File file) {
	String path = file.getAbsolutePath();
	log.debug("Path: {}", path);
	String lastDir = File.separator+StringUtils.substringAfterLast(path, File.separator);
	log.debug("Last dir: {}", lastDir);
	String pathWithoutLastDir = StringUtils.substringBeforeLast(path, lastDir);
	log.debug("Path without Last dir: {}", pathWithoutLastDir);
	boolean eval = lastDir.length()>1 && pathWithoutLastDir.endsWith(lastDir);
	log.debug("Eval {}", eval);
	return eval;
}
 
Example 6
Project: gitplex-mit   File: FileHit.java   View Source Code Vote up 5 votes
@Override
public Component render(String componentId) {
	String fileName = getBlobPath();
	if (fileName.contains("/")) 
		fileName = StringUtils.substringAfterLast(fileName, "/");
	
	return new HighlightableLabel(componentId, fileName, matchRange);
}
 
Example 7
Project: spring2ts   File: ServiceRequestProps.java   View Source Code Vote up 4 votes
private String enumValue(String input) {
    if(StringUtils.contains(input, '.')) {
        return StringUtils.substringAfterLast(input, ".");
    }
    return input;
}
 
Example 8
Project: OpenLRW   File: DefaultClassIdConverter.java   View Source Code Vote up 4 votes
@Override
public String convert(Tenant tenant, Event event) {
  Group group = event.getGroup();
  if (group == null) {
    return null;
  }
  
  String convertedClassId = null;
  String groupId = null;
  String groupType = group.getType();
  if (isCourseSection(groupType)) {
    groupId = group.getId();
  }
  else {
    groupId = findCourseSectionId(group.getSubOrganizationOf());
  }
  
  if (StringUtils.isBlank(groupId)) {
    return null;
  }
  
  if (StringUtils.startsWith(groupId, "http")) {
    Map<String, String> tenantMetadata = tenant.getMetadata();
    if (tenantMetadata != null && !tenantMetadata.isEmpty()) {
      String tenantClassPrefix = tenantMetadata.get(Vocabulary.TENANT_CLASS_PREFIX);
      if (StringUtils.isNotBlank(tenantClassPrefix)) {
        String classIdAfterPrefix = StringUtils.substringAfter(groupId, tenantClassPrefix);
        if (StringUtils.startsWith(classIdAfterPrefix, "/")) {
          convertedClassId = StringUtils.substringAfter(classIdAfterPrefix, "/");
        }
        else {
          convertedClassId = classIdAfterPrefix;
        }
      }
    }
    else {
      convertedClassId = StringUtils.substringAfterLast(groupId, "/");
    }
  }
  else {
    convertedClassId = groupId;
  }
  
  return convertedClassId;
}
 
Example 9
Project: aceql-http   File: FileNameFromBlobBuilder.java   View Source Code Vote up 4 votes
/**
    * Returns the table name in use type from a DML SQL order.
    * 
    * @param statementType
    *            the statement type (INSERT, ...)
    * @param sql
    *            the sql order
    * 
    * @return the table name in use (the first one in a <code>SELECT</code>
    *         statement) for a DML statement. Returns null if statement is not
    *         DML.
    */
   private String getTableNameFromDmlStatement(String statementType, String sql)
    throws IllegalArgumentException {
// Extract the first order
String statementTypeUpper = statementType.toUpperCase();

String sqlUpper = sql.toUpperCase();

// Extract the table depending on the ordOer
sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper);
sqlUpper = sqlUpper.trim();

String table = null;

if (statementTypeUpper.equals(INSERT)) {
    sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO ");
    sqlUpper = sqlUpper.trim();
    table = StringUtils.substringBefore(sqlUpper, " ");
} else if (statementTypeUpper.equals(SELECT)
	|| statementTypeUpper.equals(DELETE)) {
    sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM ");
    sqlUpper = sqlUpper.trim();
    // Remove commas in the statement and replace with blanks in case we
    // have
    // a join: "TABLE," ==> "TABLE "
    sqlUpper = sqlUpper.replaceAll(",", " ");
    table = StringUtils.substringBefore(sqlUpper, BLANK);
} else if (statementTypeUpper.equals(UPDATE)) {
    // debug("sqlLocal :" + sqlUpper + ":");
    table = StringUtils.substringBefore(sqlUpper, BLANK);
} else {
    return null; // No table
}

if (table != null) {
    table = table.trim();
}

// Return the part after last dot
if (table.contains(".")) {
    table = StringUtils.substringAfterLast(table, ".");
}

table = table.replace("\'", "");
table = table.replace("\"", "");

return table;
   }
 
Example 10
Project: gitplex-mit   File: Submodule.java   View Source Code Vote up 4 votes
public static Submodule fromString(String str) {
	String url = StringUtils.substringBeforeLast(str, SEPARATOR);
	String commitHash = StringUtils.substringAfterLast(str, SEPARATOR);
	return new Submodule(url, commitHash);
}
 
Example 11
Project: wx-idk   File: ShowQrcodeRequest.java   View Source Code Vote up 4 votes
/**
    * 构造函数
    * @param ticket 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码
    * @param fullDownPath  下载文件路径+文件名
    */
   public ShowQrcodeRequest(String ticket, String fullDownPath) {
	this.ticket = ticket;
	this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
       this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 12
Project: wx-idk   File: PerpetualMediaGetRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param mediaId  		媒体文件ID
 * @param fullDownPath  下载文件路径+文件名
 */
public PerpetualMediaGetRequest(String mediaId, String fullDownPath) {
    this.media_id = mediaId;
    this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 13
Project: wx-idk   File: NewsInnerImgAddRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param fullFilePath  媒体文件路径+文件名
 */
public NewsInnerImgAddRequest(String fullFilePath) {
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 14
Project: wx-idk   File: TempMaterialGetRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param mediaId  		媒体文件ID
 * @param fullDownPath  下载文件路径+文件名
 */
public TempMaterialGetRequest(String mediaId, String fullDownPath) {
    this.media_id = mediaId;
    this.fileName = StringUtils.substringAfterLast(fullDownPath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullDownPath, File.separator) + File.separator;
}
 
Example 15
Project: wx-idk   File: KfUploadHeadimgRequest.java   View Source Code Vote up 4 votes
/**
 * 构造函数
 * @param fullFilePath  图像文件路径+文件名
 * @param kfAccount     客户帐号
 */
public KfUploadHeadimgRequest(String kfAccount, String fullFilePath) {
    this.kf_account = kfAccount;
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 16
Project: wx-idk   File: UploadPoiImgRequest.java   View Source Code Vote up 4 votes
/**
 * 构造器
 * @param fullFilePath  媒体文件路径+文件名
 */
public UploadPoiImgRequest(String fullFilePath) {
    this.fileName = StringUtils.substringAfterLast(fullFilePath, File.separator);
    this.filePath = StringUtils.substringBeforeLast(fullFilePath, File.separator) + File.separator;
}
 
Example 17
Project: onboarding-service   File: ErrorAttributesConverter.java   View Source Code Vote up 4 votes
private String code(Map<String, Object> errorAttributes) {
  String exception = (String) errorAttributes.get("exception");
  return StringUtils.substringAfterLast(exception, ".");
}
 
Example 18
Project: solo-spring   File: IndexProcessor.java   View Source Code Vote up 2 votes
/**
 * Gets the request page number from the specified request URI.
 *
 * @param requestURI
 *            the specified request URI
 * @return page number, returns {@code -1} if the specified request URI can
 *         not convert to an number
 */
private static int getCurrentPageNum(final String requestURI) {
	final String pageNumString = StringUtils.substringAfterLast(requestURI, "/");

	return Requests.getCurrentPageNum(pageNumString);
}
 
Example 19
Project: redirector   File: StacksHelper.java   View Source Code Vote up 2 votes
/**
 * @param fullPath of full path e.g. /PO/POC5/1.40/xreGuide
 * @return serviceName e.g. xreGuide
 */
public static String getServiceName(String fullPath) {
    return StringUtils.substringAfterLast(fullPath, RedirectorConstants.DELIMETER);
}
 
Example 20
Project: redirector   File: StacksHelper.java   View Source Code Vote up 2 votes
/**
 * @param stackPathWithoutServiceName of stack path without serviceName e.g. /PO/POC5/1.40
 * @return flavor e.g. 1.40
 */
public static String getFlavorPath(String stackPathWithoutServiceName) {
    return StringUtils.substringAfterLast(stackPathWithoutServiceName, RedirectorConstants.DELIMETER);
}