Skip to content

Instantly share code, notes, and snippets.

View ConfigurationModel.java
package aem.training.core.models;
import aem.training.core.config.GoogleReCaptchaConfiguration;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
View GoogleReCaptchaConfiguration.java
package aem.training.core.config;
import org.apache.sling.caconfig.annotation.Configuration;
import org.apache.sling.caconfig.annotation.Property;
/**
* Context Aware configuration for Google ReCaptcha.
*
* @author shivani Date Created: 31 January 2020
View CAConfigModel.java
package aem.training.core.models;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.resource.ConfigurationResourceResolver;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.OSGiService;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
View SampleJbossApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class SampleJbossApplication extends SpringBootServletInitializer {
@sgaem
sgaem / UserAccountDetail.java
Created May 31, 2019
UserAccountDetail.java is the implementation of Factory OSGI Configuration.
View UserAccountDetail.java
package com.poc.osgiannotation.core.servlets;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.metatype.annotations.Designate;
@Component(service=UserAccountDetail.class,immediate=true)
@Designate(ocd = UserConfiguration.class,factoy=true)
public class UserAccountDetail {
@sgaem
sgaem / DropDownServlet.java
Created Jan 12, 2019
This gist demonstrates how to dynamically populate values based on different conditions in AEM.
View DropDownServlet.java
package com.aem.project.core.servlets;
import com.adobe.cq.commerce.common.ValueMapDecorator;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;
import com.day.cq.wcm.api.Page;
import com.day.crx.JcrConstants;
import org.apache.commons.collections4.iterators.TransformIterator;
import org.apache.sling.api.SlingHttpServletRequest;
@sgaem
sgaem / DropDownServlet.java
Created Jan 12, 2019
This gist shows the dynamic population of drop down using datasource in AEM.
View DropDownServlet.java
package com.aem.project.core.servlets;
import com.adobe.cq.commerce.common.ValueMapDecorator;
import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.adobe.granite.ui.components.ds.ValueMapResource;
import com.day.crx.JcrConstants;
import org.apache.commons.collections4.iterators.TransformIterator;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
View HelloWorldModel.java
package com.aem.project.core.models;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
@sgaem
sgaem / PageRedirectServlet.java
Last active Aug 8, 2019
The servlet that overrides OOTB of the PageRedirectServlet.java
View PageRedirectServlet.java
package com.aem.project.core.servlets;
import com.day.cq.wcm.api.WCMMode;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@sgaem
sgaem / redirect.jsp
Created Dec 29, 2018
Redirect.jsp for 301 and 302 redirection in AEM 6.2 and AEM 6.3
View redirect.jsp
<%@page session="false"
import="com.day.cq.wcm.api.WCMMode,
com.day.cq.wcm.foundation.ELEvaluator" %><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/><%
String location = properties.get("redirectTarget", "");
String type = properties.get("redirectType", "");
// resolve variables in path
location = ELEvaluator.evaluate(location, slingRequest, pageContext);
boolean wcmModeIsDisabled = WCMMode.fromRequest(request) == WCMMode.DISABLED;