java/nekurak.net-rest/src/java/cz/frantovo/nekurak/rest/ClankyREST.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 05 Apr 2010 22:30:08 +0200
changeset 90 0967d5e3b470
parent 89 59ba044de164
child 92 12268fc31114
permissions -rw-r--r--
generování XML vycpávkového článku
     1 package cz.frantovo.nekurak.rest;
     2 
     3 import cz.frantovo.nekurak.dto.Clanek;
     4 import cz.frantovo.nekurak.xml.ClanekXML;
     5 import javax.ws.rs.Consumes;
     6 import javax.ws.rs.DELETE;
     7 import javax.ws.rs.GET;
     8 import javax.ws.rs.POST;
     9 import javax.ws.rs.PUT;
    10 import javax.ws.rs.Path;
    11 import javax.ws.rs.PathParam;
    12 import javax.ws.rs.Produces;
    13 
    14 @Path("clanek")
    15 public class ClankyREST {
    16 
    17     private static final String MIME_XML = "text/xml";
    18 
    19     /** Vypíšeme seznam všech článků v systému */
    20     @GET
    21     @Path("/")
    22     @Produces("text/plain")
    23     public String getClanky() {
    24 	return "tady bude seznam";
    25     }
    26 
    27     /** Získáme konkrétní článek */
    28     @GET
    29     @Path("/{id}")
    30     @Produces(MIME_XML)
    31     public ClanekXML ziskej(@PathParam("id") int id) {
    32 	Clanek c = new Clanek();
    33 	c.setId(id);
    34 	c.setNadpis("Nadpis článku");
    35 	c.setText("nějaký pěkný text");
    36 	return new ClanekXML(c);
    37     }
    38 
    39     /**
    40      * Vložíme nový článek
    41      * @return ID založeného článku
    42      */
    43     @POST
    44     @Consumes(MIME_XML)
    45     @Produces("text/plain")
    46     public int zaloz() {
    47 	return 0;
    48     }
    49 
    50     /** Aktualizujeme článek */
    51     @PUT
    52     @Consumes(MIME_XML)
    53     @Path("/{id}")
    54     public void uloz(@PathParam("id") int id) {
    55     }
    56 
    57     /** Smažeme článek */
    58     @DELETE
    59     @Path("/{id}")
    60     public void smaz(@PathParam("id") int id) {
    61     }
    62 }