Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
* Copyright 2012 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
package com.day.cq.mcm.landingpage.leadform.creator;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import com.day.cq.i18n.I18n;
import com.day.cq.mcm.landingpage.leadform.LeadFormParagraphPostProcessor;
import com.day.cq.wcm.api.Page;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingException;
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.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.auth.core.AuthUtil;
import org.apache.sling.engine.SlingRequestProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.AccessDeniedException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;
/**
* This CTA lead forms handling servlet accepts POSTs to a form begin paragraph but only if the selector "cta-form" and the extension "html"
* is used.
*/
@Component
@Service(value = LeadFormsCreator.class)
public class LeadFormsCreator
{
public static final String FORMSTART = ":formstart";
public static final String REP_USER_ID = "rep:userId";
public static final String EMAIL = "email";
public static final String AUTHORIZABLE_ID = "authorizableId";
public static final String REP_PASSWORD = "rep:password";
public static final String CQ_AUTHORIZABLE_CATEGORY = "cq:authorizableCategory";
public static final String MCM = "mcm";
public static final String GROUP_NAME = "groupName";
public static final String CREATE_GROUP = "createGroup";
public static final String CREATE_USER = "createUser";
public static final String ADD_MEMBERS = "addMembers";
public static final String LIBS_GRANITE_SECURITY_POST_AUTHORIZABLES = "/libs/granite/security/post/authorizables";
//error codes
public static final String ERR_01 = "Err_01"; //"UserId and email, both cannot be null or empty";
public static final String ERR_02 = "Err_02"; //"Please enter a valid list for unsubscription";
public static final String ERR_03 = "Err_03"; //"Please enter a valid list for unsubscription"
public static final String ERR_04 = "Err_04"; //"Pleaser enter a valid user id for unsubscription"
protected static final String EXTENSION = "html";
protected static final String SELECTOR = "cta-form";
protected static final String ATTR_RESOURCE = LeadFormsCreator.class.getName() + "/resource";
protected final static String PARAM_GROUP_NAME = "groupName";
protected static final String PARAM_INTERMEDIATE_PATH = "intermediatePath";
protected final static String PARAM_PASSWORD = "rep:password";
protected final static String PARAM_SUBMIT = "Submit";
public static final String PROFILE_PATH = "path";
protected final Logger logger = LoggerFactory.getLogger(getClass());
private static final Set RESERVED = new HashSet();
static {
RESERVED.add(PARAM_GROUP_NAME);
RESERVED.add(AUTHORIZABLE_ID);
RESERVED.add(CQ_AUTHORIZABLE_CATEGORY);
RESERVED.add(PARAM_PASSWORD);
RESERVED.add(CREATE_USER);
RESERVED.add(FORMSTART);
RESERVED.add(PARAM_SUBMIT);
}
@Reference
private RequestResponseFactory requestResponseFactory;
@Reference
private SlingRequestProcessor slingRequestProcessor;
/**
* Return all form elements for this form.
*
* @param formResource
* @return An iterator for all form elements.
*/
public static Iterator getFormElements(final Resource formResource) {
final List list = new ArrayList();
// get all siblings
final Iterator iter = ResourceUtil.listChildren(ResourceUtil.getParent(formResource));
// while ( !iter.next().getPath().equals(formResource.getPath()) );
collectFormElements(list, iter);
return list.iterator();
}
/**
* Helper method to collect all form elements.
*
* @param list
* @param iter
* @return
*/
private static boolean collectFormElements(final List list, final Iterator iter) {
boolean stop = false;
while (!stop && iter.hasNext()) {
final Resource n = iter.next();
if (n.getResourceType().startsWith(LeadFormParagraphPostProcessor.RT_LEAD_FORM_PREFIX)
|| (n.getResourceSuperType() != null && n.getResourceSuperType().startsWith(
LeadFormParagraphPostProcessor.RT_LEAD_FORM_PREFIX))) {
list.add(n);
} else {
// do deep search
final Iterator cI = ResourceUtil.listChildren(n);
if (cI != null) {
stop = collectFormElements(list, cI);
}
}
}
return stop;
}
/**
* Prints lead form title with style provided in "className"
*
* @param fieldId
* @param title
* @param required
* @param hideLabel
* @param className
* @param out
* @throws IOException
*/
public static void printTitle(String fieldId, String title, boolean required, boolean hideLabel, String className, Writer out)
throws IOException {
out.write("