Example usage for org.apache.commons.lang ArrayUtils contains

List of usage examples for org.apache.commons.lang ArrayUtils contains

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils contains.

Prototype

public static boolean contains(boolean[] array, boolean valueToFind) 

Source Link

Document

Checks if the value is in the given array.

Usage

From source file:nl.strohalm.cyclos.utils.PropertyHelper.java

/**
 * Copies all possible properties from source to dest, ignoring the given properties list. Exceptions are ignored
 *//*from  www .jav a  2 s. co m*/
public static void copyProperties(final Object source, final Object dest, final String... ignored) {
    if (source == null || dest == null) {
        return;
    }
    final PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(source);
    for (final PropertyDescriptor sourceDescriptor : propertyDescriptors) {
        try {
            final String name = sourceDescriptor.getName();
            // Check for ignored properties
            if (ArrayUtils.contains(ignored, name)) {
                continue;
            }
            final PropertyDescriptor destProperty = PropertyUtils.getPropertyDescriptor(dest, name);
            if (destProperty.getWriteMethod() == null) {
                // Ignore read-only properties
                continue;
            }
            final Object value = CoercionHelper.coerce(destProperty.getPropertyType(), get(source, name));
            set(dest, name, value);
        } catch (final Exception e) {
            // Ignore this property
        }
    }
}

From source file:org.adaptto.rookie.demo.components.LikeMe.java

private void updateLikeCounter(SlingHttpServletRequest request) throws PersistenceException {

    ValueMap props = request.getResource().getValueMap();

    // check if a user with this ip address has already liked this
    String ipAddress = request.getRemoteAddr();
    String[] likedAddresses = props.get("likedAddresses", new String[0]);
    if (ArrayUtils.contains(likedAddresses, ipAddress)) {
        return;//from w w  w . ja v a 2 s  . c  om
    }

    // increment like counter and store ip address
    ValueMap writeProps = request.getResource().adaptTo(ModifiableValueMap.class);
    writeProps.put("likes", writeProps.get("likes", 0L) + 1);

    List<String> updatedLikedAddresses = new ArrayList<>(Arrays.asList(likedAddresses));
    updatedLikedAddresses.add(ipAddress);
    writeProps.put("likedAddresses", updatedLikedAddresses.toArray());

    // save to repository
    request.getResourceResolver().commit();

}

From source file:org.agnitas.web.forms.StrutsFormBase.java

protected boolean isUnsafeHtmlTagForParameter(String tagName, String paramName) {
    return !ArrayUtils.contains(GENERIC_SAFE_HTML_TAGS, tagName);
}

From source file:org.alfresco.module.org_alfresco_module_rm.model.rma.type.RecordFolderType.java

/**
 * Record folder copy callback/*from   ww  w .  j a v  a2 s.  c o m*/
 */
@Behaviour(kind = BehaviourKind.CLASS, policy = "alf:getCopyCallback")
public CopyBehaviourCallback getCopyCallback(final QName classRef, final CopyDetails copyDetails) {
    return new DefaultCopyBehaviourCallback() {
        @Override
        public Map<QName, Serializable> getCopyProperties(QName classRef, CopyDetails copyDetails,
                Map<QName, Serializable> properties) {
            Map<QName, Serializable> sourceProperties = super.getCopyProperties(classRef, copyDetails,
                    properties);

            // ensure that the 'closed' status of the record folder is not copied
            if (sourceProperties.containsKey(PROP_IS_CLOSED)) {
                sourceProperties.remove(PROP_IS_CLOSED);
            }

            return sourceProperties;
        }

        /**
         * If the targets parent is a Record Folder -- Do Not Allow Copy
         *
         * @param classQName
         * @param copyDetails
         * @return boolean
         */
        @Override
        public boolean getMustCopy(QName classQName, CopyDetails copyDetails) {
            boolean result = true;

            if (nodeService.getType(copyDetails.getTargetParentNodeRef()).equals(TYPE_RECORD_FOLDER)) {
                result = false;
            } else if (ArrayUtils.contains(unwantedAspects, classQName)) {
                result = false;
            }

            return result;
        }
    };
}

From source file:org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl.java

/**
 * Helper method that indicates whether a property is considered record metadata or not.
 *
 * @param property  property/*from w  ww . ja  v a 2 s.  c o  m*/
 * @return boolea   true if record metadata, false otherwise
 */
private boolean isRecordMetadata(NodeRef filePlan, QName property) {
    boolean result = false;

    // grab the information about the properties parent type
    ClassDefinition parent = null;
    PropertyDefinition def = dictionaryService.getProperty(property);
    if (def != null) {
        parent = def.getContainerClass();
    }

    // non-electronic record is considered a special case
    // TODO move non-electronic record support to a separate model namespace
    if (parent != null && TYPE_NON_ELECTRONIC_DOCUMENT.equals(parent.getName())) {
        result = false;
    } else {
        // check the URI's
        result = RECORD_MODEL_URIS.contains(property.getNamespaceURI());

        // check the custom model
        if (!result && !ArrayUtils.contains(NON_RECORD_MODEL_URIS, property.getNamespaceURI())) {
            if (parent != null && parent.isAspect()) {
                result = getRecordMetadataAspects(filePlan).contains(parent.getName());
            }
        }
    }

    return result;
}

From source file:org.alfresco.module.org_alfresco_module_rm.record.RecordServiceImpl.java

/**
 * Determines whether the property should always be allowed to be edited or not.
 *
 * @param property/*from  w ww .j  av a 2 s . com*/
 * @return
 */
private boolean alwaysEditProperty(QName property) {
    return (ArrayUtils.contains(ALWAYS_EDIT_URIS, property.getNamespaceURI())
            || ArrayUtils.contains(ALWAYS_EDIT_PROPERTIES, property) || isProtectedProperty(property));
}

From source file:org.alfresco.repo.action.parameter.NodeParameterProcessor.java

/**
 * @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
 *//*from   w  w  w .  j a v a2  s .  c  o m*/
@Override
public String process(String value, NodeRef actionedUponNodeRef) {
    // the default position is to return the value un-changed
    String result = value;

    // strip the processor name from the value
    value = stripName(value);
    if (!value.isEmpty()) {
        QName qname = QName.createQName(value, namespaceService);

        PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
        if (propertyDefinition == null) {
            throw new AlfrescoRuntimeException(
                    "The property " + value + " does not have a property definition.");
        }

        QName type = propertyDefinition.getDataType().getName();
        if (ArrayUtils.contains(supportedDataTypes, type)) {
            Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
            if (propertyValue != null) {
                result = propertyValue.toString();
            } else {
                // set the result to the empty string
                result = "";
            }
        } else {
            throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString()
                    + " which is not supported by parameter substitution.");
        }
    }

    return result;
}

From source file:org.alfresco.repo.action.parameter.NodeParameterProcessor.java

/**
 * Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
 *
 * @param definition  Definition (aspect or type) to get properties of and the call this method for associated aspects
 * @param substitutionFragment  Substitution fragment to search for
 * @param suggestions  The current list of suggestions to which we will add newly found suggestions
 *///from www  .j  ava2  s.c o  m
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties,
        String substitutionFragment, Set<String> suggestions) {
    boolean gotMaximumSuggestions = false;
    if (properties != null) {
        for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet()) {
            PropertyDefinition propertyDefinition = entry.getValue();
            QName type = propertyDefinition.getDataType().getName();
            if (ArrayUtils.contains(supportedDataTypes, type)) {
                String suggestion = getName() + "." + entry.getKey().getPrefixString();
                if (suggestion.toLowerCase().contains(substitutionFragment)) {
                    if (suggestions.size() < this.maximumNumberSuggestions) {
                        suggestions.add(suggestion);
                    } else {
                        gotMaximumSuggestions = true;
                        break;
                    }
                }
            }
        }
    }
    return gotMaximumSuggestions;
}

From source file:org.ambraproject.service.user.UserServiceImpl.java

@Override
@SuppressWarnings("unchecked")
public List<UserAlert> getAvailableAlerts() {
    List<UserAlert> alerts = new ArrayList<UserAlert>();

    final SortedMap<Integer, Pair> categoryNames = new ConcurrentSkipListMap<Integer, Pair>();

    HierarchicalConfiguration hc = (HierarchicalConfiguration) configuration;
    List<HierarchicalConfiguration> categories = hc.configurationsAt(ALERTS_CATEGORIES_CATEGORY);

    for (HierarchicalConfiguration c : categories) {
        String key = c.getString("[@key]");
        int order = c.getInt("[@displayOrder]", categoryNames.size());
        String value = c.getString("");

        categoryNames.put(order, new Pair<String, String>(key, value));
    }/*from  w w w.j ava2s.c o  m*/

    final String[] weeklyCategories = hc.getStringArray(ALERTS_WEEKLY);
    final String[] monthlyCategories = hc.getStringArray(ALERTS_MONTHLY);
    final String[] subjectFilters = hc.getStringArray(SUBJECT_FILTER);

    final Set<Map.Entry<Integer, Pair>> categoryNamesSet = categoryNames.entrySet();

    for (final Map.Entry<Integer, Pair> category : categoryNamesSet) {
        final String key = (String) category.getValue().getFirst();
        boolean weeklyCategoryKey = false;
        boolean monthlyCategoryKey = false;
        boolean subjectFilter = false;

        if (ArrayUtils.contains(weeklyCategories, key)) {
            weeklyCategoryKey = true;
        }
        if (ArrayUtils.contains(monthlyCategories, key)) {
            monthlyCategoryKey = true;
        }
        if (ArrayUtils.contains(subjectFilters, key)) {
            subjectFilter = true;
        }

        alerts.add(
                new UserAlert((String) category.getValue().getFirst(), (String) category.getValue().getSecond(),
                        weeklyCategoryKey, monthlyCategoryKey, subjectFilter));
    }
    return alerts;
}