// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaContentType.java
// public interface GeometrixxMediaContentType {
// 
//     JSONObject getJson();
// 
//     SolrInputDocument getSolrDoc();
// 
// }
// 
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaPage.java
// @Model(adaptables = Resource.class, adapters = {GeometrixxMediaContentType.class, GeometrixxMediaPage.class})
// public class GeometrixxMediaPage implements GeometrixxMediaContentType{
// 
//     private static final Logger LOG = LoggerFactory.getLogger(GeometrixxMediaPage.class);
// 
//     private GeometrixxMediaPageContent pageContent;
// 
//     @Inject @Named("jcr:content")
//     private Resource jcrResource;
// 
//     @PostConstruct
//     public void init() throws SlingModelsException {
// 
//         pageContent = jcrResource.adaptTo(GeometrixxMediaPageContent.class);
// 
//     }
// 
//     public GeometrixxMediaPage(Resource resource) throws SlingModelsException {
// 
//         if (null == resource) {
//             LOG.debug("resource is null");
//             throw new SlingModelsException("Resource is null");
//         }
// 
//         if (ResourceUtil.isNonExistingResource(resource)) {
//             LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath());
//             throw new SlingModelsException(
//                 "Can't adapt non existent resource." + resource.getPath());
//         }
// 
//     }
// 
//     @Override
//     public String toString() {
// 
//         final StringBuilder sb = new StringBuilder("GeometrixxMediaPage{");
//         if(null != pageContent){
//             sb.append(pageContent.toString());
//         }
//         sb.append('}');
//         return sb.toString();
//     }
// 
//     @Override
//     public JSONObject getJson() {
// 
//         return pageContent != null ? pageContent.getJson() : new JSONObject();
//     }
// 
//     @Override
//     public SolrInputDocument getSolrDoc() {
// 
//         return pageContent != null ? pageContent.getSolrDoc() : null;
//     }
// }


import com.day.cq.dam.api.DamConstants;
import com.day.cq.wcm.api.NameConstants;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaContentType;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaPage;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
package com.headwire.aemsolrsearch.geometrixxmedia.servlets;



/**
 * Renders supported Sling resource types using Solr's JSON update handler format. The following Sling resource
 * types are supported:
 *
 * <ul>
 *     <li><code>geometrixx-media/components/page/article</code></li>
 * </ul>
 *
 * <em>Note: *.solr.json should be blocked at dispatcher</em>
 *
 * @author <a href="mailto:gg@headwire.com">Gaston Gonzalez</a>
 */
@Component(immediate = true, metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = Constants.SERVICE_VENDOR, value = "headwire.com, Inc."),
        @Property(name = Constants.SERVICE_DESCRIPTION, value = "Renders content using the Solr JSON update handler format "),
        @Property(name = "sling.servlet.methods", value = "GET"),
        @Property(name = "sling.servlet.resourceTypes", value = {NameConstants.NT_PAGE, DamConstants.NT_DAM_ASSET}),
        @Property(name = "sling.servlet.selectors", value = "solr"),
        @Property(name = "sling.servlet.extensions", value = "json")
})
public class SolrUpdateHandler extends SlingSafeMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(SolrUpdateHandler.class);

    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");

        Resource page = request.getResource();
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaContentType.java
// public interface GeometrixxMediaContentType {
// 
//     JSONObject getJson();
// 
//     SolrInputDocument getSolrDoc();
// 
// }
// 
// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/model/GeometrixxMediaPage.java
// @Model(adaptables = Resource.class, adapters = {GeometrixxMediaContentType.class, GeometrixxMediaPage.class})
// public class GeometrixxMediaPage implements GeometrixxMediaContentType{
// 
//     private static final Logger LOG = LoggerFactory.getLogger(GeometrixxMediaPage.class);
// 
//     private GeometrixxMediaPageContent pageContent;
// 
//     @Inject @Named("jcr:content")
//     private Resource jcrResource;
// 
//     @PostConstruct
//     public void init() throws SlingModelsException {
// 
//         pageContent = jcrResource.adaptTo(GeometrixxMediaPageContent.class);
// 
//     }
// 
//     public GeometrixxMediaPage(Resource resource) throws SlingModelsException {
// 
//         if (null == resource) {
//             LOG.debug("resource is null");
//             throw new SlingModelsException("Resource is null");
//         }
// 
//         if (ResourceUtil.isNonExistingResource(resource)) {
//             LOG.warn("Can't adapt non existent resource: '{}'", resource.getPath());
//             throw new SlingModelsException(
//                 "Can't adapt non existent resource." + resource.getPath());
//         }
// 
//     }
// 
//     @Override
//     public String toString() {
// 
//         final StringBuilder sb = new StringBuilder("GeometrixxMediaPage{");
//         if(null != pageContent){
//             sb.append(pageContent.toString());
//         }
//         sb.append('}');
//         return sb.toString();
//     }
// 
//     @Override
//     public JSONObject getJson() {
// 
//         return pageContent != null ? pageContent.getJson() : new JSONObject();
//     }
// 
//     @Override
//     public SolrInputDocument getSolrDoc() {
// 
//         return pageContent != null ? pageContent.getSolrDoc() : null;
//     }
// }


// Path: aemsolrsearch-geometrixx-media-sample/src/main/java/com/headwire/aemsolrsearch/geometrixxmedia/servlets/SolrUpdateHandler.java
import com.day.cq.dam.api.DamConstants;
import com.day.cq.wcm.api.NameConstants;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaContentType;
import com.headwire.aemsolrsearch.geometrixxmedia.model.GeometrixxMediaPage;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;

package com.headwire.aemsolrsearch.geometrixxmedia.servlets;



/**
 * Renders supported Sling resource types using Solr's JSON update handler format. The following Sling resource
 * types are supported:
 *
 * <ul>
 *     <li><code>geometrixx-media/components/page/article</code></li>
 * </ul>
 *
 * <em>Note: *.solr.json should be blocked at dispatcher</em>
 *
 * @author <a href="mailto:gg@headwire.com">Gaston Gonzalez</a>
 */
@Component(immediate = true, metatype = true)
@Service(Servlet.class)
@Properties({
        @Property(name = Constants.SERVICE_VENDOR, value = "headwire.com, Inc."),
        @Property(name = Constants.SERVICE_DESCRIPTION, value = "Renders content using the Solr JSON update handler format "),
        @Property(name = "sling.servlet.methods", value = "GET"),
        @Property(name = "sling.servlet.resourceTypes", value = {NameConstants.NT_PAGE, DamConstants.NT_DAM_ASSET}),
        @Property(name = "sling.servlet.selectors", value = "solr"),
        @Property(name = "sling.servlet.extensions", value = "json")
})
public class SolrUpdateHandler extends SlingSafeMethodsServlet {

    private static final Logger LOG = LoggerFactory.getLogger(SolrUpdateHandler.class);

    @Override
    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");

        Resource page = request.getResource();
        GeometrixxMediaContentType contentType = page.adaptTo(GeometrixxMediaPage.class);