Skip to content

Commit fb9f67b

Browse files
committed
Reformat src, delete incorrect javadoc and comments.
1 parent 1c2ed49 commit fb9f67b

File tree

3 files changed

+223
-260
lines changed

3 files changed

+223
-260
lines changed

managedvms/async-rest/src/main/java/com/google/appengine/demos/asyncrest/AbstractRestServlet.java

Lines changed: 70 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,124 +14,95 @@
1414
import javax.servlet.http.HttpServletRequest;
1515
import javax.servlet.http.HttpServletResponse;
1616

17-
/**
18-
* Abstract Servlet implementation class AsyncRESTServlet.
19-
* Enquires ebay REST service for auctions by key word.
20-
* May be configured with init parameters: <dl>
21-
* <dt>appid</dt><dd>The eBay application ID to use</dd>
22-
* </dl>
23-
* Each request examines the following request parameters:<dl>
24-
* <dt>items</dt><dd>The keyword to search for</dd>
25-
* </dl>
17+
/**
18+
* AbstractRestServlet.
19+
*
2620
*/
27-
public class AbstractRestServlet extends HttpServlet
28-
{
29-
protected final static int MAX_RESULTS = 5;
30-
protected final static String GOOGLE_API_KEY_NAME = "async_example_place_key";
31-
protected final static String GOOGLE_API_KEY = "AIzaSyABCgUB4wc290F9LcIigNXurT6yNV92yfY";
32-
33-
protected final static String STYLE =
34-
"<style type='text/css'>"+
35-
" img.thumb:hover {height:50px}"+
36-
" img.thumb {vertical-align:text-top}"+
37-
" span.red {color: #ff0000}"+
38-
" span.green {color: #00ff00}"+
39-
" iframe {border: 0px}"+
40-
"</style>";
21+
public class AbstractRestServlet extends HttpServlet {
22+
protected final static int MAX_RESULTS = 5;
4123

24+
protected final static String GOOGLE_API_KEY = "AIzaSyABCgUB4wc290F9LcIigNXurT6yNV92yfY";
25+
26+
protected final static String STYLE = "<style type='text/css'>"
27+
+ " img.thumb:hover {height:50px}"
28+
+ " img.thumb {vertical-align:text-top}"
29+
+ " span.red {color: #ff0000}"
30+
+ " span.green {color: #00ff00}"
31+
+ " iframe {border: 0px}" + "</style>";
4232

4333
protected final static String APPID_PARAM = "appid";
4434
protected final static String LOC_PARAM = "loc";
4535
protected final static String ITEMS_PARAM = "items";
4636
protected final static String LATITUDE_PARAM = "lat";
4737
protected final static String LONGITUDE_PARAM = "long";
48-
protected final static String RADIUS_PARAM ="radius";
49-
protected String _key;
38+
protected final static String RADIUS_PARAM = "radius";
39+
protected String key;
5040

5141
@Override
52-
public void init(ServletConfig servletConfig) throws ServletException
53-
{
54-
if (servletConfig.getInitParameter(APPID_PARAM) == null)
55-
_key = GOOGLE_API_KEY;
56-
else
57-
_key = servletConfig.getInitParameter(APPID_PARAM);
42+
public void init(ServletConfig servletConfig) throws ServletException {
43+
if (servletConfig.getInitParameter(APPID_PARAM) == null)
44+
key = GOOGLE_API_KEY;
45+
else
46+
key = servletConfig.getInitParameter(APPID_PARAM);
5847
}
5948

60-
61-
public static String sanitize(String s)
62-
{
63-
if (s==null)
64-
return null;
65-
return s.replace("<","?").replace("&","?").replace("\n","?");
49+
public static String sanitize(String s) {
50+
if (s == null)
51+
return null;
52+
return s.replace("<", "?").replace("&", "?").replace("\n", "?");
6653
}
67-
68-
protected String restQuery (String coordinates, String radius, String item)
69-
{
70-
try
71-
{
72-
return "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key="+_key
73-
+"&location="+URLEncoder.encode(coordinates,"UTF-8")
74-
+"&types="+URLEncoder.encode(item,"UTF-8")
75-
+"&radius="+URLEncoder.encode(radius, "UTF-8");
76-
77-
}
78-
catch (Exception e)
79-
{
80-
throw new RuntimeException(e);
81-
}
54+
55+
protected String restQuery(String coordinates, String radius, String item) {
56+
try {
57+
return "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=" + key + "&location="
58+
+ URLEncoder.encode(coordinates, "UTF-8") + "&types=" + URLEncoder.encode(item, "UTF-8")
59+
+ "&radius=" + URLEncoder.encode(radius, "UTF-8");
60+
61+
} catch (Exception e) {
62+
throw new RuntimeException(e);
63+
}
8264
}
83-
84-
85-
86-
public String generateResults (Queue<Map<String,Object>> results)
87-
{
88-
StringBuilder thumbs = new StringBuilder();
89-
int resultCount = 0;
90-
Iterator<Map<String,Object>> itor = results.iterator();
91-
92-
while (resultCount < MAX_RESULTS && itor.hasNext())
93-
{
94-
Map m = (Map)itor.next();
95-
String name = (String)m.get("name");
96-
Object[] photos = (Object[])m.get("photos");
97-
if (photos != null && photos.length > 0)
98-
{
99-
resultCount++;
100-
thumbs.append("<img class='thumb' border='1px' height='40px'"+
101-
" src='"+getPhotoURL((String)(((Map)photos[0]).get("photo_reference")))+"'"+
102-
" title='"+name+"'"+
103-
"/>");
104-
thumbs.append("</a>&nbsp;");
105-
}
106-
}
107-
return thumbs.toString();
65+
66+
public String generateResults(Queue<Map<String, Object>> results) {
67+
StringBuilder thumbs = new StringBuilder();
68+
int resultCount = 0;
69+
Iterator<Map<String, Object>> itor = results.iterator();
70+
71+
while (resultCount < MAX_RESULTS && itor.hasNext()) {
72+
Map m = (Map) itor.next();
73+
String name = (String) m.get("name");
74+
Object[] photos = (Object[]) m.get("photos");
75+
if (photos != null && photos.length > 0) {
76+
resultCount++;
77+
thumbs.append("<img class='thumb' border='1px' height='40px'" + " src='"
78+
+ getPhotoURL((String) (((Map) photos[0]).get("photo_reference"))) + "'" + " title='" + name
79+
+ "'" + "/>");
80+
thumbs.append("</a>&nbsp;");
81+
}
82+
}
83+
return thumbs.toString();
10884
}
109-
110-
public String getPhotoURL (String photoref)
111-
{
112-
return "https://maps.googleapis.com/maps/api/place/photo?key="+_key
113-
+"&photoreference="+photoref
114-
+"&maxheight=40";
85+
86+
public String getPhotoURL(String photoref) {
87+
return "https://maps.googleapis.com/maps/api/place/photo?key=" + key + "&photoreference=" + photoref
88+
+ "&maxheight=40";
11589
}
116-
11790

118-
protected String ms(long nano)
119-
{
120-
BigDecimal dec = new BigDecimal(nano);
121-
return dec.divide(new BigDecimal(1000000L)).setScale(1,RoundingMode.UP).toString();
91+
protected String ms(long nano) {
92+
BigDecimal dec = new BigDecimal(nano);
93+
return dec.divide(new BigDecimal(1000000L)).setScale(1, RoundingMode.UP).toString();
12294
}
123-
124-
protected int width(long nano)
125-
{
126-
int w=(int)((nano+999999L)/5000000L);
127-
if (w==0)
128-
w=2;
129-
return w;
95+
96+
protected int width(long nano) {
97+
int w = (int) ((nano + 999999L) / 5000000L);
98+
if (w == 0)
99+
w = 2;
100+
return w;
130101
}
131-
132-
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
133-
{
134-
doGet(request, response);
102+
103+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
104+
throws ServletException, IOException {
105+
doGet(request, response);
135106
}
136107

137108
}

0 commit comments

Comments
 (0)