• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ModifiableValueMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ModifiableValueMap类属于org.apache.sling.api.resource包,在下文中一共展示了ModifiableValueMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: updateLikeCounter

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
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;
    }

    // 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();

  }
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:24,代码来源:LikeMe.java


示例2: isSpam

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
/**
 * Check comment against Akismet servers.
 *
 * Be aware that this method returns whether the submission is spam or not.
 * A false response means that the submission was successful and that the
 * comment is not spam. This behavior is inline with Akismet's behavior.
 *
 * @param commentResource The publick:comment resource to act upon.
 * @return true if comment is spam, false if comment is valid.
 */
public boolean isSpam(final Resource commentResource) {
    final boolean result = doAkismet(AkismetAction.CHECK_COMMENT, commentResource);

    if (result) {
        try {
            final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
            properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, true);
            commentResource.getResourceResolver().commit();
        } catch (PersistenceException e) {
            LOGGER.error("Could not save spam properties", e);
        }
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:26,代码来源:AkismetServiceImpl.java


示例3: submitSpam

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
/**
 * Submit comment as spam to the Akismet servers.
 *
 * If a comment gets checked and incorrectly is reported as ham, this will
 * submit it back to the servers as spam to help make the world a better
 * place.
 *
 * @param commentResource The publick:comment resource to act upon.
 * @return true if submission was successful.
 */
public boolean submitSpam(final Resource commentResource) {
    final boolean result = doAkismet(AkismetAction.SUBMIT_SPAM, commentResource);

    if (result) {
        try {
            final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
            properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, true);
            properties.put(PublickConstants.COMMENT_PROPERTY_DISPLAY, false);
            commentResource.getResourceResolver().commit();
        } catch (PersistenceException e) {
            LOGGER.error("Could not save spam properties", e);
        }
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:27,代码来源:AkismetServiceImpl.java


示例4: submitHam

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
/**
 * Submit comment as ham to the Akismet servers.
 *
 * If a comment gets checked and incorrectly is reported as spam, this will
 * submit it back to the servers as ham to correct a false positive.
 *
 * @param commentResource The publick:comment resource to act upon.
 * @return true if submission was successful.
 */
public boolean submitHam(final Resource commentResource) {
    final boolean result = doAkismet(AkismetAction.SUBMIT_HAM, commentResource);

    if (result) {
        try {
            final ModifiableValueMap properties = commentResource.adaptTo(ModifiableValueMap.class);
            properties.put(PublickConstants.COMMENT_PROPERTY_SPAM, false);
            properties.put(PublickConstants.COMMENT_PROPERTY_DISPLAY, true);
            commentResource.getResourceResolver().commit();
        } catch (PersistenceException e) {
            LOGGER.error("Could not save spam properties", e);
        }
    }

    return result;
}
 
开发者ID:nateyolles,项目名称:publick-sling-blog,代码行数:26,代码来源:AkismetServiceImpl.java


示例5: process

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Override
public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception {
    // First, check if our post processor implementation needs to do anything
    // Note: all registered SlingPostProcessor instances are called on all invocations of the Sling POST Servlet
    if (accepts(request)) {

        // Apply your custom changes: first, adapt the resource to a ModifiableValueMap
        final Resource resource = request.getResource();
        final ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);

        // Example: add an additional property to the resource
        String uuid = UUID.randomUUID().toString();
        properties.put("myapp.versionHash", uuid);

        // Record a "MODIFIED" entry in the modifications list
        modifications.add(Modification.onModified(resource.getPath()));
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:19,代码来源:SlingPostProcessorSample.java


示例6: persist

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
public void persist(ResourceResolver rr, String path) throws PersistenceException, RepositoryException {
    ModifiableValueMap jcrContent = ResourceUtil.getOrCreateResource(rr, path, getResourceType(), null, false).adaptTo(ModifiableValueMap.class);
    jcrContent.put("jcr:primaryType", "nt:unstructured");
    jcrContent.put("columns", getColumns().toArray(new String[0]));
    jcrContent.put("name", name);
    rr.commit();
    rr.refresh();
    JcrUtil.createPath(path + "/rows", "nt:unstructured", rr.adaptTo(Session.class));
    int rowCounter = 0;
    for (Map<String, Object> row : rows) {
        rowCounter++;
        ResourceUtil.getOrCreateResource(rr, path + "/rows/row-" + rowCounter, row, null, true);
    }
    rr.commit();
    rr.refresh();
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:17,代码来源:GenericReport.java


示例7: persistStatus

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
private void persistStatus(ResourceResolver rr) throws PersistenceException {
    try {
        Map<String, Object> props = new HashMap<>();
        props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_FOLDER);
        ResourceUtil.getOrCreateResource(rr, BASE_PATH, props, null, true);
        props.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Page");
        ResourceUtil.getOrCreateResource(rr, getPath(), props, null, true);
        ModifiableValueMap jcrContent = ResourceUtil.getOrCreateResource(rr, getPath() + "/jcr:content", ProcessInstance.RESOURCE_TYPE, null, false).adaptTo(ModifiableValueMap.class);
        jcrContent.put("jcr:primaryType", "cq:PageContent");
        jcrContent.put("jcr:title", getName());
        ValueMapSerializer.serializeToMap(jcrContent, infoBean);
        ModifiableValueMap resultNode = ResourceUtil.getOrCreateResource(rr, getPath() + "/jcr:content/result", ProcessInstance.RESOURCE_TYPE + "/result", null, false).adaptTo(ModifiableValueMap.class);
        resultNode.put("jcr:primaryType", JcrConstants.NT_UNSTRUCTURED);
        ValueMapSerializer.serializeToMap(resultNode, infoBean.getResult());
        rr.commit();
        rr.refresh();
    } catch (NullPointerException ex) {
        throw new PersistenceException("Null encountered when persisting status", ex);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:21,代码来源:ProcessInstanceImpl.java


示例8: setTitles

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
private void setTitles(final Resource folder, final AssetFolderDefinition assetFolderDefinition) throws RepositoryException {
    if (folder == null) {
        log.error("Asset Folder resource [ {} ] is null", assetFolderDefinition.getPath());
        return;
    }

    Resource jcrContent = folder.getChild(JcrConstants.JCR_CONTENT);
    if (jcrContent == null) {
        log.error("Asset Folder [ {} ] does not have a jcr:content child", assetFolderDefinition.getPath());
        return;
    }

    final ModifiableValueMap properties = jcrContent.adaptTo(ModifiableValueMap.class);

    if (!StringUtils.equals(assetFolderDefinition.getTitle(), properties.get(com.day.cq.commons.jcr.JcrConstants.JCR_TITLE, String.class))) {
        // Ensure if the asset folder definition already exists that the title is set properly
        properties.put(com.day.cq.commons.jcr.JcrConstants.JCR_TITLE, assetFolderDefinition.getTitle());
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:20,代码来源:AssetFolderCreator.java


示例9: testMerge_NoDuplicates_String

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_NoDuplicates_String() throws Exception {

    properties.put("cats", new String[]{"felix", "hobbes", "fluffy"});
    properties.put("dogs", new String[]{"snoopy", "ira", "fluffy"});
    properties.put("fish", "nemo");

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "animals",
            Arrays.asList("cats", "dogs", "fish"),
            String.class,
            false);

    Assert.assertArrayEquals(new String[]{"felix", "hobbes", "fluffy", "snoopy", "ira", "nemo"},
            properties.get("animals", String[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:19,代码来源:PropertyMergePostProcessorTest.java


示例10: testMerge_NoDuplicates_Long

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_NoDuplicates_Long() throws Exception {

    properties.put("odd", new Long[]{1L, 3L});
    properties.put("even", new Long[]{2L, 4L});
    properties.put("duplicates", new Long[]{1L, 2L, 3L, 4L});

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "longs",
            Arrays.asList("even", "odd", "duplicates"),
            Long.class,
            false);

    Assert.assertArrayEquals(new Long[]{2L, 4L, 1L, 3L},
            properties.get("longs", Long[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:19,代码来源:PropertyMergePostProcessorTest.java


示例11: testMerge_NoDuplicates_Double

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_NoDuplicates_Double() throws Exception {

    properties.put("tenths", new Double[]{1.1D, 1.2D});
    properties.put("hundredths", 3.01D);
    properties.put("duplicates", new Double[]{1.1D});

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "doubles",
            Arrays.asList("tenths", "hundredths", "duplicates"),
            Double.class,
            false);

    Assert.assertArrayEquals(new Double[]{1.1D, 1.2D, 3.01D},
            properties.get("doubles", Double[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:19,代码来源:PropertyMergePostProcessorTest.java


示例12: testMerge_NoDuplicates_Boolean

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_NoDuplicates_Boolean() throws Exception {

    properties.put("first", new Boolean[]{true, false, true});
    properties.put("second", true);

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "booleans",
            Arrays.asList("first", "second"),
            Boolean.class,
            false);

    Assert.assertArrayEquals(new Boolean[]{true, false},
            properties.get("booleans", Boolean[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:18,代码来源:PropertyMergePostProcessorTest.java


示例13: testMerge_NoDuplicates_Calendar

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_NoDuplicates_Calendar() throws Exception {

    Calendar january = Calendar.getInstance();
    january.set(2015, Calendar.JANUARY, 1);

    Calendar july = Calendar.getInstance();
    july.set(2015, Calendar.JULY, 4);

    Calendar september = Calendar.getInstance();
    september.set(2015, Calendar.SEPTEMBER, 16);

    properties.put("cold", new Calendar[]{january, september});
    properties.put("hot", new Calendar[]{july, september});

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "dates",
            Arrays.asList("cold", "hot"),
            Calendar.class,
            false);

    Assert.assertArrayEquals(new Calendar[]{january, september, july},
            properties.get("dates", Calendar[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:27,代码来源:PropertyMergePostProcessorTest.java


示例14: testMerge_Duplicates_String

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_Duplicates_String() throws Exception {

    properties.put("cats", new String[]{"felix", "hobbes", "fluffy"});
    properties.put("dogs", new String[]{"snoopy", "ira", "fluffy"});
    properties.put("fish", "nemo");

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "animals",
            Arrays.asList("cats", "dogs", "fish"),
            String.class,
            true);

    Assert.assertArrayEquals(new String[]{"felix", "hobbes", "fluffy", "snoopy", "ira", "fluffy", "nemo"},
            properties.get("animals", String[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:19,代码来源:PropertyMergePostProcessorTest.java


示例15: testMerge_Duplicates_Calendar

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Test
public void testMerge_Duplicates_Calendar() throws Exception {

    Calendar january = Calendar.getInstance();
    january.set(2015, Calendar.JANUARY, 1);

    Calendar july = Calendar.getInstance();
    july.set(2015, Calendar.JULY, 4);

    Calendar september = Calendar.getInstance();
    september.set(2015, Calendar.SEPTEMBER, 16);

    properties.put("cold", new Calendar[]{january, september});
    properties.put("hot", new Calendar[]{july, september});

    when(resource.adaptTo(ModifiableValueMap.class)).thenReturn(properties);

    propertyMerge.merge(resource,
            "dates",
            Arrays.asList("cold", "hot"),
            Calendar.class,
            true);

    Assert.assertArrayEquals(new Calendar[]{january, september, july, september},
            properties.get("dates", Calendar[].class));
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:27,代码来源:PropertyMergePostProcessorTest.java


示例16: setProperty

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
public void setProperty(String name, Object value) throws PersistenceException {
	Resource resource = resolver.getResource(script.getPath());
	ModifiableValueMap vm = resource.getChild(JcrConstants.JCR_CONTENT).adaptTo(ModifiableValueMap.class);
	ResourceMixinUtil.addMixin(vm, ScriptContent.CQSM_FILE);
	vm.put(name, convertValue(value));

	resource.getResourceResolver().commit();
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:9,代码来源:ModifiableScriptWrapper.java


示例17: save

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
public void save(ResourceResolver resolver, String checksum) {
	try {
		Resource storage = getOrCreateChecksumStorage(resolver, CHECKSUM_STORAGE_PATH);
		storage.adaptTo(ModifiableValueMap.class).put(filename, checksum);
		resolver.commit();
	} catch (PersistenceException e) {
		LOG.error("Cannot update checksum for {} script", filename, e);
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:10,代码来源:Checksum.java


示例18: 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


示例19: setProperty

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
public Resource setProperty(Resource resource) {
	ModifiableValueMap resourceProperties = resource.adaptTo(ModifiableValueMap.class);
	if (resourceProperties != null) {
		resourceProperties.put("test", resource.getName());
	}
	return resource;
}
 
开发者ID:Cognifide,项目名称:AEM-Rules-for-SonarQube,代码行数:8,代码来源:ModifiableValueMapUsageCheck.java


示例20: doWork

import org.apache.sling.api.resource.ModifiableValueMap; //导入依赖的package包/类
@Override
public final void doWork(final ResourceResolver resourceResolver) throws PersistenceException {
    // Generally you always want to pass in the security context (JCR Session/Resource Resolver, Resource, etc.)
    // into OSGi services rather than using administrative level repo access.

    // Do some work...
    Resource resource = resourceResolver.getResource("/content/some/resource");
    ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);
    properties.put("workDone", true);
    resourceResolver.commit();
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:12,代码来源:SampleServiceImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UserRealm类代码示例发布时间:2022-05-22
下一篇:
Java DbRefResolver类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap