// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/JspSlingHttpServletResponseWrapper.java
// public class JspSlingHttpServletResponseWrapper extends SlingHttpServletResponseWrapper {
// 
//     // The original JspWriter of the wrapped response
//     private final JspWriter jspWriter;
// 
//     // The PrintWriter returned by the getWriter method. Wraps jspWriter
//     private final PrintWriter printWriter;
// 
//     public JspSlingHttpServletResponseWrapper(final SlingHttpServletResponse response,
//                                               final JspWriter writer) {
//         super(response);
// 
//         this.jspWriter = writer;
//         this.printWriter = new PrintWriter(this.jspWriter);
//     }
// 
//     /**
//      * Returns the writer for this response wrapper.
//      */
//     public PrintWriter getWriter() {
//         return this.printWriter;
//     }
// 
//     /**
//      * Throws an <code>IllegalStateException</code> as this wrapper only
//      * supports writers.
//      */
//     public ServletOutputStream getOutputStream() {
//         throw new IllegalStateException();
//     }
// 
//     /**
//      * Resets the buffer of the JspWriter underlying the writer of this
//      * instance.
//      */
//     public void resetBuffer() {
//         try {
//             this.jspWriter.clearBuffer();
//         } catch (IOException ignore) {
//             // don't care
//         }
//     }
// }
// 
// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/ResourceWrapper.java
// public class ResourceWrapper extends org.apache.sling.api.resource.ResourceWrapper {
// 
//     private final String resourceType;
// 
//     private final String resourceSuperType;
// 
//     public ResourceWrapper(final Resource r, final String rt, final String rst) {
//         super(r);
//         this.resourceType = rt;
//         this.resourceSuperType = rst;
//     }
// 
//     public String getResourceSuperType() {
//         return this.resourceSuperType;
//     }
// 
//     public String getResourceType() {
//         return this.resourceType;
//     }
// }


import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import org.apache.commons.lang3.StringEscapeUtils;
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.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import com.day.cq.wcm.foundation.forms.impl.JspSlingHttpServletResponseWrapper;
import com.day.cq.wcm.foundation.forms.impl.ResourceWrapper;
        }
        return true;
    }

    /**
     * Convenience method to check the constraint of a form element.
     * @param request
     * @param resource The form element resource.
     * @deprecated Use {@link FieldHelper#checkConstraint(SlingHttpServletRequest, SlingHttpServletResponse, FieldDescription)}
     */
    @Deprecated
    public static void checkConstraint(final SlingHttpServletRequest request,
                                       final SlingHttpServletResponse response,
                                       final Resource resource)
    throws IOException, ServletException {
        final ValueMap properties = ResourceUtil.getValueMap(resource);
        final String name = FormsHelper.getParameterName(resource);
        final String value = request.getParameter(name);

        final boolean isEmpty = (value == null || value.trim().length() == 0);

        // we evaluate the constraint only if the field is not null
        if ( !isEmpty ) {
            // additional constraint?
            final String constraint = properties.get(FormsConstants.ELEMENT_PROPERTY_CONSTRAINT_TYPE, "");
            if ( constraint.length() > 0 ) {
                String rt = constraint;
                if ( constraint.indexOf('/') == -1) {
                    rt = FormsConstants.RT_FORM_CONSTRAINT + "s/" + rt;
                }
// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/JspSlingHttpServletResponseWrapper.java
// public class JspSlingHttpServletResponseWrapper extends SlingHttpServletResponseWrapper {
// 
//     // The original JspWriter of the wrapped response
//     private final JspWriter jspWriter;
// 
//     // The PrintWriter returned by the getWriter method. Wraps jspWriter
//     private final PrintWriter printWriter;
// 
//     public JspSlingHttpServletResponseWrapper(final SlingHttpServletResponse response,
//                                               final JspWriter writer) {
//         super(response);
// 
//         this.jspWriter = writer;
//         this.printWriter = new PrintWriter(this.jspWriter);
//     }
// 
//     /**
//      * Returns the writer for this response wrapper.
//      */
//     public PrintWriter getWriter() {
//         return this.printWriter;
//     }
// 
//     /**
//      * Throws an <code>IllegalStateException</code> as this wrapper only
//      * supports writers.
//      */
//     public ServletOutputStream getOutputStream() {
//         throw new IllegalStateException();
//     }
// 
//     /**
//      * Resets the buffer of the JspWriter underlying the writer of this
//      * instance.
//      */
//     public void resetBuffer() {
//         try {
//             this.jspWriter.clearBuffer();
//         } catch (IOException ignore) {
//             // don't care
//         }
//     }
// }
// 
// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/ResourceWrapper.java
// public class ResourceWrapper extends org.apache.sling.api.resource.ResourceWrapper {
// 
//     private final String resourceType;
// 
//     private final String resourceSuperType;
// 
//     public ResourceWrapper(final Resource r, final String rt, final String rst) {
//         super(r);
//         this.resourceType = rt;
//         this.resourceSuperType = rst;
//     }
// 
//     public String getResourceSuperType() {
//         return this.resourceSuperType;
//     }
// 
//     public String getResourceType() {
//         return this.resourceType;
//     }
// }


// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/ValidationHelper.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspWriter;
import org.apache.commons.lang3.StringEscapeUtils;
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.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import com.day.cq.wcm.foundation.forms.impl.JspSlingHttpServletResponseWrapper;
import com.day.cq.wcm.foundation.forms.impl.ResourceWrapper;

        }
        return true;
    }

    /**
     * Convenience method to check the constraint of a form element.
     * @param request
     * @param resource The form element resource.
     * @deprecated Use {@link FieldHelper#checkConstraint(SlingHttpServletRequest, SlingHttpServletResponse, FieldDescription)}
     */
    @Deprecated
    public static void checkConstraint(final SlingHttpServletRequest request,
                                       final SlingHttpServletResponse response,
                                       final Resource resource)
    throws IOException, ServletException {
        final ValueMap properties = ResourceUtil.getValueMap(resource);
        final String name = FormsHelper.getParameterName(resource);
        final String value = request.getParameter(name);

        final boolean isEmpty = (value == null || value.trim().length() == 0);

        // we evaluate the constraint only if the field is not null
        if ( !isEmpty ) {
            // additional constraint?
            final String constraint = properties.get(FormsConstants.ELEMENT_PROPERTY_CONSTRAINT_TYPE, "");
            if ( constraint.length() > 0 ) {
                String rt = constraint;
                if ( constraint.indexOf('/') == -1) {
                    rt = FormsConstants.RT_FORM_CONSTRAINT + "s/" + rt;
                }
                final Resource includeResource = new ResourceWrapper(resource, rt, FormsConstants.RST_FORM_CONSTRAINT);