view 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
line wrap: on
line source

package de.mpiwg.indexmeta.web.servlet.methods;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import de.mpiwg.indexmeta.bo.Contextualization;

public abstract class AbstractServletMethod {
	
	public static String p_indexMetaId = "indexMetaId";
	public static String p_type = "type";
	public static String p_remoteId = "remoteId";
	public static String p_elementId = "elementId";
	
	protected static String RUNTIME = "runtime";
	
	public static Long getLong(HttpServletRequest request, String name){
		Long value = null;
		try{
			String s = request.getParameter(name);
			value = new Long(s);
		}catch (Exception e) {
		}
		return value;
	}
	
	public static String getString(HttpServletRequest request, String name){
		String value = null;
		try{
			value = request.getParameter(name);
		}catch (Exception e) {
		}
		return value;
	}
	
	public static Boolean getBoolean(HttpServletRequest request, String name){
		Boolean value = null;
		try{
			String s = request.getParameter(name);
			value = new Boolean(s);
		}catch (Exception e) {
		}
		return value;
	}
	
	public static Integer getInteger(HttpServletRequest request, String name){
		Integer value = null;
		try{
			String s = request.getParameter(name);
			value = new Integer(s);
		}catch (Exception e) {
		}
		return value;
	}
	
	protected static List<Contextualization> filterByType(List<Contextualization> list, String type){
		if(StringUtils.isEmpty(type)){
			return list;
		}
		List<Contextualization> rs = new ArrayList<Contextualization>();		
		for(Contextualization ctx : list){
			if(type.equals(ctx.getType())){
				rs.add(ctx);
			}
		}		
		return rs;
	}
	
	protected static List<Contextualization> filterByElementId(List<Contextualization> list, String elementId){
		if(StringUtils.isEmpty(elementId)){
			return list;
		}
		List<Contextualization> rs = new ArrayList<Contextualization>();		
		for(Contextualization ctx : list){
			if(elementId.equals(elementId)){
				rs.add(ctx);
			}
		}		
		return rs;
	}
	
	protected static List<Contextualization> filterByRemoteId(List<Contextualization> list, String remoteId){
		if(StringUtils.isEmpty(remoteId)){
			return list;
		}
		List<Contextualization> rs = new ArrayList<Contextualization>();		
		for(Contextualization ctx : list){
			if(remoteId.equals(ctx.getRemoteId())){
				rs.add(ctx);
			}
		}		
		return rs;
	}
	
	public static List<Long> getLongList(HttpServletRequest request, String name){
		List<Long> list = new ArrayList<Long>();
		String s = request.getParameter(name);
		String[] array = s.split("[|]");
		for(String sID : array){
			try{
				Long id = new Long(sID);
				list.add(id);
			}catch (Exception e) {}
		}
		return list;
	}
}