Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Map; public class Main { public static final String FIELD_BACKUP_SOURCE_IDENTIFICATION = "backup_source_identification"; public static final String FIELD_BACKUP_SOURCE_PLUGIN_NAME = "backup_source_plugin_name"; public static final String FIELD_BACKUP_AT = "backup_at"; public static final String FIELD_JOB_NAME = "job_name"; public static String getFilterSuffix(Map<String, List<String>> filters) { if (filters == null) return ""; String filterstr = ""; if (filters.containsKey("type") == true) { filterstr += "("; for (String filter : filters.get("type")) { if (filter.toLowerCase().equals("html")) { filterstr += "Content-Type:*html* OR "; } else if (filter.toLowerCase().equals("image")) { filterstr += "Content-Type:image* OR "; } else if (filter.toLowerCase().equals("video")) { filterstr += "Content-Type:video* OR "; } else if (filter.toLowerCase().equals("audio")) { filterstr += "Content-Type:audio* OR "; } else if (filter.toLowerCase().equals("text")) { filterstr += "Content-Type:text* OR "; } } // remove the last " OR " and close the search string for this part filterstr = filterstr.substring(0, filterstr.length() - 4); filterstr += ") AND "; } // TODO if "ProfileName" includes special chars like (,", ... we will have a problem with the search? if (filters.containsKey("source") == true) { filterstr += "("; // something like this will come "org.backmeup.source (ProfileName)" for (String filter : filters.get("source")) { // get out the source plugin, result will be "org.backmeup.source" String source = filter.substring(0, filter.indexOf(" ")); // get out the profile "(Profilename)" String profile = filter.substring(filter.indexOf(" ") + 1, filter.length()); // remove the brackets at begin and end, result will be "ProfileName" profile = profile.substring(1, profile.length() - 1); filterstr += "(" + FIELD_BACKUP_SOURCE_PLUGIN_NAME + ":" + source + " AND " + FIELD_BACKUP_SOURCE_IDENTIFICATION + ":" + profile + ") OR "; } // remove the last " OR " and close the search string for this part filterstr = filterstr.substring(0, filterstr.length() - 4); filterstr += ") AND "; } // TODO if job contains special chars ... if (filters.containsKey("job") == true) { filterstr += "("; // something like this will come "JobName (Timestamp)" (java timestamp -> 13 chars) for (String filter : filters.get("job")) { // get out the timestamp (also remove the "()"). String timestamp = filter.substring(filter.length() - 14, filter.length() - 1); // get out the job name String jobname = filter.substring(0, filter.length() - 16); filterstr += "(" + FIELD_BACKUP_AT + ":" + timestamp + " AND " + FIELD_JOB_NAME + ":" + jobname + ") OR "; } // remove the last " OR " and close the search string for this part filterstr = filterstr.substring(0, filterstr.length() - 4); filterstr += ") AND "; } return filterstr; } }