Mercurial > hg > IndexMetaContextualizer
comparison src/main/java/de/mpiwg/indexmeta/web/servlet/methods/AbstractServletMethod.java @ 7:bc57f2660b0f
implementation of web service
author | Jorge Urzua <jurzua@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 12 Apr 2013 17:48:42 +0200 |
parents | |
children | 9ce7979fd037 |
comparison
equal
deleted
inserted
replaced
5:7d231e4e86e5 | 7:bc57f2660b0f |
---|---|
1 package de.mpiwg.indexmeta.web.servlet.methods; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import javax.servlet.http.HttpServletRequest; | |
7 | |
8 import org.apache.commons.lang.StringUtils; | |
9 | |
10 import de.mpiwg.indexmeta.bo.Contextualization; | |
11 | |
12 public abstract class AbstractServletMethod { | |
13 | |
14 public static String p_indexMetaId = "indexMetaId"; | |
15 public static String p_type = "type"; | |
16 public static String p_remoteId = "remoteId"; | |
17 public static String p_elementId = "elementId"; | |
18 | |
19 protected static String RUNTIME = "runtime"; | |
20 | |
21 public static Long getLong(HttpServletRequest request, String name){ | |
22 Long value = null; | |
23 try{ | |
24 String s = request.getParameter(name); | |
25 value = new Long(s); | |
26 }catch (Exception e) { | |
27 } | |
28 return value; | |
29 } | |
30 | |
31 public static String getString(HttpServletRequest request, String name){ | |
32 String value = null; | |
33 try{ | |
34 value = request.getParameter(name); | |
35 }catch (Exception e) { | |
36 } | |
37 return value; | |
38 } | |
39 | |
40 public static Boolean getBoolean(HttpServletRequest request, String name){ | |
41 Boolean value = null; | |
42 try{ | |
43 String s = request.getParameter(name); | |
44 value = new Boolean(s); | |
45 }catch (Exception e) { | |
46 } | |
47 return value; | |
48 } | |
49 | |
50 public static Integer getInteger(HttpServletRequest request, String name){ | |
51 Integer value = null; | |
52 try{ | |
53 String s = request.getParameter(name); | |
54 value = new Integer(s); | |
55 }catch (Exception e) { | |
56 } | |
57 return value; | |
58 } | |
59 | |
60 protected static List<Contextualization> filterByType(List<Contextualization> list, String type){ | |
61 if(StringUtils.isEmpty(type)){ | |
62 return list; | |
63 } | |
64 List<Contextualization> rs = new ArrayList<Contextualization>(); | |
65 for(Contextualization ctx : list){ | |
66 if(type.equals(ctx.getType())){ | |
67 rs.add(ctx); | |
68 } | |
69 } | |
70 return rs; | |
71 } | |
72 | |
73 protected static List<Contextualization> filterByElementId(List<Contextualization> list, String elementId){ | |
74 if(StringUtils.isEmpty(elementId)){ | |
75 return list; | |
76 } | |
77 List<Contextualization> rs = new ArrayList<Contextualization>(); | |
78 for(Contextualization ctx : list){ | |
79 if(elementId.equals(elementId)){ | |
80 rs.add(ctx); | |
81 } | |
82 } | |
83 return rs; | |
84 } | |
85 | |
86 protected static List<Contextualization> filterByRemoteId(List<Contextualization> list, String remoteId){ | |
87 if(StringUtils.isEmpty(remoteId)){ | |
88 return list; | |
89 } | |
90 List<Contextualization> rs = new ArrayList<Contextualization>(); | |
91 for(Contextualization ctx : list){ | |
92 if(remoteId.equals(ctx.getRemoteId())){ | |
93 rs.add(ctx); | |
94 } | |
95 } | |
96 return rs; | |
97 } | |
98 | |
99 public static List<Long> getLongList(HttpServletRequest request, String name){ | |
100 List<Long> list = new ArrayList<Long>(); | |
101 String s = request.getParameter(name); | |
102 String[] array = s.split("[|]"); | |
103 for(String sID : array){ | |
104 try{ | |
105 Long id = new Long(sID); | |
106 list.add(id); | |
107 }catch (Exception e) {} | |
108 } | |
109 return list; | |
110 } | |
111 } |