Skip to content

Instantly share code, notes, and snippets.

View nateyolles's full-sized avatar
😄

Nate Yolles nateyolles

😄
View GitHub Profile
@nateyolles
nateyolles / aemTouchUIPhoneNumberValidator.js
Created February 24, 2016 21:56
AEM Touch UI phone number validator
/**
* Register phone number validation field looking for format "xxx-xxx-xxxx".
*
* The validator keys off of the ".field-phonenumber" selector. To use in Touch
* UI dialogs, add the class "field-phonenumber" to a textfield.
*
* <phonenumber
* jcr:primaryType="nt:unstructured"
* sling:resourceType="granite/ui/components/foundation/form/textfield"
* fieldLabel="Phone Number"
@nateyolles
nateyolles / ClientLibUseObject.java
Created June 1, 2016 04:08
Custom ClientLibUseObject Java-Use POJO to create custom HTML markup
package apps.clientlib_async.sightly.templates;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import javax.script.Bindings;
@nateyolles
nateyolles / SlingResourceResolutionServlet.java
Created October 9, 2015 04:29
Get the HTML markup for a resource in Apache Sling.
package com.nateyolles.sling;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.engine.SlingRequestProcessor;
@nateyolles
nateyolles / OsgiServlet.java
Created May 25, 2017 20:54
Sample OSGi servlet in AEM
@Component(
immediate = true,
service = Servlet.class,
property = {
"sling.servlet.resourceTypes=project/components/component"
}
)
@Designate(ocd = SampleOsgiServlet.Configuration.class)
public class SampleOsgiServlet extends SlingSafeMethodsServlet {
@nateyolles
nateyolles / ResourceToJSONServlet.java
Created December 9, 2015 04:47
Sample servlet which easily prints an AEM/Sling Resource/Node as JSON to the PrintWriter.
package com.nateyolles.aem;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.jcr.JsonItemWriter;
@nateyolles
nateyolles / aemMultifieldAdapter.js
Last active August 9, 2020 23:13
AEM Touch UI, Granite UI Multifield adapter
/**
* Granite UI Multifield adapter
*
* Has improved setDisabled method which disables all form input fields, the
* delete buttons, the reorder buttons and the add button within the Multifield.
* The adapter also contains a new method to enable and disable just the add
* button which can be used to limit the size of the multifield.
*
* Usage:
* var field = $('.coral-Multifield').adaptTo('nateyolles-field');
@nateyolles
nateyolles / .content.xml
Created July 13, 2016 05:14
AEM using Granite Custom Render Condition
<widgetCustomRenderConditionHasProperty
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="This only shows if &quot;/content/renderconditiondemo/en/jcr:content/par/text&quot; has property &quot;text&quot;"
name="./widgetCustomRenderConditionHasProperty">
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="renderconditiondemo/components/renderconditions/hasProperty"
resourcePath="${requestPathInfo.suffix}"
propertyName="text"/>
@nateyolles
nateyolles / SlingServletAnnotation.java
Created May 25, 2017 20:51
A sample AEM SlingServlet Felix SCR Annotation
@SlingServlet(
metatype = true,
paths = {
"/bin/foo",
"/bin/bar"
},
extensions = {"html"},
selectors = {"foo"},
resourceTypes = {"nt:file", "project/components/component"}
methods = "GET",
@nateyolles
nateyolles / OsgiServletAnnotation.java
Last active June 23, 2020 07:06
A sample OSGi Declarative Services Servlet Annotation
@Component(
service = Servlet.class,
property = {
"sling.servlet.extensions=html",
"sling.servlet.selectors=foo",
"sling.servlet.paths=/bin/foo",
"sling.servlet.paths=/bin/bar",
"sling.servlet.methods=get",
"sling.servlet.resourceTypes=nt:file",
"sling.servlet.resourceTypes=project/components/component"
@nateyolles
nateyolles / AkamaiTransportHandler.java
Last active November 27, 2019 09:03
AEM custom Akamai replication agent TransportHandler
package com.nateyolles.aem.core.replication;
import java.io.IOException;
import java.util.Arrays;
import com.day.cq.replication.AgentConfig;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationLog;
import com.day.cq.replication.ReplicationResult;