List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank
public static String defaultIfBlank(String str, String defaultStr)
Returns either the passed in String, or if the String is whitespace, empty ("") or null
, the value of defaultStr
.
From source file:ddf.catalog.resource.impl.URLResourceReader.java
private ResourceResponse retrieveFileProduct(URI resourceURI, String productName, String bytesToSkip) throws ResourceNotFoundException { URLConnection connection = null; try {/*from ww w.j a va 2 s . c o m*/ LOGGER.debug("Opening connection to: {}", resourceURI.toString()); connection = resourceURI.toURL().openConnection(); productName = StringUtils.defaultIfBlank( handleContentDispositionHeader(connection.getHeaderField(HttpHeaders.CONTENT_DISPOSITION)), productName); String mimeType = getMimeType(resourceURI, productName); InputStream is = connection.getInputStream(); skipBytes(is, bytesToSkip); return new ResourceResponseImpl( new ResourceImpl(new BufferedInputStream(is), mimeType, FilenameUtils.getName(productName))); } catch (MimeTypeResolutionException | IOException e) { LOGGER.error("Error retrieving resource", e); throw new ResourceNotFoundException("Unable to retrieve resource at: " + resourceURI.toString(), e); } }
From source file:jenkins.plugins.git.GitSCMSourceContext.java
/** * Configures the remote name to use for the git repository. * * @param remoteName the remote name to use for the git repository ({@code null} or the empty string are * equivalent to passing {@link AbstractGitSCMSource#DEFAULT_REMOTE_NAME}). * @return {@code this} for method chaining. */// ww w. j a v a2 s . c o m @SuppressWarnings("unchecked") @NonNull public final C withRemoteName(String remoteName) { this.remoteName = StringUtils.defaultIfBlank(remoteName, AbstractGitSCMSource.DEFAULT_REMOTE_NAME); return (C) this; }
From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java
private String normalizeUrlPart(String urlPart) { // remove slashes at the beginning and end of the URL part // and return null if it empty or contains only whitespace urlPart = StringUtils.stripStart(urlPart, "/"); urlPart = StringUtils.stripEnd(urlPart, "/"); return StringUtils.defaultIfBlank(urlPart, null); }
From source file:com.adaptris.core.services.jdbc.AbstractJdbcSequenceNumberService.java
String resetStatement() {
return StringUtils.defaultIfBlank(getResetStatement(), DEFAULT_RESET_STATEMENT);
}
From source file:com.adaptris.core.services.jdbc.AbstractJdbcSequenceNumberService.java
String insertStatement() {
return StringUtils.defaultIfBlank(getInsertStatement(), DEFAULT_INSERT_STATEMENT);
}
From source file:com.adaptris.core.services.jdbc.AbstractJdbcSequenceNumberService.java
String selectStatement() {
return StringUtils.defaultIfBlank(getSelectStatement(), DEFAULT_SELECT_STATEMENT);
}
From source file:ddf.catalog.resource.impl.URLResourceReader.java
private ResourceResponse retrieveHttpProduct(URI resourceURI, String productName, String bytesToSkip, Map<String, Serializable> properties) throws ResourceNotFoundException { try {//w ww . j av a2s. c o m LOGGER.debug("Opening connection to: {}", resourceURI.toString()); WebClient client = getWebClient(resourceURI.toString()); Object subjectObj = properties.get(SecurityConstants.SECURITY_SUBJECT); if (subjectObj != null) { Subject subject = (Subject) subjectObj; LOGGER.debug("Setting Subject on webclient: {}", subject); RestSecurity.setSubjectOnClient(subject, client); } Response response = client.get(); MultivaluedMap<String, Object> headers = response.getHeaders(); List<Object> cdHeaders = headers.get(HttpHeaders.CONTENT_DISPOSITION); if (cdHeaders != null && !cdHeaders.isEmpty()) { String contentHeader = (String) cdHeaders.get(0); productName = StringUtils.defaultIfBlank(handleContentDispositionHeader(contentHeader), productName); } String mimeType = getMimeType(resourceURI, productName); Response clientResponse = client.get(); InputStream is = null; Object entityObj = clientResponse.getEntity(); if (entityObj instanceof InputStream) { is = (InputStream) entityObj; if (Response.Status.OK.getStatusCode() != clientResponse.getStatus()) { String error = null; try { if (is != null) { error = IOUtils.toString(is); } } catch (IOException ioe) { LOGGER.debug("Could not convert error message to a string for output.", ioe); } String errorMsg = "Received error code while retrieving resource (status " + clientResponse.getStatus() + "): " + error; LOGGER.warn(errorMsg); throw new ResourceNotFoundException(errorMsg); } } else { throw new ResourceNotFoundException("Received null response while retrieving resource."); } skipBytes(is, bytesToSkip); return new ResourceResponseImpl( new ResourceImpl(new BufferedInputStream(is), mimeType, FilenameUtils.getName(productName))); } catch (MimeTypeResolutionException | IOException | WebApplicationException e) { LOGGER.error("Error retrieving resource", e); throw new ResourceNotFoundException("Unable to retrieve resource at: " + resourceURI.toString(), e); } }
From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.DocumentChartDataManagerImpl.java
@Override public void createPersonDocumentHistoryChart(final AbstractOrderedLayout content, final String personId) { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DD_MMM_YYYY, Locale.ENGLISH); final DataSeries dataSeries = new DataSeries(); final Series series = new Series(); final Map<String, List<ViewRiksdagenPoliticianDocumentDailySummary>> allMap = getViewRiksdagenPoliticianDocumentDailySummaryMap(); final List<ViewRiksdagenPoliticianDocumentDailySummary> itemList = allMap .get(personId.toUpperCase(Locale.ENGLISH).replace(UNDER_SCORE, EMPTY_STRING).trim()); if (itemList != null) { final Map<String, List<ViewRiksdagenPoliticianDocumentDailySummary>> map = itemList.parallelStream() .filter(t -> t != null).collect(Collectors.groupingBy( t -> StringUtils.defaultIfBlank(t.getEmbeddedId().getDocumentType(), NO_INFO))); addDocumentHistoryByPersonData(simpleDateFormat, dataSeries, series, map); }//w ww. j a v a2s.c o m addChart(content, "Document history ", new DCharts().setDataSeries(dataSeries) .setOptions(chartOptions.createOptionsXYDateFloatLegendOutside(series)).show()); }
From source file:com.adaptris.core.services.jdbc.AbstractJdbcSequenceNumberService.java
String updateStatement() {
return StringUtils.defaultIfBlank(getUpdateStatement(), DEFAULT_UPDATE_STATEMENT);
}
From source file:com.bstek.dorado.web.loader.DoradoLoader.java
public synchronized void preload(ServletContext servletContext, boolean processOriginContextConfigLocation) throws Exception { if (preloaded) { throw new IllegalStateException("Dorado base configurations already loaded."); }/*from w w w .ja va 2 s . c o m*/ preloaded = true; // ? ConsoleUtils.outputLoadingInfo("Initializing " + DoradoAbout.getProductTitle() + " engine..."); ConsoleUtils.outputLoadingInfo("[Vendor: " + DoradoAbout.getVendor() + "]"); ConfigureStore configureStore = Configure.getStore(); doradoHome = System.getenv("DORADO_HOME"); // ?DoradoHome String intParam; intParam = servletContext.getInitParameter("doradoHome"); if (intParam != null) { doradoHome = intParam; } if (doradoHome == null) { doradoHome = DEFAULT_DORADO_HOME; } configureStore.set(HOME_PROPERTY, doradoHome); ConsoleUtils.outputLoadingInfo("[Home: " + StringUtils.defaultString(doradoHome, "<not assigned>") + "]"); // ResourceLoader ResourceLoader resourceLoader = new ServletContextResourceLoader(servletContext) { @Override public Resource getResource(String resourceLocation) { if (resourceLocation != null && resourceLocation.startsWith(HOME_LOCATION_PREFIX)) { resourceLocation = ResourceUtils.concatPath(doradoHome, resourceLocation.substring(HOME_LOCATION_PREFIX_LEN)); } return super.getResource(resourceLocation); } }; String runMode = null; if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, false); } runMode = configureStore.getString("core.runMode"); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); if (StringUtils.isNotEmpty(doradoHome)) { loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } ConsoleUtils.outputConfigureItem("core.runMode"); ConsoleUtils.outputConfigureItem("core.addonLoadMode"); File tempDir; String tempDirPath = configureStore.getString("core.tempDir"); if (StringUtils.isNotBlank(tempDirPath)) { tempDir = new File(tempDirPath); } else { tempDir = new File(WebUtils.getTempDir(servletContext), ".dorado"); } boolean supportsTempFile = configureStore.getBoolean("core.supportsTempFile"); TempFileUtils.setSupportsTempFile(supportsTempFile); if (supportsTempFile) { if ((tempDir.exists() && tempDir.isDirectory()) || tempDir.mkdir()) { TempFileUtils.setTempDir(tempDir); } ConsoleUtils.outputLoadingInfo("[TempDir: " + TempFileUtils.getTempDir().getPath() + "]"); } else { ConsoleUtils.outputLoadingInfo("Temp file is forbidden."); } // File storeDir; String storeDirSettring = configureStore.getString("core.storeDir"); if (StringUtils.isNotEmpty(storeDirSettring)) { storeDir = new File(storeDirSettring); File testFile = new File(storeDir, ".test"); if (!testFile.mkdirs()) { throw new IllegalStateException( "Store directory [" + storeDir.getAbsolutePath() + "] is not writable in actually."); } testFile.delete(); } else { storeDir = new File(tempDir, "dorado-store"); configureStore.set("core.storeDir", storeDir.getAbsolutePath()); } ConsoleUtils.outputConfigureItem("core.storeDir"); // gothrough packages String addonLoadMode = Configure.getString("core.addonLoadMode"); String[] enabledAddons = StringUtils.split(Configure.getString("core.enabledAddons"), ",; \n\r"); String[] disabledAddon = StringUtils.split(Configure.getString("core.disabledAddon"), ",; \n\r"); Collection<PackageInfo> packageInfos = PackageManager.getPackageInfoMap().values(); int addonNumber = 0; for (PackageInfo packageInfo : packageInfos) { String packageName = packageInfo.getName(); if (packageName.equals("dorado-core")) { continue; } if (addonNumber > 9999) { packageInfo.setEnabled(false); } else if (StringUtils.isEmpty(addonLoadMode) || "positive".equals(addonLoadMode)) { packageInfo.setEnabled(!ArrayUtils.contains(disabledAddon, packageName)); } else { // addonLoadMode == negative packageInfo.setEnabled(ArrayUtils.contains(enabledAddons, packageName)); } if (packageInfo.isEnabled()) { addonNumber++; } } // print packages int i = 0; for (PackageInfo packageInfo : packageInfos) { ConsoleUtils.outputLoadingInfo( StringUtils.rightPad(String.valueOf(++i) + '.', 4) + "Package [" + packageInfo.getName() + " - " + StringUtils.defaultIfBlank(packageInfo.getVersion(), "<Unknown Version>") + "] found." + ((packageInfo.isEnabled() ? "" : " #DISABLED# "))); } // load packages for (PackageInfo packageInfo : packageInfos) { if (!packageInfo.isEnabled()) { pushLocations(contextLocations, packageInfo.getComponentLocations()); continue; } PackageListener packageListener = packageInfo.getListener(); if (packageListener != null) { packageListener.beforeLoadPackage(packageInfo, resourceLoader); } PackageConfigurer packageConfigurer = packageInfo.getConfigurer(); if (StringUtils.isNotEmpty(packageInfo.getPropertiesLocations())) { for (String location : org.springframework.util.StringUtils.tokenizeToStringArray( packageInfo.getPropertiesLocations(), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } String[] locations; if (packageConfigurer != null) { locations = packageConfigurer.getPropertiesConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } } // ?Spring? pushLocations(contextLocations, packageInfo.getContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(contextLocations, location); } } } pushLocations(servletContextLocations, packageInfo.getServletContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getServletContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(servletContextLocations, location); } } } packageInfo.setLoaded(true); } // ?dorado-homepropertiesaddon if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, true); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } Resource resource; // context if (processOriginContextConfigLocation) { intParam = servletContext.getInitParameter(CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(contextLocations, intParam); } } resource = resourceLoader.getResource(HOME_CONTEXT_XML); if (resource.exists()) { pushLocations(contextLocations, HOME_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(contextLocations, extHomeContext); } } // servlet-context intParam = servletContext.getInitParameter(SERVLET_CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(servletContextLocations, intParam); } resource = resourceLoader.getResource(HOME_SERVLET_CONTEXT_XML); if (resource.exists()) { pushLocations(servletContextLocations, HOME_SERVLET_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_SERVLET_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(servletContextLocations, extHomeContext); } } ConsoleUtils.outputConfigureItem(RESOURCE_LOADER_PROPERTY); ConsoleUtils.outputConfigureItem(BYTE_CODE_PROVIDER_PROPERTY); String contextLocationsFromProperties = configureStore.getString(CONTEXT_CONFIG_PROPERTY); if (contextLocationsFromProperties != null) { pushLocations(contextLocations, contextLocationsFromProperties); } configureStore.set(CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(contextLocations), ';')); ConsoleUtils.outputConfigureItem(CONTEXT_CONFIG_PROPERTY); String serlvetContextLocationsFromProperties = configureStore.getString(SERVLET_CONTEXT_CONFIG_PROPERTY); if (serlvetContextLocationsFromProperties != null) { pushLocations(servletContextLocations, serlvetContextLocationsFromProperties); } configureStore.set(SERVLET_CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(servletContextLocations), ';')); ConsoleUtils.outputConfigureItem(SERVLET_CONTEXT_CONFIG_PROPERTY); // ?WebContext DoradoContext context = DoradoContext.init(servletContext, false); Context.setFailSafeContext(context); }