List of usage examples for org.springframework.util StringUtils isEmpty
public static boolean isEmpty(@Nullable Object str)
From source file:de.hybris.platform.marketplaceintegration.utils.impl.MarketplaceintegrationHttpUtilImpl.java
private void initConnection(final HttpURLConnection conn) { if (!StringUtils.isEmpty(baseAuthUser) && !StringUtils.isEmpty(baseAuthPassword)) { final String encoding = Base64.getEncoder() .encodeToString(String.format("%s:%s", baseAuthUser, baseAuthPassword).getBytes()); conn.setRequestProperty("Authorization", "Basic " + encoding); }/*from w w w . j av a 2s . c o m*/ for (final Entry<String, String> entry : httpHeaders.entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } }
From source file:com.comcast.video.dawg.show.video.VideoSnap.java
/** * Retrieve the images with input device ids from cache and stores it in zip * output stream./*from w w w. jav a 2 s . c o m*/ * * @param capturedImageIds * Ids of captures images * @param deviceMacs * Mac address of selected devices * @param response * http servelet response * @param session * http session. */ public void addImagesToZipFile(String[] capturedImageIds, String[] deviceMacs, HttpServletResponse response, HttpSession session) { UniqueIndexedCache<BufferedImage> imgCache = getClientCache(session).getImgCache(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Images_" + getCurrentDateAndTime() + ".zip\""); response.setContentType("application/zip"); ServletOutputStream serveletOutputStream = null; ZipOutputStream zipOutputStream = null; try { serveletOutputStream = response.getOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); zipOutputStream = new ZipOutputStream(byteArrayOutputStream); BufferedImage image; ZipEntry zipEntry; ByteArrayOutputStream imgByteArrayOutputStream = null; for (int i = 0; i < deviceMacs.length; i++) { // Check whether id of captured image is null or not if (!StringUtils.isEmpty(capturedImageIds[i])) { image = imgCache.getItem(capturedImageIds[i]); zipEntry = new ZipEntry(deviceMacs[i].toUpperCase() + "." + IMG_FORMAT); zipOutputStream.putNextEntry(zipEntry); imgByteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(image, IMG_FORMAT, imgByteArrayOutputStream); imgByteArrayOutputStream.flush(); zipOutputStream.write(imgByteArrayOutputStream.toByteArray()); zipOutputStream.closeEntry(); } } zipOutputStream.flush(); zipOutputStream.close(); serveletOutputStream.write(byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { LOGGER.error("Image zipping failed !!!", ioe); } finally { IOUtils.closeQuietly(zipOutputStream); } }
From source file:com.ocs.dynamo.ui.composite.layout.ServiceBasedSplitLayout.java
/** * Constructs a quick search field// w w w. j av a 2 s .co m */ @Override protected TextField constructSearchField() { if (getFormOptions().isShowQuickSearchField()) { TextField searchField = new TextField(message("ocs.search")); // respond to the user entering a search term searchField.addTextChangeListener(new TextChangeListener() { @Override public void textChange(TextChangeEvent event) { String text = event.getText(); if (!StringUtils.isEmpty(text)) { Filter extra = constructQuickSearchFilter(text); Filter f = extra; if (getFilter() != null) { f = new And(extra, getFilter()); } getContainer().search(f); } else { getContainer().search(filter); } } }); return searchField; } return null; }
From source file:cn.guoyukun.spring.jpa.repository.support.SimpleBaseRepositoryFactoryBean.java
private Object doGetTargetRepository(RepositoryMetadata metadata) { Class<?> repositoryInterface = metadata.getRepositoryInterface(); JpaEntityInformation<M, ID> entityInformation = getEntityInformation((Class<M>) metadata.getDomainType()); SimpleBaseRepository<M, ID> repository = new SimpleBaseRepository<M, ID>(entityInformation, entityManager); SearchableQuery searchableQuery = AnnotationUtils.findAnnotation(repositoryInterface, SearchableQuery.class); if (searchableQuery != null) { String countAllQL = searchableQuery.countAllQuery(); if (!StringUtils.isEmpty(countAllQL)) { repository.setCountAllQL(countAllQL); }/*from ww w. j a va 2s . com*/ String findAllQL = searchableQuery.findAllQuery(); if (!StringUtils.isEmpty(findAllQL)) { repository.setFindAllQL(findAllQL); } Class<? extends SearchCallback> callbackClass = searchableQuery.callbackClass(); if (callbackClass != null && callbackClass != SearchCallback.class) { repository.setSearchCallback(BeanUtils.instantiate(callbackClass)); } repository.setJoins(searchableQuery.joins()); } LOG.debug("?DAO {}", repository); return repository; }
From source file:cz.muni.fi.mir.tools.SiteTitleInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (handler instanceof HandlerMethod && modelAndView != null) { HandlerMethod handlerMethod = (HandlerMethod) handler; SiteTitleContainer result = new SiteTitleContainer(); Annotation classTitleAnotation = null; Annotation methodTitleAnnotation = null; SiteTitle classCast = null;/*from w ww .ja v a 2 s.co m*/ SiteTitle methodCast = null; for (Annotation a : handlerMethod.getMethod().getDeclaringClass().getAnnotations()) { if (a.annotationType().equals(SiteTitle.class)) { classTitleAnotation = a; break; } } for (Annotation a : handlerMethod.getMethod().getAnnotations()) { if (a.annotationType().equals(SiteTitle.class)) { methodTitleAnnotation = a; break; } } if (classTitleAnotation != null) { classCast = (SiteTitle) classTitleAnotation; } if (methodTitleAnnotation != null) { methodCast = (SiteTitle) methodTitleAnnotation; } // method has annotation if (methodCast != null) { // current method does not have set main title // so main title may be at class level, or set via // bean initialization process if (StringUtils.isEmpty(methodCast.mainTitle())) { resolveClassLevelTitle(classCast, result); } else { //method has annotation and set maintitle result.setMainTitle(methodCast.mainTitle()); } // current method does not have set separator // so separator may be at class level, or set via // bean initialization process if (StringUtils.isEmpty(methodCast.separator())) { resolveClassLevelSeparator(classCast, result); } else { // method has annotation and set separator result.setSeparator(methodCast.separator()); } // current method does not have set subtitle // so subtitle may be at class level, or set via // bean initialization process if (StringUtils.isEmpty(methodCast.value())) { resolveClassLevelSubTitle(classCast, result); } else { // method has annotation and set subtitle result.setSubTitle(methodCast.value()); } modelAndView.addObject(modelAttributeName, result.toString()); } else { // called method does not have annotation // so we check if there is class one if (classCast != null) { resolveClassLevelTitle(classCast, result); resolveClassLevelSeparator(classCast, result); resolveClassLevelSubTitle(classCast, result); modelAndView.addObject(modelAttributeName, result.toString()); } else { if (this.composeOnMissingAnnotation) { // there is no class nor method annotation // if compose is set to true we create title // from bean property otherwise we do nothing result.setMainTitle(this.mainTitle); result.setSeparator(this.separator); result.setSubTitle(this.subTitle); modelAndView.addObject(modelAttributeName, result.toString()); } } } } super.postHandle(request, response, handler, modelAndView); }
From source file:com.chexiang.idb.controller.DatabaseSlowSelController.java
@RequestMapping(value = "/queryPage/{pageNum}/{pageSize}") public @ResponseBody String queryPage(HttpServletRequest request, Model model, @PathVariable int pageNum, @PathVariable int pageSize) { System.out.println("??" + System.currentTimeMillis()); if (pageNum <= 0) { pageNum = 1;/*from ww w. jav a2s . c o m*/ } if (pageSize <= 0) { pageSize = 15; } ; HashMap<String, String> paraMap = new HashMap<String, String>(); String remParSign = request.getParameter("remParSign"); boolean sign = false; if ("remParSign".equals(remParSign)) { sign = true; } String searchStr = "&q="; String sortStr = "&sort="; Enumeration<String> parName = request.getParameterNames(); while (parName.hasMoreElements()) { String key = parName.nextElement(); if ("remParSign".equals(key)) { continue; } String value = request.getParameter(key); if (!StringUtils.isEmpty(value)) { if (key.endsWith("_wa8554d8r7gew")) { key = key.replace("_wa8554d8r7gew", ""); sortStr += (key + " asc,"); } else if (key.endsWith("wa8554d8r7gew_")) { key = key.replace("wa8554d8r7gew_", ""); sortStr += (key + " desc,"); } else { String[] vals = value.split(","); String prefix = ""; String suffix = ""; if (key.equals("user_host")) { prefix = "*"; suffix = "*"; } if (vals.length == 1) { searchStr += (key + ":" + prefix + vals[0] + suffix + " AND "); } else { searchStr += key + ":("; for (int i = 0; i < vals.length; i++) { if (i == vals.length - 1) { searchStr += (prefix + vals[i] + suffix + ") AND "); } else { searchStr += (prefix + vals[i] + suffix + " OR "); } } } } } } if ("&q=".equals(searchStr)) { searchStr += "*:*"; } else { searchStr = searchStr.substring(0, searchStr.length() - 5); } if ("&sort=".equals(sortStr)) { sortStr += "start_time desc"; } else { sortStr = sortStr.substring(0, sortStr.length() - 1); } String httpUrl = ""; String parUrl = ""; String solrAddress = ""; int start = (pageNum - 1) * pageSize; int rows = pageSize; if (sign) { paraMap.put("dicName", "RemPar_SolrAddredd"); List<Dictionary> dicList = dictionaryService.find(paraMap); solrAddress = "http://10.32.117.73:8983/solr/db_slow_query_novariable_shard1_replica1/select"; if (dicList.size() > 0) { solrAddress = dicList.get(0).getDicValue(); } httpUrl = solrAddress + "?fl=dbtype,db,start_time,query_time,lock_tim&rows=-1&group=true&group.field=sql_text"; } else { paraMap.put("dicName", "SlowSel_SolrAddredd"); List<Dictionary> dicList = dictionaryService.find(paraMap); solrAddress = "http://solr01.hadoop:8983/solr/db_slow_query_shard1_replica1/select"; if (dicList.size() > 0) { solrAddress = dicList.get(0).getDicValue(); } httpUrl = solrAddress + "?fl=dbtype,db,start_time,user_host,query_time,lock_time,rows_sent,rows_examined,sql_text&start=" + start + "&rows=" + rows; } parUrl += sortStr; parUrl += "&wt=json"; parUrl += searchStr; parUrl = parUrl.replaceAll(" ", "%20"); String url = httpUrl + parUrl; System.out.println("???" + System.currentTimeMillis()); System.out.println("??" + System.currentTimeMillis()); System.out.println(url); String jsonStr = HttpClientUtils.get(url); System.out.println("???" + System.currentTimeMillis()); System.out.println(jsonStr); System.out.println("?" + System.currentTimeMillis()); if (sign) { //json??json Map<String, Object> retMap = JSON.parseObject(jsonStr, new TypeReference<LinkedHashMap<String, Object>>() { }); Map<String, Map<String, Object>> groupMap = (Map<String, Map<String, Object>>) retMap.get("grouped"); Map<String, Object> sqlTextMap = groupMap.get("sql_text"); Object[] objs = (Object[]) sqlTextMap.get("groups"); //resonse Map<String, Object> respMap = new LinkedHashMap<String, Object>(); respMap.put("numFound", sqlTextMap.get("matches")); respMap.put("start", start); //docs Object[] docArrayList = new Object[objs.length]; respMap.put("docs", docArrayList); for (int i = 0; i < objs.length; i++) { Map<String, Object> groupobjMap = (Map<String, Object>) objs[i]; Map<String, Object> doclist = (Map<String, Object>) groupobjMap.get("doclist"); Object[] docObjects = (Object[]) doclist.get("docs"); //query_time lock_time int queryCount = 0; int lockCount = 0; ArrayList<Integer> queryMap = new ArrayList<Integer>(); ArrayList<Integer> lockMap = new ArrayList<Integer>(); for (int j = 0; j < docObjects.length; j++) { Map<String, Object> resultMap = (Map<String, Object>) docObjects[j]; int queryTime = getTime(resultMap.get("query_time")); int lock_time = getTime(resultMap.get("lock_time")); queryMap.add(queryTime); lockMap.add(lock_time); queryCount += queryTime; lockCount += lock_time; } Collections.sort(queryMap); Collections.sort(lockMap); Map<String, Object> resultMap = (Map<String, Object>) docObjects[0]; //querytaime?? String min_query_time = getTimeStr(queryMap.get(0)); String max_query_time = getTimeStr(queryMap.get(queryMap.size() - 1)); String acg_query_time = getTimeStr(queryCount / docObjects.length); resultMap.put("query_time", min_query_time + "<span class='sign'>(min)</span><br/>" + acg_query_time + "<span class='sign'>(avg)</span><br/>" + max_query_time + "<span class='sign'>(max)</span><br/>"); String min_lock_time = getTimeStr(lockMap.get(0)); String max_lock_time = getTimeStr(lockMap.get(lockMap.size() - 1)); String acg_lock_time = getTimeStr(lockCount / docObjects.length); resultMap.put("lock_time", min_lock_time + "<span class='sign'>(min)</span><br/>" + acg_lock_time + "<span class='sign'>(avg)</span><br/>" + max_lock_time + "<span class='sign'>(max)</span><br/>"); resultMap.put("sql_text", groupobjMap.get("groupValue")); resultMap.put("sql_count", doclist.get("numFound")); docArrayList[i] = resultMap; } retMap.remove("grouped"); retMap.put("response", respMap); jsonStr = JSON.toJSONString(retMap); jsonStr = jsonStr.replaceAll(" ", " "); jsonStr = jsonStr.replaceAll(" ", " "); jsonStr = jsonStr.replaceAll(" ", " "); jsonStr = jsonStr.replaceAll(" ", " "); } System.out.println("??" + System.currentTimeMillis()); return jsonStr; }
From source file:net.jiaoqsh.backend.mail.utils.JsonMapper.java
/** * ?????CollectionList<Bean>, createCollectionType()contructMapType(), ?. * *///from www .ja v a2 s .c o m public <T> T fromJson(String jsonString, JavaType javaType) { if (StringUtils.isEmpty(jsonString)) { return null; } try { return (T) mapper.readValue(jsonString, javaType); } catch (IOException e) { logger.warn("parse json string error:" + jsonString, e); return null; } }
From source file:io.pivotal.spring.cloud.service.eureka.EurekaInstanceAutoConfiguration.java
@Bean public EurekaInstanceConfigBean eurekaInstanceConfigBean() { if (!StringUtils.isEmpty(registrationMethod)) { LOGGER.info("Eureka registration method: " + registrationMethod); if (ROUTE_REGISTRATION_METHOD.equals(registrationMethod)) { return getRouteRegistration(); }// w ww.j a v a 2 s. c o m if (DIRECT_REGISTRATION_METHOD.equals(registrationMethod)) { return getDirectRegistration(); } } return getDefaultRegistration(); }
From source file:com.founder.zykc.controller.FdbzcrjryController.java
@RestfulAnnotation(serverId = "3") @RequestMapping(value = "/queryFdbzcrjList", method = RequestMethod.POST) public @ResponseBody EasyUIPage queryList(EasyUIPage page, @RequestParam(value = "rows", required = false) Integer rows, String sfzhm, String zwxm, SessionBean sessionBean) {/* w w w. j av a2 s. co m*/ page.setPagePara(rows); String url = "http://10.78.17.154:9999/lbs"; String urlParameter = "operation=ForbiddenDepartureManagement_GetInfoByIDName_v001&license=a756244eb0236bdc26061cb6b6bdb481&content="; int total = 0; List<FdbzcrjryVo> list = new ArrayList<FdbzcrjryVo>(); String content = ""; boolean isUpdated = false; if (!StringUtils.isEmpty(sfzhm) && !StringUtils.isEmpty(zwxm)) { content = "{\"data\":[{\"SFZHM\":\"" + sfzhm + "\"," + "\"ZWXM\":\"" + zwxm + "\"}]," + "\"pageindex\":" + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}"; } else if (StringUtils.isEmpty(sfzhm)) { content = "{\"data\":[{\"ZWXM\":\"" + zwxm + "\"}]," + "\"pageindex\":" + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}"; } else if (StringUtils.isEmpty(zwxm)) { // content = "{\"data\":[{\"SFZHM\":\"" + sfzhm // + "\"}]}"; content = "{\"data\":[{\"SFZHM\":\"" + sfzhm + "\"}]," + "\"pageindex\":" + (Integer.valueOf(page.getPage()) - 1) + "," + "\"pagesize\":" + rows + "}"; } try { content = urlParameter + java.net.URLEncoder.encode(content, "UTF-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } PostMethod postMethod = new PostMethod(url); byte[] b; try { b = content.getBytes("utf-8"); InputStream is = new ByteArrayInputStream(b, 0, b.length); RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/soap+xml; charset=utf-8"); postMethod.setRequestEntity(re); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpClient httpClient = new HttpClient(); HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams(); managerParams.setConnectionTimeout(50000); int statusCode = 0; try { statusCode = httpClient.executeMethod(postMethod); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (statusCode == 200) { String soapResponseData = ""; try { soapResponseData = postMethod.getResponseBodyAsString(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jb = JSONObject.fromObject(soapResponseData); if ((Integer) jb.get("datalen") > 0) { Map<String, String> dictHkszd = new HashMap<String, String>();//? Map<String, String> dictFlyj = new HashMap<String, String>();//?? Map<String, String> dictCsd = new HashMap<String, String>();// Map<String, String> dictBbrylx = new HashMap<String, String>();// Map<String, String> dictPcs = new HashMap<String, String>();// Map<String, String> dictXb = new HashMap<String, String>();// Map<String, String> dictZjzl = new HashMap<String, String>();//?? Map<String, String> dictZzjg = new HashMap<String, String>();// Map<String, String> dictMj = new HashMap<String, String>();// try { dictHkszd = sysDictGlService.getDictMap("BD_D_FDBZCJHKSZD"); dictFlyj = sysDictGlService.getDictMap("BD_D_FDBZCJFLYJ"); dictCsd = sysDictGlService.getDictMap("BD_D_FDBZCJCSD"); dictBbrylx = sysDictGlService.getDictMap("BD_D_FDBZCJBBRYLB"); dictPcs = sysDictGlService.getDictMap("BD_D_FDBZCJPCS"); dictXb = sysDictGlService.getDictMap("BD_D_FDBZCJXB"); dictZjzl = sysDictGlService.getDictMap("BD_D_FDBZCJZJZL"); dictZzjg = sysDictGlService.getDictMap("BD_D_FDBZCJORG"); dictMj = sysDictGlService.getDictMap("BD_D_FDBZCJMJ"); } catch (Exception e2) { // TODO Auto-generated catch block e2.printStackTrace(); } total = Integer.valueOf(jb.getString("total")); for (int i = 0; i < (Integer) jb.get("datalen"); i++) { JSONObject jo = jb.getJSONArray("data").getJSONObject(i); FdbzcrjryVo vo = new FdbzcrjryVo(); if (jo.containsKey("BBDWBM")) { vo.setBbdwbm(dictZzjg.get(jo.getString("BBDWBM"))); } if (jo.containsKey("BBLXDH")) { vo.setBblxdh(jo.getString("BBLXDH")); } if (jo.containsKey("BBLXR")) { vo.setBblxr(jo.getString("BBLXR")); } if (jo.containsKey("BBQX")) { vo.setBbqx(jo.getString("BBQX")); } if (jo.containsKey("BBRQ")) { vo.setBbrq(jo.getString("BBRQ")); } if (jo.containsKey("BBRYLB")) { vo.setBbrylb(dictBbrylx.get(jo.getString("BBRYLB"))); } if (jo.containsKey("BBYY")) { vo.setBbyy(jo.getString("BBYY")); } if (jo.containsKey("BZ")) { vo.setBz(jo.getString("BZ")); } if (jo.containsKey("CSD")) { vo.setCsd(dictCsd.get(jo.getString("CSD"))); } if (jo.containsKey("DAH")) { vo.setDah(jo.getString("DAH")); } if (jo.containsKey("DWDH")) { vo.setDwdh(jo.getString("DWDH")); } if (jo.containsKey("FLYJ")) { vo.setFlyj(dictFlyj.get(jo.getString("FLYJ"))); } if (jo.containsKey("GZDW")) { vo.setGzdw(jo.getString("GZDW")); } if (jo.containsKey("HKSZD")) { vo.setHkszd(dictHkszd.get(jo.getString("HKSZD"))); } if (jo.containsKey("FLYJ")) { vo.setFlyj(dictFlyj.get(jo.getString("FLYJ"))); } if (jo.containsKey("JTDH")) { vo.setJtdh(jo.getString("JTDH")); } if (jo.containsKey("MJ")) { vo.setMj(dictMj.get(jo.getString("MJ"))); } if (jo.containsKey("PCSSZD")) { vo.setPcsszd(dictPcs.get(jo.getString("PCSSZD"))); } if (jo.containsKey("PYXM")) { vo.setPyxm(jo.getString("PYXM")); } if (jo.containsKey("SFZDCK")) { vo.setSfzdck(jo.getString("SFZDCK")); } if (jo.containsKey("SFZHM")) { vo.setSfzhm(jo.getString("SFZHM")); } if (jo.containsKey("XB")) { vo.setXb(dictXb.get(jo.getString("XB"))); } if (jo.containsKey("XZZ")) { vo.setXzz(jo.getString("XZZ")); } if (jo.containsKey("ZJHM")) { vo.setZjhm(jo.getString("ZJHM")); } if (jo.containsKey("ZJZL")) { vo.setZjzl(dictZjzl.get(jo.getString("ZJZL"))); } if (jo.containsKey("ZWM")) { vo.setZwm(jo.getString("ZWM")); } if (jo.containsKey("ZWX")) { vo.setZwx(jo.getString("ZWX")); } if (jo.containsKey("RYDH")) { vo.setRydh(jo.getString("RYDH")); } list.add(vo); } } } else { System.out.println("????" + statusCode); } page.setRows(list); page.setTotal(total); return page; }