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:no.kantega.publishing.common.data.Multimedia.java
public void setModifiedBy(String modifiedBy) { this.modifiedBy = StringUtils.defaultString(modifiedBy, ""); }
From source file:nz.co.testamation.common.util.PrefixMapNamespaceContext.java
public String getNamespaceURI(String prefix) { switch (prefix) { case XMLConstants.XML_NS_PREFIX: return XMLConstants.XML_NS_URI; case XMLConstants.XMLNS_ATTRIBUTE: return XMLConstants.XMLNS_ATTRIBUTE_NS_URI; default:/*from w w w . j a va 2s. com*/ return StringUtils.defaultString(prefixNamespaceMap.get(prefix), XMLConstants.NULL_NS_URI); } }
From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java
@Transactional(readOnly = true) @RequestMapping(value = "/articles/page/{pageNumber}", method = RequestMethod.GET) public ResponseEntity<?> listDois(@PathVariable(value = "pageNumber") int pageNumber, @RequestParam(value = "pageSize", required = false, defaultValue = "100") int pageSize, @RequestParam(value = "orderBy", required = false, defaultValue = "newest") String orderBy, @RequestParam(value = "since", required = false, defaultValue = "") String sinceRule) throws IOException { final ArticleCrudService.SortOrder sortOrder = ArticleCrudService.SortOrder .valueOf(StringUtils.upperCase(StringUtils.defaultString(orderBy, "newest" /* defaultStr */))); final Map<String, LocalDateTime> dateRange = calculateDateRange(sinceRule); final Optional<LocalDateTime> fromDate = Optional.ofNullable(dateRange.getOrDefault(FROM_DATE, null)); final Optional<LocalDateTime> toDate = Optional.ofNullable(dateRange.getOrDefault(TO_DATE, null)); final Collection<String> articleDois = articleCrudService.getArticleDoisForDateRange(pageNumber, pageSize, sortOrder, fromDate, toDate); return ServiceResponse.serveView(articleDois).asJsonResponse(entityGson); }
From source file:org.apache.marmotta.commons.http.MarmottaHttpUtils.java
public static ContentType performContentNegotiation(String accept, List<ContentType> producedContentTypes) { List<ContentType> acceptedContentTypes = MarmottaHttpUtils .parseAcceptHeader(StringUtils.defaultString(accept, "")); return MarmottaHttpUtils.bestContentType(producedContentTypes, acceptedContentTypes); }
From source file:org.apache.marmotta.platform.sparql.webservices.SparqlWebService.java
/** * Actual SELECT implementation/*w w w . j av a 2s .c om*/ * * @param query * @param resultType * @param request * @return */ private Response select(String query, String resultType, HttpServletRequest request) { try { String acceptHeader = StringUtils.defaultString(request.getHeader(ACCEPT), ""); if (StringUtils.isBlank(query)) { //empty query if (acceptHeader.contains("html")) { return Response .seeOther(new URI(configurationService.getServerUri() + "sparql/admin/squebi.html")) .build(); } else { return Response.status(Status.ACCEPTED).entity("no SPARQL query specified").build(); } } else { //query duck typing QueryType queryType = sparqlService.getQueryType(QueryLanguage.SPARQL, query); List<ContentType> acceptedTypes; List<ContentType> offeredTypes; if (resultType != null) { acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(resultType); } else { acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader); } if (QueryType.TUPLE.equals(queryType)) { offeredTypes = MarmottaHttpUtils .parseQueryResultFormatList(TupleQueryResultWriterRegistry.getInstance().getKeys()); } else if (QueryType.BOOL.equals(queryType)) { offeredTypes = MarmottaHttpUtils .parseQueryResultFormatList(BooleanQueryResultWriterRegistry.getInstance().getKeys()); } else if (QueryType.GRAPH.equals(queryType)) { Set<String> producedTypes = new HashSet<String>(exportService.getProducedTypes()); producedTypes.remove("application/xml"); producedTypes.remove("text/plain"); producedTypes.remove("text/html"); producedTypes.remove("application/xhtml+xml"); offeredTypes = MarmottaHttpUtils.parseStringList(producedTypes); } else { return Response.status(Response.Status.BAD_REQUEST) .entity("no result format specified or unsupported result format").build(); } ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes); if (bestType == null) { return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE) .entity("no result format specified or unsupported result format").build(); } else { return buildQueryResponse(bestType, query, queryType); } } } catch (InvalidArgumentException e) { log.error("query parsing threw an exception", e); return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); } catch (Exception e) { log.error("query execution threw an exception", e); return Response.serverError().entity("query not supported").build(); } }
From source file:org.apache.sling.servlethelpers.ResponseBodySupport.java
private String defaultCharset(String charset) { return StringUtils.defaultString(charset, CharEncoding.UTF_8); }
From source file:org.apache.sling.testing.mock.jcr.MockJcr.java
/** * Create a new mocked in-memory JCR session. It contains only the root * node. All data of the session is thrown away if it gets garbage * collected.//w w w . ja v a 2s . co m * @param userId User id for the mock environment. * @param workspaceName Workspace name for the mock environment. * @return JCR session */ public static Session newSession(String userId, String workspaceName) { try { return newRepository().login( new SimpleCredentials(StringUtils.defaultString(userId, DEFAULT_USER_ID), new char[0]), StringUtils.defaultString(workspaceName, DEFAULT_WORKSPACE)); } catch (RepositoryException ex) { throw new RuntimeException("Creating mocked JCR session failed.", ex); } }
From source file:org.apache.sling.testing.mock.jcr.MockRepository.java
@Override public Session login(final Credentials credentials, final String workspaceName) throws RepositoryException { String userId = null;/* w ww.java 2 s . c o m*/ if (credentials instanceof SimpleCredentials) { userId = ((SimpleCredentials) credentials).getUserID(); } return new MockSession(this, items, StringUtils.defaultString(userId, MockJcr.DEFAULT_USER_ID), StringUtils.defaultString(workspaceName, MockJcr.DEFAULT_WORKSPACE)); }
From source file:org.apache.sling.testing.mock.sling.loader.ContentLoader.java
/** * Detected mime type from name (file extension) using Mime Type service. * Fallback to application/octet-stream. * @param name Node name//from w w w. ja v a 2 s . c o m * @return Mime type (never null) */ private String detectMimeTypeFromName(String name) { String mimeType = null; String fileExtension = StringUtils.substringAfterLast(name, "."); if (bundleContext != null && StringUtils.isNotEmpty(fileExtension)) { ServiceReference<MimeTypeService> ref = bundleContext.getServiceReference(MimeTypeService.class); if (ref != null) { MimeTypeService mimeTypeService = (MimeTypeService) bundleContext.getService(ref); mimeType = mimeTypeService.getMimeType(fileExtension); } } return StringUtils.defaultString(mimeType, CONTENTTYPE_OCTET_STREAM); }
From source file:org.apache.struts2.oval.interceptor.OValValidationInterceptor.java
/** * Get field name and message, used to add the validation error to fieldErrors *//* ww w .j a v a 2 s . c o m*/ protected ValidationError buildValidationError(ConstraintViolation violation, String message) { OValContext context = violation.getContext(); if (context instanceof FieldContext) { Field field = ((FieldContext) context).getField(); String className = field.getDeclaringClass().getName(); //the default OVal message shows the field name as ActionClass.fieldName String finalMessage = StringUtils.removeStart(message, className + "."); return new ValidationError(field.getName(), finalMessage); } else if (context instanceof MethodReturnValueContext) { Method method = ((MethodReturnValueContext) context).getMethod(); String className = method.getDeclaringClass().getName(); String methodName = method.getName(); //the default OVal message shows the field name as ActionClass.fieldName String finalMessage = StringUtils.removeStart(message, className + "."); String fieldName = null; if (methodName.startsWith("get")) { fieldName = StringUtils.uncapitalize(StringUtils.removeStart(methodName, "get")); } else if (methodName.startsWith("is")) { fieldName = StringUtils.uncapitalize(StringUtils.removeStart(methodName, "is")); } //the result will have the full method name, like "getName()", replace it by "name" (obnly if it is a field) if (fieldName != null) finalMessage = finalMessage.replaceAll(methodName + "\\(.*?\\)", fieldName); return new ValidationError(StringUtils.defaultString(fieldName, methodName), finalMessage); } return new ValidationError(violation.getCheckName(), message); }