本文整理汇总了Java中org.apache.sling.api.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于org.apache.sling.api.resource包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
public IndexEntry create(String path, @Nonnull ResourceResolver resolver) {
String[] indexRules = getIndexRules(PRIMARY_TYPE_VALUE);
if (ArrayUtils.isNotEmpty(indexRules)) {
PageManager pageManager = resolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page page = pageManager.getPage(path);
if (page != null) {
IndexEntry ret = new IndexEntry("idx", "page", path);
Resource res = page.getContentResource();
if (res != null) {
ret.addContent(getProperties(res, indexRules));
}
return ret;
}
}
}
else {
LOG.warn("Could not load indexRules for " + PRIMARY_TYPE_VALUE);
}
return null;
}
示例2: isApplicable
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
private boolean isApplicable(SlingHttpServletRequest request) {
Object appliable = request.getAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE);
if (appliable == null) {
Resource resource = request.getResource();
PageManager pMgr = resource.getResourceResolver().adaptTo(PageManager.class);
Page page = pMgr.getContainingPage(resource);
AEMDataLayerConfig config = AEMDataLayerConfig.getDataLayerConfig(page);
if (config != null) {
DataLayer dataLayer = new DataLayer(config, page);
request.setAttribute(DataLayerConstants.REQUEST_PROPERTY_AEM_DATALAYER, dataLayer);
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(true));
return true;
} else {
request.setAttribute(REQUEST_PROPERTY_AEM_DATALAYER_APPLICABLE, new Boolean(false));
return false;
}
} else {
return new Boolean(true).equals(appliable);
}
}
示例3: updateSubCategoriesAndPatterns
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
private void updateSubCategoriesAndPatterns(Resource resource, List<PatternCategoryModel> subCategories, List<PatternModel> patterns,
PatternCategoryModel parentCategory, String patternsPath, String patternId) throws IOException {
if (isHtlFile(resource)) {
final List<String> templateNames = retrieveTemplatesFromFile(resource);
if (CollectionUtils.isEmpty(templateNames)) {
patterns.add(new PatternModel(resource, patternsPath, patternId, this.resourceResolver));
} else {
patterns.addAll(getTemplatesPatterns(resource, patternsPath, patternId, templateNames));
}
} else if (isFolder(resource)) {
final PatternCategoryModel category = createCategory(resource, patternsPath, patternId, parentCategory);
if (category != null && category.isValid()) {
subCategories.add(category);
}
}
}
示例4: adaptTo
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
if (type.isAssignableFrom(Map.class)) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (Entry<String, Resource> e : children.entrySet()) {
Resource o = e.getValue();
String[] stringArray = o.adaptTo(String[].class);
String stringValue = o.adaptTo(String.class);
if (stringValue != null) {
map.put(e.getKey(), stringValue);
} else if (stringArray != null) {
map.put(e.getKey(), stringArray);
}
}
return (AdapterType) map;
} else {
return null;
}
}
示例5: process
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
log.debug("for {}", resource.getPath());
if (resource != null) {
ResourceResolver resourceResolver = request.getResourceResolver();
String globalPropertiesPath = ResourceUtils.getGlobalPropertiesPath(resource, resourceResolver);
if (globalPropertiesPath != null) {
Resource globalPropertiesResource = resourceResolver.getResource(globalPropertiesPath);
Map<String, Object> globalProperties = (globalPropertiesResource != null) ? PropertyUtils.propsToMap(globalPropertiesResource) : new HashMap<String, Object>();
contentModel.set(GLOBAL_PROPERTIES_KEY, globalProperties);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例6: process
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
ResourceResolver resourceResolver = request.getResourceResolver();
Style style = GeneralRequestObjects.getCurrentStyle(request);
if (style != null) {
Resource designResource = resourceResolver.getResource(style.getPath()); //get design resource
if (designResource != null) {
String imagePath = assetPathService.getComponentImagePath(designResource);
contentModel.set(DESIGN_PROPERTIES_KEY + DOT + IMAGE_PATH, imagePath);
}
}
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例7: process
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void process(final ExecutionContext executionContext, TemplateContentModel contentModel)
throws ProcessException {
try {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Collection<String> fileReferences = ResourceUtils.getPropertyAsStrings(resource, FILE_REFERENCES);
Collection<String> imagePathList = new ArrayList<>();
for(int i = 0; i < fileReferences.size(); i++) {
imagePathList.add(assetPathService.getComponentAssetPath(resource, i));
}
contentModel.set(CONTENT + DOT + IMAGE_PATHS, imagePathList);
} catch (Exception e) {
throw new ProcessException(e);
}
}
示例8: process
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
throws ProcessException {
SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
Resource resource = request.getResource();
Map<String, Object> content = (contentModel.has(RESOURCE_CONTENT_KEY)) ? ((Map<String, Object>) contentModel.get(RESOURCE_CONTENT_KEY)) : new HashMap<String, Object>();
if (resource != null) {
Node node = resource.adaptTo(Node.class);
if (node != null) {
String componentContentId = DigestUtils.md5Hex(resource.getPath());
content.put(XK_CONTENT_ID_CP, componentContentId);
} else {
content.put(XK_CONTENT_ID_CP, "_NONE");
}
content.put(PATH, resource.getPath());
content.put(NAME, resource.getName());
}
}
示例9: constructPatternLabPageModel
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@PostConstruct
private void constructPatternLabPageModel() {
final Resource pageContentResource = request.getResource();
rawMode = PatternLabUtils.isRawSelectorPresent(request);
patternId = PatternLabUtils.getPatternIdFromSelector(request);
patternCategoryFactory = new PatternPatternCategoryFactoryImpl(request.getResourceResolver());
currentPagePath = pageContentResource.getPath();
try {
constructCategories(pageContentResource);
constructSearchPatternResults();
constructPatternsReferences();
} catch (IOException e) {
LOGGER.error("Error during constructing Pattern Lab page:", e);
}
}
示例10: PatternModel
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
public PatternModel(Resource resource, String patternsPath, String patternId, String jsonDataFile, String templateName, ResourceResolver resourceResolver) throws IOException {
this.id = PatternLabUtils.constructPatternId(resource.getPath(), patternsPath, templateName, jsonDataFile);
this.name = StringUtils.lowerCase(StringUtils.isBlank(jsonDataFile) ? templateName : jsonDataFile);
this.template = templateName;
this.path = resource.getPath();
this.dataPath = StringUtils.isNotBlank(jsonDataFile) ? resource.getParent().getPath() + PatternLabConstants.SLASH + jsonDataFile : StringUtils.EMPTY;
this.displayed = StringUtils.isBlank(patternId) || StringUtils.startsWith(getId(), patternId);
this.breadcrumb = Lists.newArrayList(new BreadcrumbItemModel(PatternLabUtils.constructPatternId(resource.getPath(), patternsPath), PatternLabUtils.getResourceTitleOrName(resource)));
if (StringUtils.isNotBlank(jsonDataFile)) {
this.breadcrumb.add(new BreadcrumbItemModel(PatternLabUtils.constructPatternId(resource.getPath(), patternsPath, templateName), templateName));
}
this.breadcrumb.add(new BreadcrumbItemModel(id, name));
this.code = PatternLabUtils.getDataFromFile(path, resourceResolver);
this.data = PatternLabUtils.getDataFromFile(dataPath, resourceResolver);
this.description = constructDescription(jsonDataFile, templateName, resourceResolver);
this.embeddedPatterns = Sets.newHashSet();
this.includingPatterns = Sets.newHashSet();
}
示例11: getProperties
import org.apache.sling.api.resource.Resource; //导入依赖的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;
}
示例12: getMultiplePropertyAs
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
/**
* Takes type, resource, and property name and returns the list of value of the object based on the given type
*
* @param type This is type parameter
* @param resource The resource to fetch the value from
* @param propertyName The property name to be used to fetch the value from the resource
* @return valueList The list of values of the object based on the given type
*/
private static <T> List<T> getMultiplePropertyAs(Class<T> type, Resource resource, String propertyName) {
List<T> val = Collections.EMPTY_LIST;
try {
if (null != resource) {
Node node = resource.adaptTo(Node.class);
if (null != node) {
if (node.hasProperty(propertyName)) {
Property property = node.getProperty(propertyName);
if (property.isMultiple()) {
Value[] value = property.getValues();
val = PropertyUtils.as(type, value);
}
}
}
}
} catch (Exception e) {
LOG.error(ERROR, e);
}
return val;
}
示例13: testUnique
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Test
public void testUnique() {
Resource r1 = tree.getChild("home");
Resource r2 = tree.getChild("application");
Resource r3 = tree.getChild("home/java");
SlingQuery query = $(r1, r1, r1, r2, r2, r3, r3, r3, r1).unique();
assertResourceListEquals(query.iterator(), "home", "application", "java", "home");
}
示例14: getComponentList
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
/**
* This method gets the component list with the clientaccessible property as true on the current page resource
*
* @param resource
* @return a jsonobject with the component list
*/
private JSONObject getComponentList(Resource resource) {
JSONObject componentContentModels = new JSONObject();
int prefixLength = resource.getPath().length();
List<Resource> pageComponentResources = $(resource).searchStrategy(SearchStrategy.QUERY).find(NT_UNSTRUCTURED).filter(SECTION_BASE_PREDICATE).asList();
if (pageComponentResources != null && pageComponentResources.size() > 0) {
for (Resource componentResource : pageComponentResources) {
componentContentModels.put(DigestUtils.md5Hex(componentResource.getPath()), componentResource.getPath().substring(prefixLength));
}
}
return componentContentModels;
}
示例15: doGet
import org.apache.sling.api.resource.Resource; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws IOException, ServletException {
//TODO: put all of the logic in a context processor (need to fix templating support filter bug first)
String transformName = BLANK;
if (PathInfoUtil.getSuffixSegments(request).length == 2) {
String firstSuffixSegment = PathInfoUtil.getFirstSuffixSegment(request);
if (this.namedImageTransformers.keySet().contains(firstSuffixSegment)) {
transformName = firstSuffixSegment;
}
}
//Adds the asset binary to the inputStream
try {
Resource assetResource = getAssetResource(request);
if (DamUtil.isAsset(assetResource)) {
Binary binary;
String mimeType = BLANK;
Asset asset = DamUtil.resolveToAsset(assetResource);
Resource original = asset.getOriginal();
Node assetNode = original.adaptTo(Node.class);
if (assetNode.hasNode(JCR_CONTENT)) {
Node assetInfo = assetNode.getNode(JCR_CONTENT);
if (assetInfo.hasProperty(JCR_MIMETYPE)) {
mimeType = assetInfo.getProperty(JCR_MIMETYPE).getString();
}
if (StringUtils.isNotBlank(mimeType)) {
response.setContentType(mimeType);
}
binary = assetInfo.getProperty(JCR_DATA).getBinary();
InputStream inputStream = binary.getStream();
OutputStream outputStream = response.getOutputStream();
boolean shouldTransform = StringUtils.isNotBlank(transformName);
if (shouldTransform && ImageUtils.isImage(assetResource)) {
double quality = 1;
double maxGifQuality = 255;
// Transform the image
final Layer layer = new Layer(inputStream, new Dimension(maxWidth, maxHeight));
Layer newLayer = null;
try {
final NamedImageTransformer namedImageTransformer = this.namedImageTransformers.get(transformName);
newLayer = namedImageTransformer.transform(layer);
if (StringUtils.isBlank(mimeType) || !ImageIO.getImageWritersByMIMEType(mimeType).hasNext()) {
mimeType = getImageMimeType(layer, asset.getName());
response.setContentType(mimeType);
}
// For GIF images the colors will be reduced according to the quality argument.
if (StringUtils.equals(mimeType, GIF_MIME_TYPE)) {
quality = quality * maxGifQuality;
}
newLayer.write(mimeType, quality, outputStream);
} finally {
if (layer != null) {
layer.dispose();
}
if (newLayer != null) {
newLayer.dispose();
}
}
} else {
ByteStreams.copy(inputStream, outputStream);
}
response.flushBuffer();
outputStream.close();
}
}
} catch (RepositoryException repoException) {
LOGGER.error("Repository Exception. ", repoException);
}
}