List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str)
Returns either the passed in String, or if the String is null , an empty String ("").
StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"
From source file:com.netsteadfast.greenstep.util.SystemSettingConfigureUtils.java
public static String getLeftAccordionContainerEnableValue() { SysCodeVO sysCode = getLeftAccordionContainerEnable(); return StringUtils.defaultString(sysCode.getParam1()); }
From source file:com.navercorp.pinpoint.web.mapper.MapStatisticsCalleeMapper.java
@Override public LinkDataMap mapRow(Result result, int rowNum) throws Exception { if (result.isEmpty()) { return new LinkDataMap(); }/*from ww w .j ava 2s . c om*/ logger.debug("mapRow:{}", rowNum); final byte[] rowKey = getOriginalKey(result.getRow()); final Buffer row = new FixedBuffer(rowKey); final Application calleeApplication = readCalleeApplication(row); final long timestamp = TimeUtils.recoveryTimeMillis(row.readLong()); final LinkDataMap linkDataMap = new LinkDataMap(); for (Cell cell : result.rawCells()) { final byte[] qualifier = CellUtil.cloneQualifier(cell); final Application callerApplication = readCallerApplication(qualifier, calleeApplication.getServiceType()); if (filter.filter(callerApplication)) { continue; } long requestCount = Bytes.toLong(cell.getValueArray(), cell.getValueOffset()); short histogramSlot = ApplicationMapStatisticsUtils.getHistogramSlotFromColumnName(qualifier); String callerHost = ApplicationMapStatisticsUtils.getHost(qualifier); // There may be no callerHost for virtual queue nodes from user-defined entry points. // Terminal nodes, such as httpclient will not have callerHost set as well, but since they're terminal // nodes, they would not have reached here in the first place. if (calleeApplication.getServiceType().isQueue()) { callerHost = StringUtils.defaultString(callerHost); } boolean isError = histogramSlot == (short) -1; if (logger.isDebugEnabled()) { logger.debug(" Fetched Callee. {} callerHost:{} -> {} (slot:{}/{}), ", callerApplication, callerHost, calleeApplication, histogramSlot, requestCount); } final short slotTime = (isError) ? (short) -1 : histogramSlot; linkDataMap.addLinkData(callerApplication, callerApplication.getName(), calleeApplication, callerHost, timestamp, slotTime, requestCount); if (logger.isDebugEnabled()) { logger.debug(" Fetched Callee. statistics:{}", linkDataMap); } } return linkDataMap; }
From source file:com.yqboots.menu.core.MenuItemManagerImpl.java
/** * {@inheritDoc}/*from w w w. j a va 2s .c o m*/ */ @Override public Page<MenuItem> getMenuItems(final String wildcardName, final Pageable pageable) { final String searchStr = StringUtils.trim(StringUtils.defaultString(wildcardName)); return menuItemRepository.findByNameLikeIgnoreCaseOrderByName(DBUtils.wildcard(searchStr), pageable); }
From source file:de.micromata.genome.util.text.PipeValueList.java
/** * der Text wird getrimmt. Es sei denn, an letzter Stelle ist ein escapetes(mit Backsclash) Zeichen. * // w w w .ja va 2 s . c om * aus "a=b|c=d\\\n" wird a=b|c=d\n und aus "a=b|c=d\n" wird a=b|c=d * * @param text the text * @return the map */ public static Map<String, String> decode(String text) { Map<String, String> map = new HashMap<String, String>(); if (StringUtils.isEmpty(text) == true) { return map; } text = trim(text); List<String> tlist = TextSplitterUtils.parseStringTokens(text, "|\\=", true); StringBuilder sb = new StringBuilder(); String curKey = null; String curValue = null; State state = State.ParseKey; for (int i = 0; i < tlist.size(); ++i) { String t = tlist.get(i); if ("null".equals(t)) { //skip because null } else if ("\\".equals(t) == true) { ++i; t = tlist.get(i); sb.append(t); continue; } else if ("=".equals(t) == true) { if (state != State.ParseKey) { throw new IllegalStateException("Parsing '=' in state: " + state); } curKey = sb.toString(); sb = new StringBuilder(); state = State.ParseValue; } else if ("|".equals(t) == true) { if (state != State.ParseValue) { throw new IllegalStateException("Parsing '=' in state: " + state); } curValue = sb.toString(); map.put(curKey, curValue); sb = new StringBuilder(); curKey = null; curValue = null; state = State.ParseKey; } else { sb.append(t); } } if (curKey != null) { curValue = sb.toString(); map.put(curKey, StringUtils.defaultString(curValue)); } return map; }
From source file:com.ibasco.agql.protocols.valve.source.query.SourceRconPacketBuilder.java
@Override public byte[] deconstruct(SourceRconPacket packet) { //1) size = int (4 bytes) //2) id = int (4 bytes) //3) type = int (4 bytes) //4) body = string (length + 1 null byte) //5) trailer = null byte int id = packet.getId(); int type = packet.getType(); final String body = StringUtils.defaultString(packet.getBody()); int packetSize = 10 + body.length(); final ByteBuf buf = createBuffer(packetSize); byte[] data;//w w w.ja v a 2 s .co m try { buf.writeIntLE(packetSize); buf.writeIntLE(id); buf.writeIntLE(type); buf.writeBytes(body.getBytes()); buf.writeByte(0); buf.writeByte(0); data = new byte[buf.readableBytes()]; buf.readBytes(data); } finally { buf.release(); } return data; }
From source file:de.micromata.genome.gwiki.page.search.expr.SearchExpressionContentSearcher.java
@Override public QueryResult search(GWikiContext ctx, SearchQuery query) { long startSearchTime = System.currentTimeMillis(); List<SearchResult> ret = getSearchBase(ctx, query); int totalItems = ret.size(); query.setResults(ret);// w w w.j av a 2s .co m if (StringUtils.isEmpty(query.getSearchExpression()) == true) { QueryResult qs = new QueryResult(ret, ret.size()); qs.setTotalItems(totalItems); qs.setTotalFoundItems(ret.size()); qs.setSearchTime(System.currentTimeMillis() - startSearchTime); return qs; } SearchExpression se = parser.parse(StringUtils.defaultString(query.getSearchExpression())); String strsearch = se.toString(); GLog.info(GWikiLogCategory.Wiki, "Search; " + query.getSearchExpression() + ": " + strsearch); startSearchTime = System.currentTimeMillis(); Collection<SearchResult> res = se.filter(ctx, query); if (res instanceof List) { ret = (List<SearchResult>) res; } else { ret = new ArrayList<SearchResult>(); ret.addAll(res); } if ((se instanceof SearchExpressionOrderBy) == false) { Collections.sort(ret, new SearchResultByRelevanceComparator()); } long now = System.currentTimeMillis(); long searchTime = now - startSearchTime; LoggingServiceManager.get().getStatsDAO().addPerformance(GWikiLogCategory.Wiki, "WikiSearch.search", searchTime, 0); long startQuerySampleTime = now; int totalFound = ret.size(); if (query.getSearchOffset() > 0 || query.getMaxCount() < totalFound) { int startIdx = query.getSearchOffset(); int eidx = startIdx + (totalFound < query.getMaxCount() ? totalFound : query.getMaxCount()); eidx = eidx < ret.size() ? eidx : ret.size(); if (startIdx < eidx) { ret = ret.subList(startIdx, eidx); } else { ret = new ArrayList<SearchResult>(0); } } if (query.isWithSampleText() == true) { for (int i = 0; i < ret.size() && i < query.getMaxCount(); ++i) { querySampleText(ctx, se, query, ret.get(i)); } } QueryResult qr = new QueryResult(ret, ret.size()); qr.setTotalItems(totalItems); qr.setLookupWords(se.getLookupWords()); qr.setTotalFoundItems(totalFound); qr.setSearchTime(searchTime); qr.setGetTextExamleTime(System.currentTimeMillis() - startQuerySampleTime); return qr; }
From source file:de.blizzy.documentr.access.DocumentrSecurityExpressionRoot.java
public boolean projectExists(String projectName) { return repoManager.listProjects().contains(StringUtils.defaultString(projectName)); }
From source file:de.blizzy.documentr.web.system.SystemController.java
private SortedMap<String, SortedMap<String, String>> getMacroSettingsFromSystemSettings() { Set<IMacroDescriptor> descriptors = macroFactory.getDescriptors(); SortedMap<String, SortedMap<String, String>> allMacroSettings = Maps.newTreeMap(); for (IMacroDescriptor descriptor : descriptors) { Set<MacroSetting> settingDescriptors = descriptor.getSettings(); if (!settingDescriptors.isEmpty()) { SortedMap<String, String> macroSettings = Maps.newTreeMap(); String macroName = descriptor.getMacroName(); for (MacroSetting settingDescriptor : settingDescriptors) { String key = settingDescriptor.value(); String value = StringUtils.defaultString(systemSettingsStore.getMacroSetting(macroName, key)); macroSettings.put(key, value); }//from w w w .j ava2 s . c om allMacroSettings.put(macroName, macroSettings); } } return allMacroSettings; }
From source file:ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy.java
/** * Determines the servlet's context path. * //from w w w . j a va 2s . co m * This is here to try and deal with the wide variation in servers and what they return. * * getServletContext().getContextPath() is supposed to return the path to the specific servlet we are deployed as but it's not available everywhere. On some servers getServletContext() can return * null (old Jetty seems to suffer from this, see hapi-fhir-base-test-mindeps-server) and on other old servers (Servlet 2.4) getServletContext().getContextPath() doesn't even exist. * * theRequest.getContextPath() returns the context for the specific incoming request. It should be available everywhere, but it's likely to be less predicable if there are multiple servlet mappings * pointing to the same servlet, so we don't favour it. This is possibly not the best strategy (maybe we should just always use theRequest.getContextPath()?) but so far people seem happy with this * behavour across a wide variety of platforms. * * If you are having troubles on a given platform/configuration and want to suggest a change or even report incompatibility here, we'd love to hear about it. */ public static String determineServletContextPath(HttpServletRequest theRequest, RestfulServer server) { String retVal; if (server.getServletContext() != null) { if (server.getServletContext().getMajorVersion() >= 3 || (server.getServletContext().getMajorVersion() > 2 && server.getServletContext().getMinorVersion() >= 5)) { retVal = server.getServletContext().getContextPath(); } else { retVal = theRequest.getContextPath(); } } else { retVal = theRequest.getContextPath(); } retVal = StringUtils.defaultString(retVal); return retVal; }
From source file:io.wcm.config.core.persistence.impl.AbstractConfigPagePersistenceProvider.java
private Page createPage(ResourceResolver resolver, String path, String template) throws PersistenceException { // ensure parent path hierarchy exists - if not create it using pages with structure template String parentPath = ResourceUtil.getParent(path); if (parentPath == null) { throw new RuntimeException("Unable to get parent path from: " + path); }// ww w . j a v a2 s. c om if (resolver.getResource(parentPath) == null) { createPage(resolver, parentPath, getStructurePageTemplate()); } // create path with given template String name = ResourceUtil.getName(path); PageManager pageManager = resolver.adaptTo(PageManager.class); try { return pageManager.create(parentPath, name, StringUtils.defaultString(template), name, true); } catch (WCMException ex) { throw new PersistenceException("Creating page at " + path + " failed.", ex); } }