当前位置: 首页>>代码示例>>Java>>正文


Java ModifiableValueMap.get方法代码示例

本文整理汇总了Java中org.apache.sling.api.resource.ModifiableValueMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java ModifiableValueMap.get方法的具体用法?Java ModifiableValueMap.get怎么用?Java ModifiableValueMap.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.sling.api.resource.ModifiableValueMap的用法示例。


在下文中一共展示了ModifiableValueMap.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateFormStructure

import org.apache.sling.api.resource.ModifiableValueMap; //导入方法依赖的package包/类
@Override
public Resource updateFormStructure(Resource formResource) {
    if (formResource != null) {
        ResourceResolver resolver = formResource.getResourceResolver();
        if (isFormContainer(formResource)) {
            // add default action type, form id and action path
            ModifiableValueMap formProperties = formResource.adaptTo(ModifiableValueMap.class);
            if (formProperties != null) {
                try {
                    if (formProperties.get(FormsConstants.START_PROPERTY_ACTION_TYPE,
                            String.class) == null) {
                        formProperties.put(FormsConstants.START_PROPERTY_ACTION_TYPE,
                                FormsConstants.DEFAULT_ACTION_TYPE);
                        String defaultContentPath = "/content/usergenerated" +
                                formResource.getPath().replaceAll("^.content", "").replaceAll("jcr.content.*", "") +
                                "cq-gen" + System.currentTimeMillis() + "/";
                        formProperties.put(FormsConstants.START_PROPERTY_ACTION_PATH,
                                defaultContentPath);
                    }
                    resolver.commit();
                } catch (PersistenceException e) {
                    LOGGER.error("Unable to add default action type and form id " + formResource, e);
                }
            } else {
                LOGGER.error("Resource is not adaptable to ValueMap - unable to add default action type and " +
                        "form id for " + formResource);
            }
        }
    }
    return null;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:32,代码来源:FormStructureHelperImpl.java

示例2: getPropertyFromResource

import org.apache.sling.api.resource.ModifiableValueMap; //导入方法依赖的package包/类
public Object getPropertyFromResource(Resource resource) {
	ModifiableValueMap createdResourceProperties = resource.adaptTo(ModifiableValueMap.class); // Noncompliant ValueMap should be used
	return createdResourceProperties.get("propName");
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:5,代码来源:ModifiableValueMapUsageCheck.java

示例3: merge

import org.apache.sling.api.resource.ModifiableValueMap; //导入方法依赖的package包/类
/**
 * Merges the values found in the the source properties into the destination
 * property as a multi-value. The values of the source properties and
 * destination properties must all be the same property type.
 *
 * The unique set of properties will be stored in
 *
 * @param resource the resource to look for the source and destination
 * properties on
 * @param destination the property to store the collected properties.
 * @param sources the properties to collect values from for merging
 * @param typeHint the data type that should be used when reading and
 * storing the data
 * @param allowDuplicates true to allow duplicates values in the destination
 * property; false to make values unique
 * @return Optional resource updated, if any
 */
protected final <T> Optional<Resource> merge(final Resource resource, final String destination,
        final Collection<String> sources, final Class<T> typeHint,
        final boolean allowDuplicates) throws PersistenceException {

    ResourceResolver rr = resource.getResourceResolver();

    // Create an empty array of type T
    @SuppressWarnings("unchecked")
    final T[] emptyArray = (T[]) Array.newInstance(typeHint, 0);

    Collection<T> collectedValues;

    if (allowDuplicates) {
        collectedValues = new ArrayList<>();
    } else {
        collectedValues = new LinkedHashSet<>();
    }

    for (final String source : sources) {
        Resource sourceProperties = resource;
        String sourceParam = source;
        if (source.contains("/")) {
            sourceParam = StringUtils.substringAfterLast(source, "/");
            sourceProperties = rr.getResource(resource, StringUtils.substringBeforeLast(source, "/"));
        }
        T[] tmp = sourceProperties.adaptTo(ModifiableValueMap.class).get(sourceParam, emptyArray);
        collectedValues.addAll(Arrays.asList(tmp));
    }

    Resource targetResource = resource;
    String targetProperty = destination;
    if (destination.contains("/")) {
        targetProperty = StringUtils.substringAfterLast(destination, "/");
        targetResource = rr.getResource(resource, StringUtils.substringBeforeLast(destination, "/"));
    }
    ModifiableValueMap targetProperties = targetResource.adaptTo(ModifiableValueMap.class);

    final T[] currentValues = targetProperties.get(targetProperty, emptyArray);

    if (!collectedValues.equals(Arrays.asList(currentValues))) {
        targetProperties.put(targetProperty, collectedValues.toArray(emptyArray));

        return Optional.of(targetResource);
    } else {
        return Optional.empty();
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:65,代码来源:PropertyMergePostProcessor.java


注:本文中的org.apache.sling.api.resource.ModifiableValueMap.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。