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

The following examples show how to use org.apache.commons.lang3.StringUtils#trimToEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAWSProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
protected void initializeRegionAndEndpoint(ProcessContext context) {
    // if the processor supports REGION, get the configured region.
    if (getSupportedPropertyDescriptors().contains(REGION)) {
        final String region = context.getProperty(REGION).getValue();
        if (region != null) {
            this.region = Region.getRegion(Regions.fromName(region));
            client.setRegion(this.region);
        } else {
            this.region = null;
        }
    }

    // if the endpoint override has been configured, set the endpoint.
    // (per Amazon docs this should only be configured at client creation)
    final String urlstr = StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).getValue());
    if (!urlstr.isEmpty()) {
        this.client.setEndpoint(urlstr);
    }

}
 
Example 2
Source File: Item.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public void onPersist() throws Exception {
	this.path0 = StringUtils.trimToEmpty(this.path0);
	this.path1 = StringUtils.trimToEmpty(this.path1);
	this.path2 = StringUtils.trimToEmpty(this.path2);
	this.path3 = StringUtils.trimToEmpty(this.path3);
	this.path4 = StringUtils.trimToEmpty(this.path4);
	this.path5 = StringUtils.trimToEmpty(this.path5);
	this.path6 = StringUtils.trimToEmpty(this.path6);
	this.path7 = StringUtils.trimToEmpty(this.path7);
	this.path0Location = NumberUtils.toInt(this.path0, -1);
	this.path1Location = NumberUtils.toInt(this.path1, -1);
	this.path2Location = NumberUtils.toInt(this.path2, -1);
	this.path3Location = NumberUtils.toInt(this.path3, -1);
	this.path4Location = NumberUtils.toInt(this.path4, -1);
	this.path5Location = NumberUtils.toInt(this.path5, -1);
	this.path6Location = NumberUtils.toInt(this.path6, -1);
	this.path7Location = NumberUtils.toInt(this.path7, -1);
}
 
Example 3
Source File: ExpressionParser.java    From vscrawler with Apache License 2.0 5 votes vote down vote up
private SyntaxNode parseFunction(StringFunctionTokenQueue tokenQueue) {
    String functionString = tokenQueue.consumeFunction();
    StringFunctionTokenQueue tempTokenQueue = new StringFunctionTokenQueue(functionString);
    String functionName = tempTokenQueue.consumeIdentify();
    StringFunction function = StringFunctionEnv.findFunction(functionName);
    if (function == null) {
        throw new IllegalStateException("not such function: " + functionName);
    }
    tempTokenQueue.consumeWhitespace();
    if (tempTokenQueue.isEmpty() || tempTokenQueue.peek() != '(') {
        throw new IllegalStateException(
                "can not parse token: " + functionString + "  ,it is not same to a function");
    }

    String paramsStr = StringUtils.trimToEmpty(tempTokenQueue.chompBalanced('(', ')'));

    StringFunctionTokenQueue paramTokenQueue = new StringFunctionTokenQueue(paramsStr);

    String parameter;
    List<SyntaxNode> params = Lists.newLinkedList();
    while ((parameter = paramTokenQueue.consumeIgnoreQuote(',')) != null) {
        params.add(new ExpressionParser(new StringFunctionTokenQueue(parameter)).parse());
    }
    paramTokenQueue.consumeWhitespace();
    if (!paramTokenQueue.isEmpty()) {
        params.add(new ExpressionParser(new StringFunctionTokenQueue(paramTokenQueue.remainder())).parse());
    }
    return new FunctionSyntaxNode(function, params);
}
 
Example 4
Source File: EntityStatistics.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(StringUtils.trimToEmpty(name));
    sb.append(": instanceCount=").append(instanceCount != null ? instanceCount : 0);
    if (lazyCollectionThreshold != null)
        sb.append(", lazyCollectionThreshold=").append(lazyCollectionThreshold);
    if (maxFetchUI != null)
        sb.append(", maxFetchUI=").append(maxFetchUI);
    return sb.toString();
}
 
Example 5
Source File: XmlUtils.java    From OpenEstate-IO with Apache License 2.0 5 votes vote down vote up
/**
 * Create a {@link XPath} expression.
 *
 * @param expression      string with the XPath expression to create
 * @param doc             the document, whose namespace is bound to the XPath expression
 * @param namespacePrefix prefix of the document namespace, that is bound to the XPath expression
 * @return the created XPath expression
 * @throws JaxenException if the XPath is not creatable
 */
public static XPath newXPath(String expression, Document doc, String namespacePrefix) throws JaxenException {
    DOMXPath xpath = new DOMXPath(expression);
    //LOGGER.debug( "new xpath: " + xpath.debug() );
    if (doc != null && namespacePrefix != null) {
        Element root = XmlUtils.getRootElement(doc);
        String uri = StringUtils.trimToEmpty(root.getNamespaceURI());
        xpath.addNamespace(namespacePrefix, uri);
    }
    return xpath;
}
 
Example 6
Source File: TimerStartWorkApplicationStubs.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private String getApplicationName(Business business, DateRange dateRange, String applicationId) throws Exception {
	String value = this.getApplicationNameFromWork(business, dateRange, applicationId);
	if (null == value) {
		value = this.getApplicationNameFromWorkCompleted(business, dateRange, applicationId);
	}
	return StringUtils.trimToEmpty(value);
}
 
Example 7
Source File: DetectOverrideableFilter.java    From hub-detect with Apache License 2.0 5 votes vote down vote up
private Set<String> createSetFromString(final String s) {
    final Set<String> set = new HashSet<>();
    final StringTokenizer stringTokenizer = new StringTokenizer(StringUtils.trimToEmpty(s), ",");
    while (stringTokenizer.hasMoreTokens()) {
        set.add(StringUtils.trimToEmpty(stringTokenizer.nextToken()));
    }
    return set;
}
 
Example 8
Source File: ResourceHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public boolean isDescCustom(String itemDescription)
{
    String resDesc = StringUtils.trimToEmpty(getResourceProperties().getProperty(ResourceProperties.PROP_DESCRIPTION));
    String itemDesc = StringUtils.trimToEmpty(itemDescription);
    
    // if the descriptions are not equal, the item description is assumed to be custom
    return !resDesc.equalsIgnoreCase(itemDesc);
}
 
Example 9
Source File: BaseHibernateManager.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public Long createUngradedAssignmentForCategory(final Long gradebookId, final Long categoryId, final String name, final Date dueDate, final Boolean isNotCounted,
                                                final Boolean isReleased) throws ConflictingAssignmentNameException, StaleObjectModificationException, IllegalArgumentException {

    if (gradebookId == null || categoryId == null) {
        throw new IllegalArgumentException("gradebookId or categoryId is null in BaseHibernateManager.createUngradedAssignmentForCategory");
	}
	final HibernateCallback<Long> hc = session -> {
        final Gradebook gb = (Gradebook) session.load(Gradebook.class, gradebookId);
        final Category cat = (Category) session.load(Category.class, categoryId);

        // trim the name before the validation
        final String trimmedName = StringUtils.trimToEmpty(name);

        if (assignmentNameExists(trimmedName, gb)) {
            throw new ConflictingAssignmentNameException("You can not save multiple assignments in a gradebook with the same name");
        }

        final GradebookAssignment asn = new GradebookAssignment();
        asn.setGradebook(gb);
        asn.setCategory(cat);
        asn.setName(trimmedName);
        asn.setDueDate(dueDate);
        asn.setUngraded(true);
        if (isNotCounted != null) {
            asn.setNotCounted(isNotCounted);
        }
        if (isReleased != null) {
            asn.setReleased(isReleased);
        }

        return (Long) session.save(asn);
    };

	return getHibernateTemplate().execute(hc);
}
 
Example 10
Source File: TimerExpiredTaskApplicationStubs.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private String getApplicationName(Business business, DateRange dateRange, String applicationId) throws Exception {
	String value = this.getApplicationNameFromTask(business, dateRange, applicationId);
	if (null == value) {
		value = this.getApplicationNameFromTaskCompleted(business, dateRange, applicationId);
	}
	return StringUtils.trimToEmpty(value);
}
 
Example 11
Source File: OpenImmoFeedbackDocument.java    From OpenEstate-IO with Apache License 2.0 4 votes vote down vote up
@Override
public void setDocumentVersion(OpenImmoVersion version) {
    try {
        Document doc = this.getDocument();

        String currentVersion = StringUtils.trimToEmpty(XmlUtils
                .newXPath("/io:openimmo/io:uebertragung/@version", doc)
                .stringValueOf(doc));
        String[] ver = StringUtils.split(currentVersion, "/", 2);

        Element node = (Element) XmlUtils
                .newXPath("/io:openimmo_feedback/io:version", doc)
                .selectSingleNode(doc);

        // versions older then 1.2.4 do not support the <version> element
        if (OpenImmoVersion.V1_2_4.isNewerThen(version)) {
            if (node != null) {
                Element root = XmlUtils.getRootElement(doc);
                root.removeChild(node);
            }
            return;
        }

        if (node == null) {
            Element parentNode = (Element) XmlUtils
                    .newXPath("/io:openimmo_feedback", doc)
                    .selectSingleNode(doc);
            if (parentNode == null) {
                LOGGER.warn("Can't find an <openimmo_feedback> element in the document!");
                return;
            }
            node = doc.createElement("version");
            parentNode.insertBefore(node, parentNode.getFirstChild());
        }

        String newVersion = version.toReadableVersion();
        if (ver.length > 1) newVersion += "/" + ver[1];
        node.setTextContent(newVersion);
    } catch (JaxenException ex) {
        LOGGER.error("Can't evaluate XPath expression!");
        LOGGER.error("> " + ex.getLocalizedMessage(), ex);
    }
}
 
Example 12
Source File: DbUserService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Get the fields for the database from the edit for this id, and the id again at the end if needed
 *
 * @param id
 *        The resource id
 * @param edit
 *        The edit (may be null in a new)
 * @param idAgain
 *        If true, include the id field again at the end, else don't.
 * @return The fields for the database.
 */
protected Object[] fields(String id, UserEdit edit, boolean idAgain)
{
	Object[] rv = new Object[idAgain ? 12 : 11];
	rv[0] = caseId(id);
	if (idAgain)
	{
		rv[11] = rv[0];
	}

	if (edit == null)
	{
		String attribUser = sessionManager().getCurrentSessionUserId();

		// if no current user, since we are working up a new user record, use the user id as creator...
		if ((attribUser == null) || (attribUser.length() == 0)) attribUser = (String) rv[0];

		Time now = timeService().newTime();
		rv[1] = "";
		rv[2] = "";
		rv[3] = "";
		rv[4] = "";
		rv[5] = "";
		rv[6] = "";
		rv[7] = attribUser;
		rv[8] = attribUser;
		rv[9] = now;
		rv[10] = now;
	}

	else
	{
		rv[1] = StringUtils.trimToEmpty(edit.getEmail());
		rv[2] = StringUtils.trimToEmpty(edit.getEmail().toLowerCase());
		rv[3] = StringUtils.trimToEmpty(edit.getFirstName());
		rv[4] = StringUtils.trimToEmpty(edit.getLastName());
		rv[5] = StringUtils.trimToEmpty(edit.getType());
		rv[6] = StringUtils.trimToEmpty(((BaseUserEdit) edit).m_pw);

		// for creator and modified by, if null, make it the id
		rv[7] = StringUtils.trimToNull(((BaseUserEdit) edit).m_createdUserId);
		if (rv[7] == null)
		{
			rv[7] = rv[0];
		}
		rv[8] = StringUtils.trimToNull(((BaseUserEdit) edit).m_lastModifiedUserId);
		if (rv[8] == null)
		{
			rv[8] = rv[0];
		}

		rv[9] = edit.getCreatedDate();
		rv[10] = edit.getModifiedDate();
	}

	return rv;
}
 
Example 13
Source File: TemplatePage.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void onPersist() throws Exception {
	this.category = StringUtils.trimToEmpty(this.category);
}
 
Example 14
Source File: BigButtonSettings.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public void setEmailSubject(String emailSubject) {
    this.emailSubject = StringUtils.trimToEmpty(emailSubject);
}
 
Example 15
Source File: ComWorkflowEQLHelper.java    From openemm with GNU Affero General Public License v3.0 4 votes vote down vote up
private String generateRuleEQL(String resolvedFieldName, String field, String type, List<WorkflowRule> rules, String dateFormat, boolean disableThreeValuedLogic) throws EQLCreationException {
  List<String> expressions = new ArrayList<>();
     
     for (WorkflowRule rule : rules) {
         
         int operator = rule.getPrimaryOperator();
         String value = rule.getPrimaryValue();
         StringBuilder expression = new StringBuilder();
         
         if(!expressions.isEmpty()) {
             expression.append(EqlUtils.convertChainOperator(rule.getChainOperator())).append(" ");
         }
         
         if(rule.getParenthesisOpened() == 1) {
             expression.append("(");
         }
 
         switch (StringUtils.trimToEmpty(DbColumnType.dbType2String(type))) {
	case GENERIC_TYPE_VARCHAR:
	case GENERIC_TYPE_CHAR:
		expression.append(generateStringEQL(resolvedFieldName, operator, value, disableThreeValuedLogic));
		break;
	case GENERIC_TYPE_INTEGER:
	case GENERIC_TYPE_DOUBLE:
		expression.append(generateNumericEQL(resolvedFieldName, operator, value, disableThreeValuedLogic));
		break;
	case GENERIC_TYPE_DATE:
		expression.append(generateDateEQL(resolvedFieldName, field, operator, dateFormat, value, disableThreeValuedLogic));
		break;
	default:
		//nothing to do
}

if(rule.getParenthesisClosed() == 1) {
             expression.append(")");
         }
         
         expressions.add(expression.toString());
     }
     
     return StringUtils.join(expressions, " ");
 }
 
Example 16
Source File: TimerCompletedWorkApplicationStubs.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private String getProcessName(Business business, DateRange dateRange, String processId) throws Exception {
	String value = this.getProcessNameFromWorkCompleted(business, dateRange, processId);
	return StringUtils.trimToEmpty(value);
}
 
Example 17
Source File: EmbeddedItemData.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * Constructor
 * @param description an optional description for the items (as shown on the page in Lessons)
 * @param parentPage the page the item is embedded into
 */
public EmbeddedItemData(String description, PageData parentPage)
{
	desc = StringUtils.trimToEmpty(description);
	this.parentPage = parentPage;
}
 
Example 18
Source File: Portal.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public void onPersist() throws Exception {
	this.portalCategory = StringUtils.trimToEmpty(this.portalCategory);
	this.firstPage = StringUtils.trimToEmpty(this.firstPage);
}
 
Example 19
Source File: TimerCompletedTaskApplicationStubs.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private String getActivityName(Business business, DateRange dateRange, String activityId) throws Exception {
	String value = this.getActivityNameFromTaskCompleted(business, dateRange, activityId);
	return StringUtils.trimToEmpty(value);
}
 
Example 20
Source File: CoincheckContext.java    From cryptotrader with GNU Affero General Public License v3.0 2 votes vote down vote up
@VisibleForTesting
String executePrivate(RequestType type, String url, Map<String, String> parameters, String data) throws Exception {

    String apiKey = getStringProperty("api.id", null);
    String secret = getStringProperty("api.secret", null);

    if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(secret)) {
        return null;
    }

    String result;

    synchronized (lastNonce) {

        long currNonce = 0;

        while (currNonce <= lastNonce.get()) {

            TimeUnit.MILLISECONDS.sleep(1);

            currNonce = getNow().toEpochMilli();

        }

        lastNonce.set(currNonce);

        String path = url + buildQueryParameter(parameters);
        String nonce = String.valueOf(currNonce);
        String message = nonce + path + StringUtils.trimToEmpty(data);
        String hash = computeHash("HmacSHA256", secret.getBytes(), message.getBytes());

        Map<String, String> headers = new LinkedHashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("ACCESS-KEY", apiKey);
        headers.put("ACCESS-NONCE", nonce);
        headers.put("ACCESS-SIGNATURE", hash);

        result = request(type, path, headers, data);


    }

    return result;

}