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:code.tianmao.h5.controller.BackendExceptionController.java
private boolean noNeedWrapper(HttpServletRequest request) { String xmlHttpRequest = request.getHeader("X-Requested-With"); String noWrapperParameter = StringUtils.defaultString(request.getParameter("noSiteMeshWapper")); return "XMLHttpRequest".equalsIgnoreCase(xmlHttpRequest) || noWrapperParameter.equalsIgnoreCase("true") || noWrapperParameter.equalsIgnoreCase("yes") || noWrapperParameter.equals("1"); }
From source file:com.netsteadfast.greenstep.base.model.CheckFieldHandler.java
@SuppressWarnings("unchecked") public CheckFieldHandler add(String fieldsName, Class<?> checkUtilsClass, String message) { this.fieldsNames.add(fieldsName); this.fieldsMessages.add(StringUtils.defaultString(message)); this.checkUtilsClazzs.add((Class<IActionFieldsCheckUtils>) checkUtilsClass); return this; }
From source file:net.andydvorak.intellij.lessc.state.LessProfile.java
@NotNull public String getExcludePattern() { return StringUtils.defaultString(excludePattern); }
From source file:com.netsteadfast.greenstep.bsc.command.LoadMeasureDataCommand.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a v a 2 s . c om*/ public boolean execute(Context context) throws Exception { measureDataService = (IMeasureDataService<MeasureDataVO, BbMeasureData, String>) AppContext .getBean("bsc.service.MeasureDataService"); String frequency = (String) context.get("frequency"); String startYearDate = StringUtils.defaultString((String) context.get("startYearDate")).trim(); String endYearDate = StringUtils.defaultString((String) context.get("endYearDate")).trim(); String startDate = StringUtils.defaultString((String) context.get("startDate")).trim(); String endDate = StringUtils.defaultString((String) context.get("endDate")).trim(); startDate = startDate.replaceAll("/", "").replaceAll("-", ""); endDate = endDate.replaceAll("/", "").replaceAll("-", ""); String date1 = startDate; String date2 = endDate; if (BscMeasureDataFrequency.FREQUENCY_QUARTER.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_HALF_OF_YEAR.equals(frequency) || BscMeasureDataFrequency.FREQUENCY_YEAR.equals(frequency)) { date1 = startYearDate + "0101"; date2 = endYearDate + "12" + SimpleUtils.getMaxDayOfMonth(Integer.parseInt(endYearDate), 12); } String measureDataOrgaId = (String) context.get("orgId"); String measureDataEmplId = (String) context.get("empId"); if (this.getResult(context) == null || !(this.getResult(context) instanceof BscStructTreeObj)) { return false; } BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context); for (VisionVO vision : treeObj.getVisions()) { for (PerspectiveVO perspective : vision.getPerspectives()) { for (ObjectiveVO objective : perspective.getObjectives()) { for (KpiVO kpi : objective.getKpis()) { this.fillMeasureData(kpi, frequency, date1, date2, measureDataOrgaId, measureDataEmplId); } } } } return false; }
From source file:com.github.jknack.handlebars.helper.DefaultFilterHelper.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*w w w .j a v a2s. c om*/ public CharSequence apply(final Object context, final Options options) throws IOException { if (context == null) { return StringUtils.EMPTY; } if (context instanceof Iterable) { String[] filterValues = null; String filterValue = ""; String targetField = ""; if (options.hash.size() > 0) { for (Map.Entry<String, Object> item : options.hash.entrySet()) { if (item != null) { filterValues = StringUtils.defaultString(item.getValue().toString()).split(","); if (filterValues != null && filterValues.length > 0) { filterValue = StringUtils.defaultString(filterValues[0]).trim(); if (filterValues.length > 1) { targetField = StringUtils.defaultString(filterValues[1]).trim(); } } break; } } } if (filterValues != null && filterValues.length > 0) { Set<Entry<String, Object>> propertySet = options.propertySet(context); Iterator<Entry<String, Object>> contextLoop = ((Iterable) context).iterator(); while (contextLoop.hasNext()) { Object item = contextLoop.next(); if (item != null) { String typeValue = getFieldValue(item, TYPEVALUE); boolean matched = StringUtils.isNotBlank(typeValue) && filterValue.equalsIgnoreCase(typeValue); if (matched) { return getFieldValue(item, targetField); } } } } } return hashContext(context, options); }
From source file:io.wcm.samples.handler.util.AppTemplate.java
private AppTemplate(String templatePath) { mTemplatePath = templatePath;/*from w ww . j av a2 s .c o m*/ // build resource type from template path String resourceType = null; final Pattern TEMPLATE_PATH_PATTERN = Pattern.compile("^/apps/([^/]+)/templates(/.*)?/([^/]+)$"); Matcher templateParts = TEMPLATE_PATH_PATTERN.matcher(templatePath); if (templateParts.matches()) { resourceType = "/apps/" + templateParts.group(1) + "/components" + StringUtils.defaultString(templateParts.group(2)) + "/page/" + templateParts.group(3); } mResourceType = resourceType; }
From source file:edu.gatech.i3l.fhir.jpa.provider.BaseJpaProvider.java
public void startRequest(HttpServletRequest theRequest) { if (theRequest == null) { return;/* w w w. j a v a 2 s .com*/ } Set<String> headerNames = new TreeSet<String>(); for (Enumeration<String> enums = theRequest.getHeaderNames(); enums.hasMoreElements();) { headerNames.add(enums.nextElement()); } ourLog.debug("Request headers: {}", headerNames); Enumeration<String> forwardedFors = theRequest.getHeaders("x-forwarded-for"); StringBuilder b = new StringBuilder(); for (Enumeration<String> enums = forwardedFors; enums.hasMoreElements();) { if (b.length() > 0) { b.append(" / "); } b.append(enums.nextElement()); } String forwardedFor = b.toString(); String ip = theRequest.getRemoteAddr(); if (StringUtils.isBlank(forwardedFor)) { org.slf4j.MDC.put(REMOTE_ADDR, ip); ourLog.debug("Request is from address: {}", ip); } else { org.slf4j.MDC.put(REMOTE_ADDR, forwardedFor); ourLog.debug("Request is from forwarded address: {}", forwardedFor); } String userAgent = StringUtils.defaultString(theRequest.getHeader("user-agent")); org.slf4j.MDC.put(REMOTE_UA, userAgent); }
From source file:io.redlink.solrlib.standalone.SolrServerConnector.java
public SolrServerConnector(Set<SolrCoreDescriptor> coreDescriptors, SolrServerConnectorConfiguration configuration, ExecutorService executorService) { super(coreDescriptors, executorService); this.configuration = configuration; prefix = StringUtils.defaultString(configuration.getPrefix()); solrBaseUrl = StringUtils.removeEnd(configuration.getSolrUrl(), "/"); initialized = new AtomicBoolean(false); }
From source file:net.siegmar.japtproxy.fetcher.FetcherHttp.java
/** * {@inheritDoc}// w ww.j a v a2s.c o m */ @Override public FetchedResourceHttp fetch(final URL targetResource, final long lastModified, final String originalUserAgent) throws IOException, ResourceUnavailableException { final HttpGet httpGet = new HttpGet(targetResource.toExternalForm()); httpGet.addHeader(HttpHeaderConstants.USER_AGENT, StringUtils.trim(StringUtils.defaultString(originalUserAgent) + " " + Util.USER_AGENT)); if (lastModified != 0) { final String lastModifiedSince = Util.getRfc822DateFromTimestamp(lastModified); LOG.debug("Setting If-Modified-Since: {}", lastModifiedSince); httpGet.setHeader(HttpHeaderConstants.IF_MODIFIED_SINCE, lastModifiedSince); } CloseableHttpResponse httpResponse = null; try { httpResponse = httpClient.execute(httpGet); if (LOG.isDebugEnabled()) { logResponseHeader(httpResponse.getAllHeaders()); } final int retCode = httpResponse.getStatusLine().getStatusCode(); if (retCode == HttpServletResponse.SC_NOT_FOUND) { httpGet.releaseConnection(); throw new ResourceUnavailableException("Resource '" + targetResource + " not found"); } if (retCode != HttpServletResponse.SC_OK && retCode != HttpServletResponse.SC_NOT_MODIFIED) { throw new IOException("Invalid status code returned: " + httpResponse.getStatusLine()); } final FetchedResourceHttp fetchedResourceHttp = new FetchedResourceHttp(httpResponse); fetchedResourceHttp.setModified(lastModified == 0 || retCode != HttpServletResponse.SC_NOT_MODIFIED); if (LOG.isDebugEnabled()) { final long fetchedTimestamp = fetchedResourceHttp.getLastModified(); if (fetchedTimestamp != 0) { LOG.debug("Response status code: {}, Last modified: {}", retCode, Util.getSimpleDateFromTimestamp(fetchedTimestamp)); } else { LOG.debug("Response status code: {}", retCode); } } return fetchedResourceHttp; } catch (final IOException e) { // Closing only in case of an exception - otherwise closed by FetchedResourceHttp if (httpResponse != null) { httpResponse.close(); } throw e; } }
From source file:com.netsteadfast.greenstep.sys.SysQueryParamInspectUtils.java
private static String getFieldValue(String fieldName, HttpServletRequest request) throws Exception { String value = null;/* w ww . j av a 2 s. com*/ value = request.getParameter(fieldName); if (StringUtils.defaultString(value).length() > MAX_VALUE_LENGTH) { value = value.substring(0, MAX_VALUE_LENGTH); } return value; }