List of usage examples for org.apache.commons.lang StringUtils equalsIgnoreCase
public static boolean equalsIgnoreCase(String str1, String str2)
Compares two Strings, returning true
if they are equal ignoring the case.
From source file:com.yahoo.flowetl.core.util.EnumUtils.java
/** * Attempts to convert a string that represents an enumeration of a given * class into the actual enum object./* w ww . j ava2 s . c o m*/ * * @param <T> * the generic type of the enum class to use * * @param enumKlass * the enum class that has the enumerations to select from * * @param enumStr * the enum string we will attempt to match * * @param caseSensitive * whether to compare case sensitive or not * * @return the enum object or null if not found/invalid... */ @SuppressWarnings("unchecked") public static <T extends Enum> T fromString(Class<T> enumKlass, String enumStr, boolean caseSensitive) { if (StringUtils.isEmpty(enumStr) || enumKlass == null) { // not valid return null; } Object[] types = enumKlass.getEnumConstants(); if (types == null) { // not an enum return null; } Object enumInstance = null; for (int i = 0; i < types.length; i++) { enumInstance = types[i]; if (caseSensitive == false) { if (StringUtils.equalsIgnoreCase(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } else { if (StringUtils.equals(ObjectUtils.toString(enumInstance), enumStr)) { return (T) (enumInstance); } } } // not found throw new IllegalArgumentException( "Unknown enumeration [" + enumStr + "] for enum class [" + enumKlass + "]"); }
From source file:net.shopxx.controller.admin.LoginController.java
@RequestMapping public String index(HttpServletRequest request, ModelMap model) { String loginToken = WebUtils.getCookie(request, Admin.LOGIN_TOKEN_COOKIE_NAME); if (!StringUtils.equalsIgnoreCase(loginToken, adminService.getLoginToken())) { return "redirect:/"; }//from ww w . j a va2 s. c o m if (adminService.isAuthenticated()) { return "redirect:common/main.jhtml"; } Message failureMessage = null; String loginFailure = (String) request .getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if (StringUtils.isNotEmpty(loginFailure)) { if (loginFailure.equals("net.shopxx.exception.IncorrectCaptchaException")) { failureMessage = Message.error("admin.captcha.invalid"); } else if (loginFailure.equals("org.apache.shiro.authc.UnknownAccountException")) { failureMessage = Message.error("admin.login.unknownAccount"); } else if (loginFailure.equals("org.apache.shiro.authc.DisabledAccountException")) { failureMessage = Message.error("admin.login.disabledAccount"); } else if (loginFailure.equals("org.apache.shiro.authc.LockedAccountException")) { failureMessage = Message.error("admin.login.lockedAccount"); } else if (loginFailure.equals("org.apache.shiro.authc.IncorrectCredentialsException")) { Setting setting = SystemUtils.getSetting(); if (ArrayUtils.contains(setting.getAccountLockTypes(), Setting.AccountLockType.admin)) { failureMessage = Message.error("admin.login.accountLockCount", setting.getAccountLockCount()); } else { failureMessage = Message.error("admin.login.incorrectCredentials"); } } else if (loginFailure.equals("net.shopxx.exception.IncorrectLicenseException")) { failureMessage = Message.error("admin.login.incorrectLicense"); } else if (loginFailure.equals("org.apache.shiro.authc.AuthenticationException")) { failureMessage = Message.error("admin.login.authentication"); } } RSAPublicKey publicKey = rsaService.generateKey(request); model.addAttribute("modulus", Base64.encodeBase64String(publicKey.getModulus().toByteArray())); model.addAttribute("exponent", Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray())); model.addAttribute("captchaId", UUID.randomUUID().toString()); model.addAttribute("failureMessage", failureMessage); return "/admin/login/index"; }
From source file:com.github.restdriver.serverdriver.matchers.HasHeader.java
@Override protected boolean matchesSafely(Response response) { for (Header header : response.getHeaders()) { if (StringUtils.equalsIgnoreCase(header.getName(), name)) { return true; }/* ww w . j av a2 s . co m*/ } return false; }
From source file:com.baifendian.swordfish.execserver.job.impexp.Args.HqlColumn.java
/** * HqlColumn hiveColumn ??/*from w w w . ja v a2s . com*/ */ public boolean equals(HiveColumn hiveColumn) { return StringUtils.equalsIgnoreCase(name, hiveColumn.getName()) && StringUtils.containsIgnoreCase(type, hiveColumn.getType().name()); }
From source file:com.twitter.hraven.etl.JobHistoryFileParserFactory.java
/** * determines the verison of hadoop that the history file belongs to * * @return // w ww . j a va 2 s .com * returns 1 for hadoop 1 (pre MAPREDUCE-1016) * returns 2 for newer job history files * (newer job history files have "AVRO-JSON" as the signature at the start of the file, * REFERENCE: https://issues.apache.org/jira/browse/MAPREDUCE-1016? \ * focusedCommentId=12763160& \ page=com.atlassian.jira.plugin.system * .issuetabpanels:comment-tabpanel#comment-12763160 * * @throws IllegalArgumentException if neither match */ public static HadoopVersion getVersion(byte[] historyFileContents) { if (historyFileContents.length > HADOOP2_VERSION_LENGTH) { // the first 10 bytes in a hadoop2.0 history file contain Avro-Json String version2Part = new String(historyFileContents, 0, HADOOP2_VERSION_LENGTH); if (StringUtils.equalsIgnoreCase(version2Part, HADOOP2_VERSION_STRING)) { return HadoopVersion.TWO; } else { if (historyFileContents.length > HADOOP1_VERSION_LENGTH) { // the first 18 bytes in a hadoop1.0 history file contain Meta VERSION="1" . String version1Part = new String(historyFileContents, 0, HADOOP1_VERSION_LENGTH); if (StringUtils.equalsIgnoreCase(version1Part, HADOOP1_VERSION_STRING)) { return HadoopVersion.ONE; } } } } // throw an exception if we did not find any matching version throw new IllegalArgumentException(" Unknown format of job history file: " + historyFileContents); }
From source file:de.burlov.amazon.s3.dirsync.CLI.java
/** * @param args//from w ww .ja va 2 s .c om */ @SuppressWarnings("static-access") public static void main(String[] args) { Logger.getLogger("").setLevel(Level.OFF); Logger deLogger = Logger.getLogger("de"); deLogger.setLevel(Level.INFO); Handler handler = new ConsoleHandler(); handler.setFormatter(new VerySimpleFormatter()); deLogger.addHandler(handler); deLogger.setUseParentHandlers(false); // if (true) // { // LogFactory.getLog(CLI.class).error("test msg", new Exception("test extception")); // return; // } Options opts = new Options(); OptionGroup gr = new OptionGroup(); /* * Befehlsgruppe initialisieren */ gr = new OptionGroup(); gr.setRequired(true); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download changed or new files").create(CMD_UPDATE)); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download directory snapshot").create(CMD_SNAPSHOT)); gr.addOption(OptionBuilder.withDescription("Delete remote folder").create(CMD_DELETE_DIR)); gr.addOption(OptionBuilder.withDescription("Delete a bucket").create(CMD_DELETE_BUCKET)); gr.addOption(OptionBuilder.create(CMD_HELP)); gr.addOption(OptionBuilder.create(CMD_VERSION)); gr.addOption(OptionBuilder.withDescription("Prints summary for stored data").create(CMD_SUMMARY)); gr.addOption(OptionBuilder.withDescription("Clean up orphaned objekts").create(CMD_CLEANUP)); gr.addOption(OptionBuilder.withDescription("Changes encryption password").withArgName("new password") .hasArg().create(CMD_CHANGE_PASSWORD)); gr.addOption(OptionBuilder.withDescription("Lists all buckets").create(CMD_LIST_BUCKETS)); gr.addOption(OptionBuilder.withDescription("Lists raw objects in a bucket").create(CMD_LIST_BUCKET)); gr.addOption(OptionBuilder.withDescription("Lists files in remote folder").create(CMD_LIST_DIR)); opts.addOptionGroup(gr); /* * Parametergruppe initialisieren */ opts.addOption(OptionBuilder.withArgName("key").isRequired(false).hasArg().withDescription("S3 access key") .create(OPT_S3S_KEY)); opts.addOption(OptionBuilder.withArgName("secret").isRequired(false).hasArg() .withDescription("Secret key for S3 account").create(OPT_S3S_SECRET)); opts.addOption(OptionBuilder.withArgName("bucket").isRequired(false).hasArg().withDescription( "Optional bucket name for storage. If not specified then an unique bucket name will be generated") .create(OPT_BUCKET)); // opts.addOption(OptionBuilder.withArgName("US|EU").hasArg(). // withDescription( // "Where the new bucket should be created. Default US").create( // OPT_LOCATION)); opts.addOption(OptionBuilder.withArgName("path").isRequired(false).hasArg() .withDescription("Local directory path").create(OPT_LOCAL_DIR)); opts.addOption(OptionBuilder.withArgName("name").isRequired(false).hasArg() .withDescription("Remote directory name").create(OPT_REMOTE_DIR)); opts.addOption(OptionBuilder.withArgName("password").isRequired(false).hasArg() .withDescription("Encryption password").create(OPT_ENC_PASSWORD)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs() .withDescription("Comma separated exclude file patterns like '*.tmp,*/dir/*.tmp'") .create(OPT_EXCLUDE_PATTERNS)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs().withDescription( "Comma separated include patterns like '*.java'. If not specified, then all files in specified local directory will be included") .create(OPT_INCLUDE_PATTERNS)); if (args.length == 0) { printUsage(opts); return; } CommandLine cmd = null; try { cmd = new GnuParser().parse(opts, args); if (cmd.hasOption(CMD_HELP)) { printUsage(opts); return; } if (cmd.hasOption(CMD_VERSION)) { System.out.println("s3dirsync version " + Version.CURRENT_VERSION); return; } String awsKey = cmd.getOptionValue(OPT_S3S_KEY); String awsSecret = cmd.getOptionValue(OPT_S3S_SECRET); String bucket = cmd.getOptionValue(OPT_BUCKET); String bucketLocation = cmd.getOptionValue(OPT_LOCATION); String localDir = cmd.getOptionValue(OPT_LOCAL_DIR); String remoteDir = cmd.getOptionValue(OPT_REMOTE_DIR); String password = cmd.getOptionValue(OPT_ENC_PASSWORD); String exclude = cmd.getOptionValue(OPT_EXCLUDE_PATTERNS); String include = cmd.getOptionValue(OPT_INCLUDE_PATTERNS); if (StringUtils.isBlank(awsKey) || StringUtils.isBlank(awsSecret)) { System.out.println("S3 account data required"); return; } if (StringUtils.isBlank(bucket)) { bucket = awsKey + ".dirsync"; } if (cmd.hasOption(CMD_DELETE_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } int deleted = S3Utils.deleteBucket(awsKey, awsSecret, bucket); System.out.println("Deleted objects: " + deleted); return; } if (cmd.hasOption(CMD_LIST_BUCKETS)) { for (String str : S3Utils.listBuckets(awsKey, awsSecret)) { System.out.println(str); } return; } if (cmd.hasOption(CMD_LIST_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } for (String str : S3Utils.listObjects(awsKey, awsSecret, bucket)) { System.out.println(str); } return; } if (StringUtils.isBlank(password)) { System.out.println("Encryption password required"); return; } char[] psw = password.toCharArray(); DirSync ds = new DirSync(awsKey, awsSecret, bucket, bucketLocation, psw); ds.setExcludePatterns(parseSubargumenths(exclude)); ds.setIncludePatterns(parseSubargumenths(include)); if (cmd.hasOption(CMD_SUMMARY)) { ds.printStorageSummary(); return; } if (StringUtils.isBlank(remoteDir)) { System.out.println("Remote directory name required"); return; } if (cmd.hasOption(CMD_DELETE_DIR)) { ds.deleteFolder(remoteDir); return; } if (cmd.hasOption(CMD_LIST_DIR)) { Folder folder = ds.getFolder(remoteDir); if (folder == null) { System.out.println("No such folder found: " + remoteDir); return; } for (Map.Entry<String, FileInfo> entry : folder.getIndexData().entrySet()) { System.out.println(entry.getKey() + " (" + FileUtils.byteCountToDisplaySize(entry.getValue().getLength()) + ")"); } return; } if (cmd.hasOption(CMD_CLEANUP)) { ds.cleanUp(); return; } if (cmd.hasOption(CMD_CHANGE_PASSWORD)) { String newPassword = cmd.getOptionValue(CMD_CHANGE_PASSWORD); if (StringUtils.isBlank(newPassword)) { System.out.println("new password required"); return; } char[] chars = newPassword.toCharArray(); ds.changePassword(chars); newPassword = null; Arrays.fill(chars, ' '); return; } if (StringUtils.isBlank(localDir)) { System.out.println(OPT_LOCAL_DIR + " argument required"); return; } String direction = ""; boolean up = false; boolean snapshot = false; if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_UPDATE))) { direction = cmd.getOptionValue(CMD_UPDATE); } else if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_SNAPSHOT))) { direction = cmd.getOptionValue(CMD_SNAPSHOT); snapshot = true; } if (StringUtils.isBlank(direction)) { System.out.println("Operation direction required"); return; } up = StringUtils.equalsIgnoreCase(OPT_UP, direction); File baseDir = new File(localDir); if (!baseDir.exists() && !baseDir.mkdirs()) { System.out.println("Invalid local directory: " + baseDir.getAbsolutePath()); return; } ds.syncFolder(baseDir, remoteDir, up, snapshot); } catch (DirSyncException e) { System.out.println(e.getMessage()); e.printStackTrace(); } catch (ParseException e) { System.out.println(e.getMessage()); printUsage(opts); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:io.udvi.amqp.mq.transport.link.CAMQPLinkKey.java
@Override public boolean equals(Object obj) { if ((obj == null) || (!(obj instanceof CAMQPLinkKey))) return false; CAMQPLinkKey otherKey = (CAMQPLinkKey) obj; return (StringUtils.equalsIgnoreCase(this.source, otherKey.source) && StringUtils.equalsIgnoreCase(this.target, otherKey.target)); }
From source file:com.adobe.acs.commons.util.impl.AemCapabilityHelperImpl.java
@Override public final boolean isOak() throws RepositoryException { final String repositoryName = slingRepository.getDescriptorValue(SlingRepository.REP_NAME_DESC).getString(); return StringUtils.equalsIgnoreCase("Apache Jackrabbit Oak", repositoryName); }
From source file:broadwick.graph.Vertex.java
/** * Obtain an attribute of this vertex by the attributes name. * @param attributeName the name of the attribute to be found. * @return the attribute (or null if no attribute matches the name). */// www . j a v a 2s. co m public final VertexAttribute getAttributeByName(final String attributeName) { for (VertexAttribute attr : attributes) { if (StringUtils.equalsIgnoreCase(attributeName, attr.getName())) { return attr; } } return null; }
From source file:com.sfs.whichdoctor.formatter.UrlGenerator.java
public static String modify(final PreferencesBean preferences, final String type, final int objectId, String parenttype, final int parentGUID, final int parentId) { String url = ""; if (parenttype == null) { parenttype = "member"; }/*from w w w. j a v a 2s .c om*/ if (StringUtils.equalsIgnoreCase(parenttype, "person")) { parenttype = "member"; } parenttype = parenttype.toLowerCase(); if (StringUtils.equalsIgnoreCase(type, "membership")) { url = preferences.buildUrl("save", "people_edit", "modifyitem", "membership_Id=" + objectId); } if (StringUtils.equalsIgnoreCase(type, "memo")) { if (StringUtils.equalsIgnoreCase(parenttype, "member")) { parenttype = "person"; } url = preferences.buildUrl("save", "memo", "modifyitem", parentGUID, objectId, "Type=" + parenttype); } if (StringUtils.equalsIgnoreCase(type, "address")) { url = preferences.buildUrl("save", "address", "modifyitem", parentGUID, objectId, "Type=" + parenttype); } if (StringUtils.equalsIgnoreCase(type, "phone")) { url = preferences.buildUrl("save", "phone", "modifyitem", parentGUID, objectId, "Type=" + parenttype); } if (StringUtils.equalsIgnoreCase(type, "email")) { url = preferences.buildUrl("save", "email", "modifyitem", parentGUID, objectId, "Type=" + parenttype); } if (StringUtils.equalsIgnoreCase(type, "specialty")) { url = preferences.buildUrl("save", "specialty", "modifyitem", parentGUID, objectId, "Type=" + parenttype); } if (StringUtils.equalsIgnoreCase(type, "workshop")) { url = preferences.buildUrl("save", "workshop", "modifyitem", parentId, objectId); } if (StringUtils.equalsIgnoreCase(type, "rotation")) { url = preferences.buildUrl("save", "rotations_modify", "modify", objectId, "PersonId=" + parentGUID); } if (StringUtils.equalsIgnoreCase(type, "project")) { url = preferences.buildUrl("save", "project", "modifyitem", parentId, objectId); } if (StringUtils.equalsIgnoreCase(type, "exam")) { url = preferences.buildUrl("save", "exam", "modifyitem", parentId, objectId); } if (StringUtils.equalsIgnoreCase(type, "qualification")) { url = preferences.buildUrl("save", "qualification", "modifyitem", parentGUID, objectId); } if (StringUtils.equalsIgnoreCase(type, "accreditation")) { url = preferences.buildUrl("save", "accreditation", "modifyitem", parentGUID, objectId, "Type=rotatoin"); } if (StringUtils.equalsIgnoreCase(type, "assessment")) { url = preferences.buildUrl("save", "assessment", "modifyitem", parentId, objectId); } if (StringUtils.equalsIgnoreCase(type, "report")) { url = preferences.buildUrl("save", "report", "modifyitem", parentGUID, objectId); } if (StringUtils.equalsIgnoreCase(type, "expenseclaim")) { url = preferences.buildUrl("save", "expenseclaim", "modifyitem", parentGUID, objectId); } if (StringUtils.equalsIgnoreCase(type, "payment")) { url = preferences.buildUrl("save", "payment", "modifyitem", parentId, objectId); } return url; }