List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str, final String defaultStr)
Returns either the passed in String, or if the String is null , the value of defaultStr .
StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"
From source file:CheckService.java
/** * Create object provide action for check of repository. * * @param bckIdxName name for indexes (default value if null is "*") * @param repository repository provider *//*from w w w .j ava 2s. c om*/ public CheckService(String bckIdxName, Repository repository) { this.bckIdxName = StringUtils.defaultString(bckIdxName, "*"); this.repository = repository; }
From source file:eionet.webq.converter.XmlSchemaExtractor.java
/** * Extracts {@code @xsi:noNamespaceSchemaLocation} or {@code @xsi:schemaLocation} attribute value from xml root element. * * @param source source to be searched./*from w w w . j av a 2 s . c om*/ * @return {@code @xsi:noNamespaceSchemaLocation} or {@code @xsi:schemaLocation} attribute value, default {@code null} */ public String extractXmlSchema(byte[] source) { XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); ByteArrayInputStream bais = new ByteArrayInputStream(source); XMLStreamReader xmlStreamReader = null; try { xmlStreamReader = xmlInputFactory.createXMLStreamReader(bais); while (xmlStreamReader.hasNext()) { if (xmlStreamReader.next() == START_ELEMENT) { return StringUtils.defaultString( parseNoNamespaceSchemaLocation(xmlStreamReader.getAttributeValue(XSI_NAMESPACE_URI, "noNamespaceSchemaLocation")), parseSchemaLocation( xmlStreamReader.getAttributeValue(XSI_NAMESPACE_URI, "schemaLocation"))); } } } catch (Exception e) { LOGGER.warn("exception thrown during extracting xml schema", e); } finally { IOUtils.closeQuietly(bais); if (xmlStreamReader != null) { try { xmlStreamReader.close(); } catch (XMLStreamException e) { LOGGER.warn("unable to close xml stream", e); } } } return null; }
From source file:ca.simplegames.micro.extensions.i18n.I18NExtension.java
public Extension register(String name, SiteContext site, Map<String, Object> locales) throws Exception { Assert.notNull(name, "The name of the extension must not be null!"); this.name = StringUtils.defaultIfBlank(name, "i18N"); if (locales != null) { Map interceptConfig = (Map<String, Object>) locales.get("intercept"); if (interceptConfig != null) { intercept = StringUtils.defaultString((String) interceptConfig.get("parameter_name"), "lang"); scopesSrc = StringUtils.defaultString((String) interceptConfig.get("scope"), "context"); scopes = StringUtils.split(scopesSrc, ","); }/* w ww . j a v a2s . co m*/ defaultEncoding = StringUtils.defaultString((String) locales.get("default_encoding"), Globals.UTF8); fallbackToSystemLocale = locales.get("fallback_to_system_locale") != null ? (Boolean) locales.get("fallback_to_system_locale") : true; resourceCacheRefreshInterval = Integer .parseInt(StringUtils.defaultString((locales.get("resource_cache")).toString(), "10")); List<String> paths = (List<String>) locales.get("base_names"); if (paths != null && !paths.isEmpty()) { List<String> absPaths = new ArrayList<String>(); for (String path : paths) { File realPath = new File(path); if (!realPath.exists()) { realPath = new File(site.getWebInfPath().getAbsolutePath(), path); } try { absPaths.add(realPath.toURI().toURL().toString()); //absPaths.add(pathConfig.getValue()); } catch (MalformedURLException e) { e.printStackTrace(); } } resourceBasePaths = absPaths.toArray(new String[absPaths.size()]); } else { resourceBasePaths = new String[] { "config/locales/messages" }; } //Configure the i18n messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setDefaultEncoding(defaultEncoding); messageSource.setFallbackToSystemLocale(fallbackToSystemLocale); messageSource.setCacheSeconds(resourceCacheRefreshInterval); messageSource.setBasenames(resourceBasePaths); Filter i18N = new I18NFilter(this); final FilterManager filterManager = site.getFilterManager(); filterManager.addFilter(i18N); // now make sure the i18N filter is always first (if present) Collections.swap(filterManager.getBeforeFilters(), 0, filterManager.getBeforeFilters().size() - 1); infoDetails.add(String.format(" default encoding ........: %s", defaultEncoding)); infoDetails.add(String.format(" fallback to system locale: %s", fallbackToSystemLocale)); infoDetails.add(String.format(" cache refresh ...........: %s", resourceCacheRefreshInterval)); infoDetails.add(String.format(" resource bundle .........: %s", Arrays.toString(resourceBasePaths))); infoDetails.add(String.format(" Listening for ...........: '%s'", intercept)); infoDetails.add(String.format(" in scope(s) ........: %s", scopesSrc)); } return this; }
From source file:io.wcm.samples.handler.controller.navigation.SiteRootRelativePageLink.java
/** * @param siteHelper/*from w w w . j a v a2s. com*/ * @param linkHandler * @param relativePath Relative path of page to link to * @param titleType Type of title to display: pageTitle or navigationTitle */ @Inject public SiteRootRelativePageLink(@Self SiteHelper siteHelper, @Self LinkHandler linkHandler, @RequestAttribute(name = "relativePath", optional = true) String relativePath, @RequestAttribute(name = "titleType", optional = true) @Default(values = "navigationTitle") String titleType) { Page page; if (StringUtils.isNotEmpty(relativePath)) { page = siteHelper.getRelativePage(relativePath); } else { page = siteHelper.getSiteRootPage(); } if (page != null) { link = linkHandler.get(page).build(); switch (titleType) { case "pageTitle": title = StringUtils.defaultString(page.getPageTitle(), page.getTitle()); break; case "navigationTitle": default: title = StringUtils.defaultString(page.getNavigationTitle(), page.getTitle()); break; } } }
From source file:de.blizzy.backup.BackupPlugin.java
boolean isCheckGui() { return Boolean.parseBoolean( StringUtils.defaultString(getApplicationArg(ARG_CHECK_GUI), Boolean.FALSE.toString())); }
From source file:io.wcm.handler.mediasource.dam.impl.DamAsset.java
@Override public String getTitle() { // default title is the asset name String title = this.damAsset.getName(); Object titleObj = this.properties.get(DamConstants.DC_TITLE); if (titleObj != null) { // it might happen that the adobe xmp lib creates an array, e.g. if the asset file already has a title attribute if (titleObj instanceof Object[]) { Object[] titleArray = (Object[]) titleObj; if (titleArray.length > 0) { title = StringUtils.defaultString(titleArray[0].toString(), title); }//from w w w .j a va2 s.c o m } else { title = titleObj.toString(); } } return title; }
From source file:io.wcm.handler.media.markup.AbstractImageMediaMarkupBuilder.java
/** * Apply Markup for Drag&Drop mode and Diff decoration in WCM edit/preview mode. * @param mediaElement Media element/*from w w w.j a v a 2 s . c om*/ * @param media Media */ protected void applyWcmMarkup(HtmlElement<?> mediaElement, Media media) { // further processing in edit or preview mode Resource resource = media.getMediaRequest().getResource(); if (mediaElement != null && resource != null && wcmMode != null) { switch (wcmMode) { case EDIT: // enable drag&drop from content finder media.getMediaSource().enableMediaDrop(mediaElement, media.getMediaRequest()); break; case PREVIEW: // enable drag&drop from content finder media.getMediaSource().enableMediaDrop(mediaElement, media.getMediaRequest()); // add diff decoration if (request != null) { String refProperty = StringUtils.defaultString(media.getMediaRequest().getRefProperty(), MediaNameConstants.PN_MEDIA_REF); MediaMarkupBuilderUtil.addDiffDecoration(mediaElement, resource, refProperty, request); } break; default: // do nothing } } }
From source file:com.base2.kagura.core.report.configmodel.parts.ColumnDef.java
/** * Gets the display label, if no label has been set, uses the "name" field. * @return */ public String getLabel() { return StringUtils.defaultString(label, name); }
From source file:io.wcm.handler.mediasource.dam.impl.DamAsset.java
@Override public String getAltText() { return StringUtils.defaultString(this.defaultMediaArgs.getAltText(), getTitle()); }
From source file:info.magnolia.ui.admincentral.shellapp.pulse.message.MessageDetailPresenter.java
@Override protected String getItemViewName() { return StringUtils.defaultString(item.getView(), DEFAULT_VIEW); }