org.apache.sling.hapi.HApiUtil Maven / Gradle / Ivy
Show all versions of aem-sdk-api Show documentation
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.sling.hapi;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.annotation.versioning.ProviderType;
@ProviderType
public interface HApiUtil {
String DEFAULT_RESOURCE_TYPE = "sling/hapi/components/type";
String RESOURCE_TYPE = "org.apache.sling.hapi.tools.resourcetype";
String RESOURCE_TYPE_DESC = "The resource used for hapi types";
String DEFAULT_COLLECTION_RESOURCE_TYPE = "sling/hapi/components/typescollection";
String COLLECTION_RESOURCE_TYPE = "org.apache.sling.hapi.tools.collectionresourcetype";
String COLLECTION_RESOURCE_TYPE_DESC = "The resource used for hapi type collections";
String DEFAULT_SEARCH_PATH = "/libs/sling/hapi/types";
String SEARCH_PATHS = "org.apache.sling.hapi.tools.searchpaths";
String SEARCH_PATHS_DESC = "The path under which children resources can be identified as hapi types by their FQDN value in addition to the type path";
String DEFAULT_SERVER_URL = "http://localhost:8080";
String EXTERNAL_URL = "org.apache.sling.hapi.tools.externalurl";
String EXTERNAL_URL_DESC = "The external URL of the instance. This will prefix hapi absolute URLs";
boolean DEFAULT_ENABLED = true;
String ENABLED = "org.apache.sling.hapi.tools.enabled";
String ENABLED_DESC = "Whether hapi is enabled or completely disabled (no output rendered in components)";
/**
* Get a HApi type jcr node from a type identifier.
* The JCR node must be [nt:unstructured], a descendant of any of the HAPi search path defined by the
* {@see HAPI_PATHS} config and the sling:resourceType should be set to the value defined by the {@see HAPI_RESOURCE_TYPE} config
* The first result is returned
* @param resolver The sling resource resolver object
* @param type The type identifier, which is either in the form of a jcr path,
* same as the path for {@link: ResourceResolver#getResource(String)}. If the path cannot be resolved, type is treated like
* a fully qualified domain name, which has to match the "fqdn" property on the JCR node which represents the type.
* @return The first node that matches that type or null if none is found.
* @throws RepositoryException
*/
@Deprecated
Node getTypeNode(ResourceResolver resolver, String type) throws RepositoryException;
/**
* Get a HApi type Resource from a type identifier.
* The Resource must be [nt:unstructured], a descendant of any of the HAPi search path defined by the
* {@see HAPI_PATHS} config and the sling:resourceType should be set to the value defined by the {@see HapiUtil#RESOURCE_TYPE}
* config
* The first result is returned
* @param resolver The sling resource resolver object
* @param type The type identifier, which is either in the form of a jcr path,
* same as the path for {@link: ResourceResolver#getResource(String)}. If the path cannot be resolved, type is treated like
* a fully qualified domain name, which has to match the "fqdn" property on the Resource which represents the type.
* @return The first Resource that matches that type or null if none is found.
* @throws RepositoryException
*/
Resource getTypeResource(ResourceResolver resolver, String type) throws RepositoryException;
/**
* Get a HApi type collection Resource from a collection identifier.
* The Resource must be [nt:unstructured], a descendant of any of the HAPi search path defined by the
* {@see HAPI_PATHS} config and the sling:resourceType should be set to the value defined by the
* {@see HapiUtil#COLLECTION_RESOURCE_TYPE} config
* The first result is returned
* @param resolver The sling resource resolver object
* @param collection The collection identifier, which is either in the form of a jcr path,
* same as the path for {@link: ResourceResolver#getResource(String)}. If the path cannot be resolved, collection is
* treated like a fully qualified domain name, which has to match the "fqdn" property on the Resource which
* represents the type.
* @return The first Resource that matches that collection or null if none is found.
* @throws RepositoryException
*/
Resource getTypeCollectionResource(ResourceResolver resolver, String collection) throws RepositoryException;
/**
* Get a HApi type object from a type identifier.
* The type identifier is resolved to a {@link javax.jcr.Node} and then
* {@link #fromNode(org.apache.sling.api.resource.ResourceResolver, javax.jcr.Node)} is called.
* For restrictions on the {@link javax.jcr.Node}
* see {@link HApiUtil#getTypeNode(org.apache.sling.api.resource.ResourceResolver, String)}
* @param resolver The sling resource resolver object
* @param type The type identifier, which is either in the form of a jcr path,
* same as the path for{@link: ResourceResolver#getResource(String)}. If the path cannot be resolved, type is treated like
* a fully qualified domain name, which has to match the "fqdn" property on the JCR node which represents the type.
* @return The HApiType resolved from the type identifier
* @throws javax.jcr.RepositoryException
*/
HApiType fromPath(ResourceResolver resolver, String type) throws RepositoryException;
/**
* Get a HApi type object from the {@link javax.jcr.Node}.
* The Node has the following properties:
*
* - name: A 'Name' of the type (mandatory)
* - description: A 'String' with the description text for this type (mandatory)
* - fqdn: A 'String' with the fully qualified domain name; A namespace like a java package (mandatory)
* - extends: A type identifier (either a path or a fqdn); (optional). This defines the parent type of this type
* - parameter: A multivalue property to define a list of java-like generic types
* that can be used as types for properties; (optional)
*
*
* The properties of this type are defined as children nodes.
* The name of property node defines the name of the property for this type.
* The children property nodes have the following properties:
*
* - type: The type identifier (mandatory). Can be of type 'Name' or 'Path'
* See {@link HApiUtil#getTypeNode(org.apache.sling.api.resource.ResourceResolver, String)}
* for the format of this value
* - description: A 'String' with the description for this property (mandatory)
* - multiple: A 'Boolean' that defines whether this property can exist multiple times on an object of this type (optional)
*
*
* @param resolver The resource resolver
* @param typeNode The jcr node of the HApi type
* @return The HApiType
* @throws RepositoryException
*/
@Deprecated
HApiType fromNode(ResourceResolver resolver, Node typeNode) throws RepositoryException;
/**
* Get a HApi type object from the {@link org.apache.sling.api.resource.Resource}.
* The Resource has the following properties:
*
* - name: A 'Name' of the type (mandatory)
* - description: A 'String' with the description text for this type (mandatory)
* - fqdn: A 'String' with the fully qualified domain name; A namespace like a java package (mandatory)
* - extends: A type identifier (either a path or a fqdn); (optional). This defines the parent type of this type
* - parameter: A multivalue property to define a list of java-like generic types
* that can be used as types for properties; (optional)
*
*
* The properties of this type are defined as children resources.
* The name of property resource defines the name of the property for this type.
* The children property nodes have the following properties:
*
* - type: The type identifier (mandatory). Can be of type 'Name' or 'Path'
* See {@link HApiUtil#getTypeNode(org.apache.sling.api.resource.ResourceResolver, String)}
* for the format of this value
* - description: A 'String' with the description for this property (mandatory)
* - multiple: A 'Boolean' that defines whether this property can exist multiple times on an object of this type (optional)
*
*
* @param resolver The resource resolver
* @param typeResource The sling Resource of the HApi type
* @return The HApiType
* @throws RepositoryException
*/
HApiType fromResource(ResourceResolver resolver, Resource typeResource) throws RepositoryException;
/**
* Get a {@link HApiTypesCollection} object from a {@link org.apache.sling.api.resource.Resource}.
* The Resource has the following properties:
*
* - name: A 'Name' of the type collection (mandatory)
* - description: A 'String' with the description text for this type collection (mandatory)
* - fqdn: A 'String' with the fully qualified domain name; A namespace like a java package (mandatory)
*
*
* The types collection will be populated with direct child Resources of the {{collectionResource}},
* which have the resourceType equal to the value of the {@link HApiUtil#RESOURCE_TYPE} property
*
* @param resolver The resource resolver
* @param collectionResource The sling Resource of the HApi type collection
* @return The HApiTypesCollection
* @throws RepositoryException
*/
HApiTypesCollection collectionFromResource(ResourceResolver resolver, Resource collectionResource) throws RepositoryException;
/**
*
Get a {@link HApiTypesCollection} object from a path String.
* {@see HApiUtil#collectionFromResource}
*
* @param resolver The resource resolver
* @param collectionPath The sling resource path of the HApi type collection
* @return The HApiTypesCollection
* @throws RepositoryException
*/
HApiTypesCollection collectionFromPath(ResourceResolver resolver, String collectionPath) throws RepositoryException;
/**
* Get a new instance of AttributeHelper for the type identified by 'type'
* @param resolver
* @param type See {@link #getTypeNode(org.apache.sling.api.resource.ResourceResolver, String)}
* for the format of the type identifier
* @return
* @throws RepositoryException
*/
MicrodataAttributeHelper getHelper(ResourceResolver resolver, String type) throws RepositoryException;
}