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


Java ValueMap类代码示例

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


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

示例1: pageExistsAt

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
public static Matcher<Page> pageExistsAt(String path) {
	return new TypeSafeMatcher<Page>() {
		
		@Override
		protected boolean matchesSafely(Page actual) {
			if (actual == null || actual.getContentResource() == null) {
				return false;
			}
			Resource resource = actual.adaptTo(Resource.class);
			ValueMap content  = actual.getContentResource().adaptTo(ValueMap.class);
			return resource != null
			       && !resource.isResourceType(Resource.RESOURCE_TYPE_NON_EXISTING)
			       && ResourceType.PAGE_CONTENT_TYPE.getName().equals(actual.getProperties().get(ResourceProperty.PRIMARY_TYPE))
			       && StringUtils.isNotBlank(actual.getTemplate().getPath())
			       && path.endsWith(content.get(ResourceProperty.TITLE).toString())
			       && path.equals(resource.getPath());
			
		}
		
		@Override
		public void describeTo(Description description) {
			description.appendText(MessageFormat.format("Page with valid jcr:resourceType at {0} should exist.", path));
		}
	};
}
 
开发者ID:quatico-solutions,项目名称:aem-testing,代码行数:26,代码来源:AemMatchers.java

示例2: doTag

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
@Override
public void doTag() throws JspException, IOException {
	
	// get property of current page or traverse up tree:
	String inheritedPropertyValue = null;
	if(!ResourceUtil.isSyntheticResource(this.resource)) {
		inheritedPropertyValue = this.resource.adaptTo(ValueMap.class).get(this.propertyName, "").toString();	
	}
	if (inheritedPropertyValue == null || inheritedPropertyValue.length() == 0) {
		InheritanceValueMap iProperties = new HierarchyNodeInheritanceValueMap(this.resource);
		inheritedPropertyValue = iProperties.getInherited(this.propertyName, this.defaultValue);
	}
	
	getJspContext().setAttribute("inheritedPropertyValue", inheritedPropertyValue);
	
}
 
开发者ID:infielddigital,项目名称:aem-id-googlesearch,代码行数:17,代码来源:GoogleSearchInheritanceTag.java

示例3: getLength

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
/**
 * Get length from an object in a ValueMap
 *
 * @param valueMap This is the ValueMap to fetch the object from
 * @param index This is the position of where the length is
 * @param key This is the position of where the object is in the ValueMap
 * @param stream This is the InputStream to be closed (if connection is still alive)
 * @return length
 */
private static long getLength(final ValueMap valueMap, final int index, final String key, final InputStream stream) {
    try {
        stream.close();
    } catch (IOException ignore) {
    }
    long length = -1;
    if (valueMap != null) {
        if (index == -1) {
            length = valueMap.get(key, length);
        } else {
            Long[] lengths = valueMap.get(key, Long[].class);
            if (lengths != null && lengths.length > index) {
                length = lengths[index];
            }
        }
    }
    return length;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:28,代码来源:ResourceToJSONSerializer.java

示例4: getProperties

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
/**
 * Recursively searches all child-resources for the given resources and returns a map with all of them
 *
 * @param res
 * @param properties
 * @return
 */
protected Map<String, Object> getProperties(Resource res, String[] properties) {
  //TODO: add support for * property
  ValueMap vm = res.getValueMap();
  Map<String, Object> ret = Arrays.stream(properties)
          .filter(property -> vm.containsKey(property))
          .collect(Collectors.toMap(Function.identity(), property -> vm.get(property)));

  for (Resource child : res.getChildren()) {
    Map<String, Object> props = getProperties(child, properties);
    // merge properties
    props.entrySet().forEach(entry -> {
      //TODO: Merge properties
      if (!ret.containsKey(entry.getKey())) {
        ret.put(entry.getKey(), entry.getValue());
      }
      else {
        ret.put(entry.getKey(), mergeProperties(ret.get(entry.getKey()), entry.getValue()));
      }
    });
  }
  return ret;
}
 
开发者ID:deveth0,项目名称:elasticsearch-aem,代码行数:30,代码来源:AbstractElasticSearchContentBuilder.java

示例5: resourceExistsAt

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
public static Matcher<Resource> resourceExistsAt(String path) {
	return new TypeSafeMatcher<Resource>() {
		
		@Override
		protected boolean matchesSafely(Resource actual) {
			if (actual == null) {
				return false;
			}
			return !actual.isResourceType(Resource.RESOURCE_TYPE_NON_EXISTING)
			       && StringUtils.isNotBlank((CharSequence) actual.adaptTo(ValueMap.class).get(ResourceProperty.PRIMARY_TYPE))
			       && path.equals(actual.getPath());
			
		}
		
		@Override
		public void describeTo(Description description) {
			description.appendText(MessageFormat.format("Resource with valid jcr:primaryType at {0} should exist.", path));
		}
	};
}
 
开发者ID:quatico-solutions,项目名称:aem-testing,代码行数:21,代码来源:AemMatchers.java

示例6: 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;
}
 
开发者ID:bdelacretaz,项目名称:sling-adaptto-2016,代码行数:19,代码来源:DefaultServlet.java

示例7: fillEntryProperties

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
private void fillEntryProperties(ModifiableEntryBuilder entryBuilder, Mode mode, Progress progressLogger,
		InstanceDetails.InstanceType instanceType, String hostname, Calendar executionTime,
		Resource source, ValueMap values, String executor) {
	entryBuilder.setFileName(source.getName()) //
			.setFilePath(source.getPath()) //
			.setMode(mode.toString()) //
			.setProgressLog(ProgressHelper.toJson(progressLogger.getEntries())) //
			.setExecutionTime(executionTime) //
			.setAuthor(values.get(JcrConstants.JCR_CREATED_BY, StringUtils.EMPTY)) //
			.setUploadTime(values.get(JcrConstants.JCR_CREATED, StringUtils.EMPTY)) //
			.setInstanceType(instanceType.getInstanceName()) //
			.setInstanceHostname(hostname);
	if (StringUtils.isNotBlank(executor)) {
		entryBuilder.setExecutor(executor);
	}
	entryBuilder.save();
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:18,代码来源:HistoryImpl.java

示例8: handleAction

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
@Override
public void handleAction(final ValueMap valueMap) {
	Preconditions
			.checkState(instanceTypeProvider.isOnAuthor(), "Action Receiver has to be called in author");
	String userId = valueMap.get(ReplicationAction.PROPERTY_USER_ID, String.class);
	SlingHelper.operateTraced(resolverFactory, userId, new OperateCallback() {
		@Override
		public void operate(ResourceResolver resolver) throws Exception {
			//FIXME would be lovely to cast ValueMap -> ModifiableEntryBuilder
			String scriptLocation = valueMap.get(ModifiableEntryBuilder.FILE_PATH_PROPERTY, String.class);
			Resource scriptResource = resolver.getResource(scriptLocation);
			Script script = scriptResource.adaptTo(ScriptImpl.class);
			InstanceDetails instanceDetails = getInstanceDetails(valueMap);
			Progress progress = getProgress(valueMap, resolver.getUserID());
			Calendar executionTime = getCalendar(valueMap);
			Mode mode = getMode(valueMap);
			history.logRemote(script, mode, progress, instanceDetails, executionTime);
		}
	});
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:21,代码来源:RemoteScriptExecutionActionReceiver.java

示例9: findCities

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
public List<City> findCities(String basePath, String relPath) {
	List<City> cities = new ArrayList<>();
	Resource resource = resourceResolver.getResource(basePath);

	Page page = resourceResolver.adaptTo(PageManager.class).getContainingPage(resource);
	Iterator<Page> cityPages = page.listChildren();
	while (cityPages.hasNext()) {
		Page cityPage = cityPages.next();
		ValueMap cityProps = cityPage.getContentResource().getValueMap();
		City city = new City();
		city.name = cityProps.get("jcr:title", String.class);
		city.id = cityPage.getName();
		Resource cityView = cityPage.getContentResource().getChild(relPath);
		Download download = new Download(cityView.getChild("image"));
		city.imageSrc = download.getHref();

		cities.add(city);

	}
	return cities;

}
 
开发者ID:sinnerschrader,项目名称:aem-react,代码行数:23,代码来源:CityFinderModel.java

示例10: getCropRect

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
/**
 * Retrieves the cropping rectangle, if one is defined for the image.
 *
 * @param properties the image component's properties
 * @return the cropping rectangle, if one is found, {@code null} otherwise
 */
private Rectangle getCropRect(@Nonnull ValueMap properties) {
    String csv = properties.get(ImageResource.PN_IMAGE_CROP, String.class);
    if (StringUtils.isNotEmpty(csv)) {
        try {
            int ratio = csv.indexOf("/");
            if (ratio >= 0) {
                // skip ratio
                csv = csv.substring(0, ratio);
            }
            String[] coords = csv.split(",");
            int x1 = Integer.parseInt(coords[0]);
            int y1 = Integer.parseInt(coords[1]);
            int x2 = Integer.parseInt(coords[2]);
            int y2 = Integer.parseInt(coords[3]);
            return new Rectangle(x1, y1, x2 - x1, y2 - y1);
        } catch (Exception e) {
            LOGGER.warn(String.format("Invalid cropping rectangle %s.", csv), e);
        }
    }
    return null;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:28,代码来源:AdaptiveImageServlet.java

示例11: getAllowedTypes

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
private List<Resource> getAllowedTypes(@Nonnull SlingHttpServletRequest request) {
    List<Resource> allowedTypes = new ArrayList<>();
    ResourceResolver resolver = request.getResourceResolver();
    Resource contentResource = resolver.getResource((String) request.getAttribute(Value.CONTENTPATH_ATTRIBUTE));
    ContentPolicyManager policyMgr = resolver.adaptTo(ContentPolicyManager.class);
    if (policyMgr != null) {
        ContentPolicy policy = policyMgr.getPolicy(contentResource);
        if (policy != null) {
            ValueMap props = policy.getProperties();
            if (props != null) {
                String[] titleTypes = props.get("allowedTypes", String[].class);
                if (titleTypes != null && titleTypes.length > 0) {
                    for (String titleType : titleTypes) {
                        allowedTypes.add(new TitleTypeResource(titleType, resolver));
                    }
                }
            }
        }
    }
    return allowedTypes;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:22,代码来源:AllowedTitleSizesDataSourceServlet.java

示例12: getThumbnailUrl

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
private String getThumbnailUrl(Page page, int width, int height) {
    String ck = "";

    ValueMap metadata = page.getProperties(PN_IMAGE_FILE_JCR_CONTENT);
    if (metadata != null) {
        Calendar imageLastModified = metadata.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class);
        Calendar pageLastModified = page.getLastModified();
        if (pageLastModified != null && pageLastModified.after(imageLastModified)) {
            ck += pageLastModified.getTimeInMillis() / 1000;
        } else if (imageLastModified != null) {
            ck += imageLastModified.getTimeInMillis() / 1000;
        } else if (pageLastModified != null) {
            ck += pageLastModified.getTimeInMillis() / 1000;
        }
    }

    return page.getPath() + ".thumb." + width + "." + height + ".png?ck=" + ck;
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:19,代码来源:SocialMediaHelperImpl.java

示例13: testBasicWrapping

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
@Test
public void testBasicWrapping() {
    Map<String, Object> properties = new HashMap<String, Object>(){{
        put("a", 1);
        put("b", 2);
        put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c");
    }};
    Resource wrappedResource = new ImageResourceWrapper(prepareResourceToBeWrapped(properties), "d/e/f");
    ArrayList<Map.Entry> keyValuePairs = new ArrayList<>();
    keyValuePairs.add(new DefaultMapEntry("a", 1));
    keyValuePairs.add(new DefaultMapEntry("b", 2));
    keyValuePairs.add(new DefaultMapEntry(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f"));
    testValueMap(keyValuePairs, wrappedResource.adaptTo(ValueMap.class));
    testValueMap(keyValuePairs, wrappedResource.getValueMap());
    assertEquals("d/e/f", wrappedResource.getResourceType());
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:17,代码来源:ImageResourceWrapperTest.java

示例14: testWrappingWithHiddenProperties

import org.apache.sling.api.resource.ValueMap; //导入依赖的package包/类
@Test
public void testWrappingWithHiddenProperties() {
    Map<String, Object> properties = new HashMap<String, Object>(){{
        put("a", 1);
        put("b", 2);
        put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c");
    }};
    Resource wrappedResource = new ImageResourceWrapper(prepareResourceToBeWrapped(properties), "d/e/f", new ArrayList<String>() {{
        add("b");
    }});
    ArrayList<Map.Entry> keyValuePairs = new ArrayList<>();
    keyValuePairs.add(new DefaultMapEntry("a", 1));
    keyValuePairs.add(new DefaultMapEntry(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f"));
    testValueMap(keyValuePairs, wrappedResource.adaptTo(ValueMap.class));
    testValueMap(keyValuePairs, wrappedResource.getValueMap());
    assertFalse(wrappedResource.getValueMap().containsKey("b"));
    assertEquals("d/e/f", wrappedResource.getResourceType());
}
 
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:19,代码来源:ImageResourceWrapperTest.java

示例15: updateLikeCounter

import org.apache.sling.api.resource.ValueMap; //导入依赖的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


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