Example usage for org.apache.commons.lang StringUtils equals

List of usage examples for org.apache.commons.lang StringUtils equals

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils equals.

Prototype

public static boolean equals(String str1, String str2) 

Source Link

Document

Compares two Strings, returning true if they are equal.

Usage

From source file:com.lingxiang2014.controller.admin.ProfileController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String currentPassword, String password, String email,
        RedirectAttributes redirectAttributes) {
    if (!isValid(Admin.class, "email", email)) {
        return ERROR_VIEW;
    }/*from  w w  w  .  j  a  va2 s .  c  o  m*/
    Admin pAdmin = adminService.getCurrent();
    if (StringUtils.isNotEmpty(currentPassword) && StringUtils.isNotEmpty(password)) {
        if (!isValid(Admin.class, "password", password)) {
            return ERROR_VIEW;
        }
        if (!StringUtils.equals(DigestUtils.md5Hex(currentPassword), pAdmin.getPassword())) {
            return ERROR_VIEW;
        }
        pAdmin.setPassword(DigestUtils.md5Hex(password));
    }
    pAdmin.setEmail(email);
    adminService.update(pAdmin);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:edit.jhtml";
}

From source file:com.thoughtworks.webanalyticsautomation.Engine.java

boolean isWebAnalyticsTestingEnabled() {
    String threadLocalID = Utils.getThreadLocalID();
    logger.info(//ww w  .  j  ava  2  s.  c  o  m
            "Is Web Analytics Testing Enabled? - Getting variable value from ThreadLocal: " + threadLocalID);
    boolean status = StringUtils.equals(threadLocal.get(), threadLocalID);
    logger.info("Is Web Analytics Testing Enabled? - WebAnalytics enabled status: " + status);
    return status;
}

From source file:com.intel.cosbench.driver.operator.Cleaner.java

@Override
protected void operate(int idx, int all, Session session) {
    String[] path = null;//from  ww  w.ja  v  a2 s. c  o m
    String opType = getOpType();
    String lastContainer = null;

    while ((path = objScanner.nextObjPath(path, idx, all)) != null) {
        if (deleteContainer && !StringUtils.equals(lastContainer, path[0])) {
            if (lastContainer != null)
                doDispose(lastContainer, config, session);
            lastContainer = path[0];
        }
        if (path[1] == null)
            continue;
        Sample sample = doDelete(path[0], path[1], config, session);
        sample.setOpType(opType);
        session.getListener().onSampleCreated(sample);
    }

    if (deleteContainer && lastContainer != null)
        doDispose(lastContainer, config, session);

    Date now = new Date();
    Result result = new Result(now, opType, getSampleType(), true);
    session.getListener().onOperationCompleted(result);
}

From source file:com.tesora.dve.sql.node.expression.IntervalExpression.java

@Override
protected boolean schemaSelfEqual(LanguageNode other) {
    IntervalExpression ofc = (IntervalExpression) other;
    return StringUtils.equals(unit, ofc.getUnit());
}

From source file:de.hybris.platform.b2b.WorkflowIntegrationTest.java

public boolean waitForProcessAction(final String businessProcessCode, final String actionCode,
        final long maxWait) throws InterruptedException {
    final long start = System.currentTimeMillis();

    while (true) {
        final BusinessProcessModel bp = businessProcessService.getProcess(businessProcessCode);
        modelService.refresh(bp); // without refresh this object is stale

        final String currentAction = bp.getCurrentTasks() != null && bp.getCurrentTasks().iterator().hasNext()
                ? bp.getCurrentTasks().iterator().next().getAction()
                : null;/*www. j  av  a  2  s  .co  m*/
        if (StringUtils.equals(actionCode, currentAction)) {
            return true;
        }

        if (System.currentTimeMillis() - start > maxWait) {
            throw new InterruptedException(String.format(
                    "BusinessProcess %s [%s] did not go into a specified action %s, " + "current action %s, "
                            + "waited for %s ",
                    bp.getCode(), bp.getProcessState(), actionCode, currentAction,
                    Utilities.formatTime(System.currentTimeMillis() - start)));
        } else {
            Thread.sleep(1000);
            if (bp instanceof B2BApprovalProcessModel) {
                final OrderModel order = ((B2BApprovalProcessModel) bp).getOrder();
                //               this.modelService.refresh(order);
                final WorkflowModel workflow = order.getWorkflow();
                if (LOG.isInfoEnabled() && workflow != null) {
                    LOG.debug(String.format("Workflow %s [$s] for order %s [%s] has status %s",
                            workflow.getCode(), workflow.getDescription(), order.getCode(), order.getStatus(),
                            workflow.getStatus()));
                }
            }
            LOG.debug(String.format("Waited for process state of %s for %s current state is %s", actionCode,
                    Utilities.formatTime(System.currentTimeMillis() - start), bp.getProcessState()));
        }
    }
}

From source file:com.example.license.LicenseUtil.java

@SuppressWarnings("unchecked")
public static LicenseData parseLicense(String secret, String license, PublicKey pub_key) {
    try {//  w  ww.  jav a 2 s .  c  o  m
        Map<String, String> _obj = convertToObjcet(RSAUtil.decrypt(license, pub_key), Map.class);
        LicenseData data = (LicenseData) convertToObjcet(DESUtil.decrypt(_obj.get("data"), _obj.get("secret")),
                LicenseData.class);
        if (StringUtils.equals(generateSecret(secret, data), _obj.get("secret"))) {
            return data;
        }
    } catch (JsonStr2ObjException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.harvard.iq.dataverse.DatasetFieldValueValidator.java

public boolean isValid(DatasetFieldValue value, ConstraintValidatorContext context) {

    context.disableDefaultConstraintViolation(); // we do this so we can have different messages depending on the different issue

    boolean lengthOnly = false;

    DatasetFieldType dsfType = value.getDatasetField().getDatasetFieldType();
    FieldType fieldType = dsfType.getFieldType();

    if (value.getDatasetField().getTemplate() != null) {
        lengthOnly = true;//w w  w.  j  a v  a 2  s.c  o  m
    }

    if (value.getDatasetField().getParentDatasetFieldCompoundValue() != null && value.getDatasetField()
            .getParentDatasetFieldCompoundValue().getParentDatasetField().getTemplate() != null) {
        lengthOnly = true;
    }

    if (StringUtils.isBlank(value.getValue()) || StringUtils.equals(value.getValue(), DatasetField.NA_VALUE)) {
        return true;
    }

    if (fieldType.equals(FieldType.TEXT) && !lengthOnly
            && value.getDatasetField().getDatasetFieldType().getValidationFormat() != null) {
        boolean valid = value.getValue()
                .matches(value.getDatasetField().getDatasetFieldType().getValidationFormat());
        if (!valid) {
            try {
                context.buildConstraintViolationWithTemplate(
                        dsfType.getDisplayName() + " is not a valid entry.").addConstraintViolation();
            } catch (NullPointerException e) {
                return false;
            }
            return false;
        }
    }

    if (fieldType.equals(FieldType.DATE) && !lengthOnly) {
        boolean valid = false;
        String testString = value.getValue();

        if (!valid) {
            valid = isValidDate(testString, "yyyy-MM-dd");
        }
        if (!valid) {
            valid = isValidDate(testString, "yyyy-MM");
        }

        //If AD must be a 4 digit year
        if (value.getValue().contains("AD")) {
            testString = (testString.substring(0, testString.indexOf("AD"))).trim();
        }

        String YYYYformat = "yyyy";
        if (!valid) {
            valid = isValidDate(testString, YYYYformat);
            if (!StringUtils.isNumeric(testString)) {
                valid = false;
            }
        }

        //If BC must be numeric
        if (!valid && value.getValue().contains("BC")) {
            testString = (testString.substring(0, testString.indexOf("BC"))).trim();
            if (StringUtils.isNumeric(testString)) {
                valid = true;
            }
        }

        // Validate Bracket entries
        // Must start with "[", end with "?]" and not start with "[-"
        if (!valid && value.getValue().startsWith("[") && value.getValue().endsWith("?]")
                && !value.getValue().startsWith("[-")) {
            testString = value.getValue().replace("[", " ").replace("?]", " ").replace("-", " ")
                    .replace("BC", " ").replace("AD", " ").trim();
            if (value.getValue().contains("BC") && StringUtils.isNumeric(testString)) {
                valid = true;
            } else {
                valid = isValidDate(testString, YYYYformat);
                if (!StringUtils.isNumeric(testString)) {
                    valid = false;
                }
            }
        }

        if (!valid) {
            // TODO: 
            // This is a temporary fix for the early beta! 
            // (to accommodate dates with time stamps from Astronomy files)
            // As a real fix, we need to introduce a different type - 
            // "datetime" for ex. and use it for timestamps; 
            // We do NOT want users to be able to enter a full time stamp
            // as the release date... 
            // -- L.A. 4.0 beta 

            valid = (isValidDate(value.getValue(), "yyyy-MM-dd'T'HH:mm:ss")
                    || isValidDate(value.getValue(), "yyyy-MM-dd'T'HH:mm:ss.SSS")
                    || isValidDate(value.getValue(), "yyyy-MM-dd HH:mm:ss"));

        }
        if (!valid) {
            try {
                context.buildConstraintViolationWithTemplate(dsfType.getDisplayName()
                        + " is not a valid date. \"" + YYYYformat + "\" is a supported format.")
                        .addConstraintViolation();
            } catch (NullPointerException npe) {

            }

            return false;
        }
    }

    if (fieldType.equals(FieldType.FLOAT) && !lengthOnly) {
        try {
            Double.parseDouble(value.getValue());
        } catch (Exception e) {
            logger.fine("Float value failed validation: " + value.getValue() + " (" + dsfType.getDisplayName()
                    + ")");
            try {
                context.buildConstraintViolationWithTemplate(
                        dsfType.getDisplayName() + " is not a valid number.").addConstraintViolation();
            } catch (NullPointerException npe) {

            }

            return false;
        }
    }

    if (fieldType.equals(FieldType.INT) && !lengthOnly) {
        try {
            Integer.parseInt(value.getValue());
        } catch (Exception e) {
            try {
                context.buildConstraintViolationWithTemplate(
                        dsfType.getDisplayName() + " is not a valid integer.").addConstraintViolation();
            } catch (NullPointerException npe) {

            }

            return false;
        }
    }
    // Note, length validation for FieldType.TEXT was removed to accommodate migrated data that is greater than 255 chars.

    if (fieldType.equals(FieldType.URL) && !lengthOnly) {
        try {
            URL url = new URL(value.getValue());
        } catch (MalformedURLException e) {
            try {
                context.buildConstraintViolationWithTemplate(
                        dsfType.getDisplayName() + " " + value.getValue() + "  is not a valid URL.")
                        .addConstraintViolation();
            } catch (NullPointerException npe) {

            }

            return false;
        }
    }

    if (fieldType.equals(FieldType.EMAIL) && !lengthOnly) {
        if (value.getDatasetField().isRequired() && value.getValue() == null) {
            return false;
        }

        return EMailValidator.isEmailValid(value.getValue(), context);

    }

    return true;
}

From source file:edu.cornell.kfs.module.purap.document.validation.impl.VendorCreditMemoPaymentMethodCodeValidation.java

public boolean validate(AttributedDocumentEvent event) {
    if (event.getDocument() instanceof VendorCreditMemoDocument) {
        VendorCreditMemoDocument doc = (VendorCreditMemoDocument) event.getDocument();
        // check if from a PREQ document
        if (doc.isSourceDocumentPaymentRequest()) {
            // load the document
            PaymentRequestDocument preqDoc = doc.getPaymentRequestDocument();
            // if a UA PREQ, get the PMC
            if (preqDoc instanceof PaymentRequestDocument) {
                // check if the PMC on this document is the same
                String preqPaymentMethodCode = ((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode();
                if (!StringUtils.equals(preqPaymentMethodCode,
                        ((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode())) {
                    GlobalVariables.getMessageMap().putError(
                            CUPurapPropertyConstants.DOCUMENT_PAYMENT_METHOD_CODE,
                            CUPurapKeyConstants.ERROR_PAYMENTMETHODCODE_MUSTMATCHPREQ, preqPaymentMethodCode);
                    return false;
                }//from w  w  w .  java  2  s.  com
            }
        }
    }
    // if not (for some reason) the UA CM document, just return true
    return true;
}

From source file:hydrograph.ui.common.util.WorkbenchWidgetsUtils.java

/**
 * Returns tool-bar instance of given id
 * @param toolBarId//from w  w  w . java2s.  c  o m
 *       toolBar -  Id
 * @return
 *       toolBar with given toolBar-id 
 */
public ToolBarContributionItem getToolBarMangerOrMenuManagerFromCoolBar(String toolBarId) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IContributionItem[] contributionItems = ((WorkbenchWindow) workbenchWindow).getActionBars()
            .getCoolBarManager().getItems();
    for (IContributionItem contributionItem : contributionItems) {
        if (contributionItem instanceof ToolBarContributionItem
                && StringUtils.equals(contributionItem.getId(), toolBarId)) {
            return (ToolBarContributionItem) contributionItem;
        }
    }
    return null;
}

From source file:com.bluexml.xforms.actions.GetAction.java

@Override
public Node resolve() throws ServletException {
    Page currentPage = navigationPath.peekCurrentPage();
    String formName = currentPage.getFormName();
    String dataId = currentPage.getDataId();
    FormTypeEnum formType = currentPage.getFormType();
    Document node = currentPage.getNode();

    boolean formIsReadOnly = !StringUtils.equals(currentPage.getDataType(), currentPage.getFormName());
    if (StringUtils.trimToNull(dataId) != null || node == null) {
        if (formType == FormTypeEnum.FORM) {
            boolean massTagging = currentPage.isMassTagging(); // #1241
            String massIds = currentPage.getMassIds();

            GetInstanceFormBean bean = new GetInstanceFormBean(formName, dataId, formIsReadOnly, massTagging,
                    massIds);//from   w ww  .  j a v a 2 s  .co  m
            node = controller.getInstanceForm(transaction, bean);
        } else if (formType == FormTypeEnum.CLASS) {
            node = controller.getInstanceClass(transaction, formName, dataId, formIsReadOnly, false);
        } else if (formType == FormTypeEnum.WKFLW) {
            node = getInstanceWorkflow(currentPage, formName);
        } else if ((formType == FormTypeEnum.LIST) || (formType == FormTypeEnum.SELECTOR)) {
            return getInstanceListOrSelector(formName, formType);
        } else if (formType == FormTypeEnum.SEARCH) {
            node = controller.getInstanceSearch(formName);
        }
    }

    return node;
}