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:com.xpn.xwiki.gwt.api.server.XWikiServiceImpl.java
private String localizePlainOrKey(String key, Object... parameters) { return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key); }
From source file:io.wcm.caravan.io.http.impl.ResilientHttpImpl.java
private Throwable mapToKnownException(String serviceName, Request request, Throwable ex) { if (ex instanceof RequestFailedRuntimeException || ex instanceof IllegalResponseRuntimeException) { return ex; }/* w w w .j a v a2 s . co m*/ if (ex instanceof HystrixRuntimeException && ex.getCause() != null) { return mapToKnownException(serviceName, request, ex.getCause()); } throw new RequestFailedRuntimeException(serviceName, request, StringUtils.defaultString(ex.getMessage(), ex.getClass().getSimpleName()), ex); }
From source file:com.navercorp.pinpoint.web.vo.callstacks.RecordFactory.java
private String getArgumentFromExceptionMessage(String exceptionMessage) { return StringUtils.defaultString(exceptionMessage, ""); }
From source file:ca.uhn.fhir.model.api.Bundle.java
/** * Creates a new entry using the given resource and populates it accordingly * /*from ww w . j a v a 2 s . co m*/ * @param theResource * The resource to add * @return Returns the newly created bundle entry that was added to the bundle */ public BundleEntry addResource(IResource theResource, FhirContext theContext, String theServerBase) { BundleEntry entry = addEntry(); entry.setResource(theResource); RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource); String title = ResourceMetadataKeyEnum.TITLE.get(theResource); if (title != null) { entry.getTitle().setValue(title); } else { entry.getTitle().setValue( def.getName() + " " + StringUtils.defaultString(theResource.getId().getValue(), "(no ID)")); } if (theResource.getId() != null) { if (theResource.getId().isAbsolute()) { entry.getLinkSelf().setValue(theResource.getId().getValue()); entry.getId().setValue(theResource.getId().toVersionless().getValue()); } else if (StringUtils.isNotBlank(theResource.getId().getValue())) { StringBuilder b = new StringBuilder(); b.append(theServerBase); if (b.length() > 0 && b.charAt(b.length() - 1) != '/') { b.append('/'); } b.append(def.getName()); b.append('/'); String resId = theResource.getId().getIdPart(); b.append(resId); entry.getId().setValue(b.toString()); if (isNotBlank(theResource.getId().getVersionIdPart())) { b.append('/'); b.append(Constants.PARAM_HISTORY); b.append('/'); b.append(theResource.getId().getVersionIdPart()); } else { IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource); if (versionId != null) { b.append('/'); b.append(Constants.PARAM_HISTORY); b.append('/'); b.append(versionId.getValue()); } } String qualifiedId = b.toString(); entry.getLinkSelf().setValue(qualifiedId); // String resourceType = theContext.getResourceDefinition(theResource).getName(); } } InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource); if (published == null) { entry.getPublished().setToCurrentTimeInLocalTimeZone(); } else { entry.setPublished(published); } InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource); if (updated != null) { entry.setUpdated(updated); } InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource); if (deleted != null) { entry.setDeleted(deleted); } IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource); if (previous != null) { entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()).getValue()); } TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource); if (tagList != null) { for (Tag nextTag : tagList) { entry.addCategory(nextTag); } } String linkSearch = ResourceMetadataKeyEnum.LINK_SEARCH.get(theResource); if (isNotBlank(linkSearch)) { if (!UrlUtil.isAbsolute(linkSearch)) { linkSearch = (theServerBase + "/" + linkSearch); } entry.getLinkSearch().setValue(linkSearch); } String linkAlternate = ResourceMetadataKeyEnum.LINK_ALTERNATE.get(theResource); if (isNotBlank(linkAlternate)) { if (!UrlUtil.isAbsolute(linkAlternate)) { linkSearch = (theServerBase + "/" + linkAlternate); } entry.getLinkAlternate().setValue(linkSearch); } BundleEntrySearchModeEnum entryStatus = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(theResource); if (entryStatus != null) { entry.getSearchMode().setValueAsEnum(entryStatus); } BundleEntryTransactionMethodEnum entryTransactionOperation = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD .get(theResource); if (entryTransactionOperation != null) { entry.getTransactionMethod().setValueAsEnum(entryTransactionOperation); } DecimalDt entryScore = ResourceMetadataKeyEnum.ENTRY_SCORE.get(theResource); if (entryScore != null) { entry.setScore(entryScore); } return entry; }
From source file:com.epam.catgenome.controller.ExceptionHandlerAdvice.java
@ResponseBody @Order(Ordered.HIGHEST_PRECEDENCE)/*from w ww .j a va2s.co m*/ @ExceptionHandler(Throwable.class) public final ResponseEntity<Result<String>> handleUncaughtException(final Throwable exception, final WebRequest request) { // adds information about encountered error to application log LOG.error(MessageHelper.getMessage("logger.error", request.getDescription(true)), exception); HttpStatus code = HttpStatus.OK; String message; if (exception instanceof FileNotFoundException) { // any details about real path of a resource should be normally prevented to send to the client message = MessageHelper.getMessage("error.io.not.found"); } else if (exception instanceof DataAccessException) { // any details about data access error should be normally prevented to send to the client, // as its message can contain information about failed SQL query or/and database schema if (exception instanceof BadSqlGrammarException) { // for convenience we need to provide detailed information about occurred BadSqlGrammarException, // but it can be retrieved SQLException root = ((BadSqlGrammarException) exception).getSQLException(); if (root.getNextException() != null) { LOG.error(MessageHelper.getMessage("logger.error.root.cause", request.getDescription(true)), root.getNextException()); } message = MessageHelper.getMessage("error.sql.bad.grammar"); } else { message = MessageHelper.getMessage("error.sql"); } } else if (exception instanceof UnauthorizedClientException) { message = exception.getMessage(); code = HttpStatus.UNAUTHORIZED; } else { message = exception.getMessage(); } return new ResponseEntity<>(Result.error(StringUtils.defaultString(StringUtils.trimToNull(message), MessageHelper.getMessage("error" + ".default"))), code); }
From source file:com.xpn.xwiki.plugin.XWikiDefaultPlugin.java
protected String localizePlainOrKey(String key, Object... parameters) { return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key); }
From source file:io.wcm.handler.link.type.InternalLinkType.java
@Override public Link resolveLink(Link link) { LinkRequest linkRequest = link.getLinkRequest(); ValueMap props = linkRequest.getResourceProperties(); // flag to indicate whether any link reference parameter set boolean referenceSet = false; // first try to get direct link target page Page targetPage = link.getLinkRequest().getPage(); if (targetPage != null) { referenceSet = true;/*from w ww . jav a 2 s. c o m*/ } // if no target page is set get internal path that points to target page if (targetPage == null) { String targetPath = props.get(getPrimaryLinkRefProperty(), String.class); if (StringUtils.isNotEmpty(targetPath)) { referenceSet = true; } targetPage = getTargetPage(targetPath); } // if target page is a redirect or integrator page recursively resolve link to which the redirect points to // (skip this redirection if edit mode is active) if (targetPage != null && (linkHandlerConfig.isRedirect(targetPage) || urlHandlerConfig.isIntegrator(targetPage)) && wcmMode != WCMMode.EDIT) { return recursiveResolveLink(targetPage, link); } // build link url String linkUrl = null; if (targetPage != null) { link.setTargetPage(targetPage); LinkArgs linkArgs = linkRequest.getLinkArgs(); String selectors = linkArgs.getSelectors(); String fileExtension = StringUtils.defaultString(linkArgs.getExtension(), FileExtension.HTML); String suffix = linkArgs.getSuffix(); String queryString = linkArgs.getQueryString(); String fragment = linkArgs.getFragment(); // optionally override query parameters and fragment from link resource queryString = props.get(LinkNameConstants.PN_LINK_QUERY_PARAM, queryString); fragment = props.get(LinkNameConstants.PN_LINK_FRAGMENT, fragment); // build link url linkUrl = urlHandler.get(targetPage).selectors(selectors).extension(fileExtension).suffix(suffix) .queryString(queryString).fragment(fragment).urlMode(linkArgs.getUrlMode()) .buildExternalLinkUrl(targetPage); } // mark link as invalid if a reference was set that could not be resolved if (linkUrl == null && referenceSet) { link.setLinkReferenceInvalid(true); } // set link url link.setUrl(linkUrl); return link; }
From source file:com.formkiq.core.service.sign.SigningServiceImpl.java
/** * Create Docsign Result./* www .j a va2s.c o m*/ * @param request {@link HttpServletRequest} * @param workflow {@link Workflow} * @return {@link FormJSON} */ @Override public FormJSON createDocsignResult(final HttpServletRequest request, final Workflow workflow) { String ipaddress = request.getRemoteAddr(); String xforwardedfor = request.getHeader("X-FORWARDED-FOR"); String latitude = request.getParameter("latitude"); String longitude = request.getParameter("longitude"); FormJSON form = new FormJSON(); form.setUUID(UUID.randomUUID().toString()); form.setParentUUID(workflow.getParentUUID()); form.setBuiltintype(DOCSIGN_RESULT.toString()); int i = 0; FormJSONField f0 = createFormField(++i, FormJSONFieldType.TEXTBOX, "Inserted Date", new Date()); FormJSONField f1 = createFormField(++i, FormJSONFieldType.TEXTBOX, "IP Address", ipaddress); FormJSONField f2 = createFormField(++i, FormJSONFieldType.TEXTBOX, "X-FORWARDED-FOR", StringUtils.defaultString(xforwardedfor, "")); FormJSONField f3 = createFormField(++i, FormJSONFieldType.TEXTBOX, "Latitude", latitude); FormJSONField f4 = createFormField(++i, FormJSONFieldType.TEXTBOX, "Longitude", longitude); List<FormJSONField> fields = Arrays.asList(f0, f1, f2, f3, f4); FormJSONSection sect = buildFormJSONSection(null, fields); form.setSections(Arrays.asList(sect)); return form; }
From source file:com.mirth.connect.server.util.javascript.JavaScriptTask.java
public Object executeScript(Script compiledScript, Scriptable scope) throws InterruptedException { try {/*w ww.ja v a 2 s .c om*/ // if the executor is halting this task, we don't want to initialize the context yet synchronized (this) { ThreadUtils.checkInterruptedStatus(); context = Context.getCurrentContext(); Thread.currentThread().setContextClassLoader(contextFactory.getApplicationClassLoader()); logger.debug(StringUtils.defaultString(StringUtils.trimToNull(getClass().getSimpleName()), getClass().getName()) + " using context factory: " + contextFactory.hashCode()); /* * This should never be called but exists in case executeScript is called from a * different thread than the one that entered the context. */ if (context == null) { contextCreated = true; context = JavaScriptScopeUtil.getContext(contextFactory); } if (context instanceof MirthContext) { ((MirthContext) context).setRunning(true); } } return compiledScript.exec(context, scope); } finally { if (contextCreated) { Context.exit(); contextCreated = false; } } }
From source file:net.sf.appstatus.web.StatusServlet.java
/** * Init the AppStatus Web UI.// w ww .java 2 s. co m * <p> * Read <b>bean</> init parameter. If defined, switch to Spring-enabled * behavior. */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); super.init(); SpringObjectInstantiationListener instantiation = null; String beanName = getInitParameter("bean"); String[] pagesBeanNames = StringUtils.split(getInitParameter("custom-pages"), ", "); Map<String, IPage> pages = new LinkedHashMap<String, IPage>(); ; AppStatus status; if (beanName != null) { // Using Spring instantiation = new SpringObjectInstantiationListener(this.getServletContext()); // Status status = (AppStatus) instantiation.getInstance(beanName); } else { status = AppStatusStatic.getInstance(); } status.setServletContextProvider(new IServletContextProvider() { public ServletContext getServletContext() { return StatusServlet.this.getServletContext(); } }); // // Pages addPage(pages, new StatusPage()); if (status.getServiceManager() != null) { addPage(pages, new ServicesPage()); } if (status.getBatchManager() != null) { addPage(pages, new BatchPage()); } if (status.getLoggersManager() != null) { addPage(pages, new LoggersPage()); } // Custom pages if (pagesBeanNames != null) { for (String pageBean : pagesBeanNames) { IPage newPage = null; if (instantiation != null) { newPage = (IPage) instantiation.getInstance(pageBean); if (newPage == null) { try { newPage = (IPage) Thread.currentThread().getContextClassLoader().loadClass(pageBean) .newInstance(); } catch (ClassNotFoundException e) { logger.warn("Class {} not found ", pageBean, e); } catch (InstantiationException e) { logger.warn("Cannot instanciate {} ", pageBean, e); } catch (IllegalAccessException e) { logger.warn("Cannot access class {} for instantiation ", pageBean, e); } } } addPage(pages, newPage); } } // Radiator at the end. addPage(pages, new RadiatorPage()); // Init statusWeb = new StatusWebHandler(); statusWeb.setAppStatus(status); statusWeb.setApplicationName( StringUtils.defaultString(config.getServletContext().getServletContextName(), "No name")); statusWeb.setPages(pages); statusWeb.init(); }