Java Code Examples for org.apache.commons.lang.StringUtils.substringBetween()

The following are Jave code examples for showing how to use substringBetween() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: DBus   File: Support.java   Source Code and License Vote up 6 votes
public static int[] getColumnLengthAndPrecision(Column column){
	int[] ret = new int[2];
	String data = StringUtils.substringBetween(column.getMysqlType(), "(",")");
	String length = StringUtils.substringBefore(data, ",");
	String precision = StringUtils.substringAfter(data, ",");
	String type = getColumnType(column).toUpperCase();
	if("SET".equals(type) || "ENUM".equals(type)){
		ret[0] = 0;
		ret[1] = 0;
	}else{
		if(StringUtils.isEmpty(length)){
			ret[0] = 0;
		}else{
			ret[0] = Integer.parseInt(length);
		}
		if(StringUtils.isEmpty(precision)){
			ret[1] = 0;
		}else{
			ret[1] = Integer.parseInt(precision);
		}
	}
	return ret;
}
 
Example 2
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 6 votes
/**
 * 根据hex文本数组截取数据,返回截获的hex数组
 * @param data 类型:[0, 7, -63, -108]
 * @param startHexStr 类型:["0C", "B6", "05", "00"]
 * @param endHexStr 类型:["0C", "B6", "05", "00"]
 * @return 类型:["0C", "B6", "05", "00"] 失败返回null
 */
public String[] subHexArray(byte[] data,String[] startHexStr,String[] endHexStr)
{
	if(data==null||data.length<=0)
	{
		System.out.println("data数据无效!");
		return null;
	}
	String[] result=null;
	String[] hexarray=toHexArray(data);
	String hexstr=Arrays.toString(hexarray);
	hexstr=StringUtils.substringBetween(hexstr, "[", "]").replaceAll("\\s", "");//原数据字符串去括号空格
	String start=Arrays.toString(startHexStr);//转换为字符串
	start=StringUtils.substringBetween(start, "[", "]").replaceAll("\\s", "");//去括号空格
	String end=Arrays.toString(endHexStr);
	end=StringUtils.substringBetween(end, "[", "]").replaceAll("\\s", "");//去括号空格
	String resultHex=StringUtils.substringBetween(hexstr, start, end);//取中间数据
	if(resultHex==null)
	{
		//System.out.println("注意:截取内容为空,无数据!");
		return null;
	}
	result=StringUtils.split(resultHex, ',');//重组为hexstr数组
	return result;
}
 
Example 3
Project: util4j   File: DataTools.java   Source Code and License Vote up 6 votes
/**
 * 失败返回null
 * 根据hex字符数组截取数据,返回截获数据的hex数组
 * @param data 类型:[0, 7, -63, -108]
 * @param startHexStr 类型:["0C", "B6", "05", "00"]
 * @param endHexStr 类型:["0C", "B6", "05", "00"]
 * @return 类型:["0C", "B6", "05", "00"]
 */
public String[] SubHexArrays(byte[] data,String[] startHexStr,String[] endHexStr)
{
	if(data==null||data.length<=0)
	{
		System.out.println("data数据无效!");
		return null;
	}
	String[] result=null;
	String[] hexarray=byteArrayToHexArray(data);
	String hexstr=Arrays.toString(hexarray);
	hexstr=StringUtils.substringBetween(hexstr, "[", "]").replaceAll("\\s", "");//原数据字符串去括号空格
	String start=Arrays.toString(startHexStr);//转换为字符串
	start=StringUtils.substringBetween(start, "[", "]").replaceAll("\\s", "");//去括号空格
	String end=Arrays.toString(endHexStr);
	end=StringUtils.substringBetween(end, "[", "]").replaceAll("\\s", "");//去括号空格
	String resultHex=StringUtils.substringBetween(hexstr, start, end);//取中间数据
	if(resultHex==null)
	{
		//System.out.println("注意:截取内容为空,无数据!");
		return null;
	}
	result=StringUtils.split(resultHex, ',');//重组为hexstr数组
	return result;
}
 
Example 4
Project: Hydrograph   File: ExportXSDWidget.java   Source Code and License Vote up 6 votes
private String getRootElementName(String rowTag) {

		String rootElementName = null;

		if (StringUtils.isBlank(rowTag) || !rowTag.startsWith("/")) {
			return null;
		}

		// TODO: Ask for requirement how row tag will be come
		if (rowTag.startsWith("/")) {
			rootElementName = StringUtils.substringBetween(rowTag, "/", "/");
		}
		if (StringUtils.isBlank(rootElementName)) {
			rootElementName = StringUtils.substringAfter(rowTag, "/");
		}

		return rootElementName;
	}
 
Example 5
Project: Hydrograph   File: Utils.java   Source Code and License Vote up 6 votes
/**
	 * 
	 * checking the parameter in paramsMap
	 * @param value
	 * @return value of Parameter if found in Map otherwise Parameter not found
	 */
 public String getParamValue(String value){
	 Optional<String> optional = Optional.of(value);
	 if(jobProps != null && !jobProps.isEmpty() && optional.isPresent() && value.contains("@{")){
		String param = "";
		String[] splitString = value.split("/");
		for(String field : splitString){
			if(field.startsWith("@{")){
				field = StringUtils.substringBetween(field, "@{", "}");
				for (Map.Entry<String, String> entry : paramsMap.entrySet()){
					if(StringUtils.equals(entry.getKey(), field)){
						if(entry.getValue().endsWith("/")){
							param = param == null ? entry.getValue() : param.concat(entry.getValue() + "/");
						}
						param = param == null ? entry.getValue() : param.concat(entry.getValue() + "/");
					}
				}
			}else{
				param += field + "/";
			}
		}
		return getResult(param);
	}
		return PARAMETER_NOT_FOUND;
}
 
Example 6
Project: alfresco-repository   File: ResetPasswordServiceImplTest.java   Source Code and License Vote up 5 votes
public static Pair<String, String> getWorkflowIdAndKeyFromUrl(String url)
{
    //url example: http://localhost:8081/share/page/reset-password?key=164e37bf-2590-414e-94db-8b8cfe5be790&id=activiti$156
    assertNotNull(url);

    String id = StringUtils.trimToNull(
                StringUtils.substringAfter(url, "id="));
    String key = StringUtils.substringBetween(url, "key=", "&id=");

    Pair<String, String> pair = new Pair<>(id, key);
    return pair;
}
 
Example 7
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 5 votes
/**
 * 将一个装有16进制的string数组变成一个16进制字符串
 * "[01, 16, 1F, 0E]" ==> 01161F0E
 * @param hexStringArray
 * @return
 */
public String toHexStr(String[] hexStringArray)
{
	String hexStr=Arrays.toString(hexStringArray);
	hexStr=StringUtils.substringBetween(hexStr, "[", "]");
	hexStr=hexStr.replaceAll("\\s", "");//去空格
	hexStr=hexStr.replaceAll(",", "");
	return hexStr;
}
 
Example 8
Project: util4j   File: HexStrBytes.java   Source Code and License Vote up 5 votes
/**
 * 将一个16进制文本数组字符串转为16进制文本数组
 * "[01, 16, 1F, 0E]" ==> [01, 16, 1F, 0E]
 * @param hexArrayStr
 * @return
 */
public String[] toHexStrArray(String hexArrayStr)
{
	String hexStr=StringUtils.substringBetween(hexArrayStr, "[", "]");
	hexStr=hexStr.replaceAll("\\s", "");//去空格
	String[] hexStrArray=hexStr.split(",");
	return hexStrArray;
}
 
Example 9
Project: util4j   File: DataTools.java   Source Code and License Vote up 5 votes
/**
 * 将数组形式的16进制文本替换为普通文本
 * @param str
 * @return
 */
public String hexStringArrayToHexStr(String[] str)
{
	String hexStr=Arrays.toString(str);
	hexStr=StringUtils.substringBetween(hexStr, "[", "]");
	hexStr=hexStr.replaceAll("\\s", "");//去空格
	hexStr=hexStr.replaceAll(",", "");
	return hexStr;
}
 
Example 10
Project: GitCommitMessage   File: PanelDialog.java   Source Code and License Vote up 5 votes
private String getLongDescription(String templateString) {
    String longDescription = panel.getLongDescription();
    // Get the empty Spaces in templates in new Line and the longDescription Variable
    String searchString = "${" + Consts.LONG_DESCRIPTION + "}";
    String emptySpaces =
            StringUtils.substringBetween(templateString, identifyLineDelimiter(templateString), searchString);
    String lineDelimiter = identifyLineDelimiter(longDescription);
    return StringUtils.replace(longDescription, lineDelimiter, lineDelimiter + emptySpaces).trim();
}
 
Example 11
Project: DBus   File: Support.java   Source Code and License Vote up 4 votes
public static void main(String[] args){
	String str="int";
	String length = StringUtils.substringBetween(str, "(",")");
	String precision = StringUtils.substringBefore(length, ",");
	String scale = StringUtils.substringAfter(length, ",");
}
 
Example 12
Project: uDetective   File: ServiceNowRetriever.java   Source Code and License Vote up 4 votes
@Override
   public Object retrieve(IDataSource snDataSource, Object object) throws RetrieverException {
                               
       HttpClient client = (HttpClient)snDataSource.connect();
       
       // We should use an encoded query in this case because URL parameters do not support the full semantics of a filter.        
       String serviceUrl     = AppProperties.getProperty("service_url");
       String restPath       = AppProperties.getProperty("rest_path");
       String resultLimit    = AppProperties.getProperty("result_limit");
       String period_of_time = AppProperties.getProperty("period_of_time");
       String url1           = "?sysparm_query=active%3Dtrue%5Estate!%3D6%5Esys_created_onRELATIVEGE%40hour%40ago%40" + period_of_time;
       String url2           = "%5Eassignment_group%3D81db147e2b5c79444dde23f119da153b&sysparm_display_value=true&sysparm_fields=sys_id%2Cnumber%2Cshort_description%2Cdescription&sysparm_limit=" + resultLimit;
       
       String finalUrl = serviceUrl + restPath + url1 + url2;
       
       HttpMethod method = new GetMethod(finalUrl);
       method.addRequestHeader("Accept", "application/json");
       String message = "";
       try {
           int status = client.executeMethod(method);
           log.info("Status:" + status);
           BufferedReader rd = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));     
           message = org.apache.commons.io.IOUtils.toString(rd);
       } catch (IOException ioe) {
           throw new RetrieverException(ioe.toString());
       }
       
       // remove leading and ending "{"
       int index = message.indexOf("\"result\":");
       message = message.substring(index+9, message.length()-1);
       
Gson gson = new Gson(); 
       ServiceNowTicket[] wrapper = null;
       try {
           wrapper = gson.fromJson(message, ServiceNowTicket[].class);   
       } catch (Exception e) {
           log.error(e.toString());
       }
       
       if (wrapper == null) {
           log.error("Problem retrieving information from ServiceNow");
           return null;
       }
       log.info("number of fetched tickets: " + wrapper.length);
       List<ServiceNowTicket> ticketList = Arrays.asList(wrapper);  
       
       for (Iterator<ServiceNowTicket> it = ticketList.iterator(); it.hasNext();) {
           ServiceNowTicket ticket = it.next();
           log.info("Fetching IP address and date");
           String source    = StringUtils.substringBetween(ticket.getDescription(), "<Source>", "</Source>");
           String timeStamp = StringUtils.substringBetween(source, "<TimeStamp>", "</TimeStamp>");
           String ipAddress = StringUtils.substringBetween(source, "<IP_Address>", "</IP_Address>");
           log.info("--------------------------");
           log.info("Sys_Id:    " + ticket.getSysId());
           log.info("Number:    " + ticket.getNumber());
           log.info("Timestamp: " + timeStamp);
           log.info("IPAddress: " + ipAddress);      
           log.info("--------------------------");
           log.info("");
           ClaimService service = new ClaimService();
           try {
               // fixing timestamp
               timeStamp = fixTimeStampFormat(timeStamp);
               
               // Sends data to ElasticSearch to find CWL
               IDataSource esDataSource = new ElasticSearchDataSource();
               esDataSource.connect();
               
               // Sends data to CWL database to find email address, first and last name
               
               
               
               
               // save data in the database
               service.addTicket(ticket.getNumber(), ticket.getDescription(), java.sql.Timestamp.valueOf(timeStamp), ipAddress);
           } catch (Exception de) {
               log.error(de.toString());
           }
       }
       return null;
   }
 
Example 13
Project: pac4j-plus   File: PostSAML2ClientTests.java   Source Code and License Vote up 4 votes
private String getDecodedAuthnRequest(final String content) throws Exception {
    assertTrue(content.contains("<form"));
    final String samlRequestField = StringUtils.substringBetween(content, "SAMLRequest", "</div");
    final String value = StringUtils.substringBetween(samlRequestField, "value=\"", "\"");
    return new String(Base64.getDecoder().decode(value), HttpConstants.UTF8_ENCODING);
}