List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:com.gzj.tulip.jade.context.spring.JadeBeanFactoryPostProcessor.java
public String getCacheProviderName(ConfigurableListableBeanFactory beanFactory) { if (cacheProviderName == null) { String[] names = beanFactory.getBeanNamesForType(CacheProvider.class); if (names.length == 0) { cacheProviderName = "none"; } else if (names.length == 1) { cacheProviderName = names[0]; } else {//ww w . ja va 2 s .co m String topPriority = "jade.cacheProvider"; if (ArrayUtils.contains(names, topPriority)) { cacheProviderName = topPriority; } else { throw new IllegalStateException( "required not more than 1 CacheProvider, but found " + names.length); } } } return "none".equals(cacheProviderName) ? null : cacheProviderName; }
From source file:com.adobe.acs.tools.csv_asset_importer.impl.CsvAssetImporterServlet.java
/** * Updates the Metadata Properties of the Asset. * * @param columns the Columns of the CSV * @param row the row data/*from w w w . jav a 2 s. co m*/ * @param ignoreProperties Properties which to ignore when persisting property values to the Asset * @param asset the Asset to persist the data to */ private void updateProperties(final Map<String, Column> columns, final String[] row, final String[] ignoreProperties, final Asset asset) throws RepositoryException, CsvAssetImportException { // Copy properties for (final Map.Entry<String, Column> entry : columns.entrySet()) { if (ArrayUtils.contains(ignoreProperties, entry.getKey())) { continue; } if (StringUtils.isBlank(entry.getKey())) { log.warn("Found a blank property name for: {}", Arrays.asList(entry.getValue())); continue; } final Column column = entry.getValue(); final String valueStr = row[column.getIndex()]; final Node metaProps = this.getMetadataProperties(asset, column.getRelPropertyPath()); final String propName = column.getPropertyName(); if (StringUtils.isNotBlank(valueStr)) { if (metaProps.hasProperty(propName)) { Property prop = metaProps.getProperty(propName); if ((prop.getType() != column.getJcrPropertyType()) || (column.isMulti() && !prop.isMultiple()) || (!column.isMulti() && prop.isMultiple())) { prop.remove(); } } if (column.isMulti()) { Object val = column.getMultiData(valueStr); JcrUtil.setProperty(metaProps, propName, val); log.debug("Setting multi property [ {} ~> {} ]", column.getRelPropertyPath(), Arrays.asList(column.getMultiData(valueStr))); } else { Object val = column.getData(valueStr); JcrUtil.setProperty(metaProps, propName, val); log.debug("Setting property [ {} ~> {} ]", column.getRelPropertyPath(), column.getData(valueStr)); } } else { if (metaProps.hasProperty(propName)) { metaProps.getProperty(propName).remove(); log.debug("Removing property [ {} ]", column.getRelPropertyPath()); } } } }
From source file:com.dp2345.plugin.PaymentPlugin.java
/** * Map/* w w w . j a va2s . co m*/ * * @param map * Map * @param prefix * ? * @param suffix * ? * @param separator * * @param ignoreEmptyValue * * @param ignoreKeys * Key * @return */ protected String joinValue(Map<String, Object> map, String prefix, String suffix, String separator, boolean ignoreEmptyValue, String... ignoreKeys) { List<String> list = new ArrayList<String>(); if (map != null) { for (Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); String value = ConvertUtils.convert(entry.getValue()); if (StringUtils.isNotEmpty(key) && !ArrayUtils.contains(ignoreKeys, key) && (!ignoreEmptyValue || StringUtils.isNotEmpty(value))) { list.add(value != null ? value : ""); } } } return (prefix != null ? prefix : "") + StringUtils.join(list, separator) + (suffix != null ? suffix : ""); }
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.estores.impl.DirectWriteBlueprintsResourceEStoreImpl.java
@Override public boolean contains(InternalEObject object, EStructuralFeature feature, Object value) { if (value == null) { return false; } else {/* ww w . ja v a 2 s. c o m*/ return ArrayUtils.contains(toArray(object, feature), value); } }
From source file:com.manydesigns.elements.fields.search.SelectSearchField.java
public void valueToXhtmlRadio(XhtmlBuffer xb) { Object[] values = getValues(); Map<Object, SelectionModel.Option> options = selectionModel.getOptions(selectionModelIndex); xb.writeLabel(StringUtils.capitalize(label), id, ATTR_NAME_HTML_CLASS); xb.openElement("div"); xb.addAttribute("class", "controls"); int counter = 0; if (!required) { String radioId = id + "_" + counter; boolean checked = (values == null && !notSet); writeRadioWithLabel(xb, radioId, getText("elements.search.select.none"), "", checked); counter++;// ww w . j a va 2 s . co m radioId = id + "_" + counter; writeRadioWithLabel(xb, radioId, getText("elements.search.select.notset.radio"), VALUE_NOT_SET, notSet); counter++; } for (Map.Entry<Object, SelectionModel.Option> option : options.entrySet()) { if (!option.getValue().active) { continue; } Object optionValue = option.getKey(); String optionStringValue = OgnlUtils.convertValueToString(optionValue); String optionLabel = option.getValue().label; String radioId = id + "_" + counter; boolean checked = ArrayUtils.contains(values, optionValue); writeRadioWithLabel(xb, radioId, optionLabel, optionStringValue, checked); counter++; } xb.closeElement("div"); // TODO: gestire radio in cascata }
From source file:javacommon.excel.ExcelReader.java
/** * ???/*w ww . j a v a 2 s . c o m*/ * * @param c ? * @return */ private String getCellStringFormatValue(Cell c) { if (c == null) { return ""; } String value = null; NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.setMaximumFractionDigits(12); switch (c.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: value = String.valueOf(c.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(c)) { return DateFormatUtils.ISO_DATE_FORMAT.format(c.getDateCellValue()); } else if ("@".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if ("General".equals(c.getCellStyle().getDataFormatString())) { value = nf.format(c.getNumericCellValue()); } else if (ArrayUtils.contains(ExcelConstants.DATE_PATTERNS, c.getCellStyle().getDataFormatString())) { value = DateFormatUtils.format(HSSFDateUtil.getJavaDate(c.getNumericCellValue()), c.getCellStyle().getDataFormatString()); } else { value = nf.format(c.getNumericCellValue()); } break; case Cell.CELL_TYPE_STRING: value = c.getStringCellValue(); break; case Cell.CELL_TYPE_FORMULA: return c.getCellFormula(); } return value == null ? "" : value.trim(); }
From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Workspace.java
/** * Adds the payload group to the list of active payload groups. * * @param payloadGroup the payload group to add as active */// ww w . j a v a 2s . c om public void addActivePayloadGroup(PayloadGroup payloadGroup) { if (payloadGroup != null && !ArrayUtils.contains(activePayloadGroups, payloadGroup.getDereferencedPath())) { activePayloadGroups = (String[]) ArrayUtils.add(activePayloadGroups, payloadGroup.getDereferencedPath()); properties.put(PN_ACTIVE_PAYLOAD_GROUPS, activePayloadGroups); } }
From source file:com.plm.util.RCSRMInterfaceConstants.java
public static boolean isEndingState(int recordingState) { return ArrayUtils.contains(getEndingStates(), recordingState); }
From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImplTest.java
@Test public void testGetPreviewJSON() throws Exception { final Set<Resource> resources = new HashSet<Resource>(); resources.add(slingContext.create().resource("/a/b/c")); resources.add(slingContext.create().resource("/d/e/f")); resources.add(slingContext.create().resource("/g/h/i")); final String actual = packageHelper.getPreviewJSON(resources); final JSONObject json = new JSONObject(actual); assertEquals("preview", json.getString("status")); assertEquals("Not applicable (Preview)", json.getString("path")); final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" }; JSONArray actualArray = json.getJSONArray("filterSets"); for (int i = 0; i < actualArray.length(); i++) { JSONObject tmp = actualArray.getJSONObject(i); assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath"))); }/* w w w. j a v a 2 s. co m*/ assertEquals(expectedFilterSets.length, actualArray.length()); }
From source file:com.hs.mail.mailet.RemoteDelivery.java
/** * We arranged that the recipients are all going to the same mail server. We * will now rely on the DNS server to do DNS MX record lookup and try to * deliver to the multiple mail servers. If it fails, we should decide that * the failure is permanent or temporary. * //from w w w . ja v a 2 s. c o m * @param host * the same host of recipients * @param recipients * recipients who are all going to the same mail server * @param message * Mail object to be delivered * @param mimemsg * MIME message representation of the message * @return true if the delivery was successful or permanent failure so the * message should be deleted, otherwise false and the message will * be tried to send again later */ private boolean deliver(String host, Collection<Recipient> recipients, SmtpMessage message, MimeMessage mimemsg) { // Prepare javamail recipients InternetAddress[] addresses = new InternetAddress[recipients.size()]; Iterator<Recipient> it = recipients.iterator(); for (int i = 0; it.hasNext(); i++) { Recipient rcpt = it.next(); addresses[i] = rcpt.toInternetAddress(); } try { // Lookup the possible targets Iterator<HostAddress> targetServers = null; if (null == gateway) { targetServers = getSmtpHostAddresses(host); } else { targetServers = getGatewaySmtpHostAddresses(gateway); } if (!targetServers.hasNext()) { logger.info("No mail server found for: " + host); StringBuilder exceptionBuffer = new StringBuilder(128) .append("There are no DNS entries for the hostname ").append(host) .append(". I cannot determine where to send this message."); return failMessage(message, addresses, new MessagingException(exceptionBuffer.toString()), false); } Properties props = session.getProperties(); if (message.isNotificationMessage()) { props.put("mail.smtp.from", "<>"); } else { props.put("mail.smtp.from", message.getFrom().getMailbox()); } MessagingException lastError = null; StringBuilder logBuffer = null; HostAddress outgoingMailServer = null; while (targetServers.hasNext()) { try { outgoingMailServer = targetServers.next(); logBuffer = new StringBuilder(256).append("Attempting to deliver message to host ") .append(outgoingMailServer.getHostName()).append(" at ") .append(outgoingMailServer.getHost()).append(" for addresses ") .append(Arrays.asList(addresses)); logger.info(logBuffer.toString()); Transport transport = null; try { transport = session.getTransport(outgoingMailServer); try { if (authUser != null) { transport.connect(outgoingMailServer.getHostName(), authUser, authPass); } else { transport.connect(); } } catch (MessagingException e) { // Any error on connect should cause the mailet to // attempt to connect to the next SMTP server // associated with this MX record. logger.error(e.getMessage()); continue; } transport.sendMessage(mimemsg, addresses); } finally { if (transport != null) { try { transport.close(); } catch (MessagingException e) { } transport = null; } } logBuffer = new StringBuilder(256).append("Successfully sent message to host ") .append(outgoingMailServer.getHostName()).append(" at ") .append(outgoingMailServer.getHost()).append(" for addresses ") .append(Arrays.asList(addresses)); logger.info(logBuffer.toString()); recipients.clear(); return true; } catch (SendFailedException sfe) { if (sfe.getValidSentAddresses() != null) { Address[] validSent = sfe.getValidSentAddresses(); if (validSent.length > 0) { logBuffer = new StringBuilder(256).append("Successfully sent message to host ") .append(outgoingMailServer.getHostName()).append(" at ") .append(outgoingMailServer.getHost()).append(" for addresses ") .append(Arrays.asList(validSent)); logger.info(logBuffer.toString()); // Remove the addresses to which this message was // sent successfully List<InternetAddress> temp = new ArrayList<InternetAddress>(); for (int i = 0; i < addresses.length; i++) { if (!ArrayUtils.contains(validSent, addresses[i])) { if (addresses[i] != null) { temp.add(addresses[i]); } } } addresses = temp.toArray(new InternetAddress[temp.size()]); removeAll(recipients, validSent); } } if (sfe instanceof SMTPSendFailedException) { SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe; // If permanent error 5xx, terminate this delivery // attempt by re-throwing the exception if (ssfe.getReturnCode() >= 500 && ssfe.getReturnCode() <= 599) throw sfe; } if (!ArrayUtils.isEmpty(sfe.getValidUnsentAddresses())) { // Valid addresses remained, so continue with any other server. if (logger.isDebugEnabled()) logger.debug("Send failed, " + sfe.getValidUnsentAddresses().length + " valid recipients(" + Arrays.asList(sfe.getValidUnsentAddresses()) + ") remain, continuing with any other servers"); lastError = sfe; continue; } else { // There are no valid addresses left to send, so re-throw throw sfe; } } catch (MessagingException me) { Exception ne; if ((ne = me.getNextException()) != null && ne instanceof IOException) { // It can be some socket or weird I/O related problem. lastError = me; continue; } throw me; } } // end while if (lastError != null) { throw lastError; } } catch (SendFailedException sfe) { boolean deleteMessage = false; if (sfe instanceof SMTPSendFailedException) { SMTPSendFailedException ssfe = (SMTPSendFailedException) sfe; deleteMessage = (ssfe.getReturnCode() >= 500 && ssfe.getReturnCode() <= 599); } else { // Sometimes we'll get a normal SendFailedException with nested // SMTPAddressFailedException, so use the latter RetCode MessagingException me = sfe; Exception ne; while ((ne = me.getNextException()) != null && ne instanceof MessagingException) { me = (MessagingException) ne; if (me instanceof SMTPAddressFailedException) { SMTPAddressFailedException ssfe = (SMTPAddressFailedException) me; deleteMessage = (ssfe.getReturnCode() >= 500 && ssfe.getReturnCode() <= 599); } } } if (!ArrayUtils.isEmpty(sfe.getInvalidAddresses())) { // Invalid addresses should be considered permanent Address[] invalid = sfe.getInvalidAddresses(); removeAll(recipients, invalid); deleteMessage = failMessage(message, invalid, sfe, true); } if (!ArrayUtils.isEmpty(sfe.getValidUnsentAddresses())) { // Vaild-unsent addresses should be considered temporary deleteMessage = failMessage(message, sfe.getValidUnsentAddresses(), sfe, false); } return deleteMessage; } catch (MessagingException mex) { // Check whether this is a permanent error (like account doesn't // exist or mailbox is full or domain is setup wrong) // We fail permanently if this was 5xx error. return failMessage(message, addresses, mex, ('5' == mex.getMessage().charAt(0))); } // If we get here, we've exhausted the loop of servers without sending // the message or throwing an exception. // One case where this might happen is if there is no server we can // connect. So this should be considered temporary return failMessage(message, addresses, new MessagingException("No mail server(s) available at this time."), false); }