Java™ API Best Practices
Adobe Experience Manager (AEM) is built on a rich open-source software stack that exposes many Java™ APIs for use during development. This article explores the major APIs and when and why they should be used.
AEM is built on four primary Java™ API sets.
Adobe Experience Manager (AEM)
- Product abstractions such as pages, assets, workflows, etc.
Apache Sling Web Framework
- REST and resource-based abstractions such as resources, value maps, and HTTP requests.
JCR (Apache Jackrabbit Oak)
- Data and content abstractions such as node, properties, and sessions.
OSGi (Apache Felix)
- OSGi application container abstractions such as services and (OSGi) components.
The general rule is to prefer the APIs/abstractions the following order:
- AEM
- Sling
- JCR
- OSGi
AEM APIs provide abstractions and functionality specific to productized use cases.
For example, AEM’s PageManager and Page APIs provide abstractions for cq:Page nodes in AEM that represent web pages.
While these nodes are available via Sling APIs as Resources, and JCR APIs as Nodes, AEM’s APIs provide abstractions for common use cases. Using the AEM APIs ensures consistent behavior between AEM the product, and customizations and extensions to AEM.
com.adobe.cq -supports product use casescom.adobe.granite -cross-product platform use-cases, such as workflow or tasks (which are used across products: AEM Assets, Sites, and so on)com.day.cq -contains “original” APIs. These APIs address core abstractions and functionalities that existed before and/or around Adobe’s acquisition of Day CQ.
Accessing JCR nodes as Sling Resources and accessing their data via ValueMaps.
Providing security context via the ResourceResolver.
Creating and removing resources via ResourceResolver’s create/move/copy/delete methods.
Updating properties via the ModifiableValueMap.
Building request processing building blocks
Asynchronous work processing building blocks
The JCR (Java™ Content Repository) 2.0 APIs is part of a specification for JCR implementations (in the case of AEM, Apache Jackrabbit Oak). All JCR implementation must conform to and implement these APIs, and thus, is the lowest level API for interacting with AEM’s content.
No comments:
Post a Comment