Author Archive: sbhaskar

Translating strings in a CQ component to user’s preferred language

Adobe CQ provides an easy way to translate strings (fieldLabel) in a component. Inside the component folder, create the i18n sling folder. Then create language folders (sling:folder)  and assign  Mixins of mix:language type. In the language folder, add the jcr:language property and assign the language code.

Dake Smith blog, Internationalization within Sling (and CQ), has some great inputs.

In the image displayed below, the Localization component has two fields: first name and last name. They are localized in two languages: Spanish (es) and French (fr).

hierarchy

In each language folder, create two nodes of sling:MessageEntry type. In the first node, add Slig:key and Sling:Message as shown above. This is for the first string (First Name.) Repeat this for the second node.

After you are done with creating MessageEntry nodes for all the strings that you have in the component, go to the items in the dialog node, and change the fieldLabel value to the slingKey value you defined in the language node.

first_name

To test, go to useradmin, select the user. In the Preferences tab, change the language to the language of your choice.

See the component in French as displayed below:

dialog

 

 

Creating a Facebook component in Adobe CQ

In this blog entry, we will see how to create a component that displays the Facebook Like button.
A Facebook Like button needs no explanation. It allows a user to like your company’s Facebook page and also keeps a record of the number of people “Liked” the page.
facebook_like

Facebook provides great documentation on how to add this into your website. It’s very much straightforward. Get the code from Facebook’s Configurator. If you add the code to a webpage that is available locally and test it, it won’t work. If you are testing the code, ensure that you uploaded the webpage in a server.

Edit the template to include the following script:

<div id="fb-root">
</div>
<script>(function(d, s, id) {
 var js, fjs = d.getElementsByTagName(s)[0];
 if (d.getElementById(id)) return;
 js = d.createElement(s); js.id = id;
 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
 fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

(Don’t ask me for details. I got it from Facebook. :) )

Now create a component, Facebook. We need only one field that’s configurable. It’s for providing the Facebook page URL of your company.
See the screenshot below that depicts the node hierarchy. (The component development is explained in detail in one of my previous posts.)

node_hierarchy

Following is the JavaServer page associated with the component. (facebook.jsp)

<%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<%
 String facebook=properties.get("facebook", "Enter the product page.");
 if (facebook=="Enter the product page.")
 {
 out.write(facebook);
 }
out.write("<p><div class=\"fb-like\" id=\"fb\" data-href=\""+ facebook +"\" data-send=\"false\" data-width=\"450\" data-show-faces=\"true\"></div></p>");
%>

Drag-and-drop the component to the web page. Right-click, select Edit, and provide the Facebook page’s URL.
Note that the component is not displayed at this moment. Close the page and open it again to see the component. (I think it has something to do with the Facebook implementation; I will experiment more later.)

Displaying the newly created component in the sidekick of Adobe CQ

By default, the sidekick doesn’t display the newly created components. You need to enable them explicitly in a CQ author instance.

  1. Create the component.
  2. Using SiteAdmin, open the page that you want to edit in the Author instance.
  3. From the sidekick, click the Design tab.
  4. In the Design of Paragraph tab that appears, click Edit.

    design

  5. Find the component based on the ComponentGroup property you defined and enable it.
    design_par

 

Developing a Quiz component using Adobe CQ

In this blog entry, I will show you how to develop a CQ component. A CQ component, typically, has two parts. The first one is the CQ widget – the Graphical User  Interface (GUI) in which an author adds content. Second one is a script; in this example, a JSP page that defines the logic that you want to apply to the content.

You will see how to develop a widget and get the data included in the widget using the script. We can demonstrate the same using a “Hello World” example; there is no fun in developing such a component!! :)

Here, we are going to develop a Quiz component. An author can enter a question and multiple possible answers to check the mastery of the reader. When the reader selects an answer and submits, the appropriate message appears in the page. Following is the screenshot of the Quiz component in the Author instance.

component1

Basic understanding of the following is a prerequisite:

  • CQ Author and Publisher instance (You should ideally have them running in your machine.)
  • CQ templates (You should have a template that you can modify for this example.)
  • JavaScript
  • Java Server Pages (JSP)

I will not provide details on how to create a template. Refer to the  “How to Create a Fully Featured Internet Website” document that has lots of good information on how to accomplish this task.

Create the component node

  1. Login to CRXDE Lite as an admin.
  2. Inside the app folder, go to your website directory and locate the Components folder.
  3. Right-click the folder and then select Create Component. Create a component, question, with the following details:
    allowedParents = */parsys
    resourceSuperType = foundation/components/page

Develop GUI of the component

In the Quiz component, we need six text fields. First one for the question, four text fields for various options, and the sixth one is for the author to enter the correct answer. The first step to develop GUI of the component is to add a Dialog node that can hold various elements such as text boxes.

  1. Right-click the question node and select Create Dialog.
  2. Right-click the dialog node, and add another node with the following properties:
    name: items
    Type: cq:WidgetCollection
  3. Right-click and create a Panel, Tab1, with the following properties. We need only one tab in the GUI.
    name: Tab1
    Type: cq:Panel
  4. Right-click and add another node of widget collection that can hold the text fields.
    Name: items
    Type: cq:WidgetCollection
  5. Now, let us add the text fields. Right-click and add a node.
    Name: question
    Type: cq:Widget
  6. Add the following properties manually.
    fieldLabel – String – Question
    name – String – ./question
    xtype – String – textfield
  7. Repeat step 5 and 6 for the following:
    optionA
    optionB
    optionC
    optionD
    answer

Ensure that you changed the name and fieldLabel based on the text field. After completing this operation, this is what your node hierarchy looks like:

node_hierarchy

 

Update the JSP file to include the logic to process the content

Update the content of the question.jsp page as shown below:

<%@include file=”/libs/foundation/global.jsp”%>
<%@page session=”false” %>
<%
<!– section1 –>
String question=properties.get(“question”, “Type the question”);
String optionA=properties.get(“optionA”, “Type the option A”);
String optionB=properties.get(“optionB”, “Type the option B”);
String optionC=properties.get(“optionC”, “Type the option C”);
String optionD=properties.get(“optionD”, “Type the option D”);
String answer=properties.get(“answer”, “Type the answer”);
<!– section2 –>
out.write(“<FORM><B>”+question+”</B><P>”);
out.write(“<INPUT TYPE=hidden name=\”answer\” VALUE=\””+answer+”\”>”);
out.write(“<INPUT TYPE=\”radio\” NAME=\”options\” VALUE=\””+optionA+”\”>”+optionA+”<br>”);
out.write(“<INPUT TYPE=\”radio\” NAME=\”options\” VALUE=\””+optionB+”\”>”+optionB+”<br>”);
out.write(“<INPUT TYPE=\”radio\” NAME=\”options\” VALUE=\””+optionC+”\”>”+optionC+”<br>”);
out.write(“<INPUT TYPE=\”radio\” NAME=\”options\” VALUE=\””+optionD+”\”>”+optionD+”<P> “);
out.write(“<INPUT TYPE=\”button\” NAME=\”Validate\” VALUE=\”Validate\” onClick=\”checkAnswer(this.form)\”>”);
out.write(“</FORM>”);
%>

If you know the basics of JSP, you have already figured out what we are doing.

String question=properties.get(“question”, “Type the question”);

In section 1, we assign the value provided in the question text box to a string variable.
properties.get(“question”, “Type the question”) method gets data in the question field and the second argument is the default value that an author sees while editing the component.

The second section in the code is nothing but a form in a JavaScript. We dynamically change the values and labels using the inputs from the author. When a reader, submits an answer, we call a method checkAnwser(). We have not yet defined this method in the JSP page. It is defined in the template page.

Include the script in your template

You can include JavaScript functions that you use in the header of your template. The following code checks the correct answer and provides the user appropriate error message.

<head> <script type=”text/javascript”>
function checkAnswer(form) { for (var i = 0; i < form.options.length; i++) { if (form.options[i].checked)
{
break
}
}
if (form.options[i].value == form.answer.value)
{ alert(“You selected the correct answer!!”) } else { alert(“You selected an incorrect answer!!”) }
}
</script> </head>
 

Add the component in the Author instance

  1. Create a page with the template that you used.
  2. From the side-kick, drag-and-drop the Question component to the page.
  3. Right-click the component and click Edit.
  4. Enter the details and click OK.

edit

The question and options appear in your page. Now publish the page to see it in the Author instance.

Creating PDF output in Adobe CQ

When you author in Adobe CQ, you may need to create a pdf version of the page. PDF pages would be helpful for users if they need to read the content when they are not connected to Internet.

Adobe CQ allows you to create the pdf version of the page using an OSGi bundle, PDF rewriter. After activating the content, call the page with the .pdf extension in the Author instance. The call will be automatically resolved to provide you with the pdf view of the content.

This blog entry explains how to create a pdf output using Adobe CQ 5.5 QuickStart.

It is assumed that:

  • Author instance is installed on port 4502 on the local machine.
  • Writer instance is installed on port 4503 on the local machine.

Check if PDF Writer bundle is installed and it’s Active in your instance.

  1. Login to Adobe CQ Web Console Configuration.  (http://localhost:4502/system/console/configMgr)
  2. Select OSGi > Bundles.
  3. Filter for Day Communique 5 Rewriter.
  4. Ensure that the bundle is installed and is Active.
    pdf_bundle

Update the XSLT based on your component

While generating a pdf from html, you need to define the XSLT that transforms each element (component) to pdf format. Basically, you need to map all the components to a new style.
By default, Adobe CQ uses the XSLT defined in the following path: /libs/wcm/core/content/pdf/page2fo.xsl
Assume that you use the image component that inherits foundation/components/textimage. And, in the author instance, you have inserted an image using the component. To include the image in the pdf view, add the following in the XSLT.

<xsl:template match="*[contains(@sling:resourceType,'foundation/components/textimage')]">
 <xsl:if test="@jcr:title">
 <fo:block font-size="18pt" space-before.optimum="12pt" text-align="start"><xsl:value-of select="@jcr:title"/></fo:block>
 </xsl:if>
 <xsl:if test="file">
 <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/file" content-width="100pt" content-height="100pt"/></fo:block>
 </xsl:if>
 <xsl:if test="@FileRef">
 <fo:block><fo:external-graphic src="sling:/{@FileRef}" content-width="100pt" content-height="100pt"/></fo:block>
 </xsl:if>
 <xsl:if test="image/@fileReference">
 <fo:block><fo:external-graphic src="sling:/{$resource}/par/{local-name()}/image.img.png" content-width="100pt" content-height="100pt"/></fo:block>
 </xsl:if>
 <fo:block font-size="12pt" space-before.optimum="12pt" text-align="start"><xsl:apply-templates select="text"/></fo:block>
 </xsl:template>

Ensure that every component you use in the page has a corresponding XSLT match.

Replicate the XSLT file to the publish instance

This is an important step, since the author instance still has the outdated version of XSLT. You need to activate the XSLT that you updated and make the most updated version available in your author instance.

  1. Login to SiteAdmin. (http://localhost:4502/siteadmin)
  2. Click Tools and in the left navigator select Replication > Activate Tree.
  3. Double-click Activate Tree.
  4. Provide the start path as /libs/wcm/core/content/pdf/page2fo.xsl
  5. Click Dry Run to see the file that is updated after the last Activation.
  6. Select the page2fo.xsl file and click Activate.
    activate_tree

Three mistakes I made while creating a website using Adobe CQ

  1. While activating (publishing) pages in the new website, I didn’t activate the template, components, and style folders.And, I got a blank screen without any content. Content in the Live CQ pages checks for the corresponding JSP page to render the content. If these pages are not activated, the page won’t display anything. Activating a page can be done in the Website tab of the Siteadmin. However, to activate templates, components, and so on, go to the Tools tab. Then, select Replication in the left-side pane and double-click Activate Tree. Search for the node that you want to activate. For example, if you want to activate a component, go to the apps folder and then select the corresponding folder and activate all components in which you added the content.
  2. New components in the sidekick were not enabled explicitly. And, in the sidekick menu, I couldn’t see the components that I created when I was in the Edit mode.Create a page that uses the template that you created. Click the Design icon in the sidekick. The Design of Par tab appears. Select the Edit button. The Allowed Components list displays the components that you created. Select the components to display in the Edit mode.
  3. Sidekick is not enabled because of the script errors in newly created components.You can figure out if it’s an issue with the component by creating a new folder in the apps directory and then drag and drop the newly created components to it. Do it one-by-one while checking the authoring page to see the sidekick.

Flash Player 11.4 is available for download

The latest Flash Player version (11.4.402.265) is available. Please go to Adobe site to update Flash Player.

Flash Player 11.3 issues on Mozilla Firefox

A new version of Flash Player plug-in is available today (June 21st). The latest version is 11.3.300.262.
Go to http://get.adobe.com/flashplayer/ to get the latest version.

This version is for Mozilla Firefox and Safari.
If you have any issues with Flash Player 11.3 on Mozilla Firefox, see Issues | Flash Player 11.3 | Mozilla Firefox.

 If you have issues with installing Flash Player, please post the issue @ http://forums.adobe.com/community/flashplayer/installing_flashplayer.

Fireworks CS6 What’s New

Here is the link: http://helpx.adobe.com/fireworks/using/whats-new-cs6.html
Help & support page: http://helpx.adobe.com/fireworks.html
Archive of old docs: http://helpx.adobe.com/fireworks/archive.html

FrameMaker 10 ACE is live

Check your mastery by registering @ www.pearsonvue.com/adobe/exams/