List of usage examples for org.apache.commons.lang StringUtils equals
public static boolean equals(String str1, String str2)
Compares two Strings, returning true
if they are equal.
From source file:com.glaf.core.db.DataTableBean.java
/** * ????/*ww w . j a va 2 s .c om*/ * * @param sysDataTable * ? * @param loginContext * * @param ipAddress * IP? */ public void checkPermission(SysDataTable sysDataTable, LoginContext loginContext, String ipAddress) { boolean hasPermission = false; /** * ?????? */ if (!StringUtils.equals(sysDataTable.getAccessType(), "PUB")) { /** * IP??? */ if (StringUtils.isNotEmpty(sysDataTable.getAddressPerms())) { List<String> addressList = StringTools.split(sysDataTable.getAddressPerms()); for (String addr : addressList) { if (StringUtils.equals(ipAddress, addr)) { hasPermission = true; } if (StringUtils.equals(ipAddress, "127.0.0.1")) { hasPermission = true; } if (StringUtils.equals(ipAddress, "localhost")) { hasPermission = true; } if (addr.endsWith("*")) { String tmp = addr.substring(0, addr.indexOf("*")); if (StringUtils.contains(ipAddress, tmp)) { hasPermission = true; } } } if (!hasPermission) { throw new RuntimeException("Permission denied."); } } /** * ??? */ if (StringUtils.isNotEmpty(sysDataTable.getPerms()) && !StringUtils.equalsIgnoreCase(sysDataTable.getPerms(), "anyone")) { if (loginContext.hasSystemPermission() || loginContext.hasAdvancedPermission()) { hasPermission = true; } List<String> permissions = StringTools.split(sysDataTable.getPerms()); for (String perm : permissions) { if (loginContext.getPermissions().contains(perm)) { hasPermission = true; } if (loginContext.getRoles().contains(perm)) { hasPermission = true; } if (StringUtils.isNotEmpty(perm) && StringUtils.isNumeric(perm)) { if (loginContext.getRoleIds().contains(Long.parseLong(perm))) { hasPermission = true; } } } if (!hasPermission) { throw new RuntimeException("Permission denied."); } } } }
From source file:de.forsthaus.backend.dao.impl.LanguageDAOImpl.java
@Override public Language getLanguageByLocale(final String lanLocale) { return (Language) CollectionUtils.find(LANGUAGES, new Predicate() { @Override/* ww w . ja va2 s. c o m*/ public boolean evaluate(Object object) { return StringUtils.equals(lanLocale, ((Language) object).getLanLocale()); } }); }
From source file:mitm.application.djigzo.impl.NamedCertificateUtils.java
/** * Replaces all the named certificates with the given name in the target set with the new certificates. The replacement is * done in-place (ie. target is modified) */// ww w . ja v a2 s . c om public static void replaceNamedCertificates(Collection<NamedCertificate> target, String name, Collection<X509Certificate> certificates) { Check.notNull(name, "name"); if (target != null) { /* * We need to store the items we need to remove. We cannot change target * while looping. */ List<NamedCertificate> toRemove = new LinkedList<NamedCertificate>(); for (NamedCertificate namedCertificate : target) { if (namedCertificate != null && StringUtils.equals(name, namedCertificate.getName())) { toRemove.add(namedCertificate); } } for (NamedCertificate namedCertificate : toRemove) { target.remove(namedCertificate); } if (certificates != null) { for (X509Certificate certificate : certificates) { target.add(new NamedCertificateImpl(name, certificate)); } } } }
From source file:de.cosmocode.palava.services.mail.EmailFactory.java
@SuppressWarnings("unchecked") Email build(Document document, Embedder embed) throws EmailException, FileNotFoundException { /* CHECKSTYLE:ON */ final Element root = document.getRootElement(); final List<Element> messages = root.getChildren("message"); if (messages.isEmpty()) throw new IllegalArgumentException("No messages found"); final List<Element> attachments = root.getChildren("attachment"); final Map<ContentType, String> available = new HashMap<ContentType, String>(); for (Element element : messages) { final String type = element.getAttributeValue("type"); final ContentType messageType = StringUtils.equals(type, "html") ? ContentType.HTML : ContentType.PLAIN; if (available.containsKey(messageType)) { throw new IllegalArgumentException("Two messages with the same types have been defined."); }//from www . j av a 2 s . c o m available.put(messageType, element.getText()); } final Email email; if (available.containsKey(ContentType.HTML) || attachments.size() > 0) { final HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setCharset(CHARSET); if (embed.hasEmbeddings()) { htmlEmail.setSubType("related"); } else if (attachments.size() > 0) { htmlEmail.setSubType("related"); } else { htmlEmail.setSubType("alternative"); } /** * Add html message */ if (available.containsKey(ContentType.HTML)) { htmlEmail.setHtmlMsg(available.get(ContentType.HTML)); } /** * Add plain text alternative */ if (available.containsKey(ContentType.PLAIN)) { htmlEmail.setTextMsg(available.get(ContentType.PLAIN)); } /** * Embedded binary data */ for (Map.Entry<String, String> entry : embed.getEmbeddings().entrySet()) { final String path = entry.getKey(); final String cid = entry.getValue(); final String name = embed.name(path); final File file; if (path.startsWith(File.separator)) { file = new File(path); } else { file = new File(embed.getResourcePath(), path); } if (file.exists()) { htmlEmail.embed(new FileDataSource(file), name, cid); } else { throw new FileNotFoundException(file.getAbsolutePath()); } } /** * Attached binary data */ for (Element attachment : attachments) { final String name = attachment.getAttributeValue("name", ""); final String description = attachment.getAttributeValue("description", ""); final String path = attachment.getAttributeValue("path"); if (path == null) throw new IllegalArgumentException("Attachment path was not set"); File file = new File(path); if (!file.exists()) file = new File(embed.getResourcePath(), path); if (file.exists()) { htmlEmail.attach(new FileDataSource(file), name, description); } else { throw new FileNotFoundException(file.getAbsolutePath()); } } email = htmlEmail; } else if (available.containsKey(ContentType.PLAIN)) { email = new SimpleEmail(); email.setCharset(CHARSET); email.setMsg(available.get(ContentType.PLAIN)); } else { throw new IllegalArgumentException("No valid message found in template."); } final String subject = root.getChildText("subject"); email.setSubject(subject); final Element from = root.getChild("from"); final String fromAddress = from == null ? null : from.getText(); final String fromName = from == null ? fromAddress : from.getAttributeValue("name", fromAddress); email.setFrom(fromAddress, fromName); final Element to = root.getChild("to"); if (to != null) { final String toAddress = to.getText(); if (StringUtils.isNotBlank(toAddress) && toAddress.contains(EMAIL_SEPARATOR)) { final String[] toAddresses = toAddress.split(EMAIL_SEPARATOR); for (String address : toAddresses) { email.addTo(address); } } else if (StringUtils.isNotBlank(toAddress)) { final String toName = to.getAttributeValue("name", toAddress); email.addTo(toAddress, toName); } } final Element cc = root.getChild("cc"); if (cc != null) { final String ccAddress = cc.getText(); if (StringUtils.isNotBlank(ccAddress) && ccAddress.contains(EMAIL_SEPARATOR)) { final String[] ccAddresses = ccAddress.split(EMAIL_SEPARATOR); for (String address : ccAddresses) { email.addCc(address); } } else if (StringUtils.isNotBlank(ccAddress)) { final String ccName = cc.getAttributeValue("name", ccAddress); email.addCc(ccAddress, ccName); } } final Element bcc = root.getChild("bcc"); if (bcc != null) { final String bccAddress = bcc.getText(); if (StringUtils.isNotBlank(bccAddress) && bccAddress.contains(EMAIL_SEPARATOR)) { final String[] bccAddresses = bccAddress.split(EMAIL_SEPARATOR); for (String address : bccAddresses) { email.addBcc(address); } } else if (StringUtils.isNotBlank(bccAddress)) { final String bccName = bcc.getAttributeValue("name", bccAddress); email.addBcc(bccAddress, bccName); } } final Element replyTo = root.getChild("replyTo"); if (replyTo != null) { final String replyToAddress = replyTo.getText(); if (StringUtils.isNotBlank(replyToAddress) && replyToAddress.contains(EMAIL_SEPARATOR)) { final String[] replyToAddresses = replyToAddress.split(EMAIL_SEPARATOR); for (String address : replyToAddresses) { email.addReplyTo(address); } } else if (StringUtils.isNotBlank(replyToAddress)) { final String replyToName = replyTo.getAttributeValue("name", replyToAddress); email.addReplyTo(replyToAddress, replyToName); } } return email; }
From source file:gov.nih.nci.cabig.caaers.service.synchronizer.report.PreExistingConditionSynchronizer.java
public void migrate(ExpeditedAdverseEventReport src, ExpeditedAdverseEventReport dest, DomainObjectImportOutcome<ExpeditedAdverseEventReport> outcome) { List<SAEReportPreExistingCondition> newPreConditions = new ArrayList<SAEReportPreExistingCondition>(); List<SAEReportPreExistingCondition> existingConditions = new ArrayList<SAEReportPreExistingCondition>(); if (dest.getSaeReportPreExistingConditions() != null) existingConditions.addAll(dest.getSaeReportPreExistingConditions()); if (src.getSaeReportPreExistingConditions() != null) { for (SAEReportPreExistingCondition pc : src.getSaeReportPreExistingConditions()) { final SAEReportPreExistingCondition xmlPreCondition = pc; SAEReportPreExistingCondition found = CollectionUtils.find(existingConditions, new Predicate<SAEReportPreExistingCondition>() { public boolean evaluate(SAEReportPreExistingCondition saeReportPreExistingCondition) { if (saeReportPreExistingCondition.getPreExistingCondition() == null && xmlPreCondition.getPreExistingCondition() == null) { return StringUtils.equals(saeReportPreExistingCondition.getOther(), xmlPreCondition.getOther()); }//from w w w.jav a 2 s . c o m return xmlPreCondition.getPreExistingCondition().getId() .equals(saeReportPreExistingCondition.getPreExistingCondition().getId()); } }); if (found != null) { //nothing to sync, just remove the pre-existing condition found existingConditions.remove(found); } else { newPreConditions.add(xmlPreCondition); } } } //remove unwanted for (SAEReportPreExistingCondition unwanted : existingConditions) { dest.getSaeReportPreExistingConditions().remove(unwanted); } //add newly added for (SAEReportPreExistingCondition newPc : newPreConditions) { dest.addSaeReportPreExistingCondition(newPc); } }
From source file:com.iggroup.oss.restdoclet.plugin.util.XmlUtils.java
/** * Returns the child-elements of a XML node with a particular name. * /* w w w . j a v a2 s. c o m*/ * @param node the XML node. * @param name the name of the child-elements. * @return the collection of child-elements or an empty collection if no * children with the name were found. */ public static Collection<Element> children(final Node node, final String name) { final Collection<Element> elements = new ArrayList<Element>(); for (int i = 0; i < node.getChildNodes().getLength(); i++) { if (node.getChildNodes().item(i).getNodeType() == ELEMENT_NODE) { final Element child = (Element) node.getChildNodes().item(i); if (StringUtils.equals(name, child.getNodeName())) { elements.add(child); } } } return elements; }
From source file:com.evolveum.midpoint.prism.match.XmlMatchingRule.java
@Override public boolean match(String a, String b) { if (a == null && b == null) { return true; }/*w w w .j ava 2s. co m*/ if (a == null || b == null) { return false; } try { Document docA = DOMUtil.parseDocument(a); Document docB = DOMUtil.parseDocument(b); return DOMUtil.compareDocument(docA, docB, false, false); } catch (IllegalStateException | IllegalArgumentException e) { LOGGER.warn("Invalid XML in XML matching rule: {}", e.getMessage()); // Invalid XML. We do not want to throw the exception from matching rule. // So fall back to ordinary string comparison. return StringUtils.equals(a, b); } }
From source file:net.me2day.async.processor.commcast.CommcastCreateEventNotifier.java
@Override public void process(EventProcessContext context) throws ReprocessableException { String target = context.getEvent().getEventTarget(); String fireUserId = context.getEvent().getEventFireUserId(); String fireNaverUserId = userBo.getNaverIdByMe2dayUserId(fireUserId); String toNaverUserId = ""; String toUserId = ""; String eventId = ""; if (StringUtils.isEmpty(fireNaverUserId)) { LOG.info("[COMMCAST] fireUserId(" + fireUserId + ") have NO naverId."); return;//from w ww. j ava 2 s. c om } Map<String, Object> resultMap = null; if (StringUtils.equals(target, EventTarget.FRIEND_REQUEST.getTargetName())) { LOG.info("[COMMCAST] requestFriend event received ======="); toNaverUserId = userBo.getNaverUserId(context.getEvent().getEventOption("toUserId")); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("toUserId") + ") have NO naverId."); return; } Friend friend = new Friend(context.getEvent().getEventOption("authorName"), context.getEvent().getEventOption("toUserId"), context.getEvent().getEventOperation(), toNaverUserId, context.getEvent().getEventOption("content")); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(friend, null, EventTarget.FRIEND_REQUEST.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? .", fireUserId, friend.getToUserId())); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.GIFT.getTargetName())) { LOG.info("[COMMCAST] gift event received ================"); toNaverUserId = userBo.getNaverUserId(context.getEvent().getEventOption("toUserId")); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("toUserId") + ") have NO naverId."); return; } Gift gift = new Gift(fireUserId, context.getEvent().getEventOption("authorName"), context.getEvent().getEventOption("toUserId"), context.getEvent().getEventOperation(), toNaverUserId); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(gift, null, EventTarget.GIFT.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? ? .", fireUserId, gift.getToUserId())); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.MESSAGE.getTargetName())) { LOG.info("[COMMCAST] message event received ============="); toNaverUserId = userBo.getNaverUserId(context.getEvent().getEventOption("toUserId")); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("toUserId") + ") have NO naverId."); return; } if (StringUtils.isEmpty(context.getEvent().getEventOption("authorName")) || StringUtils.isEmpty(context.getEvent().getEventOption("toUserId"))) { LOG.info("[COMMCAST] message invalid argument"); return; } Message message = new Message(fireUserId, context.getEvent().getEventOption("authorName"), context.getEvent().getEventOption("toUserId"), context.getEvent().getEventOption("message"), toNaverUserId); message.setToUserUserId(context.getEvent().getEventOption("toUserId")); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(message, null, EventTarget.MESSAGE.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? .", fireUserId, message.getToUserUserId())); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.COMMENT.getTargetName())) { LOG.info("[COMMCAST] comment event received ============="); toNaverUserId = userBo.getNaverUserId(context.getEvent().getEventOption("bodyAuthorUserId")); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("bodyAuthorUserId") + ") have NO naverId."); return; } Comment comment = new Comment(context.getEvent().getEventOption("postContent"), Integer.parseInt(context.getEvent().getEventOption("commentsCount")), context.getEvent().getEventOption("authorName"), context.getEvent().getEventOption("commentBody"), context.getEvent().getEventOption("commentBodyWithoutHtml"), toNaverUserId, Integer.parseInt(context.getEvent().getEventOption("postId")), fireUserId, context.getEvent().getEventOption("registered")); eventId = StrUtil .encodedPostIdForComment(Integer.parseInt(context.getEvent().getEventOption("postId"))); resultMap = sendByPutMethod(comment, null, EventTarget.COMMENT.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? ? .", fireUserId, comment.getBodyAuthorUserId())); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.FRIEND_ACCEPT.getTargetName())) { LOG.info("[COMMCAST] acceptFriend event received ========"); toNaverUserId = userBo.getNaverUserId(fireUserId); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("fireUserId") + ") have NO naverId."); return; } Friend friend = new Friend(context.getEvent().getEventOption("toUserName"), context.getEvent().getEventOption("toUserId"), context.getEvent().getEventOperation(), toNaverUserId, context.getEvent().getEventOption("content")); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(friend, null, EventTarget.FRIEND_ACCEPT.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? ? ?.", fireUserId, friend.getToUserId())); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.MENTION.getTargetName())) { LOG.info("[COMMCAST] mention event received ============="); toUserId = context.getEvent().getEventOption("toUserId"); toNaverUserId = userBo.getNaverUserId(toUserId); String linkDate = ""; if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("toUserId") + ") have NO naverId."); return; } try { linkDate = CommcastUtil.getLinkDate(context.getEvent().getEventOption("registered")); } catch (Exception e) { LOG.error("[COMMCAST-mention] linkDate : " + e.getMessage()); } Mention mention = new Mention(fireUserId, context.getEvent().getEventOption("title"), context.getEvent().getEventOption("tag"), context.getEvent().getEventOption("authorName"), toNaverUserId, context.getEvent().getEventOption("htmlTitle"), context.getEvent().getEventOption("replyKey"), context.getEvent().getEventOption("closeComment"), StringUtils.equals(context.getEvent().getEventOption("hasPhoto"), "true") ? true : false, linkDate); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(mention, null, EventTarget.MENTION.getCatId(), MODE_SINGLE, eventId); LOG.info("[COMMCAST] closeComment : " + context.getEvent().getEventOption("closeComment")); LOG.info("[COMMCAST] isHasPhoto : " + context.getEvent().getEventOption("hasPhoto")); LOG.info(String.format("[COMMCAST] [%s]? [%s]? .", fireUserId, toUserId)); LOG.info("[COMMCAST] ===================================="); } else if (StringUtils.equals(target, EventTarget.APP.getTargetName())) { LOG.info("[COMMCAST] app event received ============="); toUserId = context.getEvent().getEventOption("toUserId"); toNaverUserId = userBo.getNaverUserId(toUserId); if (StringUtils.isEmpty(toNaverUserId)) { LOG.info("[COMMCAST] toUserId(" + context.getEvent().getEventOption("toUserId") + ") have NO naverId."); return; } App app = new App(fireUserId, context.getEvent().getEventOption("authorName"), context.getEvent().getEventOption("toUserId"), context.getEvent().getEventOption("message"), toNaverUserId, context.getEvent().getEventOption("appName"), context.getEvent().getEventOption("appId"), context.getEvent().getEventOption("appLinkUrl"), context.getEvent().getEventOption("type")); eventId = context.getEvent().getEventOption("eventId"); resultMap = sendByPutMethod(app, null, EventTarget.APP.getCatId(), MODE_SINGLE, eventId); LOG.info(String.format("[COMMCAST] [%s]? [%s]? [%s] ? .", fireUserId, toUserId, app.getAppName())); LOG.info("[COMMCAST] ===================================="); } if (resultMap != null && StringUtils.equals((String) resultMap.get("result"), "1")) { // TODO // LOG.info(String.format("[COMMCAST] target name : %s, sending result : %s", target, // resultMap)); } }
From source file:com.vmware.appfactory.config.model.ConfigSetting.java
@Override public int deepCopy(AbstractRecord record) { ConfigSetting other = (ConfigSetting) record; int numChanges = 0; if (!StringUtils.equals(getKey(), other.getKey())) { setKey(other.getKey());/*from w w w . j a va 2 s.c o m*/ numChanges++; } if (!StringUtils.equals(getValue(), other.getValue())) { setValue(other.getValue()); numChanges++; } return numChanges; }
From source file:hydrograph.ui.graph.command.CommentBoxSetConstraintCommand.java
@Override public boolean canExecute() { Object type = request.getType(); // make sure the Request is of a type we support: return (StringUtils.equals(RequestConstants.REQ_MOVE, (String) type) || StringUtils.equals(RequestConstants.REQ_MOVE_CHILDREN, (String) type) || StringUtils.equals(RequestConstants.REQ_RESIZE_CHILDREN, (String) type) || StringUtils.equals(RequestConstants.REQ_RESIZE, (String) type)); }