Sidekick Issue 0
Sidekick Issue 0
Sidekick Issue 0
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Sidekick</strong><br />
The digital magazine on Adobe Experience Manager | <strong>Issue</strong> 0<br />
Sending PhoneGap Push<br />
Notifications from Adobe<br />
Experience Manager<br />
Responsive Design with<br />
Adaptive Images<br />
ClientLibs Explained<br />
By Example<br />
Sightly -<br />
Beautiful Markup<br />
by Rob In der Maur<br />
by Vianney Baron<br />
by Feike Visser<br />
by Şenol Taş<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 1/2
<strong>Sidekick</strong><br />
▲<br />
Welcome to <strong>Sidekick</strong><br />
by Rob In der Maur (@ridmaur)<br />
Welcome to <strong>Sidekick</strong>. The first digital magazine for Adobe Experience Manager developers and architects. The title<br />
of the magazine refers to the toolbox authors use to build rich and engaging content. The same toolbox that developers<br />
are building, enhancing and/or modifying components for as part of the overall delivery of an Adobe Experience<br />
Manager implementation.<br />
But <strong>Sidekick</strong> actually refers as well to the more literal meaning of the word, being yet another, community driven,<br />
‘assistant’ to our developers and architectects on top of the communication and information that Adobe offers<br />
around Adobe Experience Manager.<br />
We believe there is an audience for a magazine that our beloved Adobe Experience Manager developers and architects<br />
can read while not being busy on the job. As a way of catching up with new ideas, concepts, implementations,<br />
etc., not necessarily part of the engagements they are working on right now.<br />
This magazine is inspired by a similar initiative started by Michael Chaize around web standards and technologies<br />
(HTML5, CSS, JSP) which is named Appliness, has established its footprint and is up to its 20th issue!<br />
The issue you are viewing on your tablet right now is named <strong>Issue</strong> 0 and that is for a particular reason. We consider<br />
this first issue a soft launch of the magazine, not yet supported by an infrastructure consisting of a web site, social<br />
channels, etc. It is almost like we are ‘dipping our toes in the water’ before going for a full launch. The feedback<br />
we receive (and we highly appreciate any feedback) will further define the content, delivery, and supporting<br />
infrastructure of the magazine.<br />
For now, enjoy this first issue of <strong>Sidekick</strong>.<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 2/2
<strong>Sidekick</strong><br />
Sending Push Notifications<br />
from Adobe Experience Manager<br />
by Rob In der Maur<br />
▼
CommuniQAEM<br />
<strong>Sidekick</strong><br />
▲<br />
It might be relevant to automatically push out a notification whenever a new piece of content is created<br />
within your AEM environment. This article is going to illustrate how you can combine the power of<br />
AEM workflows with the PhoneGap framework for building cross-device mobile applications.<br />
PhoneGap application<br />
Creating a PhoneGap application that can receive notifications is really beyond the scope of this<br />
publication. But, as usual, there are some good resources out there on the web, particularly Holly<br />
Schinsky’s articles titled Apple push notifications with PhoneGap and Android Push Notifications<br />
with PhoneGap. In this illustration we will only focus on the iOS side of the push notification space.<br />
Once you have your iOS application running on your mobile device, ready to receive notifications,<br />
an excellent way to test these out is using PushMeBaby, an OS X desktop application that allows you<br />
to send notifications to your mobile device. Be aware that you can not test your mobile application<br />
receiving notifications in the iOS simulator; it has to run on a hardware device!<br />
Push Notification Service<br />
Assuming we have the mobile application setup in place and actually working, the interesting bit in<br />
light of the theme of this publication is, obviously, to have it send notifications from our AEM platform.<br />
To invoke push notifications from AEM, we are going to make use of JavaPNS, a Java library to send<br />
notifications through the Apple Push Notification Service as well as Bouncy Castle Java cryptography<br />
API’s, as we need those to work with our iOS certificates.<br />
1. In CRXDELite, create a bundles folder underneath your application root folder.<br />
2. Right click on the bundles folder and select Create Bundle and give the bundle a symbolic<br />
name like com.adobe.demo.pn. This will create a com.adobe.demo.pn folder that contains a<br />
com.adobe.demo.pn.bnd node as well as a src<br />
folder.<br />
3. Create a libs sub folder underneath your bundles<br />
folder.<br />
4. Your src folder has been automatically set up with<br />
an Activator.java source file. At that same level<br />
create a new file node named <br />
java (which will be our interface) and an impl<br />
folder node. Within the impl folder create a<br />
file node (which will<br />
be our implementation). (play the video on the<br />
right to see how we could create a bundle within<br />
CRXDELite).<br />
Play.<br />
Video 1. Create a bundle in CRXDE Lite<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 2/5
<strong>Sidekick</strong><br />
▲<br />
5. To ensure we can use these libraries in our bundle, update the com.adobe.demo.pn.bnd file to look<br />
like<br />
<br />
javapns.test.*<br />
Import-Package: *<br />
# Private-Package: com.adobe.demo.pn<br />
Include-Resource:<br />
<br />
Bundle-Description:<br />
Bundle-SymbolicName: com.adobe.demo.pn<br />
Bundle-Version: 1.0.0-SNAPSHOT<br />
Bundle-Activator: com.adobe.demo.pn.Activator<br />
6. Our code in is straightforward as it is simply the definition of our interface.<br />
package com.adobe.demo.pn;<br />
import java.util.List;<br />
<br />
<br />
{<br />
<br />
throws Exception;<br />
}<br />
7. Our code in is of more interest.<br />
package com.adobe.demo.pn.impl;<br />
// lots of imports<br />
import ...<br />
<br />
<br />
<br />
{<br />
<br />
<br />
@Reference<br />
private SlingRepository repository;<br />
@Reference<br />
<br />
private Session adminSession;<br />
private ResourceResolver resourceResolver;<br />
<br />
@Activate<br />
<br />
{<br />
try<br />
{<br />
<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 3/5
<strong>Sidekick</strong><br />
▲<br />
resourceResolver = resourceResolverFactory.getResourceResolver<br />
(adminSession);<br />
Here we import the APN certificate<br />
InputStream is = resourceResolver.<br />
getResource(“/apps/geometrixx/bundles/apn-cert.p12”).adaptTo(InputStream.class);<br />
<br />
<br />
}<br />
<br />
{<br />
<br />
e.getStackTrace());<br />
}<br />
}<br />
<br />
<br />
{<br />
<br />
<br />
return result;<br />
}<br />
}<br />
Here we send the notification<br />
8. As part of the activation of the bundle, we actually<br />
load our certificate, which we subsequently use<br />
when sending the actual push alert. Note how<br />
we have not worried too much about password<br />
security here...<br />
9. Talking about certificates and the required libraries<br />
for our bundle; the best way to get these in your<br />
bundle is using CRXDE rather than CRXDE Lite,<br />
as CRXDE allows you to simple import (or even<br />
drag and drop) external files into your bundle /<br />
application (as shown in the video on the right).<br />
This is a bit more convoluted in CRXDE Lite.<br />
Push Notification Workflow<br />
Play.<br />
Video 2. Import files in CRXDE<br />
The final bit to our integration is to hook it all together as part of a workflow. Which we then can invoke<br />
from any page in our content.<br />
In order to do that, we need to build a custom workflow step that uses our push notification service<br />
(bundle) and then use that step in a workflow model.<br />
The workflow step we will define as an ECMAScript in <br />
ecma and could look like<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 4/5
<strong>Sidekick</strong><br />
▲<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
{<br />
<br />
<br />
<br />
<br />
<br />
}<br />
<br />
And then we are going to use this workflow functionality in a workflow by adding a process step and,<br />
as part of the definition of that step, point to our ECMAScript.<br />
On each page, when going to the Workflow tab in the <strong>Sidekick</strong>, we can kick off our Send Notifications<br />
workflow and it will send a push notification to our device containing the page title and page description.<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 5/5
<strong>Sidekick</strong><br />
Responsive Design<br />
with Adaptive Images<br />
by Vianney Baron<br />
▼
<strong>Sidekick</strong><br />
▲<br />
As you know CQ 5.6 has recently been released, and if you’ve seen demo’s or read the release notes<br />
you will have noticed that this new version offers support for responsive design. So what does this<br />
mean exactly? And how can you leverage the new features to ensure your website is responsive as<br />
well?<br />
Responsive Design, a clarification<br />
First things first, it’s important to define what responsive design means exactly. There are loads of<br />
resources available on the net of course, but I find that this small sample illustrates the concept really<br />
well: it’s really just about making sure your website design can adapt to various resolution and devices<br />
and offer an optimal user experience in all cases.<br />
So how is this supported in CQ 5.6? With two main features:<br />
• Responsive design preview in authoring<br />
• Geometrixx Media<br />
Let’s explore these and see how the magic happens.<br />
Responsive Preview<br />
When authoring content in CQ 5.6 you will notice that most features that you were used to in previous<br />
version are still there, including the small magnifying glass allowing you to switch to Preview mode.<br />
However when you click you will immediately notice a small difference.<br />
We can now select the device we’re targeting and adapt the user experience accordingly;<br />
this is really convenient, as it saves the hassle of resizing the browser window manually.<br />
Note that the list of available devices is just indicative, you can very simply add new devices<br />
Play.<br />
Video 1. Responsive design preview.<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 2/4
<strong>Sidekick</strong><br />
▲<br />
or modify the existing ones, but it’s not the topic of this post (just a small hint: look at<br />
/libs/wcm/mobile/components/emulators on your CQ 5.6 instance).<br />
Of course I did not choose a random website. This little guy is the new member of the Geometrixx<br />
family: Geometrixx Media, this website is designed for customers in the media and publishing space,<br />
and it illustrates a number of new 5.6 features, including responsive design. Play the video on the<br />
right to explore how the website looks on various devices.<br />
Now let’s see how we achieve this in Geometrixx Media, and how you can leverage this sample to<br />
kick off your responsive design work. The two main concepts here are:<br />
• Media queries<br />
• Adaptive image component<br />
Nowadays most designers are familiar with media queries, this CSS 3 feature allows us to define<br />
different styles for different screen sizes. This is the corner stone of any responsive website.<br />
For instance if you open the Geometrixx Media design you will notice several CSS stylesheets. And<br />
each of these starts with this statement:<br />
@media (max-width: 480px) {<br />
And that’s pretty much all you need to know to start working with media queries…<br />
Adaptive Image Component<br />
Next let’s have a look at the adaptive image component. As you’ve probably noticed the layout is not<br />
the only thing that changes when we resize Geometrixx Media. Images are also resized on-the-fly,<br />
using the adaptive image component.<br />
Figure 1. Overview of CSS stylesheets.<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 3/4
<strong>Sidekick</strong><br />
▲<br />
If you look at the actual code of the component (under /apps/geometrixx-media/components/<br />
adaptive-image) you will see that all we do here is use media queries to load the right image<br />
depending on the screen resolution.<br />
Images are then suffixed with specific selectors to obtain the right size, for example: myImage.<br />
adapt.620.high.jpg will generate a rendition of “myImage.jpg” with a with of 620px.<br />
The actual magic happens in a servlet, the code of which is available here:<br />
/apps/geometrixx-commons/src/core/src/main/java/info/geometrixx/<br />
commons/impl/servlets/AdaptiveImageComponentServlet.java<br />
It’s simply extends the AbstractImageServlet to produce the new image in real time, based on a<br />
pre-defined list of widths that is configured in the Felix console (as to avoid hacks, like specifying a<br />
huge resolution, to slow down the server).<br />
To ensure the right image is reloaded in real time when resizing the browser a couple of JS libraries<br />
are used, these can be found here:<br />
• /apps/geometrixx-media/components/adaptive-image/clientlibs/js/<br />
which is used to test if a media query applies;<br />
• /apps/geometrixx-media/components/adaptive-image/clientlibs/js/<br />
which mimics the Picture element proposed for the HTML5 spec.<br />
Figure 2. OSGi configuration panel for adaptive image component servlet.<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 4/4
<strong>Sidekick</strong><br />
ClientLibs Explained By Example<br />
by Feike Visser<br />
▼
CommuniQAEM<br />
<strong>Sidekick</strong><br />
▲<br />
In this article I will go through the basic functionality that the ClientLibraryFolder offers, and how<br />
you can utilize that with the tag.<br />
The clientlib functionality will manage all your Javascript and CSS resources in your application. It takes<br />
cares of dependency management, merging files and minifying content.<br />
The following application scenarios will be explained :<br />
• Multiple components with their own Javascript and CSS files.<br />
• Global Javascript and CSS files.<br />
• /apps folder is not available via the dispatcher.<br />
• CSS resources have to go in the , Javascript resources at the end of the page.<br />
• Resources need to be minified.<br />
• Some resources need to be merged.<br />
Step 1: Creating components and clientlib nodes<br />
To set up our example, create a clientlibsexplained application in CRXDE Lite and add the usual<br />
components and templates folder to your application structure.<br />
In your components folder you create a contentpage component. In your templates folder, you<br />
create a contentpage template that uses the contentpage component as its sling:resourceType.<br />
Next you create 3 additional components: MyFirstComponent, MySecondComponent and<br />
MyThirdComponent. E.g. something like:<br />
Figure 1. Initial component structure.<br />
Next we are going to add a clientlib node of type cq:ClientLibraryFolder, inside each of these<br />
node in order to store the Javascript and CSS resources<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 2/7
<strong>Sidekick</strong><br />
▲<br />
Figure 2. Create Node dialog for clientlib.<br />
Add a property to every clientlib node called categories of type String[] with the single value of<br />
myproject.components. To get a String[] type click the Multi button.<br />
Your components-folder will look now like this:<br />
Figure 3. Propertes of clientlib node.<br />
Step 2: Adding Javascript and CSS files<br />
Now we will add some files to the clientlib folder of the component. As an example, for the first<br />
component:<br />
CSS (first.css):<br />
.firstContainer {<br />
margin-top:10px;<br />
}<br />
Javascript (first.js):<br />
/*<br />
* This is the comment of the function<br />
*/<br />
function getNameFirst() {<br />
// return the name<br />
return "some value";}<br />
js.txt (refers to all the Javascript resources of the clientlib)<br />
first.js<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 3/7
<strong>Sidekick</strong><br />
▲<br />
css.txt (refers to all the CSS resources of the clientlib)<br />
first.css<br />
Do the same for the second component, where names and values should be changed where appropriate.<br />
Your components folder will now look like this:<br />
Figure 4. Final component structure.<br />
The configuration of the components is now finished.<br />
Step 3: Using <br />
Now the components are finished we can now use to write out the<br />
references inside the of our contentpage component. You can also choose to write out certain<br />
references in other places in the page, for example some Javascript at the end of the page.<br />
We start with putting the following into the <br />
<br />
<br />
Note that myproject.components is the value of the categories properties of the clientlib node.<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 4/7
<strong>Sidekick</strong><br />
▲<br />
This results in the following HTML output whenever we create a new page:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
This has a few downsides though:<br />
• The resources are retrieved from /apps.<br />
• Six server calls are to fetch the resources.<br />
• Application structure is exposed.<br />
Step 4: Redirect and Merge<br />
What we want is that the user gets the resources from /etc/designs/, so that /apps can<br />
be closed for the production configuration. And on top of that we want the resources to be merged into<br />
a single .js/.css reference.<br />
Create a new folder aproject in /etc/designs, then create the structure as shown below. The js.txt<br />
and css.txt should be empty files.<br />
The clientlib node has the following properties:<br />
Figure 5. client lib structure moved to design.<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 5/7
<strong>Sidekick</strong><br />
▲<br />
Figure 6. Properties for client lib node (including embed property).<br />
With the embed property it embeds all the resources of myproject.components.<br />
Now change the attributes in the section to:<br />
<br />
<br />
This results now in the following HTML output:<br />
<br />
<br />
<br />
If you open these files you will see that the three Javascript/CSS resources are merged into one file.<br />
And although the resources are located in the /apps folder all references are now done via the /etc/<br />
designs folder.<br />
Step 5: Dependencies<br />
Another property you can add to the clientlib node is dependencies; this way you can define<br />
dependencies between client libraries.<br />
Let’s add a dependency on cq.jquery:<br />
Figure 7. Adding dependencies property to clientlib node.<br />
When you now reload the page the dependency is created as part of your HTML:<br />
<br />
<br />
Step 6: Minify and GZip<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 6/7
<strong>Sidekick</strong><br />
▲<br />
To deliver a better performance you can enable Minify and Gzip for the Day CQ HTML Library Manager<br />
in the Felix Configuration console. These settings are recommended for production installations.<br />
Figure 8. Configuring minify and gzip in HTML Library Manager..<br />
When you now look at this resource /etc/designs/aproject/clientlib.js, it results in this:<br />
function getNameThird(){return "some value"<br />
}function getNameSecond(){return "some value"<br />
}function getNameFirst(){return "some value"<br />
};<br />
So all comments and spacing are removed to save download-time.<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 7/7
<strong>Sidekick</strong><br />
Sightly - Beautiful Markup<br />
by Şenol Taş<br />
▼
CommuniQAEM<br />
<strong>Sidekick</strong><br />
▲<br />
Behind The Scenes<br />
The remainder of this article will explain a lot more on what exactly Sightly is, but as a reference it<br />
might be valuable to know this is just one of the initiatives where, within Adobe, we are pushing the<br />
boundaries while 'drinking our own champagne'. To give that a little bit more perspective, watch the<br />
first episode in my video podcasts (posted on Youtube), that talks about 'Adobe@Adobe - Behind The<br />
Scenes'.<br />
Play.<br />
Video 1: The Refactor - Behind The Scenes<br />
sight·ly /sītlē/ (adjective: pleasing to the eye...)<br />
Sightly is an HTML template library with a strong focus on security and programming language<br />
independence, setting a new standard for templating. The template functionality is added to the HTML<br />
by using data attributes, which keeps the markup valid, readable and maintainable. Used in Adobe<br />
Experience Manager, Sightly offers a highly productive enterprise-level web framework with a clear<br />
separation of concerns, allowing Web and Java developers to efficiently work together.<br />
Currently, Sightly is still work in progress and more a concept than anything else, but we just want you<br />
to have a first 'sight' on it...<br />
Goals<br />
The essential things Slightly (wants to) offer(s) out of the box are:<br />
• Security: through the library automatic contextual XSS<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 2/5
<strong>Sidekick</strong><br />
▲<br />
protection and URL externalization is provided;<br />
• Less coding: enforcing separation of concerns between logic and markup;<br />
• Standards adoption: writing readable and valid HTML5 through data-attribute notations;<br />
• Extensibility: a straight forward API for logic;<br />
• Intuitive: a clear, simple and restricted future set.<br />
Vision<br />
The long term vision of what our engineers are aiming for with Sightly is:<br />
• Open Source Contribution: Github and Apache license;<br />
• Programming Language Independence: Javascript lexer with a<br />
plugin system for the output of a code generator;<br />
• Multi-tenant capability: supporting a 'thrust model' in order<br />
to offer a possibility to sandbox components;<br />
• Standards adoption: let Sightly grow beyond Adobe Experience Manager and Adobe;<br />
• Framework support: add capabilities like backend to frontend data binding, forms handling, etc.<br />
Architecture<br />
The high-level diagram below shows that Sightly can use the same Javascript front-end for compiling<br />
to different program languages. Only the code generator from the intermediate representation needs<br />
to be built specifically for the different environments.<br />
HTML Template Library<br />
In reality, Sightly is just the 'marketing' name for an HTML Template Library (HTL); an AEM templating<br />
engine and language implementation. HTL endeavours to supersede JSP as the scripting language for<br />
AEM components. It strives to clearly separate presentation and logic. Security measures, such as XSS<br />
prevention are automatically applied. HTL is purely based on HTML5, allowing 3rd party agencies to<br />
focus on design specifics of an AEM project without having to have deep AEM knowledge.<br />
HTL has two main concepts: Block Elements and Expression Language.<br />
HTL Block Elements<br />
An HTL block element is using the an HTML data like attribute; any tag containing the data-htlpluginName="value"<br />
will be identified as an HTL block element.<br />
some content<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 3/5
<strong>Sidekick</strong><br />
▲<br />
For example one can use the data-htl-test attribute to test an expression and based on the outcome,<br />
show or not show content. In the examples below, the block of content is shown when the expression<br />
evaluates to TRUE.<br />
<br />
This Page is in Edit Mode<br />
<br />
This Page is NOT Edit Mode<br />
<br />
This page is not published or in preview mode<br />
<br />
Show the Title<br />
With the data-htl-list attribute one can iterate of any kind of collection (List, Map, Set, Enumeration)<br />
and display the child elements; again very easy.<br />
<br />
${item.name}<br />
<br />
HTL Expression Language<br />
In the previous examples you saw the ${ } syntax, both as the value of an data-htl-PLUGINNAME<br />
attribute expression as well as part of the resulting output. The field expressions in the HTL Expression<br />
Language are very powerful. They allow to:<br />
• easily read properties of ValueMaps, e.g. ${properties.title} for title property<br />
or even sling resource types, like ${properties.sling:resourceType}.<br />
• use the following common AEM variables by default: resource, request,<br />
response, properties, wcmmode, e.g. ${wcmmode.edit}<br />
• specify options, like defaults e.g. ${properties.title default="string value"}<br />
• 'and' and 'or' expressions, e.g. ${properties.title OR properties.name}<br />
Don't mess with my markup!<br />
Play the video below for a more in-depth information on Sightly..<br />
▼<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 4/5
<strong>Sidekick</strong><br />
▲<br />
Play.<br />
Video 2: Don't mess with my markup!<br />
<strong>Sidekick</strong> | <strong>Issue</strong> 0 | page 5/5