Created

May 07, 2013

My favourite CQ5 util classes

Posted by Feike Visser

In this blogpost I want to give you an overview of my favourite CQ5 util classes.

Some of these classes might already be known to you, hopefull you will find a new one that will help you during your CQ5 development work.

With every class I will give a small code example on how you can use it.

// checks if the resource exists
ResourceUtil.isNonExistingResource(myResource);

// always gets a ValueMap from a Resource
ResourceUtil.getValueMap(myResource);
//check if the Resource is an Asset
DamUtil.isAsset(myResource);
//formats the Calendar into ISO8601 format
ISO8601.format(calendar);
// creates a valid JCR-name
JcrUtil.createValidName(myCustomName);
// if the folder doesn't exist, it will be created
JcrUtils.getOrAddFolder(parent, name);
// gets a boolean property when starting an OSGi-component

@Activate
protected void activate(ComponentContext context) {
	PropertiesUtil.toBoolean(context.getProperties().get("myproperty"), false);
}

// gets the references to services loaded in the OSGi-container
serviceTracker.getServiceReference()
// creates a full path, with autosave if needed
JcrResourceUtil.createPath(... )
// gets the SlingRequest/SlingResponse when you are creating custom tags

PageContext pageContext = (PageContext) getJspContext();

SlingHttpServletRequest slingRequest = TagUtil.getRequest(pageContext);
SlingHttpServletResponse slingResponse = TagUtil.getResponse(pageContext);

// check to see if a real user is logged in

boolean realuser = ! UserPropertiesUtil.isAnonymous(request);

COMMENTS

  • By APK - 10:19 AM on May 31, 2014   Reply
    Many Thanks.
  • By best singapore escort - 10:28 AM on May 31, 2014   Reply
    But the success of this competitors will also rely on the effective management of the software by unskilled providers and under less-than-ideal circumstances (such as with sporadic emails signals).
    • By tidung.net - 4:57 AM on Jun 02, 2014   Reply
      Thanks.
      • By hargaandroid.com - 8:50 AM on Jun 03, 2014   Reply
        Many Thanks.
        • By apk - 11:13 AM on Jun 06, 2014   Reply
          Thanks.
          • By Jasa SEO - 11:20 AM on Jun 08, 2014   Reply
            Many Thanks.
            • By Visit this link - 2:15 PM on Jun 08, 2014   Reply
              It is definitely worth it to appreciate your high quality writing. Your blog post will be very beneficial for people who seeks about this area.
              • By Targeted Traffic - 3:01 PM on Jun 08, 2014   Reply
                t is definitely worth it to appreciate your high quality writing. Your blog post will be very beneficial for people who seeks about this area.
                • By Tattoos - 4:33 PM on Jun 08, 2014   Reply
                  Many Thanks.
                  • By Commentmaster - 8:28 PM on Jun 09, 2014   Reply
                    Actually get pleasure from this fantastic submit that you've got provided for people like us. Fantastic web page along with a wonderful topic also i really find amazed to learn to read this. Its fantastic.
                    • By High Pr backlinks - 5:04 AM on Jun 11, 2014   Reply
                      t is definitely worth it to appreciate your high quality writing. Your blog post will be very beneficial for people who seeks about this area.
                      • By click here - 5:53 AM on Jun 12, 2014   Reply
                        This is one reason why many people want to download episodes and catch up on the missed parts on col3
                        • By GO here! - 7:17 AM on Jun 15, 2014   Reply
                          t is definitely worth it to appreciate your high quality writing.
                          • By best iphone 5 screen protector - 8:03 AM on Jun 17, 2014   Reply
                            In this webinar, we will continue the exciting conversations around “mobile,” focusing on the ability to deliver relevant experiences across the multitude of mobile and tablet devices available today.sda
                            • By Obat Keputihan - 9:23 AM on Jun 22, 2014   Reply
                              Many Thanks.
                              • By airul - 10:48 AM on Jul 06, 2014   Reply
                                Thanks.
                                • By venus factor system - 7:09 AM on Jul 12, 2014   Reply
                                  Recently I came across your blog and read along. I thought I would leave my first comment. I do not know what to say except that I liked reading.
                                  • By model baju lebaran - 4:09 PM on Jul 12, 2014   Reply
                                    i really to say nice tools from adobe. i like it.
                                    • By Yamaha R15 indonesia - 8:38 AM on Jul 15, 2014   Reply
                                      i really to say nice tools from adobe. i like it.
                                      • By Fast url opener - 5:44 PM on Jul 15, 2014   Reply
                                        Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.
                                        • By link m88 - 7:32 AM on Jul 17, 2014   Reply
                                          McKinnon told me that it is crucial we continue to promote the field side of the plumbing industry.
                                          • By duplichecker - 7:14 PM on Jul 18, 2014   Reply
                                            I like your website design (and your city!) but I'm suprised that the articles are not translated in English. You have obvisouly an international public, would be fine to have an international website.
                                            • By contoh kata pengantar makalah - 8:05 AM on Jul 20, 2014   Reply
                                              i love this content
                                              • By Crystal X Asli - 7:08 PM on Jul 22, 2014   Reply
                                                i really to say nice tools from adobe. i like it.
                                                • By Crystal X Asli - 7:09 PM on Jul 22, 2014   Reply
                                                  i really to say nice tools from adobe. i like it.

                                                  ADD A COMMENT