CQ5 get service without annotation (snippet)

BundleContext context = FrameworkUtil.getBundle(MyService.class).getBundleContext(); ServiceReference reference = context.getServiceReference(MyService.class.getName()); MyService myService = (MyService) context.getService(reference); ...

August 8, 2013 · 1 min · Markus Ruepp

Scheduled Service in CQ5

Cron or Quartz like behaviour in CQ5 comes out of the box. See more examples. I have seen the annotation as comments, which I think is a bad style. import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component @Service @Property(name="scheduler.expression", value = "0 * * * * ?") public class ScheduledJob implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(ScheduledJob.class); public void run() { // your code goes here ....

June 3, 2013 · 1 min · Markus Ruepp

CQ5 replace Tab in ContentFinder with custom implementation

Adobe already explained how to add a custom tab to Content Finder. In order to replace an existing tab with your custom js file, e.g. movie tab, you simply have to use the same “id” value. For the movie tab, it is cfTab-Movies { "tabTip": CQ.I18n.getMessage("Movies"), <b>"id": "cfTab-Movies"</b>, "xtype": "contentfindertab", "iconCls": "cq-cft-tab-icon movies", (..) } ...

April 17, 2013 · 1 min · Markus Ruepp

Howto disable upload of CQ5 SmartImage

According to the SmartImage API docs, there is a option to disable the upload of this component. allowUpload="false" Unfortunately, it is still possible. I tried to solve it, by –preventing the click event–. Nothing. I solved it using a CSS workaround, that hides the file upload field. Don’t forget to specify the id in both snippets. Add this to your css to hide the upload field /* Hide upload field */ #some-unique-id ....

February 8, 2013 · 1 min · Markus Ruepp

Resize an image resource in CQ5 using Java

I already posted the question on stackoverflow, but since I am not allowed yet to post a solution, I’ll post it here. I found a quite low level approach, to resizes a image identified by jcrPathToImage to int targetWidth and int targetHeight. Resize Image Resource resource = getResourceResolver().getResource(jcrPathToImage); Asset asset = resource.adaptTo(Asset.class); Layer layer = new Layer(asset.getOriginal().getStream()) layer.resize(targetWidth, targetHeight); Create new rendition in JCR Extract mime type of the original image...

February 6, 2013 · 1 min · Markus Ruepp

CQ5 Dialog Validation

By registering a listener to the beforesubmit event, you can validate a dialog. ... xtype="dialog"&gt; ... Serverside Validation After defining a custom validating servlet, you can put the following code snippet in the beforesubmit area. It is important to call the servlet using async=false, to ensure everything is handled by the same thread. CQ.Ext.Ajax.request({ method: 'POST', url: '/content.myvalidationservlet.json', async: false, success: function(response){ // do something }, params: { ... } }); ...

February 6, 2013 · 1 min · Markus Ruepp

Raw Html in CQ5

I had to solve a problem of publishing some custom HTML code usning CQ5 with Ext JS. Raw HTML can be passed to DOM using CQ.form.OwnerDraw var rawComponent = new CQ.form.OwnerDraw({ html: '&lt;div&gt;I am raw&lt;/div&gt;' }); To alter this generated code, you may use a wrapping container like var wrapper = new CQ.Ext.Panel(); and pass the raw component to it. wrapper.removeAll(); // clear parent wrapper.add(rawComponent); wrapper.doLayout(); // force redraw ...

February 6, 2013 · 1 min · Markus Ruepp

CQ5 Dialog in Js

CQ5 code exmaples are rare, so i will post some Javascript Code, that would have helped me a lot. CQ5 is shipped with Ext JS. See API docs for more options. var dialog = new CQ.Dialog({ 'width': 600, 'modal': true, 'resize': false, 'title': 'My Title', 'items': { 'xtype': 'tabpanel', 'items': [{ 'xtype': 'panel', 'title': 'Basic', 'hideMode': 'offsets', 'items': [ { 'xtype': 'textfield', 'fieldLabel': CQ.I18n.get('app.components.some.key'), }, //... ] }] }, 'buttons': [ { 'text': 'Save', 'handler': function () { //....

February 6, 2013 · 1 min · Markus Ruepp

CQ5 Internationalization

To achieve the goal of a multi lingual CQ5-based application, you may use CQ I18n implementation (API) to access the translated strings from the ResourceBundle, according to your language. In the XML definition of a component, the dialog.xml, use the key directly in the text field, e.g. fieldLabel="app.component.key" CQ5 will resolve the reference automatically. (...) &lt;/mypanel> In Java Script, CQ5 provides the method CQ.I18n.get('app.component.key') In Java we implemented a Localization service, that loads all keys from JCR....

February 6, 2013 · 1 min · Markus Ruepp