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

The following are Jave code examples for showing how to use length() 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: Hydrograph   File: ExportAction.java   Source Code and License Vote up 8 votes
private void writeDataInFile(List<String[]> fileDataList, String filePath) {
	if (filePath != null) {
		if (StringUtils.length(ConvertHexValues.parseHex(delimiter)) == 1
				&& StringUtils.length(ConvertHexValues.parseHex(quoteCharactor)) == 1) {
			try (FileWriter fileWriter = new FileWriter(filePath);
					CSVWriter writer = new CSVWriter(fileWriter,
							ConvertHexValues.parseHex(delimiter).toCharArray()[0], ConvertHexValues.parseHex(
									quoteCharactor).toCharArray()[0])) {
				writer.writeAll(fileDataList, false);
				showMessage("Data exported to " + filePath + " successfully.", INFORMATION, SWT.ICON_INFORMATION);
			} catch (IOException e1) {
				showMessage(Messages.ERROR_MESSAGE, ERROR, SWT.ICON_ERROR);
			}
		}
	}
}
 
Example 2
Project: Ace   File: RankManager.java   Source Code and License Vote up 7 votes
public static ArrayList<String> getPermissions(int id) throws SQLException{
    PreparedStatement stmt = plugin.getDb().getConnection().prepareStatement("SELECT permissions FROM ranks WHERE id = "+id+" LIMIT 1");
    ResultSet set = stmt.executeQuery();
    set.next();
    String s = set.getString("permissions");
    String[] permissions = new String[(StringUtils.isEmpty(s)?1:StringUtils.length(s)+1)];
    if(StringUtils.isNotEmpty(s)){permissions = s.split("\\s+");}
    ArrayList<String> perms = new ArrayList<>();
    perms.addAll(Arrays.asList(permissions));
    return perms;
}
 
Example 3
Project: wrdocletbase   File: AbstractDocBuilder.java   Source Code and License Vote up 6 votes
protected String getBriefFromCommentText(String commentText) {
	int index = StringUtils.indexOf(commentText, '\n');
	if (index != -1) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	index = StringUtils.indexOfAny(commentText, ".!?。!?…");
	if (index > 0) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	if (StringUtils.length(commentText) > 8) {
		commentText = StringUtils.substring(commentText, 0, 8) + "…";
	}
	return commentText;
}
 
Example 4
Project: Hydrograph   File: ViewDataPreferencesDialog.java   Source Code and License Vote up 6 votes
private boolean validateDelimiterAndQuoteCharactorProperty(String textBoxValue, String textBoxValue2,
		ControlDecoration singleCharactorDecorator, ControlDecoration duplicateDecorator) {
	if (StringUtils.length(ConvertHexValues.parseHex(textBoxValue)) == 1) {
		enableAndDisableOkButtonIfAnyDecoratorIsVisible();
		if (!(textBoxValue.equalsIgnoreCase(",") || textBoxValue.equalsIgnoreCase("\""))
				&& !textBoxValue.equalsIgnoreCase(textBoxValue2)) {
			warningLabel.setText(Messages.WARNING_MESSAGE);
			warningLabel.setVisible(true);
			warningImageLabel.setVisible(true);
			hideDelimiterAndQuoteCharactorDecorator();
			if (StringUtils.length(ConvertHexValues.parseHex(textBoxValue2)) > 1) {
				getButton(0).setEnabled(false);
			}
			else
			{
				getButton(0).setEnabled(true);
				enableAndDisableOkButtonIfAnyDecoratorIsVisible();
			}
			return false;
		} else {
			if (textBoxValue.equalsIgnoreCase(textBoxValue2)) {
				duplicateDecorator.show();
				getButton(0).setEnabled(false);
				return false;
			} else {
				showWarningMessage(textBoxValue, textBoxValue2);
				duplicateDecorator.hide();
				enableAndDisableOkButtonIfAnyDecoratorIsVisible();
				return true;
			}
		}
	} else {
		if (!textBoxValue.isEmpty()) {
			singleCharactorDecorator.show();
			getButton(0).setEnabled(false);
		}
		return false;
	}
}
 
Example 5
Project: Hydrograph   File: ViewDataPreference.java   Source Code and License Vote up 6 votes
private Notification validateDelimiter(){
	Notification notification = new Notification();
	if(StringUtils.isNotBlank(delimiterEditor.getStringValue()) &&delimiterEditor.getStringValue().equalsIgnoreCase(quoteEditor.getStringValue())){
		notification.addError(Messages.DELIMITER_VALUE_MATCH_ERROR);
	}
	if(StringUtils.length(ConvertHexValues.parseHex(delimiterEditor.getStringValue())) != 1){
		notification.addError(Messages.DELIMITER_SINGLE_CHARACTOR_ERROR_MESSAGE);
	}
	return notification;
}
 
Example 6
Project: Hydrograph   File: ViewDataPreference.java   Source Code and License Vote up 6 votes
private Notification validateQuoteCharacter(){
	Notification notification = new Notification();
	if(StringUtils.isNotBlank(quoteEditor.getStringValue()) && quoteEditor.getStringValue().equalsIgnoreCase(delimiterEditor.getStringValue())){
		notification.addError(Messages.QUOTE_VALUE_MATCH_ERROR);
	}
	if(StringUtils.length(ConvertHexValues.parseHex(quoteEditor.getStringValue())) != 1){
		notification.addError(Messages.QUOTE_SINGLE_CHARACTOR_ERROR_MESSAGE);
	}
	return notification;
}
 
Example 7
Project: Hydrograph   File: ConvertHexValues.java   Source Code and License Vote up 5 votes
/**
 * This method converts input hex-value into its equivalent character.
 * 
 * @param input
 *            , hex-value e.g. \x21 for !
 * @return string, if given input is valid hex-value then its equivalent character is returned else input is
 *         returned as it is.
 */
public static String parseHex(String input) {
	final int NO_OF_DIGITS = 2;

	if (StringUtils.isBlank(input) || StringUtils.length(input) < NO_OF_DIGITS + 2)
		return input;

	// Added support for \\t
	if (input.contains("\\t")) {
		input = input.replace("\\t", "\\x09");
	}

	String[] tokens = input.split("\\\\x");
	String hex;
	String temp;
	boolean startsWithHex = input.startsWith("\\x");

	for (int counter = 0; counter < tokens.length; counter++) {

		if (counter == 0 && !startsWithHex)
			continue;

		if (tokens[counter].equals(""))
			continue;

		temp = tokens[counter];
		hex = temp.substring(0, NO_OF_DIGITS);
		temp = temp.substring(NO_OF_DIGITS, temp.length());
		try {
			tokens[counter] = hexToChar(hex) + temp;
		} catch (NumberFormatException numberFormatException) {
			tokens[counter] = hex + temp;
		}
	}

	String result = "";
	for (String token : tokens) {
		result = result + token;
	}

	return result;

}