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

The following examples show how to use org.apache.commons.lang.StringUtils#containsOnly() . These examples are extracted from open source projects. 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 Project: hop   File: KeyValue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param lowerKey key to test.
 * @throws IllegalArgumentException if key is invalid.
 */
public static final void assertKey( final String lowerKey ) throws IllegalArgumentException {
  Assert.assertNotEmpty( lowerKey, "Key cannot be null or empty" );
  if ( !StringUtils.containsOnly( lowerKey, VALID_KEY_CHARS ) ) {
    throw new IllegalArgumentException( "Key contains invalid characters [validKeyCharacters="
      + VALID_KEY_CHARS + "]" );
  }
  if ( lowerKey.charAt( 0 ) == '-' ) {
    throw new IllegalArgumentException( "Key must not start with '-'" );
  }
  if ( lowerKey.endsWith( "-" ) ) {
    throw new IllegalArgumentException( "Key must not end with '-'" );
  }
  if ( "_".equals( lowerKey ) ) {
    throw new IllegalArgumentException( "Key must not be  '_'" );
  }
}
 
Example 2
protected boolean processSubAccount(IndirectCostRecoveryRateDetail item) {
    boolean success = true;
    Map pkMap = new HashMap();
    String chart = item.getChartOfAccountsCode();
    String acct = item.getAccountNumber();
    String subAcct = item.getSubAccountNumber();
    if(StringUtils.isNotBlank(subAcct) && !StringUtils.containsOnly(subAcct, "-")) { // if doesn't contain only dashes
        if(!propertyIsWildcard(chart)) {
            pkMap.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chart);    
        }
        if(!propertyIsWildcard(acct)) {
            pkMap.put(KFSPropertyConstants.ACCOUNT_NUMBER, acct);    
        }
        if(!propertyIsWildcard(subAcct) && StringUtils.isNotBlank(subAcct) && !StringUtils.containsOnly(subAcct, "-")) {
            pkMap.put(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, subAcct);
            if(!checkExistenceFromTable(SubAccount.class, pkMap)) {
                logErrorUtility(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, RiceKeyConstants.ERROR_EXISTENCE);
                success = false;
            }
        }
    }
    return success;
}
 
Example 3
/**
 * Helper method to build an inquiry url for a result field. Special implementation to not build an inquiry link if the value is
 * all dashes.
 * 
 * @param bo the business object instance to build the urls for
 * @param propertyName the property which links to an inquirable
 * @return String url to inquiry
 */
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
    try {
        if (PropertyUtils.isReadable(businessObject, attributeName)) {
            Object objFieldValue = ObjectUtils.getPropertyValue(businessObject, attributeName);
            String fieldValue = objFieldValue == null ? KFSConstants.EMPTY_STRING : objFieldValue.toString();

            if (StringUtils.containsOnly(fieldValue, KFSConstants.DASH)) {
                return new AnchorHtmlData();
            }
        }

        return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
    } catch ( Exception ex ) {
        LOG.error( "Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName );
        LOG.debug( "Unable to determine inquiry link for BO Class: " + businessObject.getClass() + " and property " + attributeName, ex );
        return new AnchorHtmlData();
    }
}
 
Example 4
Source Project: pentaho-kettle   File: KeyValue.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param lowerKey
 *          key to test.
 * @throws IllegalArgumentException
 *           if key is invalid.
 */
public static final void assertKey( final String lowerKey ) throws IllegalArgumentException {
  Assert.assertNotEmpty( lowerKey, "Key cannot be null or empty" );
  if ( !StringUtils.containsOnly( lowerKey, VALID_KEY_CHARS ) ) {
    throw new IllegalArgumentException( "Key contains invalid characters [validKeyCharacters="
      + VALID_KEY_CHARS + "]" );
  }
  if ( lowerKey.charAt( 0 ) == '-' ) {
    throw new IllegalArgumentException( "Key must not start with '-'" );
  }
  if ( lowerKey.endsWith( "-" ) ) {
    throw new IllegalArgumentException( "Key must not end with '-'" );
  }
  if ( "_".equals( lowerKey ) ) {
    throw new IllegalArgumentException( "Key must not be  '_'" );
  }
}
 
Example 5
private boolean resourceMatchHelper(List<String> policyResource) {
    boolean isMatchAny = false;
    if (isDebugEnabled) {
        LOG.debug("==> SimpleAtlasAuthorizer resourceMatchHelper");
    }

    boolean optWildCard = true;

    List<String> policyValues = new ArrayList<>();

    if (policyResource != null) {
        boolean isWildCardPresent = !optWildCard;
        for (String policyValue : policyResource) {
            if (StringUtils.isEmpty(policyValue)) {
                continue;
            }
            if (StringUtils.containsOnly(policyValue, WILDCARD_ASTERISK)) {
                isMatchAny = true;
            } else if (!isWildCardPresent && StringUtils.containsAny(policyValue, WILDCARDS)) {
                isWildCardPresent = true;
            }
            policyValues.add(policyValue);
        }
        optWildCard = optWildCard && isWildCardPresent;
    } else {
        isMatchAny = false;
    }

    if (isDebugEnabled) {
        LOG.debug("<== SimpleAtlasAuthorizer resourceMatchHelper");
    }
    return isMatchAny;
}
 
Example 6
@Override
public boolean isCompleteMatch(String resource, Map<String, Object> evalContext) {
	if(LOG.isDebugEnabled()) {
		LOG.debug("==> RangerAbstractResourceMatcher.isCompleteMatch(" + resource + ", " + evalContext + ")");
	}

	boolean ret = false;

	if(CollectionUtils.isEmpty(policyValues)) {
		ret = StringUtils.isEmpty(resource);
	} else if(policyValues.size() == 1) {
		String policyValue = policyValues.get(0);

		if(isMatchAny) {
			ret = StringUtils.isEmpty(resource) || StringUtils.containsOnly(resource, WILDCARD_ASTERISK);
		} else {
			ret = optIgnoreCase ? StringUtils.equalsIgnoreCase(resource, policyValue) : StringUtils.equals(resource, policyValue);
		}

		if(policyIsExcludes) {
			ret = !ret;
		}
	}

	if(LOG.isDebugEnabled()) {
		LOG.debug("<== RangerAbstractResourceMatcher.isCompleteMatch(" + resource + ", " + evalContext + "): " + ret);
	}

	return ret;
}
 
Example 7
protected boolean processSubObjectCode(IndirectCostRecoveryRateDetail item) { // chart being a wildcard implies account number being a wildcard, redundant checking?
    boolean success = true;
    Map pkMap = new HashMap();
    Integer year = indirectCostRecoveryRate.getUniversityFiscalYear();
    String chart = item.getChartOfAccountsCode();
    String acct = item.getAccountNumber();
    String objCd = item.getFinancialObjectCode();
    String subObjCd = item.getFinancialSubObjectCode();
    if(StringUtils.isNotBlank(subObjCd) && !propertyIsWildcard(subObjCd) && !StringUtils.containsOnly(subObjCd, "-")) {
        pkMap.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
        if(!propertyIsWildcard(chart)) {
            pkMap.put(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, chart);    
        }
        if(!propertyIsWildcard(acct)) {
            pkMap.put(KFSPropertyConstants.ACCOUNT_NUMBER, acct);    
        }
        if(!propertyIsWildcard(objCd)) {
            pkMap.put(KFSPropertyConstants.FINANCIAL_OBJECT_CODE, objCd);
        }
        pkMap.put(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, subObjCd);
        if(!GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY.equals(subObjCd) && !checkExistenceFromTable(SubObjectCode.class, pkMap)) {
            logErrorUtility(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, RiceKeyConstants.ERROR_EXISTENCE);
            success = false;
        }
    }
    return success;
}
 
Example 8
protected boolean checkAccountNumberWildcardRules(IndirectCostRecoveryRateDetail item) {
    String accountNumber = item.getAccountNumber();
    boolean success = true;
    if (!accountNumber.equals(item.getChartOfAccountsCode())) {
        GlobalVariables.getMessageMap().putError(
                KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
                KFSKeyConstants.IndirectCostRecovery.ERROR_DOCUMENT_ICR_WILDCARDS_MUST_MATCH,
                SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(IndirectCostRecoveryRateDetail.class, KFSPropertyConstants.ACCOUNT_NUMBER),
                SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(IndirectCostRecoveryRateDetail.class, KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE)
                );
        success = false;
    }
    
    String subAccountNumber = item.getSubAccountNumber();
    
    // If # is entered on account, then # "must" be entered for chart and sub account "must" be dashes.
    if (GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT.equals(accountNumber)) {
        if (!GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT.equals(item.getChartOfAccountsCode()) && !StringUtils.containsOnly(subAccountNumber, KFSConstants.DASH)) {
            GlobalVariables.getMessageMap().putError(
                    KFSPropertyConstants.SUB_ACCOUNT_NUMBER, 
                    KFSKeyConstants.IndirectCostRecovery.ERROR_DOCUMENT_ICR_FIELD_MUST_BE_DASHES,
                    SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(IndirectCostRecoveryRateDetail.class, KFSPropertyConstants.ACCOUNT_NUMBER),
                    GeneralLedgerConstants.PosterService.SYMBOL_USE_ICR_FROM_ACCOUNT,
                    SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(IndirectCostRecoveryRateDetail.class, KFSPropertyConstants.SUB_ACCOUNT_NUMBER));
            success = false;
        }
    }
    
    if (GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY.equals(accountNumber)) {
        if (!(StringUtils.equals(GeneralLedgerConstants.PosterService.SYMBOL_USE_EXPENDITURE_ENTRY, subAccountNumber) || !StringUtils.containsOnly(subAccountNumber, KFSConstants.DASH))) {
            GlobalVariables.getMessageMap().putError(KFSPropertyConstants.SUB_ACCOUNT_NUMBER, 
                    KFSKeyConstants.IndirectCostRecovery.ERROR_DOCUMENT_ICR_ACCOUNT_USE_EXPENDITURE_ENTRY_WILDCARD_RESTRICTION_ON_SUB_ACCOUNT);
            success = false;
        }
    }
    return success;
}
 
Example 9
/**
 * Hook for quantity and setting asset numbers.
 * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#addNewLineToCollection(java.lang.String)
 */
@Override
public void addNewLineToCollection(String collectionName) {

    // create handle for the addline section of the doc
    IndirectCostRecoveryRateDetail addLine = (IndirectCostRecoveryRateDetail) newCollectionLines.get(collectionName);
    List<IndirectCostRecoveryRateDetail> maintCollection = (List<IndirectCostRecoveryRateDetail>) ObjectUtils.getPropertyValue(getBusinessObject(), collectionName);

    if(StringUtils.isBlank(addLine.getSubAccountNumber()) || StringUtils.containsOnly(addLine.getSubAccountNumber(), "-")) {
        addLine.setSubAccountNumber(KFSConstants.getDashSubAccountNumber());
    }
    if(StringUtils.isBlank(addLine.getFinancialSubObjectCode()) || StringUtils.containsOnly(addLine.getFinancialSubObjectCode(), "-")) {
        addLine.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode());
    }

    Integer icrEntryNumberMax = 0;
    for(IndirectCostRecoveryRateDetail item : maintCollection) {
        if(icrEntryNumberMax < item.getAwardIndrCostRcvyEntryNbr()) {
            icrEntryNumberMax = item.getAwardIndrCostRcvyEntryNbr();
        }
    }

    // addLine.setActive(true); // TODO remove after active indicator fixes
    addLine.setNewCollectionRecord(true);
    addLine.setAwardIndrCostRcvyEntryNbr(icrEntryNumberMax + 1);
    maintCollection.add(addLine);
    initNewCollectionLine(collectionName);
}
 
Example 10
/** given an array of strings, compute the hex session swap, which
 * contains both the original data and the 'signature'.  so the
 * resulting string is encapsulated and can be passed around as
 * 'signed' data.
 *
 * @param in an array of strings, all of which must be valud hex
 * @return String of the signature, in the form "D1:D2:D3xHEX"
 *         where D1... are the input data and HEX is the hex signature.
 */
public static String encodeData(String[] in) {
    for (int i = 0; i < in.length; i++) {
        if (!StringUtils.containsOnly(in[i], HEX_CHARS)) {
            throw new IllegalArgumentException("encodeData input must be " +
                                               "lowercase hex, but wasn't: " + in[i]);
        }
    }

    String joined = StringUtils.join(in, ':');

    String[] components = new String[] { joined, generateSwapKey(joined) };

    return StringUtils.join(components, "x");
}
 
Example 11
void call()
{
  final boolean extracted = processPhoneNumber();
  if (extracted == true) {
    return;
  }
  if (StringUtils.containsOnly(form.getPhoneNumber(), "0123456789+-/() ") == false) {
    form.addError("address.phoneCall.number.invalid");
    return;
  }
  form.setPhoneNumber(extractPhonenumber(form.getPhoneNumber()));
  callNow();
}
 
Example 12
private boolean containsNoLabel(@QueryParameter String value) {
    return StringUtils.isEmpty(value) || StringUtils.containsOnly(value, new char[]{',', ' '});
}
 
Example 13
private boolean containsNoBranches(@QueryParameter String value) {
    return StringUtils.isEmpty(value) || StringUtils.containsOnly(value, new char[]{',', ' '});
}
 
Example 14
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
{
  final String number = req.getParameter("nr");
  if (StringUtils.isBlank(number) == true || StringUtils.containsOnly(number, "+1234567890 -/") == false) {
    log.warn("Bad request, request parameter nr not given or contains invalid characters (only +0123456789 -/ are allowed): " + number);
    resp.sendError(HttpStatus.SC_BAD_REQUEST);
    return;
  }

  final String key = req.getParameter("key");
  final String expectedKey = ConfigXml.getInstance().getPhoneLookupKey();
  if (StringUtils.isBlank(expectedKey) == true) {
    log.warn("Servlet call for receiving phonelookups ignored because phoneLookupKey is not given in config.xml file.");
    resp.sendError(HttpStatus.SC_BAD_REQUEST);
    return;
  }
  if (expectedKey.equals(key) == false) {
    log.warn("Servlet call for phonelookups ignored because phoneLookupKey does not match given key: " + key);
    resp.sendError(HttpStatus.SC_FORBIDDEN);
    return;
  }

  final String searchNumber = NumberHelper.extractPhonenumber(number);
  final AddressDao addressDao = (AddressDao) Registry.instance().getDao(AddressDao.class);

  final BaseSearchFilter filter = new BaseSearchFilter();
  filter.setSearchString("*" + searchNumber);
  final QueryFilter queryFilter = new QueryFilter(filter);

  final StringBuffer buf = new StringBuffer();
  // Use internal get list method for avoiding access checking (no user is logged-in):
  final List<AddressDO> list = addressDao.internalGetList(queryFilter);
  if (list != null && list.size() >= 1) {
    AddressDO result = list.get(0);
    if (list.size() > 1) {
      // More than one result, therefore find the newest one:
      buf.append("+"); // Mark that more than one entry does exist.
      for (final AddressDO matchingUser : list) {
        if (matchingUser.getLastUpdate().after(result.getLastUpdate()) == true) {
          result = matchingUser;
        }
      }
    }
    resp.setContentType("text/plain");
    final String fullname = result.getFullName();
    final String organization = result.getOrganization();
    StringHelper.listToString(buf, "; ", fullname, organization);
    resp.getOutputStream().print(buf.toString());
  } else {
    /* mit Thomas abgesprochen. */
    resp.getOutputStream().print(0);
  }
}