// Path: src/main/java/danta/aem/services/ContentUtils.java
// public interface ContentUtils {
// 
//     /**
//      *
//      * @param path This is a resource/page/node path
//      * @param request This is a SlignHttpServletRequest
//      * @return outputAsBytes The rendered output of a resource in bytes
//      */
//     public byte[] getOutputAsBytes(String path, SlingHttpServletRequest request);
// 
//     /**
//      *
//      * @param path This is a resource/page/node path
//      * @param resolver This is a resource resolver
//      * @return outputAsBytes The rendered output of a resource in bytes
//      */
//     public byte[] getOutputAsBytes(String path, ResourceResolver resolver);
// 
// }


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static danta.Constants.HTTP_GET;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import com.day.cq.wcm.api.WCMMode;
import danta.aem.services.ContentUtils;
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.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.engine.SlingRequestProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * Danta AEM Bundle
 *
 * Copyright (C) 2017 Tikal Technologies, Inc. All rights reserved.
 *
 * Licensed under GNU Affero General Public License, Version v3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.gnu.org/licenses/agpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
 * without even the implied warranty of MERCHANTABILITY.
 * See the License for more details.
 */

package danta.aem.services.impl;




/**
 * The content utils implementer
 *
 * @author      jbarrera
 * @version     1.0.0
 * @since       2016-12-01
 */
@Component
@Service(ContentUtils.class)
public class ContentUtilsImpl
        implements ContentUtils {

    @Reference
    private RequestResponseFactory requestResponseFactory;

    @Reference
    private SlingRequestProcessor requestProcessor;

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    /**
     * This method gets the rendered content in bytes for an AEM resource.
     *
     * @param path of the resource
     * @param request current request
     * @return the rendered output of a resource in bytes
     */
    public byte[] getOutputAsBytes(String path, SlingHttpServletRequest request) {
// Path: src/main/java/danta/aem/services/ContentUtils.java
// public interface ContentUtils {
// 
//     /**
//      *
//      * @param path This is a resource/page/node path
//      * @param request This is a SlignHttpServletRequest
//      * @return outputAsBytes The rendered output of a resource in bytes
//      */
//     public byte[] getOutputAsBytes(String path, SlingHttpServletRequest request);
// 
//     /**
//      *
//      * @param path This is a resource/page/node path
//      * @param resolver This is a resource resolver
//      * @return outputAsBytes The rendered output of a resource in bytes
//      */
//     public byte[] getOutputAsBytes(String path, ResourceResolver resolver);
// 
// }


// Path: src/main/java/danta/aem/services/impl/ContentUtilsImpl.java
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import static danta.Constants.HTTP_GET;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import com.day.cq.wcm.api.WCMMode;
import danta.aem.services.ContentUtils;
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.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.engine.SlingRequestProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Danta AEM Bundle
 *
 * Copyright (C) 2017 Tikal Technologies, Inc. All rights reserved.
 *
 * Licensed under GNU Affero General Public License, Version v3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.gnu.org/licenses/agpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
 * without even the implied warranty of MERCHANTABILITY.
 * See the License for more details.
 */

package danta.aem.services.impl;




/**
 * The content utils implementer
 *
 * @author      jbarrera
 * @version     1.0.0
 * @since       2016-12-01
 */
@Component
@Service(ContentUtils.class)
public class ContentUtilsImpl
        implements ContentUtils {

    @Reference
    private RequestResponseFactory requestResponseFactory;

    @Reference
    private SlingRequestProcessor requestProcessor;

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    /**
     * This method gets the rendered content in bytes for an AEM resource.
     *
     * @param path of the resource
     * @param request current request
     * @return the rendered output of a resource in bytes
     */
    public byte[] getOutputAsBytes(String path, SlingHttpServletRequest request) {
        return getOutputAsBytes(path, request.getResourceResolver());