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

The following are Jave code examples for showing how to use substringBefore() 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: gitplex-mit   File: MarkPos.java   View Source Code Vote up 6 votes
public static MarkPos fromString(@Nullable String str) {
	if (str != null) {
		String commit = StringUtils.substringBefore(str, ":");
		String path = null;
		TextRange mark = null;
		String pathAndMark = StringUtils.substringAfter(str, ":");
		if (pathAndMark.length() != 0) {
			path = StringUtils.substringBefore(pathAndMark, ":");
			String markStr = StringUtils.substringAfter(pathAndMark, ":");
			if (markStr.length() != 0)
				mark = new TextRange(markStr);
		}
		return new MarkPos(commit, path, mark);
	} else {
		return null;
	}
}
 
Example 2
Project: aceql-http   File: StatementAnalyzer.java   View Source Code Vote up 6 votes
/**
 * Constructor.
 * 
 * @param sql
 *            the string content of the SQL statement.
 * @param parameterValues
 *            the parameter values of a prepared statement in the natural order,
 *            empty list for a (non prepared) statement
 */
public StatementAnalyzer(String sql, List<Object> parameterValues) {

	if (sql == null) {
		throw new IllegalArgumentException(Tag.PRODUCT_PRODUCT_FAIL + "sql can not be null!");
	}

	if (parameterValues == null) {
		throw new IllegalArgumentException(Tag.PRODUCT_PRODUCT_FAIL + "parameterValues can not be null!");
	}

	sql = sql.trim();

	// Remove last ";" because may cause a problem for getting table
	// name with getTableNameFromDmlStatement()

	sql = removeTrailingSemicolons(sql);
	this.sql = sql;

	// Remove tab on input parameter only for testing statement types
	sql = sql.replace('\t', ' ');
	sql = sql.trim(); // re-trim!
	this.statementType = StringUtils.substringBefore(sql, BLANK);

	this.parameterValues = parameterValues;
}
 
Example 3
Project: saluki   File: GenericInvokeUtils.java   View Source Code Vote up 6 votes
private static Object generateMapType(ServiceDefinition def, TypeDefinition td, MetadataType metadataType,
                                      Set<String> resolvedTypes) {
    String keyType = StringUtils.substringAfter(td.getType(), "<");
    keyType = StringUtils.substringBefore(keyType, ",");
    keyType = StringUtils.strip(keyType);
    keyType = StringUtils.isNotEmpty(keyType) ? keyType : "java.lang.Object";
    Object key = generateType(def, keyType, metadataType, resolvedTypes);

    String valueType = StringUtils.substringAfter(td.getType(), ",");
    valueType = StringUtils.substringBefore(valueType, ">");
    valueType = StringUtils.strip(valueType);
    valueType = StringUtils.isNotEmpty(valueType) ? valueType : "java.lang.Object";
    Object value = generateType(def, valueType, metadataType, resolvedTypes);

    Map<Object, Object> map = new HashMap<>();
    map.put(key, value);
    return map;
}
 
Example 4
Project: springboot-shiro-cas-mybatis   File: TicketGrantingTicketImpl.java   View Source Code Vote up 5 votes
/**
 * Normalize the path of a service by removing the query string and everything after a semi-colon.
 *
 * @param service the service to normalize
 * @return the normalized path
 */
private static String normalizePath(final Service service) {
    String path = service.getId();
    path = StringUtils.substringBefore(path, "?");
    path = StringUtils.substringBefore(path, ";");
    path = StringUtils.substringBefore(path, "#");
    return path;
}
 
Example 5
Project: yadaframework   File: YadaUtil.java   View Source Code Vote up 5 votes
/**
 * Reflection to get the type of a given field, even nested or in a superclass.
 * @param rootClass
 * @param attributePath field name like "surname" or even a path like "friend.name"
 * @return
 * @throws NoSuchFieldException if the field is not found in the class hierarchy
 * @throws SecurityException
 */
public Class getType(Class rootClass, String attributePath) throws NoSuchFieldException, SecurityException {
	if (StringUtils.isBlank(attributePath)) {
		return rootClass;
	}
	String attributeName = StringUtils.substringBefore(attributePath, ".");
	Field field = null;
	NoSuchFieldException exception = null;
	while (field==null && rootClass!=null) {
		try {
			field = rootClass.getDeclaredField(attributeName);
		} catch (NoSuchFieldException e) {
			if (exception==null) {
				exception=e;
			}
			rootClass = rootClass.getSuperclass();
		}
	}
	if (field==null) {
		if (exception!=null) {
			throw exception;
		} else {
			throw new NoSuchFieldException("No field " + attributeName + " found in hierarchy");
		}
	}
	Class attributeType = field.getType();
	// If it's a list, look for the list type
	if (attributeType == java.util.List.class) {
		// TODO check if the attributeType is an instance of java.util.Collection
		ParameterizedType parameterizedType = (ParameterizedType)field.getGenericType();
		if (parameterizedType!=null) {
			Type[] types = parameterizedType.getActualTypeArguments();
			if (types.length==1) {
				attributeType = (Class<?>) types[0];
			}
		}
	}
	return getType(attributeType, StringUtils.substringAfter(attributePath, "."));
}
 
Example 6
Project: gitplex-mit   File: TextRange.java   View Source Code Vote up 5 votes
public TextRange(String markStr) {
	String begin = StringUtils.substringBefore(markStr, "-");
	String end = StringUtils.substringAfter(markStr, "-");
	beginLine = Integer.parseInt(StringUtils.substringBefore(begin, "."))-1;
	beginChar = Integer.parseInt(StringUtils.substringAfter(begin, "."));
	endLine = Integer.parseInt(StringUtils.substringBefore(end, "."))-1;
	endChar = Integer.parseInt(StringUtils.substringAfter(end, "."));
}
 
Example 7
Project: spring2ts   File: ServicePath.java   View Source Code Vote up 5 votes
private String extractVariableName(String path, int start, int end, Set<String> variables) {
    String substring = StringUtils.substring(path, start, end);
    String stripped = StringUtils.strip(substring, "{}");
    String variable = StringUtils.substringBefore(stripped, ":");
    variables.add(variable);
    return String.format("${%s}", variable);
}
 
Example 8
Project: rmq4note   File: DynaCode.java   View Source Code Vote up 5 votes
public static String getClassName(String code) {
    String className = StringUtils.substringBefore(code, "{");
    if (StringUtils.isBlank(className)) {
        return className;
    }
    if (StringUtils.contains(code, " class ")) {
        className = StringUtils.substringAfter(className, " class ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else if (StringUtils.contains(className, " implements ")) {
            className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " interface ")) {
        className = StringUtils.substringAfter(className, " interface ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " enum ")) {
        className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
    } else {
        return StringUtils.EMPTY;
    }
    return className;
}
 
Example 9
Project: xtf   File: XTFTestSuiteHelper.java   View Source Code Vote up 5 votes
private static Path getRootPackagePath(final Class<?> suiteClass) throws URISyntaxException {
	final String rootPackage = StringUtils.substringBefore(suiteClass.getName(), ".");
	final URL url = XTFTestSuite.class.getResource("/" + suiteClass.getName().replace('.', '/') + ".class");

	Path rootPackagePath = Paths.get(url.toURI());

	// get the root package
	while (!rootPackage.equals(rootPackagePath.getFileName().toString())) {
		rootPackagePath = rootPackagePath.getParent();
	}

	// return test class location (parent of root package)
	return rootPackagePath.getParent();
}
 
Example 10
Project: Amaro   File: Appoinments.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_appoinments);

    if(isNetworkAvailable()) {
        //Retrieve data from LocalDB
        fullName = LocalDB.getFullName();
        email = LocalDB.getEmail();
        phoneNumber = LocalDB.getEmail();
        profilePicUrl = LocalDB.getProfilePicUri();

        //View declerations
        profilePic = findViewById(R.id.appoinmentProfilePic);
        fullNameTextView = findViewById(R.id.userNameTextView);
        appointmentTextView = findViewById(R.id.appoinmentTextView);
        verticalLayout = findViewById(R.id.verticalLayout);

        //Set the name of the user
        fullName = StringUtils.substringBefore(fullName, " ");
        fullNameTextView.setText(fullName);


        //Set the profile pic of the user
        Picasso.with(this).
                load(profilePicUrl)
                .placeholder(R.drawable.profpic)
                .error(R.drawable.profpic)
                .transform(new CircleTransform())
                .into(profilePic);
    }

    else
    {
        Toasty.warning(Appoinments.this,"Please Check Your Internet Connection and Try Again", Toast.LENGTH_SHORT).show();
    }

}
 
Example 11
Project: DYB   File: MsgView.java   View Source Code Vote up 5 votes
/**
 * 解析弹幕服务器接收到的协议数据
 * @param data
 * @return
 */
public Map<String, Object> parseRespond(String data){
	Map<String, Object> rtnMsg = new HashMap<String, Object>();
	
	//处理数据字符串末尾的'/0字符'
	data = StringUtils.substringBeforeLast(data, "/");
	
	//对数据字符串进行拆分
	String[] buff = data.split("/");
	
	//分析协议字段中的key和value值
	for(String tmp : buff){
		//获取key值
		String key = StringUtils.substringBefore(tmp, "@=");
		//获取对应的value值
		Object value = StringUtils.substringAfter(tmp, "@=");
		
		//如果value值中包含子序列化值,则进行递归分析
		if(StringUtils.contains((String)value, "@A")){
			value = ((String)value).replaceAll("@S", "/").replaceAll("@A", "@");
			value = this.parseRespond((String)value);
		}
		
		//将分析后的键值对添加到信息列表中
		rtnMsg.put(key, value);
	}
	
	return rtnMsg;
	
}
 
Example 12
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: DynaCode.java   View Source Code Vote up 5 votes
public static String getClassName(String code) {
    String className = StringUtils.substringBefore(code, "{");
    if (StringUtils.isBlank(className)) {
        return className;
    }
    if (StringUtils.contains(code, " class ")) {
        className = StringUtils.substringAfter(className, " class ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else if (StringUtils.contains(className, " implements ")) {
            className = StringUtils.trim(StringUtils.substringBefore(className, " implements "));
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " interface ")) {
        className = StringUtils.substringAfter(className, " interface ");
        if (StringUtils.contains(className, " extends ")) {
            className = StringUtils.substringBefore(className, " extends ").trim();
        } else {
            className = StringUtils.trim(className);
        }
    } else if (StringUtils.contains(code, " enum ")) {
        className = StringUtils.trim(StringUtils.substringAfter(className, " enum "));
    } else {
        return StringUtils.EMPTY;
    }
    return className;
}
 
Example 13
Project: spring2ts   File: JavaTypescriptTypeMapping.java   View Source Code Vote up 5 votes
private String stripPackage(String name) {
    String canonicalName = StringUtils.substringBefore(name, "<");
    if(StringUtils.contains(canonicalName, '.')) {
        return StringUtils.substringAfterLast(canonicalName, ".");
    } else {
        return canonicalName;
    }
}
 
Example 14
Project: redirector   File: StackSnapshot.java   View Source Code Vote up 5 votes
public void fromString(String host) {
    if (StringUtils.isBlank(host)) {
        throw new IllegalArgumentException("host should not be blank");
    }

    String[] ips = StringUtils.split(host, ",");
    if (ips.length > 1) {
        ipv6 = ips[1];
    }
    ipv4 = StringUtils.substringBefore(ips[0], ":");
}
 
Example 15
Project: cas-server-4.2.1   File: BaseOAuthWrapperController.java   View Source Code Vote up 5 votes
/**
 * Return the method to call according to the url.
 *
 * @param request the incoming http request
 * @return the method to call according to the url
 */
private String getMethod(final HttpServletRequest request) {
    String method = request.getRequestURI();
    if (method.indexOf('?') >= 0) {
        method = StringUtils.substringBefore(method, "?");
    }
    final int pos = method.lastIndexOf('/');
    if (pos >= 0) {
        method = method.substring(pos + 1);
    }
    return method;
}
 
Example 16
Project: poppynotes   File: NoteEncryptionServiceImpl.java   View Source Code Vote up 4 votes
private String getPrincipalWithoutEmailTail(String principalName) {
	return StringUtils.substringBefore(principalName, "@");
}
 
Example 17
Project: aceql-http   File: StatementAnalyzer.java   View Source Code Vote up 4 votes
/**
 * Returns the table name in use type from a DML 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.
 */
public String getTableNameFromDmlStatement() 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
	}

	debug("table: " + 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("\"", "");

	debug("table before return: " + table);

	return table;
}
 
Example 18
Project: saluki   File: GenericInvokeUtils.java   View Source Code Vote up 4 votes
public static String findMethodName(String methodSignature) {
    return StringUtils.substringBefore(methodSignature, "~");
}
 
Example 19
Project: xtf   File: XTFTestSuiteHelperTest.java   View Source Code Vote up 4 votes
@Test
public void testRootPathResolving() throws Exception {
	final URL url = this.getClass().getResource("/" + DefaultSuite.class.getName().replace('.', '/') + ".class");
	final String root = StringUtils.substringBefore(url.toString(), DEFAULT_SUITE_URL);
	assertThat(new XTFTestSuiteHelper(DefaultSuite.class).getRootPackage()).isEqualTo(Paths.get(new URI(root)));
}
 
Example 20
Project: aceql-http   File: LinkedProperties.java   View Source Code Vote up 3 votes
/**
    * Returns the properties name in the order of their position in a file.
    * 
    * @param fileProperties
    *            the file containing the properties
    * @return a Set of Strings backed by a LinkedHashSet ordererd by the
    *         property position in the file
    * @throws IOException
    */
   public static Set<String> getLinkedPropertiesName(File fileProperties)
    throws IOException {

Set<String> linkedPropertiesName = new LinkedHashSet<String>();



try (BufferedReader bufferedReader = new BufferedReader(new FileReader(fileProperties));){
    
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {

	if (line.isEmpty()) {
	    continue;
	}

	if (line.startsWith("#")) {
	    continue;
	}

	if (line.startsWith("!")) {
	    continue;
	}

	if (!line.contains("=")) {
	    continue;
	}

	line = StringUtils.substringBefore(line, "=");

	line = line.trim();
	linkedPropertiesName.add(line);
    }
}

return linkedPropertiesName;

   }