List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull
public static boolean isBlankOrNull(String value)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardCompletedAction.java
@Override public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { AddCreditCardForm addCreditCardForm = (AddCreditCardForm) form; String accounting = addCreditCardForm.getAccounting(); if (GenericValidator.isBlankOrNull(accounting)) { // Redirect back to credit-card-manager it no accounting selected return mapping.findForward("credit-card-manager"); }//w ww. j ava2 s . com // Validation ActionMessages errors = addCreditCardForm.validate(mapping, request); if (errors != null && !errors.isEmpty()) { saveErrors(request, errors); // Init request values before showing input initRequestAttributes(request, getServlet().getServletContext()); return mapping.findForward("input"); } // Get the credit card processor for the root connector of this website AOServConnector rootConn = siteSettings.getRootAOServConnector(); CreditCardProcessor creditCardProcessor = CreditCardProcessorFactory.getCreditCardProcessor(rootConn); if (creditCardProcessor == null) throw new SQLException("Unable to find enabled CreditCardProcessor for root connector"); // Add card if (!creditCardProcessor.canStoreCreditCards()) throw new SQLException("CreditCardProcessor indicates it does not support storing credit cards."); creditCardProcessor.storeCreditCard( new AOServConnectorPrincipal(rootConn, aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()), new BusinessGroup(aoConn.getBusinesses().get(AccountingCode.valueOf(accounting)), accounting), new CreditCard(null, // persistenceUniqueId null, // principalName null, // groupName null, // providerId null, // providerUniqueId addCreditCardForm.getCardNumber(), null, // maskedCardNumber Byte.parseByte(addCreditCardForm.getExpirationMonth()), Short.parseShort(addCreditCardForm.getExpirationYear()), addCreditCardForm.getCardCode(), addCreditCardForm.getFirstName(), addCreditCardForm.getLastName(), addCreditCardForm.getCompanyName(), null, null, null, null, null, addCreditCardForm.getStreetAddress1(), addCreditCardForm.getStreetAddress2(), addCreditCardForm.getCity(), addCreditCardForm.getState(), addCreditCardForm.getPostalCode(), addCreditCardForm.getCountryCode(), addCreditCardForm.getDescription())); request.setAttribute("cardNumber", CreditCard.maskCreditCardNumber(addCreditCardForm.getCardNumber())); return mapping.findForward("success"); }
From source file:com.aoindustries.website.clientarea.accounting.EditCreditCardForm.java
@Override public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = super.validate(mapping, request); if (errors == null) errors = new ActionErrors(); // persistenceId if (GenericValidator.isBlankOrNull(persistenceId)) errors.add("persistenceId", new ActionMessage("editCreditCardForm.persistenceId.required")); // cardNumber String cardNumber = getCardNumber(); if (!GenericValidator.isBlankOrNull(cardNumber) && !GenericValidator.isCreditCard(CreditCard.numbersOnly(cardNumber))) errors.add("cardNumber", new ActionMessage("editCreditCardForm.cardNumber.invalid")); // expirationMonth and expirationYear required when cardNumber provided String expirationMonth = getExpirationMonth(); String expirationYear = getExpirationYear(); if (!GenericValidator.isBlankOrNull(cardNumber)) { if (GenericValidator.isBlankOrNull(expirationMonth) || GenericValidator.isBlankOrNull(expirationYear)) errors.add("expirationDate", new ActionMessage("editCreditCardForm.expirationDate.required")); } else {//w ww. j a v a2s. com // If either month or year provided, both must be provided if (!GenericValidator.isBlankOrNull(expirationMonth) && GenericValidator.isBlankOrNull(expirationYear)) { errors.add("expirationDate", new ActionMessage("editCreditCardForm.expirationDate.monthWithoutYear")); } else if (GenericValidator.isBlankOrNull(expirationMonth) && !GenericValidator.isBlankOrNull(expirationYear)) { errors.add("expirationDate", new ActionMessage("editCreditCardForm.expirationDate.yearWithoutMonth")); } } // cardCode required when cardNumber provided String cardCode = getCardCode(); if (!GenericValidator.isBlankOrNull(cardNumber)) { if (GenericValidator.isBlankOrNull(cardCode)) errors.add("cardCode", new ActionMessage("editCreditCardForm.cardCode.required")); else { try { CreditCard.validateCardCode(cardCode); } catch (LocalizedIllegalArgumentException e) { errors.add("cardCode", new ActionMessage(e.getLocalizedMessage(), false)); } } } else { if (!GenericValidator.isBlankOrNull(cardCode)) errors.add("cardCode", new ActionMessage("editCreditCardForm.cardCode.notAllowed")); } return errors; }
From source file:com.aoindustries.website.clientarea.accounting.EditCreditCardAction.java
@Override public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { EditCreditCardForm editCreditCardForm = (EditCreditCardForm) form; String persistenceId = editCreditCardForm.getPersistenceId(); if (GenericValidator.isBlankOrNull(persistenceId)) { // Redirect back to credit-card-manager if no persistenceId selected return mapping.findForward("credit-card-manager"); }//from w w w . j a v a2 s. c o m int pkey; try { pkey = Integer.parseInt(persistenceId); } catch (NumberFormatException err) { getServlet().log(null, err); // Redirect back to credit-card-manager if persistenceId can't be parsed to int return mapping.findForward("credit-card-manager"); } // Find the credit card CreditCard creditCard = aoConn.getCreditCards().get(pkey); if (creditCard == null) { // Redirect back to credit-card-manager if card no longer exists or is inaccessible return mapping.findForward("credit-card-manager"); } // Populate the initial details from selected card editCreditCardForm.setIsActive(creditCard.getIsActive() ? "true" : "false"); editCreditCardForm.setAccounting(creditCard.getBusiness().getAccounting().toString()); editCreditCardForm.setFirstName(creditCard.getFirstName()); editCreditCardForm.setLastName(creditCard.getLastName()); editCreditCardForm.setCompanyName(creditCard.getCompanyName()); editCreditCardForm.setStreetAddress1(creditCard.getStreetAddress1()); editCreditCardForm.setStreetAddress2(creditCard.getStreetAddress2()); editCreditCardForm.setCity(creditCard.getCity()); editCreditCardForm.setState(creditCard.getState()); editCreditCardForm.setPostalCode(creditCard.getPostalCode()); editCreditCardForm.setCountryCode(creditCard.getCountryCode().getCode()); editCreditCardForm.setDescription(creditCard.getDescription()); initRequestAttributes(request, getServlet().getServletContext()); request.setAttribute("creditCard", creditCard); return mapping.findForward("success"); }
From source file:de.codecentric.janus.plugin.ci.CIConfiguration.java
public static FormValidation doCheckApiToken(@QueryParameter String value) { if (GenericValidator.isBlankOrNull(value)) { return FormValidation.error("Please provide an API token."); }/*from w w w . j av a 2 s .c o m*/ return FormValidation.ok(); }
From source file:com.aoindustries.website.clientarea.accounting.MakePaymentNewCardAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { MakePaymentNewCardForm makePaymentNewCardForm = (MakePaymentNewCardForm) form; String accounting = makePaymentNewCardForm.getAccounting(); if (GenericValidator.isBlankOrNull(accounting)) { // Redirect back to credit-card-manager it no accounting selected return mapping.findForward("make-payment"); }// w w w .j av a 2s .c o m // Populate the initial details from the selected accounting code or authenticated user Business business = aoConn.getBusinesses().get(AccountingCode.valueOf(accounting)); if (business == null) throw new SQLException("Unable to find Business: " + accounting); BusinessProfile profile = business.getBusinessProfile(); if (profile != null) { makePaymentNewCardForm .setFirstName(AddCreditCardAction.getFirstName(profile.getBillingContact(), locale)); makePaymentNewCardForm .setLastName(AddCreditCardAction.getLastName(profile.getBillingContact(), locale)); makePaymentNewCardForm.setCompanyName(profile.getName()); makePaymentNewCardForm.setStreetAddress1(profile.getAddress1()); makePaymentNewCardForm.setStreetAddress2(profile.getAddress2()); makePaymentNewCardForm.setCity(profile.getCity()); makePaymentNewCardForm.setState(profile.getState()); makePaymentNewCardForm.setPostalCode(profile.getZIP()); makePaymentNewCardForm.setCountryCode(profile.getCountry().getCode()); } else { BusinessAdministrator thisBA = aoConn.getThisBusinessAdministrator(); makePaymentNewCardForm.setFirstName(AddCreditCardAction.getFirstName(thisBA.getName(), locale)); makePaymentNewCardForm.setLastName(AddCreditCardAction.getLastName(thisBA.getName(), locale)); makePaymentNewCardForm.setStreetAddress1(thisBA.getAddress1()); makePaymentNewCardForm.setStreetAddress2(thisBA.getAddress2()); makePaymentNewCardForm.setCity(thisBA.getCity()); makePaymentNewCardForm.setState(thisBA.getState()); makePaymentNewCardForm.setPostalCode(thisBA.getZIP()); makePaymentNewCardForm.setCountryCode(thisBA.getCountry() == null ? "" : thisBA.getCountry().getCode()); } initRequestAttributes(request, getServlet().getServletContext()); // Prompt for amount of payment defaults to current balance. BigDecimal balance = business.getAccountBalance(); if (balance.signum() > 0) { makePaymentNewCardForm.setPaymentAmount(balance.toPlainString()); } else { makePaymentNewCardForm.setPaymentAmount(""); } request.setAttribute("business", business); return mapping.findForward("success"); }
From source file:com.aoindustries.website.clientarea.accounting.EditCreditCardCompletedAction.java
@Override public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { EditCreditCardForm editCreditCardForm = (EditCreditCardForm) form; String persistenceId = editCreditCardForm.getPersistenceId(); if (GenericValidator.isBlankOrNull(persistenceId)) { // Redirect back to credit-card-manager if no persistenceId selected return mapping.findForward("credit-card-manager"); }//ww w . j a v a2 s . c om int pkey; try { pkey = Integer.parseInt(persistenceId); } catch (NumberFormatException err) { getServlet().log(null, err); // Redirect back to credit-card-manager if persistenceId can't be parsed to int return mapping.findForward("credit-card-manager"); } // Find the credit card CreditCard creditCard = aoConn.getCreditCards().get(pkey); if (creditCard == null) { // Redirect back to credit-card-manager if card no longer exists or is inaccessible return mapping.findForward("credit-card-manager"); } // Validation ActionMessages errors = editCreditCardForm.validate(mapping, request); if (errors != null && !errors.isEmpty()) { saveErrors(request, errors); // Init request values before showing input initRequestAttributes(request, getServlet().getServletContext()); request.setAttribute("creditCard", creditCard); return mapping.findForward("input"); } // Tells the view layer what was updated boolean updatedCardDetails = false; boolean updatedCardNumber = false; boolean updatedExpirationDate = false; boolean reactivatedCard = false; if (!nullOrBlankEquals(editCreditCardForm.getFirstName(), creditCard.getFirstName()) || !nullOrBlankEquals(editCreditCardForm.getLastName(), creditCard.getLastName()) || !nullOrBlankEquals(editCreditCardForm.getCompanyName(), creditCard.getCompanyName()) || !nullOrBlankEquals(editCreditCardForm.getStreetAddress1(), creditCard.getStreetAddress1()) || !nullOrBlankEquals(editCreditCardForm.getStreetAddress2(), creditCard.getStreetAddress2()) || !nullOrBlankEquals(editCreditCardForm.getCity(), creditCard.getCity()) || !nullOrBlankEquals(editCreditCardForm.getState(), creditCard.getState()) || !nullOrBlankEquals(editCreditCardForm.getPostalCode(), creditCard.getPostalCode()) || !nullOrBlankEquals(editCreditCardForm.getCountryCode(), creditCard.getCountryCode().getCode()) || !nullOrBlankEquals(editCreditCardForm.getDescription(), creditCard.getDescription())) { // Update all fields except card number and expiration // Root connector used to get processor AOServConnector rootConn = siteSettings.getRootAOServConnector(); CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey()); if (rootCreditCard == null) throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey()); CreditCardProcessor rootProcessor = CreditCardProcessorFactory .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor()); com.aoindustries.creditcards.CreditCard storedCreditCard = CreditCardFactory .getCreditCard(rootCreditCard); // Update fields storedCreditCard.setFirstName(editCreditCardForm.getFirstName()); storedCreditCard.setLastName(editCreditCardForm.getLastName()); storedCreditCard.setCompanyName(editCreditCardForm.getCompanyName()); storedCreditCard.setStreetAddress1(editCreditCardForm.getStreetAddress1()); storedCreditCard.setStreetAddress2(editCreditCardForm.getStreetAddress2()); storedCreditCard.setCity(editCreditCardForm.getCity()); storedCreditCard.setState(editCreditCardForm.getState()); storedCreditCard.setPostalCode(editCreditCardForm.getPostalCode()); storedCreditCard.setCountryCode(editCreditCardForm.getCountryCode()); storedCreditCard.setComments(editCreditCardForm.getDescription()); // Update persistence rootProcessor.updateCreditCard( new AOServConnectorPrincipal(rootConn, aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()), storedCreditCard); updatedCardDetails = true; } String newCardNumber = editCreditCardForm.getCardNumber(); String newExpirationMonth = editCreditCardForm.getExpirationMonth(); String newExpirationYear = editCreditCardForm.getExpirationYear(); String newCardCode = editCreditCardForm.getCardCode(); if (!GenericValidator.isBlankOrNull(newCardNumber)) { // Update card number and expiration // Root connector used to get processor AOServConnector rootConn = siteSettings.getRootAOServConnector(); CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey()); if (rootCreditCard == null) throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey()); CreditCardProcessor rootProcessor = CreditCardProcessorFactory .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor()); rootProcessor.updateCreditCardNumberAndExpiration( new AOServConnectorPrincipal(rootConn, aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()), CreditCardFactory.getCreditCard(rootCreditCard), newCardNumber, Byte.parseByte(newExpirationMonth), Short.parseShort(newExpirationYear), newCardCode); updatedCardNumber = true; updatedExpirationDate = true; } else { if (!GenericValidator.isBlankOrNull(newExpirationMonth) && !GenericValidator.isBlankOrNull(newExpirationYear)) { // Update expiration only // Root connector used to get processor AOServConnector rootConn = siteSettings.getRootAOServConnector(); CreditCard rootCreditCard = rootConn.getCreditCards().get(creditCard.getPkey()); if (rootCreditCard == null) throw new SQLException("Unable to find CreditCard: " + creditCard.getPkey()); CreditCardProcessor rootProcessor = CreditCardProcessorFactory .getCreditCardProcessor(rootCreditCard.getCreditCardProcessor()); rootProcessor .updateCreditCardExpiration( new AOServConnectorPrincipal(rootConn, aoConn.getThisBusinessAdministrator().getUsername().getUsername() .toString()), CreditCardFactory.getCreditCard(rootCreditCard), Byte.parseByte(newExpirationMonth), Short.parseShort(newExpirationYear)); updatedExpirationDate = true; } } if (!creditCard.getIsActive()) { // Reactivate if not active creditCard.reactivate(); reactivatedCard = true; } // Set the cardNumber request attribute String cardNumber; if (!GenericValidator.isBlankOrNull(editCreditCardForm.getCardNumber())) cardNumber = com.aoindustries.creditcards.CreditCard .maskCreditCardNumber(editCreditCardForm.getCardNumber()); else cardNumber = creditCard.getCardInfo(); request.setAttribute("cardNumber", cardNumber); // Store which steps were done request.setAttribute("updatedCardDetails", updatedCardDetails ? "true" : "false"); request.setAttribute("updatedCardNumber", updatedCardNumber ? "true" : "false"); request.setAttribute("updatedExpirationDate", updatedExpirationDate ? "true" : "false"); request.setAttribute("reactivatedCard", reactivatedCard ? "true" : "false"); return mapping.findForward("success"); }
From source file:com.aoindustries.website.clientarea.accounting.MakePaymentStoredCardForm.java
@Override public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if (GenericValidator.isBlankOrNull(paymentAmount)) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.required")); } else {/*from w w w .j a v a 2 s .c om*/ try { BigDecimal pa = new BigDecimal(this.paymentAmount); if (pa.compareTo(BigDecimal.ZERO) <= 0) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.mustBeGeaterThanZero")); } else if (pa.scale() > 2) { // Must not have more than 2 decimal places errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid")); } } catch (NumberFormatException err) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid")); } } return errors; }
From source file:com.aoindustries.website.clientarea.accounting.MakePaymentNewCardForm.java
@Override public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = super.validate(mapping, request); if (errors == null) errors = new ActionErrors(); if (GenericValidator.isBlankOrNull(paymentAmount)) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.required")); } else {//www. j a v a 2 s . c om try { // Make sure can parse as int-of-pennies format (Once we no longer use int-of-pennies, this should be removed) // Long-term plan is to use BigDecimal exclusively for all monetary values. - DRA 2007-10-09 int pennies = SQLUtility.getPennies(this.paymentAmount); // Make sure can parse as BigDecimal, and is correct value BigDecimal pa = new BigDecimal(this.paymentAmount); if (pa.compareTo(BigDecimal.ZERO) <= 0) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.mustBeGeaterThanZero")); } else if (pa.scale() > 2) { // Must not have more than 2 decimal places errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid")); } } catch (NumberFormatException err) { errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid")); } } return errors; }
From source file:jatran.stub.AStrutsAction.java
/** * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are proceeding * @param response The HTTP response we are creating * @return an ActionForward instance describing where and how * control should be forwarded, or null if response * has already been completed/*from ww w . j a v a 2 s . co m*/ */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); TotalsHourlyForm totalsHourlyForm = (TotalsHourlyForm) form; Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale == null) { locale = new Locale("en"); } Calendar calendar = Calendar.getInstance(); boolean dateIsNow = true; if (!GenericValidator.isBlankOrNull(totalsHourlyForm.getDate())) { try { Date date = DateUtil.parseDate(totalsHourlyForm.getDate(), locale); dateIsNow = false; calendar.setTime(date); } catch (ParseException e) { } } if (dateIsNow) { totalsHourlyForm.setDate(DateUtil.formatDate(calendar.getTime(), locale)); } StatisticsManager statisticsManager = (StatisticsManager) getBean(Constants.STATISTICS_MANAGER_BEAN); Integer day = new Integer(calendar.get(Calendar.DAY_OF_MONTH)); Integer month = new Integer(calendar.get(Calendar.MONTH) + 1); Integer year = new Integer(calendar.get(Calendar.YEAR)); List hours = statisticsManager.getTotalsHourly(year, month, day); int maxTotal = 1; int maxUnique = 1; for (Iterator i = hours.iterator(); i.hasNext();) { Object[] hourDescr = (Object[]) i.next(); Integer total = (Integer) hourDescr[1]; Integer unique = (Integer) hourDescr[2]; if (total.intValue() > maxTotal) { maxTotal = total.intValue(); } if (unique.intValue() > maxUnique) { maxUnique = unique.intValue(); } } request.setAttribute("hours", hours); request.setAttribute("maxTotal", new Integer(maxTotal)); request.setAttribute("maxUnique", new Integer(maxUnique)); Date date = calendar.getTime(); request.setAttribute("date", date); return mapping.findForward("showTotalsHourly"); }
From source file:info.bluefoot.component.datanavigator.DataNavigatorRenderer.java
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { if (log.isDebugEnabled()) { log.debug("encoding DataNavigatorRender"); }/* ww w .j a v a 2s. c o m*/ // ~ Getting the tools ========================================== DataNavigator dataNavigator = (DataNavigator) component; ResponseWriter writer = context.getResponseWriter(); LazyDataModel model = dataNavigator.getModel(); // ~ Root element =============================================== writer.startElement("div", dataNavigator); writer.writeAttribute("id", dataNavigator.getClientId(context), "id"); if (dataNavigator.getStyleClass() != null) { writer.writeAttribute("class", dataNavigator.getStyleClass(), "styleClass"); } // ~ Links ====================================================== String innerStyleClass = ""; if (!GenericValidator.isBlankOrNull(dataNavigator.getInnerStyleClass())) { innerStyleClass = dataNavigator.getInnerStyleClass(); } for (int i = 1; i <= model.getNumberOfPages(); i++) { if (log.isDebugEnabled()) { log.info("passing trough page " + i); } writer.startElement("span", dataNavigator); if (model.getCurrentPage() == i) { writer.writeAttribute("class", String.format("%s %s", innerStyleClass, DataNavigatorRenderer.DEFAULT_CURRENT_PAGE_CLASS), null); } else if (!GenericValidator.isBlankOrNull(innerStyleClass)) { writer.writeAttribute("class", innerStyleClass, null); } if (model.getCurrentPage() == i) { writer.writeText(i, null); } else { HtmlOutcomeTargetLink link = new HtmlOutcomeTargetLink(); UIParameter par = new UIParameter(); par.setName("page"); par.setValue(i); link.setOutcome(context.getViewRoot().getViewId()); link.getChildren().add(par); link.setIncludeViewParams(true); link.setValue(i); link.encodeBegin(context); link.encodeEnd(context); } writer.endElement("span"); } writer.endElement("div"); }