What’s my CQ WCM mode?

CQ offers you 4 different type of WCM modes: edit, preview, design and disabled. The first three are actually different modes while the forth is when none of them is available and, at the end, always represent the situation on the publish site.

Differentiate on the Java side is very easy as it provides java API and it provides Javascript API for doing it as well. Nevertheless the same object that gives you the mode is not (and should not be) available on the publish which will always end in ifs here and there.

This script should help you and it should be possible to drop it as part of your clientlibs and ready to be used for he use case.

Something very simple that hopefully will help your daily life. 🙂

https://github.com/davidegiannella/cq-misc/blob/master/EditMode.js

Advertisements

CQ5/OSGi reference a unique service implementation

You should never ever do it. If you find yourself in the need of this; there’s something extremely wrong in your code. Nevertheless I found myself in needing it for some old legacy code that was almost impossible to fix in a reasonable time.

The question is: how can I reference a specific implementation of a service/component in an OSGi (therefore CQ5 as well) environment?

In the component, where you need to reference the implementation you can specify something like the following

@Reference(target="(component.name=com.foo.BarImpl)")
Bar bar;

In the component implementing the service you’ll have something like

@Component(immediate=true, metatype=false, name="com.foo.BarImpl")
@Service
class BarImpl implements Bar{
...

By default the framework will assign the fully qualified class name as component name. I prefer to specify it for making the code more readable and no one prohibit you to specify any arbitrary string like mickey mouse or goofy as component name.

Reference:

Customising CQ5’s SiteAdmin actions

You could have the need to customise the actions available via the siteadmin interface in CQ

For better understaing the one highlighted in the below screenshot

Screen shot 2013-02-28 at 16.04.10

to do so you simply have to copy the

/libs/wcm/core/content/siteadmin/actions

as

/apps/wcm/core/content/siteadmin/actions

having care of recreating the correct folder structure and node types.

here a json extract

{

    "jcr:createdBy": "admin",
    "jcr:created": "Thu Oct 18 2012 16:55:43 GMT+0100",
    "jcr:primaryType": "nt:folder",
    "core": {
        "jcr:createdBy": "admin",
        "jcr:created": "Thu Oct 18 2012 16:55:43 GMT+0100",
        "jcr:primaryType": "nt:folder",
        "content": {
            "jcr:mixinTypes": [
                  "rep:AccessControllable"
             ],
             "jcr:createdBy": "admin",
             "jcr:created": "Thu Oct 18 2012 16:55:43 GMT+0100",
             "jcr:primaryType": "sling:Folder",
             "siteadmin": {
                "xtype": "siteadmin",
                "sling:redirect": false,
                "sling:resourceType": "cq/ui/components/widget",
                "jcr:mixinTypes": [
                   "cq:Console"
                ],
                "jcr:title": "CQ5 WCM",
                "consoleDescription": "Create and manage multiple websites.",
                "iconClass": "siteadmin",
                "jsLibs": [
                   "cq.wcm.admin"
                ],
                "sling:vanityPath": "/siteadmin",
                "consoleTitle": "Websites",
                "jcr:primaryType": "cq:Widget",
                "sling:vanityOrder": 300,
                "actions": {
                   "jcr:primaryType": "nt:unstructured"
                   //........
                   // here all the actions as subnodes
                   //........
                }
            }
        }
    }
}

Then you can simply customise the action you want: for example you could change the target, the conditions, the text or even the handler if you implement your own one.

Following an extract of the “Activate” menu (the OOTB one). I find each attribute self-explainatory.

"activate": {
    "iconCls": "cq-siteadmin-activate-icon",
    "cls": "cq-siteadmin-activate",
    "context": [
      "toolbar"
    ],
    "jcr:primaryType": "nt:unstructured",
    "split": true,
    "text": "Activate",
    "menu": {
      "jcr:primaryType": "nt:unstructured",
      "activateNow": {
        "isDefaultAction": true,
        "handler": "CQ.wcm.SiteAdmin.activatePage",
        "cls": "cq-siteadmin-activate-now",
        "conditions": [
          "CQ.wcm.SiteAdmin.hasAnySelection",
          "CQ.wcm.SiteAdmin.notLocked"
        ],
        "context": [
          "toolbar",
          "contextmenu"
        ],
        "target": "CQ.wcm.SiteAdmin.getAnyTarget",
        "jcr:primaryType": "nt:unstructured",
        "text": "Activate"
      },
      "activateLater": {
        "privileges": [
          "replicate"
        ],
        "handler": "CQ.wcm.SiteAdmin.scheduleForActivation",
        "cls": "cq-siteadmin-activate-later",
        "context": [
          "toolbar"
        ],
        "conditions": [
          "CQ.wcm.SiteAdmin.hasAnySelection",
          "CQ.wcm.SiteAdmin.notLocked"
        ],
        "target": "CQ.wcm.SiteAdmin.getTargetFromList",
        "jcr:primaryType": "nt:unstructured",
        "text": "Activate Later..."
      }
    }
}

if you instead just need to hide/show some commands on certain groups of users, you won’t need to custimise anything, just play with ACL! (See reference).

Once you overlayed you could realise that your changes are not reflected by the UI. This is done by the sling:vanityOrder. As
/siteadmin is a vanity path pointing to wcm/core/content/siteadmin. The /libs one are picked up. The default value (as of 5.5) is 300. Just update the one under /apps to a greater value. 301 is enough. As practice I like to have my vanitypath order as 400+ though.

Reference

Where’s my welcome page? (CQ5)

It could happen that on CQ5.5 SP2 after restarting the instance you see the CRX welcome page and not the CQ one.

Screen shot 2013-04-08 at 14.24.12

This is due to the fact that within the repository there are two Sling vanity paths both referencing ‘/welcome’. The sling:VanityOrder is 200 for CQ and 900 for the CRX one. The higher wins.

you can find the nodes by doing a search in CrxDE Lite.

SELECT * FROM [nt:base] AS s WHERE s.[sling:vanityPath] = '/welcome'

To solve once and for all the issue I remove the sling:vanityPath property from /libs/crx/core/content/welcome. Another option could be by changing the vanityOrder to something lower than 200.

It should not happen in 5.5 SP2.1 but in case this is how I went around it.

AEM/CQ5 AuthenticationSupport service missing

My computer crashed and on restart my local instance was not working property (blank pages). Looking at the error.log there was

org.apache.sling.engine.impl.SlingHttpContext handleSecurity: AuthenticationSupport service missing. Cannot authenticate request.

After a quick look at the felix console and having seen all the bundles up and running I went to reading backwards the error.log. I saw that during the start-up Lucene was failing to start and therefore the repository was not initialized correctly.

I managed to have my local instace back to work by having CQ fully regenerate my Lucene indexes.

See How to check and repair search index inconsistencies (Completely rebuild the index)

Removing the design icon from SideKick in CQ5

When you set-up a proper website management in large organisations you’ll end up in having two main groups: designers and content editors.

Normally you want the designers to be a more powerful content editors; with added functionality like selecting which components you can use for contributing the pages.

In order to remove the “design icon” from the Sidekick for a specific group/user you simply have to act on ACL and remove everything but Read permissions on /etc/designs.

Having so

               Read Modify Create Delete R/ACL E/ACL Repl.
/etc/designs    V     x      x      x     x      x    x