Create a Repository instance
Although there are different ways to connect to a repository and establish a connection, this development article uses a static method that belongs to the org.apache.jackrabbit.commons.JcrUtils
class. The name of the method is getRepository
. This method takes a string parameter that represents the URL of the Adobe CQ server. For example http://localhost:4503/crx/server
.
The getRepository
method returns a Repository
instance, as shown in the following code example.
Create a Session instance
The Repository
instance represents the CRX repository. You use the Repository
instance to establish a session with the repository. To create a session, invoke the Repository
instance’s login
method and pass a javax.jcr.SimpleCredentials
object. The login
method returns a javax.jcr.Session
instance.
You create a SimpleCredentials
object by using its constructor and passing the following string values:
- The user name;
- The corresponding password
When passing the second parameter, call the String object’s toCharArray
method. The following code shows how to call the login
method that returns a javax.jcr.Sessioninstance
.
Create a Node instance
Use a Session
instance to create a javax.jcr.Node
instance. A Node
instance lets you perform node operations. For example, you can create a new node. To create a node that represents the root node, invoke the Session
instance’s getRootNode
method, as shown in the following line of code.
Once you create a Node
instance, you can perform tasks such as creating another node and adding a value to it. For example, the following code creates two nodes and adds a value to the second node.
Retrieve Node Values
To retrieve a node and its value, invoke the Node
instance’s getNode
method and pass a string value that represents the fully-qualified path to the node. Consider the node structure created in the previous code example. To retrieve the day node, specify adobe/day, as shown in the following code:
Create nodes in the Adobe CQ Repository
The following Java code example represents a Java class that connects to Adobe CQ, creates a Session
instance, and adds new nodes. A node is assigned a data value and then the value of the node and its path is written out to the console. When you are done with the Session, be sure to log out.
After you run the full code example and create the nodes, you can view the new nodes in the CRXDE Lite, as shown in the following illustration.
The Perfect Blend: A New Era of Collaboration with AEM and Workfront
Adobe Customer Success Webinars
Wednesday, Apr 2, 5:00 PM UTC
Explore how Adobe Experience Manager and Workfront integrate to help teams move from ideation to delivery without the usual bottlenecks, ensuring content is organized, on-brand, and ready to go live faster.
RegisterB2B Reimagined: Transforming Go-to-Market Strategies for Profitable Growth
B2B brands are facing a digital revolution. Buyers expect hyper-relevant content and self-service, while internally AI is transforming...
Wed, Mar 19, 1:00 PM PDT (8:00 PM UTC)
Driving Marketing Agility and Scale: Transforming your Content Supply Chain with AI
Marketers everywhere are feeling the pressure to deliver impactful campaigns faster and at greater scale. This Strategy Keynote explores...
Tue, Mar 18, 2:30 PM PDT (9:30 PM UTC)
Connect with Experience League at Summit!
Get front-row access to top sessions, hands-on activities, and networking—wherever you are!
Learn more