本文整理汇总了Java中org.apache.sling.api.resource.ValueMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java ValueMap.get方法的具体用法?Java ValueMap.get怎么用?Java ValueMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.resource.ValueMap
的用法示例。
在下文中一共展示了ValueMap.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
});
}
示例3: 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;
}
示例4: 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;
}
示例5: 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
示例6: getTitle
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
* Returns the title of the given resource. If the title is empty it will fallback to the page title, title,
* or name of the given page.
* @param resource The resource.
* @param page The page to fallback to.
* @return The best suited title found (or <code>null</code> if resource is <code>null</code>).
*/
public static String getTitle(final Resource resource, final Page page) {
if (resource != null) {
final ValueMap properties = resource.adaptTo(ValueMap.class);
if (properties != null) {
final String title = properties.get(NameConstants.PN_TITLE, String.class);
if (StringUtils.isNotBlank(title)) {
return title;
} else {
return getPageTitle(page);
}
}
} else {
LOGGER.debug("Provided resource argument is null");
}
return null;
}
示例7: 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;
}
示例8: 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();
}
示例9: activate
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
public void activate() throws Exception {
Resource resource = getResource();
ValueMap properties = getProperties();
ResourceResolver resolver = getResourceResolver();
buttonLinkTo = properties.get(PROP_BUTTON_LINK_TO, "");
buttonLabel = properties.get(PROP_BUTTON_LABEL, "");
if (StringUtils.isNotEmpty(buttonLinkTo)) {
// if button label is not set, try to get it from target page's title
if (StringUtils.isEmpty(buttonLabel)) {
Resource linkResource = resolver.getResource(buttonLinkTo);
if (linkResource != null) {
Page targetPage = linkResource.adaptTo(Page.class);
if (targetPage != null) {
buttonLabel = targetPage.getTitle();
}
}
}
buttonLinkTo = buttonLinkTo + ".html";
}
log.debug("resource: {}", resource.getPath());
log.debug("buttonLinkTo: {}", buttonLinkTo);
log.debug("buttonLabel: {}", buttonLabel);
}
示例10: getAssetFolders
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private Collection<Resource> getAssetFolders(Page page, ResourceResolver resolver) {
List<Resource> allAssetFolders = new ArrayList<Resource>();
ValueMap properties = page.getProperties();
String[] configuredAssetFolderPaths = properties.get(damAssetProperty, String[].class);
if (configuredAssetFolderPaths != null) {
// Sort to aid in removal of duplicate paths.
Arrays.sort(configuredAssetFolderPaths);
String prevPath = "#";
for (String configuredAssetFolderPath : configuredAssetFolderPaths) {
// Ensure that this folder is not a child folder of another
// configured folder, since it will already be included when
// the parent folder is traversed.
if (StringUtils.isNotBlank(configuredAssetFolderPath) && !configuredAssetFolderPath.equals(prevPath)
&& !StringUtils.startsWith(configuredAssetFolderPath, prevPath + "/")) {
Resource assetFolder = resolver.getResource(configuredAssetFolderPath);
if (assetFolder != null) {
prevPath = configuredAssetFolderPath;
allAssetFolders.add(assetFolder);
}
}
}
}
return allAssetFolders;
}
示例11: GenericListImpl
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
public GenericListImpl(Resource listParsys) {
List<Item> tempItems = new ArrayList<Item>();
Map<String, Item> tempValueMapping = new HashMap<String, Item>();
Iterator<Resource> children = listParsys.listChildren();
while (children.hasNext()) {
Resource res = children.next();
ValueMap map = res.getValueMap();
String title = map.get(NameConstants.PN_TITLE, String.class);
String value = map.get(PN_VALUE, String.class);
if (title != null && value != null) {
ItemImpl item = new ItemImpl(title, value, map);
tempItems.add(item);
tempValueMapping.put(value, item);
}
}
items = Collections.unmodifiableList(tempItems);
valueMapping = Collections.unmodifiableMap(tempValueMapping);
}
示例12: getModifiedProperties
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private JsonArray getModifiedProperties(ValueMap properties) throws IOException {
JsonArray modifiedProperties = new JsonArray();
InputStream is = properties.get("cq:properties", InputStream.class);
if (is != null) {
ObjectInputStream ois = new ObjectInputStream(is);
ois.readInt();
while (ois.available() != -1) {
try {
Object obj = ois.readObject();
if (obj instanceof HashSet) {
Set<String> propertiesSet = (Set<String>) obj;
for (String property : propertiesSet) {
modifiedProperties.add(new JsonPrimitive(property));
}
break;
}
} catch (Exception e) {
break;
}
}
}
return modifiedProperties;
}
示例13: visit
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
@Override
protected void visit(Resource resource) {
final ValueMap properties = resource.adaptTo(ValueMap.class);
final String[] resourceViews = properties.get(WCMViewsFilter.PN_WCM_VIEWS, String[].class);
if (ArrayUtils.isNotEmpty(resourceViews)) {
this.views.addAll(Arrays.asList(resourceViews));
}
final Component component = WCMUtils.getComponent(resource);
if (component != null) {
final String[] componentViews = component.getProperties().get(WCMViewsFilter.PN_WCM_VIEWS, String[].class);
if (ArrayUtils.isNotEmpty(componentViews)) {
this.views.addAll(Arrays.asList(componentViews));
}
}
}
示例14: getColor
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
private Color getColor(final ValueMap properties) {
String hexcolor = properties.get(KEY_COLOR, properties.get(KEY_COLOR_ALIAS, String.class));
int alpha = normalizeAlpha(properties.get(KEY_ALPHA, properties.get(KEY_ALPHA_ALIAS, 0.0)).floatValue());
Color color = TRANSPARENT;
if (hexcolor != null) {
try {
Color parsed = Color.decode("0x" + hexcolor);
color = new Color(parsed.getRed(), parsed.getGreen(), parsed.getBlue(), alpha);
} catch (NumberFormatException ex) {
log.warn("Invalid hex color specified: {}", hexcolor);
color = TRANSPARENT;
}
}
return color;
}
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-commons,代码行数:17,代码来源:LetterPillarBoxImageTransformerImpl.java
示例15: getPageProperty
import org.apache.sling.api.resource.ValueMap; //导入方法依赖的package包/类
/**
* Allows the developer to directly get a page property from a page object (Supports null parameters).
*
* @param page AEM page object
* @param propertyName Property name
* @return The property value or a blank string if the property is not present.
*/
public static String getPageProperty(Page page, String propertyName) {
String pageProperty = BLANK;
if (page != null) {
ValueMap pageProperties = page.getProperties();
if ((pageProperties != null) && (propertyName != null)) {
pageProperty = pageProperties.get(propertyName, BLANK);
}
}
return pageProperty;
}