/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package me.ianibbo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.POST;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.core.Response;
import javax.ws.rs.*;
import javax.servlet.http.HttpServletRequest;

import javax.ws.rs.ext.ContextResolver;

import com.sun.jersey.api.view.ImplicitProduces;
import com.sun.jersey.api.json.JSONJAXBContext;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.view.Viewable;
import com.sun.jersey.api.view.ImplicitProduces;
import javax.xml.bind.JAXBContext;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * REST Web Service
 *
 * @author ibbo
 */

@Path("/")
@XmlRootElement
@ImplicitProduces("text/html;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Component
public class DCSFErrataRoot implements ApplicationContextAware {

  private ApplicationContext ctx;
  private static Log log = LogFactory.getLog(DCSFErrataRoot.class);

  @XmlTransient
  @Context
  private UriInfo context;

  @XmlTransient
  @Context
  private HttpServletRequest servlet_request;

  @XmlTransient
  private JAXBContext jaxb_context;

  public void setApplicationContext(ApplicationContext ctx) { 
    this.ctx = ctx; 
    log.debug("Setting app ctx");
  }

  public DCSFErrataRoot() {
    log.debug("DCSFErrataRoot::DCSFErrataRoot()");
  }

  /**
   */
  @GET
  @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
  public Response getXml(@QueryParam("description") String description) {
    return Response.ok(this).build();
  }

  @Consumes("multipart/form-data") 
  @POST
  @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
  public Response postXml(@FormParam("annotate_document") String annotate_document,
                          @FormParam("annotate_element") String annotate_element,
                          @FormParam("notes") String notes,
                          @FormParam("annotate_text") String annotate_text,
                          @FormParam("description") java.io.InputStream description) {
    return Response.ok("<xml>hello</xml>",javax.ws.rs.core.MediaType.APPLICATION_XML).build();
  }
}
