CQ/AEM Quick Bits

OSGI

1. Bundles = jar files + Manifest
2. Components = java classes
3. Services = special components used to interact between bundles
4. OSGi is a container in which any bundle can be added at runtime
5. Bundle jar files are dropped in folders called install to add them to CQ

Annotations: To add properties
@Properties({
@Property(name = "scheduler.expression", value = "*/5 * *
* * ?") ,// Every 5 seconds
@Property(name = "scheduler.expression.meta", options={
@PropertyOption(name="prop1", value="Option 1"),
@PropertyOption(name="prop2", value="Option 2")
}),
To read properties:
componentContext.getProperties().get(“prop-name”).getString();

Sling

1. URL Decomposition – get the contentPath, method and selectors from the
URL
2. Content Resolution – identify the content and access the
sling:resourceType Property
3. Resource Resolution - /apps or /libs
4. Script Resolution – selection+extn, selector, extn, method, default (same
name as component name)

1. Post using <form> will create new objects
2. To override point the form to currentNode <form
action=”<%=currentNode.getPath()%> .html” method =”post”/>
3. Create a <comp-name>.POST.jsp in the component folder
4. Handle all things in the JSP code

Interfaces:

1. CRX Explorer - http://localhost:4502/crx/explorer/browser/index.jsp
2. CRX DE Lite - http://localhost:4502/crx/de/index.jsp
3. Apache Felix - http://localhost:4502/system/console
4. Site admin - http://localhost:4502/siteadmin
5. etc/Tools - http://localhost:4502/miscadmin


Key Properties 

Entity Type Properties/Note
Template cq:Template allowedPaths, allowedParents,
sling:ResourceType
Page
Component
cq:Component sling:resourceSuperType, dialog,
design_dialog, cq:editConfig
Page cq:Page Is created in /content based on
template by end user
Global
Component
cq:Component sling:resourceSuperType,
componentGroup, allowedParents
Client Libs cq:ClientLibararyFolder dependencies, categories

Dialogs and Design Dialogs

1. Dialog must be named dialog
2. Design Dialog must be named design_dialog
3. All widgets should have be withing a node of type cq:widgetCollection
and it should be named items
4. In the widget the key properties are
i) xtype – the type of the component you want to use (textfield,
pathfield, richtext)
ii) fieldLabel – comes from the widgets API
iii) name (with ./<prop-name>) will create a property <prop-name>
in jcr under current node with value from the xtype as entered by
the user

API USAGE

1. properties.get(“prop-name”) – gets the property value from current node
2. currentStyle.get(“prop-name”) – gets globally stored value by
design_dialog
3. currentPage – reference of CQ Page API

// to get list of selectors in an array

String[] selectors =
slingRequest.getRequestPathInfo().getSelectors();
// to get a page from a path
Page page = pageManager.getPage(path);

// to get any containing page for a resource

Page page =
pageManager.getContainingPage(resourceResolver.getResource(pat
h));

// to get a session in JSP

final SlingRepository repos =
sling.getService(SlingRepository.class);
session = repos.loginAdministrative(null);

// to get query object and run a query

//build query using search in crx explorer or crxdelite
String stmt = "select * from cq:Page where jcr:path like
'/content/training/%' and contains(*, '" +
slingRequest.getParameter("q") + "') order by jcr:score desc";

// Get node from path

Node n = session.getItem(path); // where session = JCR session
session.save();
session.logout();
// add a property to node
Node n;
n.setProperty(“prop-name”,”value”);

//find WCM mode (if the author is in edit mode)

if(WCMMode.fromRequest(request) == WCMMode.EDIT)
//for publish instance it will be WCMMode.DISABLED

// to get repository

@Reference
SlingRepository repository;

// get session from repository

session = repository.loginAdministrative(null);

// creating a logger instance for a class ReplicationLogger

private static final Logger LOGGER =
LoggerFactory.getLogger(ReplicationLogger.class);

//to get pagemanager

@Reference
SlingRepository repositroy;
@Reference
ResourceResolverFactory resolverFactory;
Session session = null;
session = repositroy.loginAdministrative(null);
Map<String,Object> authInfo = new HashMap<String, Object>();
authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION,
session);
ResourceResolver resourceResolver =
resolverFactory.getAdministrativeResourceResolver(authInfo);
PageManager pageManager =
resourceResolver.adaptTo(PageManager.class);


Comments

Popular posts from this blog

AEM 6.3 Migration -osgi bundle whitelist error-osgi-service is NOT whitelisted to use SlingRepository.loginAdministrative