-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateNodeHeirarchy.java
68 lines (63 loc) · 1.75 KB
/
CreateNodeHeirarchy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.standalone.aem;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import com.standalone.aem.connect.Login;
/**
* The Class CreateNodeHeirarchy. Simple standalone class to create some pages
*
* @author sudheerdvn
*/
public class CreateNodeHeirarchy {
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Session session = Login.getSession(null);
System.out.println("session is :" + session);
if (null != session) {
createNodes(session);
}
}
/**
* Creates the nodes.
*
* @param session
* the session
*/
private static void createNodes(Session session) {
try {
Node node = session.getNode("/content/aem-flash");
if (null != node && node.hasNode("en")) {
System.out.println(node.getPath());
Node enNode = node.getNode("en");
if (null != enNode) {
System.out.println(enNode.getPath());
Node aboutUsPage = enNode.addNode("about-us", "cq:Page");
if (null != aboutUsPage) {
System.out.println(aboutUsPage.getPath());
Node jcrContent = aboutUsPage.addNode("jcr:content", "cq:PageContent");
if (null != jcrContent) {
jcrContent.setProperty("cq:template",
"/conf/aem-flash/settings/wcm/templates/content-page");
jcrContent.setProperty("sling:resourceType", "aem-flash/components/structure/page");
jcrContent.setProperty("jcr:title", "About Us");
}
}
session.save();
System.out.println("Node created succesfully");
}
}
} catch (PathNotFoundException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
} finally {
session.logout();
}
}
}