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:meta.proyecto.base.ProyectoJava.java
/** * @return the security realm name */ public String getSecurityRealmName() { return StringUtils.defaultIfBlank(_securityRealmName, getDefaultSecurityRealmName()); }
From source file:meta.proyecto.base.ProyectoJava.java
/** * @return the role-based-access-controller (RBAC) name *//* ww w. j a v a2 s . c o m*/ public String getRoleBasedAccessControllerName() { return StringUtils.defaultIfBlank(_roleBasedAccessControllerName, getDefaultRoleBasedAccessControllerName()); }
From source file:eu.europeana.portal2.web.presentation.model.FullDocPage.java
public String getShownAtProvider() { if (isHasDataProvider() && !ArrayUtils.contains(shownAtProviderOverride, getCollectionId())) { return getDocument().getEdmDataProvider()[0]; }/*ww w. j a v a2s . c o m*/ return StringUtils.defaultIfBlank(getShortcutFirstValue("EdmProvider"), ""); }
From source file:adalid.commons.velocity.Writer.java
private void writeFile(WriterContext templateWriterContext, File templatePropertiesFile) { VelocityContext fileContext = templateWriterContext.getVelocityContextClone(); TLB.setProgrammers(templateWriterContext.programmers); TLB.setWrapperClasses(templateWriterContext.wrapperClasses); Properties properties = mergeProperties(fileContext, templatePropertiesFile); putStrings(fileContext, properties); // String rootPath = getRootPath(fileContext); String userPath = pathString(USER_DIR); String temptype = StringUtils.defaultIfBlank(properties.getProperty(TP_TYPE), TP_TYPE_VELOCITY); String template = StringUtils.trimToNull(properties.getProperty(TP_TEMPLATE)); String filePath = StringUtils.trimToNull(properties.getProperty(TP_PATH)); String filePack = StringUtils.trimToNull(properties.getProperty(TP_PACKAGE)); String fileName = StringUtils.trimToNull(properties.getProperty(TP_FILE)); String preserve = StringUtils.trimToNull(properties.getProperty(TP_PRESERVE)); String charset1 = StringUtils.trimToNull(properties.getProperty(TP_ENCODING)); String charset2 = StringUtils.trimToNull(properties.getProperty(TP_CHARSET)); String root = getRoot().getPath(); String raiz = root.replace('\\', '/'); String hint = "; check property \"{0}\" at file \"{1}\""; if (ArrayUtils.contains(TP_TYPE_ARRAY, temptype)) { } else {/*from www .j av a2s. co m*/ String pattern = "failed to obtain a valid template type" + hint; String message = MessageFormat.format(pattern, TP_TYPE, templatePropertiesFile); logger.error(message); errors++; return; } if (template == null) { String pattern = "failed to obtain a valid template name" + hint; String message = MessageFormat.format(pattern, TP_TEMPLATE, templatePropertiesFile); logger.error(message); errors++; return; } if (fileName == null) { String pattern = "failed to obtain a valid file name" + hint; String message = MessageFormat.format(pattern, TP_FILE, templatePropertiesFile); logger.error(message); errors++; return; } String templatePathString = pathString(template); String templatePath = StringUtils.substringBeforeLast(templatePathString, FILE_SEPARATOR); fileContext.put(VC_TEMPLATE, StringEscapeUtils.escapeJava(templatePathString)); fileContext.put(VC_TEMPLATE_PATH, StringUtils.replace(templatePath, FILE_SEPARATOR, SLASH)); fileContext.put(VC_FILE, fileName); if (filePath == null) { // filePath = rootPath; filePath = userPath; } else { filePath = pathString(filePath); if (isRelativePath(filePath)) { if (filePath.startsWith(FILE_SEPARATOR)) { // filePath = rootPath + filePath; filePath = userPath + filePath; } else { // filePath = rootPath + FILE_SEPARATOR + filePath; filePath = userPath + FILE_SEPARATOR + filePath; } } } fileContext.put(VC_PATH, StringEscapeUtils.escapeJava(filePath)); if (filePack != null) { filePath += FILE_SEPARATOR + pathString(StringUtils.replace(filePack, DOT, SLASH)); fileContext.put(VC_PACKAGE, dottedString(filePack)); } File path = new File(filePath); if (path.exists()) { if (path.isDirectory() && path.canWrite()) { } else { String pattern = "{2} is not a valid directory" + hint; String message = MessageFormat.format(pattern, TP_PATH, templatePropertiesFile, path); logger.error(message); errors++; return; } } else if (path.mkdirs()) { } else { String pattern = "{2} is not a valid path" + hint; String message = MessageFormat.format(pattern, TP_PATH, templatePropertiesFile, path); logger.error(message); errors++; return; } String fullname = path.getPath() + FILE_SEPARATOR + fileName; String slashedPath = fullname.replace('\\', '/'); File file = new File(fullname); if (file.exists()) { String regex, pattern, message; for (Pattern fxp : fileExclusionPatterns) { regex = fxp.pattern(); if (slashedPath.matches(regex)) { excludedFiles++; pattern = "file {0} will be deleted; it matches exclusion expression \"{1}\""; message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz), regex); log(_alertLevel, message); warnings++; FileUtils.deleteQuietly(file); return; } } if (BitUtils.valueOf(preserve)) { preservedFiles++; pattern = "file {2} will not be replaced" + hint; message = MessageFormat.format(pattern, TP_PRESERVE, templatePropertiesFile, fullname); log(_detailLevel, message); return; } for (Pattern fxp : filePreservationPatterns) { regex = fxp.pattern(); if (slashedPath.matches(regex)) { preservedFiles++; pattern = "file {0} will not be replaced; it matches preservation expression \"{1}\""; message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz), regex); log(_alertLevel, message); warnings++; return; } } } else { String regex, pattern, message; for (Pattern fxp : fileExclusionPatterns) { regex = fxp.pattern(); if (slashedPath.matches(regex)) { excludedFiles++; pattern = "file {0} will not be written; it matches exclusion expression \"{1}\""; message = MessageFormat.format(pattern, StringUtils.removeStartIgnoreCase(slashedPath, raiz), regex); log(_alertLevel, message); warnings++; return; } } } if (charset1 != null && !Charset.isSupported(charset1)) { String pattern = "{2} is not a supported character set" + hint; String message = MessageFormat.format(pattern, TP_ENCODING, templatePropertiesFile, charset1); logger.error(message); errors++; return; } if (charset2 != null && !Charset.isSupported(charset2)) { String pattern = "{2} is not a supported character set" + hint; String message = MessageFormat.format(pattern, TP_CHARSET, templatePropertiesFile, charset2); logger.error(message); errors++; return; } fileContext.put(VC_FILE_PATH, StringEscapeUtils.escapeJava(filePath)); fileContext.put(VC_FILE_NAME, StringEscapeUtils.escapeJava(fileName)); fileContext.put(VC_FILE_PATH_NAME, StringEscapeUtils.escapeJava(fullname)); fileContext.put(VC_FILE_PATH_FILE, path); if (temptype.equals(TP_TYPE_VELOCITY)) { writeFile(fileContext, template, fullname, charset1, charset2); } else { writeFile(template, fullname); } executeFile(fileContext, templatePropertiesFile); }
From source file:net.di2e.ecdr.search.transform.atom.AbstractAtomTransformer.java
protected void addLinksToEntry(Entry entry, CDRMetacard metacard, String format, Map<String, Serializable> properties) { LOGGER.debug("Metacard with ID {} hasThumbail={} with thumbnailActionProvider={}", metacard.getId(), metacard.hasThumbnail(), thumbnailActionProvider); if (metacard.hasThumbnail()) { if (thumbnailActionProvider != null) { Action action = thumbnailActionProvider.getAction(metacard); LOGGER.debug("Thumbnail action={}", action); if (action != null && action.getUrl() != null) { entry.addLink(action.getUrl().toString(), SearchConstants.LINK_REL_PREVIEW, thumbnailMimeType.getBaseType(), action.getTitle(), null, metacard.getThumbnailLength()); }//from ww w .j a v a 2 s.c om } } if (resourceActionProvider != null && metacard.hasResource()) { Action action = resourceActionProvider.getAction(metacard); if (action != null && action.getUrl() != null) { entry.addLink(action.getUrl().toString(), Link.REL_ALTERNATE, metacard.getResourceMIMETypeString(), action.getTitle(), null, metacard.getResourceSizeLong()); } // If there is no explicit resource then the metadata serves as // the product/resource so include a link to it here } else if (metadataActionProvider != null) { Action action = metadataActionProvider.getAction(metacard); if (action != null && action.getUrl() != null) { entry.addLink(action.getUrl().toString(), Link.REL_ALTERNATE, "text/xml", "View Product", null, -1); } } if (viewMetacardActionProvider != null) { Action action = viewMetacardActionProvider.getAction(metacard); if (action != null && action.getUrl() != null) { String transformFormat = (String) properties.get(SearchConstants.METACARD_TRANSFORMER_NAME); if (StringUtils.isBlank(transformFormat)) { transformFormat = StringUtils.defaultIfBlank(format, CDR_ATOM_TRANSFORMER_ID); } entry.addLink(action.getUrl().toString() + "?transform=" + transformFormat, Link.REL_SELF, AtomResponseConstants.ATOM_MIME_TYPE, "View Atom Entry", null, -1); entry.addLink(action.getUrl().toString(), Link.REL_RELATED, "text/xml", action.getTitle(), null, -1); } } }
From source file:adalid.core.Project.java
private void annotateModule(Class<?> type) { Class<?> annotatedClass = XS1.getAnnotatedClass(type, ProjectModule.class); if (annotatedClass != null) { ProjectModule annotation = annotatedClass.getAnnotation(ProjectModule.class); if (annotation != null) { _annotatedWithProjectModule = true; _menuModule = annotation.menu().toBoolean(_menuModule); _roleModule = annotation.role().toBoolean(_roleModule); _helpFileName = StringUtils.defaultIfBlank(annotation.helpFile(), _helpFileName); }// w w w . j a va2 s. c om } }
From source file:adalid.core.Project.java
private void annotateModule(Field field) { _annotatedWithProjectModule = field.isAnnotationPresent(ProjectModule.class); if (_annotatedWithProjectModule) { ProjectModule annotation = field.getAnnotation(ProjectModule.class); _menuModule = annotation.menu().toBoolean(_menuModule); _roleModule = annotation.role().toBoolean(_roleModule); _helpFileName = StringUtils.defaultIfBlank(annotation.helpFile(), _helpFileName); }/*from w w w .j av a2 s . co m*/ }
From source file:elaborate.editor.model.orm.service.ProjectService.java
public Publication.Status createPublicationStatus(long project_id, User user) { Publisher publisher = Publisher.instance(); boolean canPublish; Project project;/*from ww w. j a va 2 s .com*/ Map<String, String> projectMetadata; openEntityManager(); try { project = getProjectIfUserCanRead(project_id, user); canPublish = user.getPermissionFor(project).can(Action.PUBLISH); projectMetadata = project.getMetadataMap(); } finally { closeEntityManager(); } if (!canPublish) { throw new UnauthorizedException(MessageFormat.format("{0} has no publishing permission for {1}", user.getUsername(), project.getTitle())); } ; String projectType = StringUtils.defaultIfBlank(projectMetadata.get(ProjectMetadataFields.TYPE), ProjectTypes.COLLECTION); List<Long> publishableAnnotationTypeIds = getPublishableAnnotationTypeIds(projectMetadata); List<String> publishableProjectEntryMetadataFields = getPublishableProjectEntryMetadataFields( projectMetadata); List<String> facetableProjectEntryMetadataFields = getFacetableProjectEntryMetadataFields(projectMetadata); List<String> publishableTextLayers = getPublishableTextLayers(projectMetadata); Publication.Settings settings = new Publication.Settings()// .setProjectId(project_id)// .setUser(user)// .setTextLayers(publishableTextLayers)// .setAnnotationTypeIds(publishableAnnotationTypeIds)// .setProjectEntryMetadataFields(publishableProjectEntryMetadataFields)// .setFacetFields(facetableProjectEntryMetadataFields)// .setProjectType(projectType); Publication.Status publicationStatus = publisher.publish(settings); return publicationStatus; }
From source file:adalid.util.velocity.BaseBuilder.java
private void check(SmallFile sf) { String cs;//from w ww. j a v a 2 s . c o m Integer count; Map<String, Integer> map; if (sf != null) { Charset charset = sf.getCharset(); String name = sf.getName(); String extension = StringUtils.defaultIfBlank(sf.getExtension().toLowerCase(), "?"); if (charset == null) { readingErrors++; logger.error(name + " could not be read using any of the specified character sets "); } else if (sf.isEmpty()) { readingWarnings++; logger.warn(name + " is empty "); } else { cs = charset.toString(); switch (cs) { case "UTF-8": if (extension.equalsIgnoreCase("java")) { } else { logger.warn(cs + "/" + extension + " " + name); } break; case "ISO_8859_1": logger.warn(cs + "/" + extension + " " + name); break; default: break; } map = extensionCharsetMap.get(extension); if (map == null) { map = new TreeMap<>(); } count = map.get(cs); if (count == null) { map.put(cs, 1); } else { map.put(cs, ++count); } extensionCharsetMap.put(extension, map); } } }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelImportServiceImpl.java
/** * Returns Building Block by the specified {@code name}, {@code id} and {@code type}. * The Building Block is first searched for by {@code name}, then by {@code id}. If inconsistencies * are detected, e.g. the retrieved Building Block has not the specified {@code id}, {@code null} * is returned. If both name and id are {@code null} or the building block cannot be found, * {@code null} will be returned.// ww w.j a v a 2s .co m * * @param id * the building block id * @param name * the name of the building block * @param type * the building block type * @return the building block instance or {@code null}, if such building block does not exist */ private BuildingBlock getDbCopy(Integer id, String name, TypeOfBuildingBlock type) { String bbName = StringUtils.defaultIfBlank(name, null); if (id == null && bbName == null) { return null; } if (bbName != null && getServiceFor(type).doesObjectWithDifferentIdExist(null, bbName)) { BuildingBlock bb = getServiceFor(type).findByNames(Sets.newHashSet(bbName)).get(0); if (id == null || bb.getId().equals(id)) { return bb; } else { String bbType = MessageAccess.getString(type.toString()); getProcessingLog().warn("ID {0} and name {1} do not match for type {2}, skipping", id, bbName, bbType); return null; } } else if (id != null) { BuildingBlock bb = getServiceFor(type).loadObjectByIdIfExists(id); if (bb != null && type.equals(bb.getTypeOfBuildingBlock())) { return bb; } else { return null; } } return null; }