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.adaptris.core.services.metadata.compare.Equals.java

@Override
public MetadataElement compare(MetadataElement firstItem, MetadataElement secondItem) {
    return new MetadataElement(getResultKey(),
            String.valueOf(StringUtils.equals(firstItem.getValue(), secondItem.getValue())));
}

From source file:gov.nih.nci.cabig.caaers.web.search.SearchUserCommand.java

public boolean isPersonAtrributesShown() {
    if (!popupRequest)
        return true;
    return StringUtils.equals(popupRequestType, "person");
}

From source file:com.cws.esolutions.security.main.PasswordUtility.java

public static void main(final String[] args) {
    final String methodName = PasswordUtility.CNAME + "#main(final String[] args)";

    if (DEBUG) {// ww  w  .j a  va  2  s  .com
        DEBUGGER.debug("Value: {}", methodName);
    }

    if (args.length == 0) {
        HelpFormatter usage = new HelpFormatter();
        usage.printHelp(PasswordUtility.CNAME, options, true);

        System.exit(1);
    }

    BufferedReader bReader = null;
    BufferedWriter bWriter = null;

    try {
        // load service config first !!
        SecurityServiceInitializer.initializeService(PasswordUtility.SEC_CONFIG, PasswordUtility.LOG_CONFIG,
                false);

        if (DEBUG) {
            DEBUGGER.debug("Options options: {}", options);

            for (String arg : args) {
                DEBUGGER.debug("Value: {}", arg);
            }
        }

        CommandLineParser parser = new PosixParser();
        CommandLine commandLine = parser.parse(options, args);

        if (DEBUG) {
            DEBUGGER.debug("CommandLineParser parser: {}", parser);
            DEBUGGER.debug("CommandLine commandLine: {}", commandLine);
            DEBUGGER.debug("CommandLine commandLine.getOptions(): {}", (Object[]) commandLine.getOptions());
            DEBUGGER.debug("CommandLine commandLine.getArgList(): {}", commandLine.getArgList());
        }

        final SecurityConfigurationData secConfigData = PasswordUtility.svcBean.getConfigData();
        final SecurityConfig secConfig = secConfigData.getSecurityConfig();
        final PasswordRepositoryConfig repoConfig = secConfigData.getPasswordRepo();
        final SystemConfig systemConfig = secConfigData.getSystemConfig();

        if (DEBUG) {
            DEBUGGER.debug("SecurityConfigurationData secConfig: {}", secConfigData);
            DEBUGGER.debug("SecurityConfig secConfig: {}", secConfig);
            DEBUGGER.debug("RepositoryConfig secConfig: {}", repoConfig);
            DEBUGGER.debug("SystemConfig systemConfig: {}", systemConfig);
        }

        if (commandLine.hasOption("encrypt")) {
            if ((StringUtils.isBlank(repoConfig.getPasswordFile()))
                    || (StringUtils.isBlank(repoConfig.getSaltFile()))) {
                System.err.println("The password/salt files are not configured. Entries will not be stored!");
            }

            File passwordFile = FileUtils.getFile(repoConfig.getPasswordFile());
            File saltFile = FileUtils.getFile(repoConfig.getSaltFile());

            if (DEBUG) {
                DEBUGGER.debug("File passwordFile: {}", passwordFile);
                DEBUGGER.debug("File saltFile: {}", saltFile);
            }

            final String entryName = commandLine.getOptionValue("entry");
            final String username = commandLine.getOptionValue("username");
            final String password = commandLine.getOptionValue("password");
            final String salt = RandomStringUtils.randomAlphanumeric(secConfig.getSaltLength());

            if (DEBUG) {
                DEBUGGER.debug("String entryName: {}", entryName);
                DEBUGGER.debug("String username: {}", username);
                DEBUGGER.debug("String password: {}", password);
                DEBUGGER.debug("String salt: {}", salt);
            }

            final String encodedSalt = PasswordUtils.base64Encode(salt);
            final String encodedUserName = PasswordUtils.base64Encode(username);
            final String encryptedPassword = PasswordUtils.encryptText(password, salt,
                    secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(),
                    secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(),
                    systemConfig.getEncoding());
            final String encodedPassword = PasswordUtils.base64Encode(encryptedPassword);

            if (DEBUG) {
                DEBUGGER.debug("String encodedSalt: {}", encodedSalt);
                DEBUGGER.debug("String encodedUserName: {}", encodedUserName);
                DEBUGGER.debug("String encodedPassword: {}", encodedPassword);
            }

            if (commandLine.hasOption("store")) {
                try {
                    new File(passwordFile.getParent()).mkdirs();
                    new File(saltFile.getParent()).mkdirs();

                    boolean saltFileExists = (saltFile.exists()) ? true : saltFile.createNewFile();

                    if (DEBUG) {
                        DEBUGGER.debug("saltFileExists: {}", saltFileExists);
                    }

                    // write the salt out first
                    if (!(saltFileExists)) {
                        throw new IOException("Unable to create salt file");
                    }

                    boolean passwordFileExists = (passwordFile.exists()) ? true : passwordFile.createNewFile();

                    if (!(passwordFileExists)) {
                        throw new IOException("Unable to create password file");
                    }

                    if (commandLine.hasOption("replace")) {
                        File[] files = new File[] { saltFile, passwordFile };

                        if (DEBUG) {
                            DEBUGGER.debug("File[] files: {}", (Object) files);
                        }

                        for (File file : files) {
                            if (DEBUG) {
                                DEBUGGER.debug("File: {}", file);
                            }

                            String currentLine = null;
                            File tmpFile = new File(FileUtils.getTempDirectory() + "/" + "tmpFile");

                            if (DEBUG) {
                                DEBUGGER.debug("File tmpFile: {}", tmpFile);
                            }

                            bReader = new BufferedReader(new FileReader(file));
                            bWriter = new BufferedWriter(new FileWriter(tmpFile));

                            while ((currentLine = bReader.readLine()) != null) {
                                if (!(StringUtils.equals(currentLine.trim().split(",")[0], entryName))) {
                                    bWriter.write(currentLine + System.getProperty("line.separator"));
                                    bWriter.flush();
                                }
                            }

                            bWriter.close();

                            FileUtils.deleteQuietly(file);
                            FileUtils.copyFile(tmpFile, file);
                            FileUtils.deleteQuietly(tmpFile);
                        }
                    }

                    FileUtils.writeStringToFile(saltFile, entryName + "," + encodedUserName + "," + encodedSalt
                            + System.getProperty("line.separator"), true);
                    FileUtils.writeStringToFile(passwordFile, entryName + "," + encodedUserName + ","
                            + encodedPassword + System.getProperty("line.separator"), true);
                } catch (IOException iox) {
                    ERROR_RECORDER.error(iox.getMessage(), iox);
                }
            }

            System.out.println("Entry Name " + entryName + " stored.");
        }

        if (commandLine.hasOption("decrypt")) {
            String saltEntryName = null;
            String saltEntryValue = null;
            String decryptedPassword = null;
            String passwordEntryName = null;

            if ((StringUtils.isEmpty(commandLine.getOptionValue("entry"))
                    && (StringUtils.isEmpty(commandLine.getOptionValue("username"))))) {
                throw new ParseException("No entry or username was provided to decrypt.");
            }

            if (StringUtils.isEmpty(commandLine.getOptionValue("username"))) {
                throw new ParseException("no entry provided to decrypt");
            }

            String entryName = commandLine.getOptionValue("entry");
            String username = commandLine.getOptionValue("username");

            if (DEBUG) {
                DEBUGGER.debug("String entryName: {}", entryName);
                DEBUGGER.debug("String username: {}", username);
            }

            File passwordFile = FileUtils.getFile(repoConfig.getPasswordFile());
            File saltFile = FileUtils.getFile(repoConfig.getSaltFile());

            if (DEBUG) {
                DEBUGGER.debug("File passwordFile: {}", passwordFile);
                DEBUGGER.debug("File saltFile: {}", saltFile);
            }

            if ((!(saltFile.canRead())) || (!(passwordFile.canRead()))) {
                throw new IOException(
                        "Unable to read configured password/salt file. Please check configuration and/or permissions.");
            }

            for (String lineEntry : FileUtils.readLines(saltFile, systemConfig.getEncoding())) {
                saltEntryName = lineEntry.split(",")[0];

                if (DEBUG) {
                    DEBUGGER.debug("String saltEntryName: {}", saltEntryName);
                }

                if (StringUtils.equals(saltEntryName, entryName)) {
                    saltEntryValue = PasswordUtils.base64Decode(lineEntry.split(",")[2]);

                    break;
                }
            }

            if (StringUtils.isEmpty(saltEntryValue)) {
                throw new SecurityException("No entries were found that matched the provided information");
            }

            for (String lineEntry : FileUtils.readLines(passwordFile, systemConfig.getEncoding())) {
                passwordEntryName = lineEntry.split(",")[0];

                if (DEBUG) {
                    DEBUGGER.debug("String passwordEntryName: {}", passwordEntryName);
                }

                if (StringUtils.equals(passwordEntryName, saltEntryName)) {
                    String decodedPassword = PasswordUtils.base64Decode(lineEntry.split(",")[2]);

                    decryptedPassword = PasswordUtils.decryptText(decodedPassword, saltEntryValue,
                            secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(),
                            secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(),
                            systemConfig.getEncoding());

                    break;
                }
            }

            if (StringUtils.isEmpty(decryptedPassword)) {
                throw new SecurityException("No entries were found that matched the provided information");
            }

            System.out.println(decryptedPassword);
        } else if (commandLine.hasOption("encode")) {
            System.out.println(PasswordUtils.base64Encode((String) commandLine.getArgList().get(0)));
        } else if (commandLine.hasOption("decode")) {
            System.out.println(PasswordUtils.base64Decode((String) commandLine.getArgList().get(0)));
        }
    } catch (IOException iox) {
        ERROR_RECORDER.error(iox.getMessage(), iox);

        System.err.println("An error occurred during processing: " + iox.getMessage());
        System.exit(1);
    } catch (ParseException px) {
        ERROR_RECORDER.error(px.getMessage(), px);

        System.err.println("An error occurred during processing: " + px.getMessage());
        System.exit(1);
    } catch (SecurityException sx) {
        ERROR_RECORDER.error(sx.getMessage(), sx);

        System.err.println("An error occurred during processing: " + sx.getMessage());
        System.exit(1);
    } catch (SecurityServiceException ssx) {
        ERROR_RECORDER.error(ssx.getMessage(), ssx);
        System.exit(1);
    } finally {
        try {
            if (bReader != null) {
                bReader.close();
            }

            if (bWriter != null) {
                bReader.close();
            }
        } catch (IOException iox) {
        }
    }

    System.exit(0);
}

From source file:de.hybris.platform.accountsummaryaddon.document.AccountSummaryDocumentQuery.java

public void addCriteria(final String criteriaName, final Object criteriaValue) {
    if (criteriaValue instanceof String && !StringUtils.equals(criteriaName, B2BDocumentModel.UNIT)) {
        this.searchCriteria.put(criteriaName, WILD_CARD + criteriaValue + WILD_CARD);
    } else {//from   ww  w  . j  a  va2s . c  om
        this.searchCriteria.put(criteriaName, criteriaValue);
    }
}

From source file:hydrograph.ui.graph.utility.MessageBox.java

private int getMessageBoxIcon(String messageBoxType) {
    if (StringUtils.equals(ERROR, messageBoxType)) {
        return SWT.ICON_ERROR;
    } else if (StringUtils.equals(WARNING, messageBoxType)) {
        return SWT.ICON_WARNING;
    } else {//from   www.  j  a  va2 s  .co m
        return SWT.ICON_INFORMATION;
    }
}

From source file:com.ibm.jaggr.core.impl.deps.DepUtils.java

/**
 * Removes URIs containing duplicate and non-orthogonal paths so that the
 * collection contains only unique and non-overlapping paths.
 *
 * @param uris collection of URIs//ww w . j a v a  2s .c  om
 *
 * @return a new collection with redundant paths removed
 */
static public Collection<URI> removeRedundantPaths(Collection<URI> uris) {
    List<URI> result = new ArrayList<URI>();
    for (URI uri : uris) {
        String path = uri.getPath();
        if (!path.endsWith("/")) { //$NON-NLS-1$
            path += "/"; //$NON-NLS-1$
        }
        boolean addIt = true;
        for (int i = 0; i < result.size(); i++) {
            URI testUri = result.get(i);
            if (!StringUtils.equals(testUri.getScheme(), uri.getScheme())
                    || !StringUtils.equals(testUri.getHost(), uri.getHost())
                    || testUri.getPort() != uri.getPort()) {
                continue;
            }
            String test = testUri.getPath();
            if (!test.endsWith("/")) { //$NON-NLS-1$
                test += "/"; //$NON-NLS-1$
            }
            if (path.equals(test) || path.startsWith(test)) {
                addIt = false;
                break;
            } else if (test.startsWith(path)) {
                result.remove(i);
            }
        }
        if (addIt)
            result.add(uri);
    }
    // Now copy the trimmed list back to the original
    return result;
}

From source file:com.example.RecursionCheck.java

private boolean isRed(Resource resource) {
    return StringUtils.equals("red", resource.getValueMap().get("colour", String.class));
}

From source file:com.alibaba.cobar.client.router.rules.ibatis.IBatisNamespaceRule.java

public boolean isDefinedAt(IBatisRoutingFact routingFact) {
    Validate.notNull(routingFact);/*from   ww w . j av a  2s  .c  o  m*/
    String namespace = StringUtils.substringBeforeLast(routingFact.getAction(), ".");
    return StringUtils.equals(namespace, getTypePattern());
}

From source file:com.btobits.automator.fix.comparator.MailComparator.java

public static void compare(final FixMessageType inMsg, final SMTPMessage inSmtpMessage) throws Exception {

    final List<String> errors = new ArrayList<String>();
    try {/*www  .  j  av a  2s .  c  o m*/
        // compare header field             
        for (final FixMessageType.Field field : inMsg.getFields()) {
            if (!field.isGroup()) {
                final String value = getHeaderField(field.getName(), inSmtpMessage);
                if (StringUtils.isBlank(value) && StringUtils.isBlank(field.getValue())) {
                    continue;
                } else if (StringUtils.isBlank(value)) {
                    errors.add("Field [" + field.getName() + "] is absend in receive email.");
                } else if (!StringUtils.equals(field.getValue(), value) && StringUtils.startsWith(value, "<")
                        && StringUtils.endsWith(value, ">")) {

                    final String subValue = StringUtils.substringBetween(value, "<", ">");
                    if (StringUtils.isBlank(subValue)) {
                        errors.add("Field [" + field.getName() + "] is not eq receive email field ['"
                                + field.getValue() + " != " + value + "'].");
                    } else if (!StringUtils.equalsIgnoreCase(subValue, field.getValue())) {
                        errors.add("Field [" + field.getName() + "] is not eq receive email field ['"
                                + field.getValue() + " != " + value + "'].");
                    }
                } else if (!StringUtils.equals(field.getValue(), value)) {
                    errors.add("Field [" + field.getName() + "] is not eq receive email field ['"
                            + field.getValue() + " != " + value + "'].");
                }
            } else {
                // compare group
                final List<String> body = getDataFields(inSmtpMessage);
                final LinkedList<FixMessageType.Field> fields = field.getFields();
                int count = 0;
                for (FixMessageType.Field grFld : fields) {
                    final String value = getValueOnPosition(body, count);
                    if (StringUtils.equals(grFld.getName(), FIX_MESSAGE_FLD)) {
                        String fixMessage = getFixField("Original FIX message:", inSmtpMessage);
                        if (!StringUtils.equals(fixMessage, grFld.getValue())) {
                            errors.add(
                                    "Data fix field [" + grFld.getName() + "] is not eq receive email field ['"
                                            + grFld.getValue() + " != " + fixMessage + "'].");
                        }
                    } else {
                        if (StringUtils.isBlank(value) && StringUtils.isBlank(grFld.getValue())) {
                        } else {
                            if (!StringUtils.equals(value, grFld.getValue())) {
                                errors.add(
                                        "Data field [" + grFld.getName() + "] is not eq receive email field ['"
                                                + grFld.getValue() + " != " + value + "'].");
                            }
                        }
                    }
                    count++;
                }
            }
        }
    } catch (Exception ex) {
        throw new BuildException("Error compare message", ex);
    }

    if (!errors.isEmpty()) {
        throw new MessageDifferenceException(FixUtils.toString(errors));
    }
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Get the named cookie from the HTTP Request
 *
 * @param request Request to get the Cookie from
 * @param cookieName name of Cookie to get
 * @return the named Cookie, null if the named Cookie cannot be found
 *//*from   w  ww  . jav  a  2 s. co  m*/
public static Cookie getCookie(HttpServletRequest request, String cookieName) {
    cookieName = StringUtils.trimToNull(cookieName);
    if (cookieName == null) {
        return null;
    }

    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }

    if (cookies.length > 0) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(cookieName, cookie.getName())) {
                return cookie;
            }
        }
    }

    return null;
}