java/nekurak.net-web/src/java/cz/frantovo/nekurak/web/Detail.java
author František Kučera <franta-hg@frantovo.cz>
Wed Apr 14 00:12:32 2010 +0200 (2010-04-14)
changeset 100 01be78803f73
child 107 e8371105fcc8
permissions -rw-r--r--
Webové služby, zjišťování souřadnic podniků.
franta-hg@100
     1
package cz.frantovo.nekurak.web;
franta-hg@100
     2
franta-hg@100
     3
import cz.frantovo.nekurak.dto.Podnik;
franta-hg@100
     4
import java.io.UnsupportedEncodingException;
franta-hg@100
     5
import java.net.URLEncoder;
franta-hg@100
     6
import java.util.logging.Level;
franta-hg@100
     7
import java.util.logging.Logger;
franta-hg@100
     8
franta-hg@100
     9
/**
franta-hg@100
    10
 *
franta-hg@100
    11
 * @author fiki
franta-hg@100
    12
 */
franta-hg@100
    13
public class Detail {
franta-hg@100
    14
franta-hg@100
    15
    private HledacSluzby hledac = new HledacSluzby();
franta-hg@100
    16
    private int id;
franta-hg@100
    17
    private Podnik podnik;
franta-hg@100
    18
franta-hg@100
    19
    /**
franta-hg@100
    20
     * @return URL mapy – obrázku nebo null při chybě nebo absenci souřadnic
franta-hg@100
    21
     */
franta-hg@100
    22
    public String getMapa() {
franta-hg@100
    23
	Podnik p = getPodnik();
franta-hg@100
    24
franta-hg@100
    25
	if (p == null || p.getSirka() == null || p.getDelka() == null) {
franta-hg@100
    26
	    return null;
franta-hg@100
    27
	} else {
franta-hg@100
    28
	    try {
franta-hg@100
    29
		String souradnice = URLEncoder.encode(p.getSirka() + ", " + p.getDelka(), "UTF-8");
franta-hg@100
    30
		return "http://maps.google.com/maps/api/staticmap?size=400x400&sensor=false&center=" + souradnice;
franta-hg@100
    31
	    } catch (UnsupportedEncodingException e) {
franta-hg@100
    32
		return null;
franta-hg@100
    33
	    }
franta-hg@100
    34
	}
franta-hg@100
    35
    }
franta-hg@100
    36
franta-hg@100
    37
    public int getId() {
franta-hg@100
    38
	return id;
franta-hg@100
    39
    }
franta-hg@100
    40
franta-hg@100
    41
    public void setId(int id) {
franta-hg@100
    42
	this.id = id;
franta-hg@100
    43
    }
franta-hg@100
    44
franta-hg@100
    45
    public Podnik getPodnik() {
franta-hg@100
    46
	if (podnik == null) {
franta-hg@100
    47
	    podnik = hledac.getPodnikEJB().getPodnik(id);
franta-hg@100
    48
	}
franta-hg@100
    49
	return podnik;
franta-hg@100
    50
    }
franta-hg@100
    51
}