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

package com.k_int.webedit;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.*;
import javax.ws.rs.Path;
import javax.ws.rs.POST;

import com.sun.jersey.api.view.Viewable;
import com.sun.jersey.api.view.ImplicitProduces;
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 java.util.logging.Logger;


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

@XmlRootElement
@ImplicitProduces("text/html;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Path("/Editor/Main")
public class Editor {
   

  // @Context SecurtyContext sc;
  private static final Logger logger = Logger.getLogger( Editor.class.getName() );

  @XmlTransient
  @Context
  private UriInfo context;

  private String uri = "This is the default URI";

  public Editor() {
    logger.info("New Editor Instance");
    System.err.println("New Editor");
  }

  public String getURI() {  
    return uri;
  }

  public void setURI(String uri) {
    this.uri = uri;
  }

  /**
   * Retrieves representation of an instance of info.made4u.made4uws.workorder.Made4UWorkOrderResource
   * @param id resource URI parameter
   * @return an instance of java.lang.String
   */
  @GET
  @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
  public Editor getXml() {
    logger.info("GetXML");
    System.err.println("GetXML");
    return this;
  }

  /**
   * Retrieves representation of an instance of info.made4u.made4uws.workorder.Made4UWorkOrderResource
   * @param id resource URI parameter
   * @return an instance of java.lang.String
   *
   * Can also be coded as 
   * @POST
   * @Consumes("application/x-www-form-urlencoded")
   * public void post(MultivaluedMap<String, String> formParams)
   * public Editor postXml(@FormParam("URI") String uri) {
   */
  @POST
  @Consumes("application/x-www-form-urlencoded")  
  @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
  public Viewable postXml(@FormParam("URI") String uri) {
    logger.info("postXML "+uri);
    System.err.println("postXML");
    this.uri = uri;
    return new Viewable("index", this);
  }

  /**
   * PUT method for updating or creating an instance of Made4UWorkOrderResource
   * @param id resource URI parameter
   * @param content representation for the resource
   * @return an HTTP response with content of the updated or created resource.
   */
  @PUT
  @Consumes("application/xml")
  public void putXml(@PathParam("id") String id, String content) {
    System.out.println(content+","+id);
  }
}
