本文整理汇总了Java中org.apache.sling.api.resource.ModifiableValueMap类的典型用法代码示例。如果您正苦于以下问题:Java ModifiableValueMap类的具体用法?Java ModifiableValueMap怎么用?Java ModifiableValueMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModifiableValueMap类属于org.apache.sling.api.resource包,在下文中一共展示了ModifiableValueMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}
}
示例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();
}
示例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);
}
}
示例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());
}
}
示例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