// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/FormsHandlingResponse.java
// public class FormsHandlingResponse extends SlingHttpServletResponseWrapper {
// 
//     private ServletOutputStream nullstream;
//     private PrintWriter nullwriter;
// 
//     public FormsHandlingResponse(SlingHttpServletResponse wrappedResponse) {
//         super(wrappedResponse);
//     }
// 
//     @Override
//     public PrintWriter getWriter() {
//         if (nullwriter == null) {
//             nullwriter = new PrintWriter(getOutputStream());
//         }
//         return nullwriter;
//     }
// 
//     @Override
//     public ServletOutputStream getOutputStream() {
//         if (nullstream == null) {
//             nullstream = new ServletOutputStream() {
// 
//                 @Override
//                 public void write(int b) {
//                     // noop
//                 }
// 
//                 @Override
//                 public void write(byte[] b) {
//                     // noop
//                 }
// 
//                 @Override
//                 public void write(byte[] b, int off, int len)
//                         {
//                     // noop
//                 }
// 
//                 @Override
//                 public void flush() {
//                     // noop
//                 }
// 
//                 @Override
//                 public void close() {
//                     // noop
//                 }
//             };
//         }
//         return nullstream;
//     }
// 
//     @Override
//     public void flushBuffer() {
//         // noop
//     }
// 
//     @Override
//     public void reset() {
//         // noop
//     }
// 
//     @Override
//     public void resetBuffer() {
//         // noop
//     }
// }
// 
// 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 java.io.PrintWriter;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringEscapeUtils;
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 com.day.cq.wcm.foundation.forms.impl.FormsHandlingResponse;
import com.day.cq.wcm.foundation.forms.impl.ResourceWrapper;
        if ( desc.isRequired() && isEmpty(request, desc.getName()) && doValidation(request, desc) ) {
            ValidationInfo.createValidationInfo(request).addErrorMessage(desc.getName(),
                                                                        desc.getRequiredMessage());
            return false;
        }
        return true;
    }

    /**
     * Determine if the field has to be validated. If no or a single post resources
     * is defined the field is always validated. Multiple post resources are only
     * validated when the @Write parameter is set.
     * is set
     */
    private static boolean doValidation(SlingHttpServletRequest request, FieldDescription desc) {
        return request.getParameter(desc.getName() + FormResourceEdit.WRITE_SUFFIX) != null ||
                FormResourceEdit.isSingleResourcePost(request);
    }

    /**
     * Private method to initialize the field.
     */
    private static void initField(final SlingHttpServletRequest req,
                                  final SlingHttpServletResponse res,
                                  final Resource rsrc)
    throws ServletException, IOException {
        final String key = getInitAttrName(rsrc);
        final Object flag = req.getAttribute(key);
        if ( flag == null ) {
            req.setAttribute(key, Boolean.TRUE);
// Path: ui/src/content/jcr_root/libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/forms/impl/FormsHandlingResponse.java
// public class FormsHandlingResponse extends SlingHttpServletResponseWrapper {
// 
//     private ServletOutputStream nullstream;
//     private PrintWriter nullwriter;
// 
//     public FormsHandlingResponse(SlingHttpServletResponse wrappedResponse) {
//         super(wrappedResponse);
//     }
// 
//     @Override
//     public PrintWriter getWriter() {
//         if (nullwriter == null) {
//             nullwriter = new PrintWriter(getOutputStream());
//         }
//         return nullwriter;
//     }
// 
//     @Override
//     public ServletOutputStream getOutputStream() {
//         if (nullstream == null) {
//             nullstream = new ServletOutputStream() {
// 
//                 @Override
//                 public void write(int b) {
//                     // noop
//                 }
// 
//                 @Override
//                 public void write(byte[] b) {
//                     // noop
//                 }
// 
//                 @Override
//                 public void write(byte[] b, int off, int len)
//                         {
//                     // noop
//                 }
// 
//                 @Override
//                 public void flush() {
//                     // noop
//                 }
// 
//                 @Override
//                 public void close() {
//                     // noop
//                 }
//             };
//         }
//         return nullstream;
//     }
// 
//     @Override
//     public void flushBuffer() {
//         // noop
//     }
// 
//     @Override
//     public void reset() {
//         // noop
//     }
// 
//     @Override
//     public void resetBuffer() {
//         // noop
//     }
// }
// 
// 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/FieldHelper.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringEscapeUtils;
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 com.day.cq.wcm.foundation.forms.impl.FormsHandlingResponse;
import com.day.cq.wcm.foundation.forms.impl.ResourceWrapper;

        if ( desc.isRequired() && isEmpty(request, desc.getName()) && doValidation(request, desc) ) {
            ValidationInfo.createValidationInfo(request).addErrorMessage(desc.getName(),
                                                                        desc.getRequiredMessage());
            return false;
        }
        return true;
    }

    /**
     * Determine if the field has to be validated. If no or a single post resources
     * is defined the field is always validated. Multiple post resources are only
     * validated when the @Write parameter is set.
     * is set
     */
    private static boolean doValidation(SlingHttpServletRequest request, FieldDescription desc) {
        return request.getParameter(desc.getName() + FormResourceEdit.WRITE_SUFFIX) != null ||
                FormResourceEdit.isSingleResourcePost(request);
    }

    /**
     * Private method to initialize the field.
     */
    private static void initField(final SlingHttpServletRequest req,
                                  final SlingHttpServletResponse res,
                                  final Resource rsrc)
    throws ServletException, IOException {
        final String key = getInitAttrName(rsrc);
        final Object flag = req.getAttribute(key);
        if ( flag == null ) {
            req.setAttribute(key, Boolean.TRUE);
            FormsHelper.includeResource(req, new FormsHandlingResponse(res), rsrc, FormsConstants.SCRIPT_FIELD_INIT);