Skip to content

Miscellaneous

David Steele edited this page Aug 30, 2014 · 6 revisions

ironsites ironsites

AEM better

Miscellaneous

Extended Page Filters

  • Composable, flexible, and configurable alternatives to PageFilter which is commonly used to create navigation and sitemap components.
  • 'hideInHav' & Page#isValid are possibly not the only criteria you want to use when generating navigation, sitemaps, archive lists, etc. ironsites has implementations of Filter<Page> which have been broken down into a few more primitive filters that can be composed together.

Extended Page Filters : List/And/Or Filters

  • ListPageFilter is an abstract class which provides extensions management around aggregated Filters.
  • AndPageFilter extends ListPageFilter and will include a page if all of the aggregate Filters include a page.
  • OrPageFilter extends ListPageFilter and will include a page if any of the aggregate Filters include a page.

Extended Page Filters : Property Equals Filters

  • PropertyEqualsFilter is an abstract class which provides structure to acquiring and checking equality for a property value, and supporting negation as an option.
  • StringEqualsFilter extends PropertyEqualsFilter and will include a page if a property value, coerced to String, is equal to another String.
  • BooleanEqualsFilter extends PropertyEqualsFilter and will include a page if a property value, coerced to a Boolean, is equal to another Boolean.

Extended Page Filters : Hide/Show/Invalid Filters

  • The out-of-box PageFilter has an option to check if a Page is invalid (Page#isInvalid), and InvalidPageFilter performs similar work, but with other checks factored away.
  • HidePageFilter operates performs the work of the out-of-box PageFilter but does so as an AndPageFilter which composes InvalidPageFilter and BooleanEqualsFilter for an opt-out property to equal true; 'hideInNav' by default. A constant instance with default behavior is available for use instead if the those assumptions are sufficient.
  • ShowPageFilter is an opt-in version of the HidePageFilter where a page is filtered out if it is invalid or it has a property that does not equal true; 'showInNav' by default. A constant instance with default behavior is available for use instead if the those assumptions are sufficient.

WCMUtil

taglib developers will find a number of useful methods in WCMUtil for acquiring SlingScriptHelper or SlingHttpServletRequest from PageContext. Another useful method is WCMUtil#getFastHash which uses Guava to build a repeatable hash given a String. Hashing information like Resource#getPath() could be used for generating DOM class/IDs to hang CSS and Javascript while avoiding IDs containing paths like "cq-image-jsp-/content/geometrixx/en/home/_jcr_content/par/image_0"; doing this wouldprovide a better uniqueness guarantee than a bad habit of using System#currentTimeMillis() or AtomicInteger.

  • static String getLanguageRoot(String path) Based on a given resource path, extract locale/language level agnostic to a AEM Launches based path
  • static Locale getLocale(org.apache.sling.api.SlingHttpServletRequest request) Attempt to acquire a locale based on the requested resource.
  • static String getPageURL(org.apache.sling.api.SlingHttpServletRequest request, String path) Most CQ Page hrefs will not need suffixes, additional reasonable default parameters are assumed for getRelativeURL
  • static String getExternalPageURL(org.apache.sling.api.SlingHttpServletRequest request, String path, String protocol, String domain) Utility for common case for externalized page paths
  • static String getProtocolRelativeURL(String fullyQualifiedURL) For protocol specific fully qualified URLs, ensure protocol relativity
  • static String getSecureURL(String fullyQualifiedURL) For non HTTPS fully qualified URLs, ensure HTTPS
  • static SlingHttpServletRequest getSlingRequest(javax.servlet.jsp.PageContext pageContext) Utility method to extract sling request from JSP page context
  • static SlingScriptHelper getSlingScriptHelper(javax.servlet.jsp.PageContext pageContext) Utility method to extract sling script helper from JSP page context
  • static SlingScriptHelper getSlingScriptHelper(org.apache.sling.api.SlingHttpServletRequest request) Utility method to extract sling script helper from SlingHttpServletRequest
  • static String getURLEncoded(String token) URL encode a given String, assuming UTF-8
  • static String getURLEncoded(String token, String encoding) URL encode a given String, per a given encoding
  • ...and much more

WCMUtil and it's related javadocs are definitely worth exploring as an AEM developer. Not only are there methods that support Externalizer usage, but building link building taglibs atop of these will be a breeze.