root / branches / v2_0_0_prep / extensions / org.gvsig.mkmvnproject / templates / SPI / org.gvsig.fortunecookies / org.gvsig.fortunecookies.prov / org.gvsig.fortunecookies.prov.webprovider / src / main / java / org / gvsig / fortunecookies / prov / webprovider / impl / FortuneCookieWebProvider.java @ 32378
History | View | Annotate | Download (2.5 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.fortunecookies.prov.webprovider.impl; |
24 |
|
25 |
import java.io.BufferedReader; |
26 |
import java.io.InputStreamReader; |
27 |
import java.net.URL; |
28 |
import java.util.regex.Pattern; |
29 |
|
30 |
import org.gvsig.fortunecookies.lib.spi.FortuneCookieProvider; |
31 |
import org.gvsig.fortunecookies.lib.spi.FortuneCookieProviderServices; |
32 |
import org.gvsig.tools.service.spi.AbstractProvider; |
33 |
import org.gvsig.tools.service.spi.ProviderServices; |
34 |
|
35 |
public class FortuneCookieWebProvider extends AbstractProvider implements FortuneCookieProvider{ |
36 |
|
37 |
public FortuneCookieWebProvider(ProviderServices providerServices) {
|
38 |
super(providerServices);
|
39 |
} |
40 |
|
41 |
public String getMessage() throws Exception { |
42 |
URL url = null; |
43 |
//url = new URL("http://www.fullerdata.com/FortuneCookie/FortuneCookie.asmx/GetFortuneCookie");
|
44 |
FortuneCookieProviderServices providerServices = (FortuneCookieProviderServices)this.getProviderServices();
|
45 |
url = new URL((String) providerServices.getParameters().getDynValue("URL")); |
46 |
String message_text = ""; |
47 |
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); |
48 |
String str;
|
49 |
// Create a pattern to match breaks
|
50 |
Pattern p = Pattern.compile("\\<[^\\>]+\\>"); |
51 |
String[] result = null; |
52 |
|
53 |
while ((str = in.readLine()) != null) { |
54 |
result = p.split(str); |
55 |
for (int i=0; i<result.length; i++) |
56 |
if(result[i].length()!=0) |
57 |
message_text = message_text + "\n" +result[i];
|
58 |
} |
59 |
in.close(); |
60 |
|
61 |
return message_text;
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public String toString() { |
66 |
return "Web provider, url="+ this.getProviderServices().getParameters().getDynValue("URL"); |
67 |
} |
68 |
} |