本文整理汇总了Java中org.apache.sling.api.resource.ValueMap.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java ValueMap.containsKey方法的具体用法?Java ValueMap.containsKey怎么用?Java ValueMap.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.ValueMap
的用法示例。
在下文中一共展示了ValueMap.containsKey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRoleFromRequest
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private String getRoleFromRequest(SlingHttpServletRequest request) {
String role = null;
final String methodPath = routingPath + "/methods/" + request.getMethod();
final Resource r = request.getResourceResolver().resolve(methodPath);
if(r != null) {
final ValueMap m = r.adaptTo(ValueMap.class);
if(m != null && m.containsKey(ROLE_PROPERTY)) {
role = m.get(ROLE_PROPERTY, String.class).trim();
}
}
if(role != null) {
U.logAndRequestProgress(request, log, "Processor role {0} set from {1}/{2}",
role, request.getMethod(), r.getPath(), ROLE_PROPERTY);
}
return role;
}
示例2: countChildren
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private int countChildren(Resource r, String expectedProperty) {
int count = 0;
for(Resource child : r.getResourceResolver().getChildren(r)) {
final ValueMap m = child.adaptTo(ValueMap.class);
if(m.containsKey(ID)) {
count++;
}
count += countChildren(child, expectedProperty);
}
return count;
}
示例3: getLastModifiedDate
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private long getLastModifiedDate(ValueMap properties) {
long lastMod = 0L;
if (properties.containsKey(JcrConstants.JCR_LASTMODIFIED)) {
lastMod = properties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class).getTimeInMillis();
} else if (properties.containsKey(JcrConstants.JCR_CREATED)) {
lastMod = properties.get(JcrConstants.JCR_CREATED, Calendar.class).getTimeInMillis();
}
return lastMod;
}
示例4: serializeToJson
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
* Returns a JSONObject that holds all the thing data we need.
*
* @param resource Resource to start serializing from
* @param serializeAssociatedItems option to resolve linked items. if true we will resolve and include them
*
* @return JSONObject of the thing
*/
@Override
public JSONObject serializeToJson(Resource resource,Boolean serializeAssociatedItems) {
JSONObject jsonObject = null;//empty result
//is it a page?
if(resource.isResourceType(NameConstants.NT_PAGE)){
try {
//ok so now that we know its a page, lets look at its jcr content
Resource contentResource = resource.getChild(NameConstants.NN_CONTENT);
ValueMap resourceVm = contentResource.adaptTo(ValueMap.class);
dumbResourcePropertiesToDebug(contentResource);
//if its not a thing we cant serialize it or we wont
if( (resourceVm.containsKey(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY)) && (resourceVm.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY).equals(ThingConstants.THING_RESOURCE_TYPE)) || (resourceVm.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY).equals(ThingConstants.THING_RESOURCE_SHORT_TYPE))){
log.debug("Doing build json");
jsonObject = buildJson(contentResource, jsonObject,serializeAssociatedItems,0,true);
}else{
log.debug("resource passed is not a thing : "+ resource.getResourceType());
}
}catch (Exception exc){
log.error(exc.getLocalizedMessage(),exc.getStackTrace());
}
}else {
log.debug("Resource passed is not a cq:Page its " + resource.getResourceType() + " so are whimping out on serializing it");
}
if(jsonObject == null){
return new JSONObject();//empty object
}else{
return jsonObject;
}
}
示例5: getMultiFieldPanelValues
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
* Extract the value of a MultiFieldPanel property into a list of maps. Will never return
* a null map, but may return an empty one. Invalid property values are logged and skipped.
*
* @param resource the resource
* @param name the property name
* @return a list of maps.
*/
@Function
public static List<Map<String, String>> getMultiFieldPanelValues(Resource resource, String name) {
ValueMap map = resource.adaptTo(ValueMap.class);
List<Map<String, String>> results = new ArrayList<Map<String, String>>();
if (map != null && map.containsKey(name)) {
String[] values = map.get(name, new String[0]);
for (String value : values) {
try {
JSONObject parsed = new JSONObject(value);
Map<String, String> columnMap = new HashMap<String, String>();
for (Iterator<String> iter = parsed.keys(); iter.hasNext();) {
String key = iter.next();
String innerValue = parsed.getString(key);
columnMap.put(key, innerValue);
}
results.add(columnMap);
} catch (JSONException e) {
log.error(
String.format("Unable to parse JSON in %s property of %s", name, resource.getPath()),
e);
}
}
}
return results;
}
示例6: updateDataLayer
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public void updateDataLayer(DataLayer dataLayer) {
EventInfo event = new EventInfo();
event.setEventAction("pageLoad");
event.setEventName("Page Load");
dataLayer.getEvents().add(event);
Page page = dataLayer.getPage();
PageInfo pageInfo = new PageInfo();
if (dataLayer.getConfig().getSetAuthor() == true) {
pageInfo.setAuthor(dataLayer.getAEMPage().getLastModifiedBy());
}
List<String> breadcrumbs = new ArrayList<String>();
com.day.cq.wcm.api.Page currentPage = dataLayer.getAEMPage();
while (currentPage != null && currentPage.getDepth() > dataLayer.getConfig().getSiteRootLevel()) {
breadcrumbs.add(currentPage.getTitle());
currentPage = currentPage.getParent();
}
Collections.reverse(breadcrumbs);
pageInfo.setBreadcrumbs(breadcrumbs.toArray(new String[breadcrumbs.size()]));
currentPage = dataLayer.getAEMPage();
ValueMap properties = currentPage.getContentResource().getValueMap();
String path = DataLayerUtil.getSiteSubpath(currentPage, dataLayer.getConfig());
pageInfo.setDestinationUrl(DataLayerUtil.getSiteUrl(currentPage, dataLayer.getConfig()));
if (currentPage.getOnTime() != null) {
pageInfo.setEffectiveDate(currentPage.getOnTime().getTime());
} else if (properties.containsKey(JcrConstants.JCR_CREATED)) {
pageInfo.setEffectiveDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
}
if (currentPage.getOffTime() != null) {
pageInfo.setExpiryDate(currentPage.getOffTime().getTime());
}
if (properties.containsKey(JcrConstants.JCR_CREATED)) {
pageInfo.setIssueDate(properties.get(JcrConstants.JCR_CREATED, Date.class));
}
pageInfo.setLanguage(currentPage.getLanguage(false).toString());
pageInfo.setPageId(path);
pageInfo.setPageName(currentPage.getTitle());
if (StringUtils.isNotEmpty(dataLayer.getConfig().getPublisher())) {
pageInfo.setPublisher(dataLayer.getConfig().getPublisher());
}
pageInfo.setSysEnv(dataLayer.getConfig().getEnvironment());
page.setPageInfo(pageInfo);
String templateName = StringUtils.substringAfterLast(properties.get(NameConstants.NN_TEMPLATE, String.class),
"/");
List<String> tags = new ArrayList<String>();
Category category = new Category();
category.setPrimaryCategory(templateName);
for (int i = 0; i < currentPage.getTags().length; i++) {
category.put("tag" + i, currentPage.getTags()[i].getTitle());
tags.add(currentPage.getTags()[i].getTitle());
}
page.setCategory(category);
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("tags", tags.toArray(new String[tags.size()]));
attributes.put("template", templateName);
page.setAttributes(attributes);
}
示例7: isHideInNav
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public boolean isHideInNav() {
ValueMap props = getProperties();
return props.containsKey("hideInNav") ? props.get("hideInNav", Boolean.class) : false;
}
示例8: getFirstProperty
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
* Returns first non-null value from the resource property value map.
* <p>
* Ex. TextUtil.getFirstProperty(Date.class,
* "jcr:lastModified",
* "jcr:created")
* <p>
* If getLastModifiedDate() returns null, and getCreatedDate() returns not-null,
* the value for getCreatedDate() is returned.
*
* @param <T>
* @param valueMap of resource properties
* @param klass data type to return
* @param keys list of property names to evaluate
* @return
*/
public static <T> T getFirstProperty(ValueMap valueMap, Class<T> klass, String... keys) {
if (valueMap == null || keys == null || keys.length < 1) {
return null;
}
List<String> keyList = Arrays.asList(keys);
for (String key : keyList) {
if (valueMap.containsKey(key) && valueMap.get(key) != null) {
return valueMap.get(key, klass);
}
}
return null;
}