Skip to content

Instantly share code, notes, and snippets.

View nateyolles's full-sized avatar
😄

Nate Yolles nateyolles

😄
View GitHub Profile
@nateyolles
nateyolles / AemGetCheckboxValue.java
Last active November 17, 2015 17:46
Get a checkbox value in an AEM/Sling Sightly Java bean
/*
* Sightly classes extending com.adobe.cq.sightly.WCMUse or com.adobe.cq.sightly.WCMUsePojo
*/
Boolean checkbox = getProperties().get("myBooleanCheckbox", Boolean.class);
/*
* Set the default value.
*/
Boolean checkbox = getProperties().get("myBooleanCheckbox", false);
Boolean checkbox = getProperties().get("myBooleanCheckbox", true);
@nateyolles
nateyolles / ConvertResourceToJSON.java
Created December 9, 2015 04:44
Easily turn an AEM/Sling Resource/Node into a JSONObject
package com.nateyolles.aem;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.json.jcr.JsonItemWriter;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@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 / AkamaiContentBuilder.java
Created January 5, 2016 19:55
AEM custom Akamai Replication Agent ContentBuilder
package com.nateyolles.aem.core.replication;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.nio.file.Files;
import java.nio.file.Path;
@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;
@nateyolles
nateyolles / aemGraniteUIAlert.js
Created January 21, 2016 07:37
AEM Granite UI "foundation ui" adapter notification
var ui = $(window).adaptTo('foundation-ui');
ui.alert('Notification', 'This alert was created using the Granite UI "foundation-ui" adapter', 'notice');
@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 / aemMultifieldAdapterExample.js
Created January 21, 2016 08:52
Using the custom AEM Granite UI / Touch UI multifield adapter
var field = $('.coral-Multifield').adaptTo('nateyolles-field');
field.setDisabled(true);
@nateyolles
nateyolles / aemTouchUIValidation.js
Last active July 25, 2018 20:30
AEM Touch UI validation
var $input = $('.my-input-field'),
errorMessege = 'This field is required';
if ($input.willValidate()) {
$input.checkValidity(); // true
$input.validationMessage(); // ''
/* Set input field as invalid */
$input.setCustomValidity(errorMessage);
$input.checkValidity(); // false
@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"