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


Java Resource.getResourceType方法代码示例

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


在下文中一共展示了Resource.getResourceType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
/**
 * Dump given resource in JSON, optionally recursing into its objects
 *
 * @param resource This is the resource to be used to create JSONObject
 * @param currentRecursionLevel This is the current level of recursion
 * @param maxRecursionLevels This is the level of recursion that needs to be executed
 * @return jsonObject
 */
private static JSONObject create(final Resource resource,
                                 final int currentRecursionLevel,
                                 final int maxRecursionLevels)
        throws Exception {
    final ValueMap valueMap = resource.adaptTo(ValueMap.class);

    @SuppressWarnings("unchecked")
    final Map propertyMap = (valueMap != null)
            ? valueMap
            : resource.adaptTo(Map.class);

    final JSONObject obj = new JSONObject();


    if (propertyMap == null) {

        // no map available, try string
        final String value = resource.adaptTo(String.class);
        if (value != null) {

            // single value property or just plain String resource or...
            obj.put(ResourceUtil.getName(resource), value);

        } else {

            // Try multi-value "property"
            final String[] values = resource.adaptTo(String[].class);
            if (values != null) {
                obj.put(ResourceUtil.getName(resource), new JSONArray().addAll(Arrays.asList(values)));
            }

        }
        if (resource.getResourceType() != null) {
            obj.put("sling:resourceType", resource.getResourceType());
        }
        if (resource.getResourceSuperType() != null) {
            obj.put("sling:resourceSuperType", resource.getResourceSuperType());
        }

    } else {

        @SuppressWarnings("unchecked")
        final Iterator<Map.Entry> props = propertyMap.entrySet().iterator();

        // the node's actual properties
        while (props.hasNext()) {
            @SuppressWarnings("unchecked")
            final Map.Entry prop = props.next();

            if (prop.getValue() != null) {
                createProperty(obj, valueMap, prop.getKey().toString(),
                        prop.getValue());
            }
        }
    }

    // the child nodes
    if (recursionLevelActive(currentRecursionLevel, maxRecursionLevels)) {
        final Iterator<Resource> children = ResourceUtil.listChildren(resource);
        while (children.hasNext()) {
            final Resource n = children.next();
            createSingleResource(n, obj, currentRecursionLevel,
                    maxRecursionLevels);
        }
    }

    return obj;
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:77,代码来源:ResourceToJSONSerializer.java

示例2: getAppName

import org.apache.sling.api.resource.Resource; //导入方法依赖的package包/类
/**
 * Takes resource and return the app name of the resource
 *
 * @param resource The resource to get the name from
 * @return appName
 */
public static String getAppName(Resource resource) {
    String resourceType = resource.getResourceType();
    resourceType = resourceType.startsWith(APPS_ROOT) ? resourceType.replace(APPS_ROOT, "") : resourceType;
    return resourceType.substring(0, resourceType.indexOf("/"));
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:12,代码来源:ResourceUtils.java


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