/** * <p> * Checks if a String is not empty (""), not null and not whitespace only. * </p> * * <pre> * StringUtils.isNotBlank(null) = false * StringUtils.isNotBlank("") = false * StringUtils.isNotBlank(" ") = false * StringUtils.isNotBlank("bob") = true * StringUtils.isNotBlank(" bob ") = true * </pre> * * @param str * the String to check, may be null * @return <code>true</code> if the String is not empty and not null and not * whitespace * @since 2.0 */ public static boolean isNotBlank(String str) { return !StringUtils.isBlank(str); }
public void setType(String placeholderType) throws JspException { if (StringUtils.isBlank(placeholderType)) { throw new JspException("The \"type\" attribute cannot be blank. Possible values: \"" + PLACEHOLDER_TYPE_JS + "\" or \"" + PLACEHOLDER_TYPE_CSS + "\""); } this.placeholderType = placeholderType; } }
public static void notBlank(String object, String message) { if (StringUtils.isBlank(object)) { throw new IllegalArgumentException(message); } }
/** * <p> * Checks if a String is not empty (""), not null and not whitespace only. * </p> * * <pre> * StringUtils.isNotBlank(null) = false * StringUtils.isNotBlank("") = false * StringUtils.isNotBlank(" ") = false * StringUtils.isNotBlank("bob") = true * StringUtils.isNotBlank(" bob ") = true * </pre> * * @param str * the String to check, may be null * @return <code>true</code> if the String is not empty and not null and not * whitespace * @since 2.0 */ public static boolean isNotBlank(String str) { return !StringUtils.isBlank(str); }
public static void notBlank(String object, String message) { if (StringUtils.isBlank(object)) { throw new IllegalArgumentException(message); } }
public void setType(String placeholderType) throws JspException { if (StringUtils.isBlank(placeholderType)) { throw new JspException("The \"type\" attribute cannot be blank. Possible values: \"" + PLACEHOLDER_TYPE_JS + "\" or \"" + PLACEHOLDER_TYPE_CSS + "\""); } this.placeholderType = placeholderType; } }
public static SortType findByName(String name) { if (StringUtils.isBlank(name)) { return null; } for (SortType sortType : values()) { if (name.trim().equalsIgnoreCase(sortType.getName())) { return sortType; } } return null; } }
public static SortType findByName(String name) { if (StringUtils.isBlank(name)) { return null; } for (SortType sortType : values()) { if (name.trim().equalsIgnoreCase(sortType.getName())) { return sortType; } } return null; } }
/** * TODO * * @param userProps */ private void loadAutoConfiguration(Properties userProps) { // The JSTL is required by Tiles, which can be used with Thymeleaf but // in any case, if Thymeleaf is available, the JstlMessageResolver // should not be enabled if (LibraryDetector.isJstlAvailable() && !LibraryDetector.isThymeleafAvailable() && userProps != null) { if (!userProps.isEmpty()) { for (Entry<Object, Object> entry : userProps.entrySet()) { String key = entry.getKey().toString(); if (key.contains(I18N_MESSAGE_RESOLVER) && StringUtils.isBlank(entry.getValue().toString())) { userProps.put(entry.getKey(), "com.github.dandelion.datatables.jsp.i18n.JstlMessageResolver"); } } } else { userProps.put("global." + I18N_MESSAGE_RESOLVER, "com.github.dandelion.datatables.jsp.i18n.JstlMessageResolver"); } } } }
/** * TODO * * @param userProps */ private void loadAutoConfiguration(Properties userProps) { // The JSTL is required by Tiles, which can be used with Thymeleaf but // in any case, if Thymeleaf is available, the JstlMessageResolver // should not be enabled if (LibraryDetector.isJstlAvailable() && !LibraryDetector.isThymeleafAvailable() && userProps != null) { if (!userProps.isEmpty()) { for (Entry<Object, Object> entry : userProps.entrySet()) { String key = entry.getKey().toString(); if (key.contains(I18N_MESSAGE_RESOLVER) && StringUtils.isBlank(entry.getValue().toString())) { userProps.put(entry.getKey(), "com.github.dandelion.datatables.jsp.i18n.JstlMessageResolver"); } } } else { userProps.put("global." + I18N_MESSAGE_RESOLVER, "com.github.dandelion.datatables.jsp.i18n.JstlMessageResolver"); } } } }
/** * {@inheritDoc} */ @Override public String getResource(String messageKey, String defaultValue, Object... objects) { Locale locale = RequestContextUtils.getLocale(request); String message = null; // Both title and titleKey attributes are not used if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } // the titleKey attribute is used else { try { message = messageSource.getMessage(messageKey, null, locale); } catch (NoSuchMessageException e) { logger.warn("No message found with the key {} and locale {}.", messageKey, locale); if (StringUtils.isBlank(message)) { message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY; } } } return message; } }
private String getView(String pageName, HandlerContext context) throws IOException { DebugPage page; // If no page is specified or if the page does not exist, let's redirect // to the "assets" page by default if (StringUtils.isBlank(pageName) || !context.getContext().getDebugPageMap().containsKey(pageName.trim().toLowerCase())) { page = context.getContext().getDebugPageMap().get(AssetsDebugPage.PAGE_ID); } else { page = context.getContext().getDebugPageMap().get(pageName.trim().toLowerCase()); } return getPage(page, context); }
private String getView(String pageName, HandlerContext context) throws IOException { DebugPage page; // If no page is specified or if the page does not exist, let's redirect // to the "assets" page by default if (StringUtils.isBlank(pageName) || !context.getContext().getDebugPageMap().containsKey(pageName.trim().toLowerCase())) { page = context.getContext().getDebugPageMap().get(AssetsDebugPage.PAGE_ID); } else { page = context.getContext().getDebugPageMap().get(pageName.trim().toLowerCase()); } return getPage(page, context); }
/** * <p> * Checks that the asset if properly configured before computing its * location. * * @param AssetStorageUnit * The asset storage unit from which the location should be * extracted. * @param request * The current HTTP request. * @throws DandelionException * if the location associated with the selected location key is * null or empty. */ @Override public String getLocation(AssetStorageUnit asu, HttpServletRequest request) { String location = asu.getLocations().get(getLocationKey()); if (StringUtils.isBlank(location)) { StringBuilder sb = new StringBuilder("The asset "); sb.append(asu.toLog()); sb.append(" configured with a '"); sb.append(getLocationKey()); sb.append("' location key has a blank location. Please correct this location in the corresponding JSON file."); throw new DandelionException(sb.toString()); } return doGetLocation(asu, request); }
@Override public void initCache(Context context) { super.initCache(context); InputStream stream = null; String cacheConfigurationPath = context.getConfiguration().getCacheConfigurationLocation(); if (StringUtils.isBlank(cacheConfigurationPath)) { LOG.warn("The 'cache.configuration.location' configuration is not set. Dandelion will scan for any ehcache.xml file inside the classpath."); cacheConfigurationPath = ClasspathResourceScanner.findResourcePath("", "ehcache.xml"); LOG.debug("ehcache.xml file found: {}", cacheConfigurationPath); } stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(cacheConfigurationPath); CacheManager cacheManager = stream == null ? CacheManager.create() : CacheManager.create(stream); if (!cacheManager.cacheExists(DANDELION_CACHE_NAME)) { cacheManager.addCache(DANDELION_CACHE_NAME); LOG.debug("Added cache called '{}' to the cache manager", DANDELION_CACHE_NAME); } cache = cacheManager.getCache(DANDELION_CACHE_NAME); }
private void checkMarkupUsage(Element element) { Element parent = (Element) element.getParent(); if (parent == null || !"div".equals(parent.getNormalizedName()) || !parent.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":conf") || StringUtils.isBlank(parent.getAttributeValue(DataTablesDialect.DIALECT_PREFIX + ":conf"))) { throw new DandelionException( "The element 'div dt:confType=\"...\"' must be inside an element 'div dt:conf=\"tableId\"'."); } }
if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue);
@Override public String getAssetVersion(Asset asset) { LOG.debug("Calculating version hash for the asset: {}", asset.toLog()); StorageEntry storageEntry = getContext().getAssetStorage().get(asset.getStorageKey()); String contents = null; if(storageEntry != null) { contents = storageEntry.getContents(); } String version = null; if (StringUtils.isBlank(contents)) { LOG.warn("Asset {} has an empty contents. Using a random String for the hash", asset.toLog()); version = DigestUtils.md5Digest(UUID.randomUUID().toString()); } else { version = DigestUtils.md5Digest(contents); } return version; } }
@Override public String getAssetVersion(Asset asset) { LOG.debug("Calculating version hash for the asset: {}", asset.toLog()); StorageEntry storageEntry = getContext().getAssetStorage().get(asset.getStorageKey()); String contents = null; if(storageEntry != null) { contents = storageEntry.getContents(); } String version = null; if (StringUtils.isBlank(contents)) { LOG.warn("Asset {} has an empty contents. Using a random String for the hash", asset.toLog()); version = DigestUtils.md5Digest(UUID.randomUUID().toString()); } else { version = DigestUtils.md5Digest(contents); } return version; } }
@Override public String getResource(String messageKey, String defaultValue, Object... params) { String message = null; PageContext pageContext = null; // I'm so ashamed about that... pageContext = (PageContext) params[0]; // Both title and titleKey attributes are not used if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) { message = StringUtils.capitalize(defaultValue); } // the titleKey attribute is used else { OgnlValueStack stack = (OgnlValueStack) TagUtils.getStack(pageContext); for (Object o : stack.getRoot()) { if (o instanceof TextProvider) { TextProvider tp = (TextProvider) o; message = tp.getText(messageKey, UNDEFINED_KEY + messageKey + UNDEFINED_KEY); break; } } } return message; } }