author | František Kučera <franta-hg@frantovo.cz> |
Sun Jul 10 19:55:05 2011 +0200 (2011-07-10) | |
changeset 184 | cab9eb4b027a |
parent 179 | 2ed9f3231a28 |
child 191 | 19128e9f7fb1 |
permissions | -rw-r--r-- |
franta-hg@177 | 1 |
package cz.frantovo.nekurak.servlet; |
franta-hg@177 | 2 |
|
franta-hg@179 | 3 |
import cz.frantovo.nekurak.dto.Podnik; |
franta-hg@179 | 4 |
import cz.frantovo.nekurak.ejb.PodnikRemote; |
franta-hg@177 | 5 |
import java.io.IOException; |
franta-hg@179 | 6 |
import java.io.UnsupportedEncodingException; |
franta-hg@179 | 7 |
import java.net.URLEncoder; |
franta-hg@179 | 8 |
import javax.ejb.EJB; |
franta-hg@177 | 9 |
import javax.servlet.ServletException; |
franta-hg@177 | 10 |
import javax.servlet.http.HttpServletRequest; |
franta-hg@177 | 11 |
import javax.servlet.http.HttpServletResponse; |
franta-hg@177 | 12 |
|
franta-hg@177 | 13 |
/** |
franta-hg@177 | 14 |
* |
franta-hg@177 | 15 |
* @author fiki |
franta-hg@177 | 16 |
*/ |
franta-hg@179 | 17 |
public class PodnikServlet extends SuperServlet { |
franta-hg@179 | 18 |
|
franta-hg@179 | 19 |
@EJB |
franta-hg@179 | 20 |
PodnikRemote ejb; |
franta-hg@177 | 21 |
|
franta-hg@177 | 22 |
@Override |
franta-hg@177 | 23 |
protected void doGet(HttpServletRequest požadavek, HttpServletResponse odpověď) throws ServletException, IOException { |
franta-hg@177 | 24 |
super.doGet(požadavek, odpověď); |
franta-hg@177 | 25 |
|
franta-hg@177 | 26 |
String[] parametryCesty = (požadavek.getPathInfo().split("/")); |
franta-hg@177 | 27 |
int id = Integer.parseInt(parametryCesty[1]); |
franta-hg@179 | 28 |
|
franta-hg@179 | 29 |
Podnik p = ejb.getPodnik(id); |
franta-hg@179 | 30 |
|
franta-hg@179 | 31 |
if (p == null) { |
franta-hg@179 | 32 |
odpověď.sendError(HttpServletResponse.SC_NOT_FOUND); |
franta-hg@179 | 33 |
} else { |
franta-hg@179 | 34 |
požadavek.setAttribute("podnik", p); |
franta-hg@179 | 35 |
požadavek.setAttribute("mapa", getMapa(p)); |
franta-hg@179 | 36 |
zpracujJSP("detail.jsp", požadavek, odpověď); |
franta-hg@179 | 37 |
} |
franta-hg@179 | 38 |
} |
franta-hg@179 | 39 |
|
franta-hg@179 | 40 |
/** |
franta-hg@179 | 41 |
* @return URL mapy – obrázku nebo null při chybě nebo absenci souřadnic |
franta-hg@179 | 42 |
*/ |
franta-hg@179 | 43 |
private String getMapa(Podnik p) { |
franta-hg@179 | 44 |
if (p == null || p.getSirka() == null || p.getDelka() == null) { |
franta-hg@179 | 45 |
return null; |
franta-hg@179 | 46 |
} else { |
franta-hg@179 | 47 |
try { |
franta-hg@179 | 48 |
String souradnice = URLEncoder.encode(p.getSirka() + ", " + p.getDelka(), "UTF-8"); |
franta-hg@184 | 49 |
return "https://maps.google.com/maps/api/staticmap?size=400x400&sensor=false&markers=size:big|color:green|" + souradnice; |
franta-hg@179 | 50 |
} catch (UnsupportedEncodingException e) { |
franta-hg@179 | 51 |
return null; |
franta-hg@179 | 52 |
} |
franta-hg@179 | 53 |
} |
franta-hg@177 | 54 |
} |
franta-hg@177 | 55 |
} |