List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr)
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .
StringUtils.defaultIfBlank(null, "NULL") = "NULL" StringUtils.defaultIfBlank("", "NULL") = "NULL" StringUtils.defaultIfBlank(" ", "NULL") = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null) = null
From source file:com.linagora.obm.ui.page.CreateContactPage.java
private void doCreateContact(UIContact contactToCreate) { firstname.sendKeys(StringUtils.defaultIfBlank(contactToCreate.getFirstName(), "")); lastname.sendKeys(StringUtils.defaultIfBlank(contactToCreate.getLastName(), "")); companyField.sendKeys(StringUtils.defaultIfBlank(contactToCreate.getCompanyField(), "")); clickCheckbox(mailokField, contactToCreate.isMailokField()); clickCheckbox(newsletterField, contactToCreate.isNewsletterField()); contactForm.submit();/*www .ja va2 s . c o m*/ }
From source file:alfio.controller.api.admin.CheckInApiController.java
@RequestMapping(value = "/check-in/event/{eventName}/ticket/{ticketIdentifier}", method = POST) public TicketAndCheckInResult checkIn(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, @RequestBody TicketCode ticketCode, @RequestParam(value = "offlineUser", required = false) String offlineUser, Principal principal) { String user = StringUtils.defaultIfBlank(offlineUser, principal.getName()); return checkInManager.checkIn(eventName, ticketIdentifier, Optional.ofNullable(ticketCode).map(TicketCode::getCode), user); }
From source file:dtu.ds.warnme.app.model.impl.User.java
@Override public void merge(User user) { setUsername(StringUtils.defaultString(user.getUsername())); setPassword(StringUtils.defaultString(user.getPassword())); setEmail(StringUtils.defaultString(user.getEmail())); setRole(user.getRole());// w w w . j a va 2s. c om setComment(StringUtils.defaultIfBlank(user.getComment(), null)); setLocked(user.isLocked()); setDeleted(user.isDeleted()); }
From source file:controllers.ProjectApp.java
@IsAllowed(Operation.READ) public static Result project(String ownerId, String projectName) throws IOException, ServletException, SVNException, GitAPIException { Project project = Project.findByOwnerAndProjectName(ownerId, projectName); List<History> histories = getProjectHistory(ownerId, project); UserApp.currentUser().visits(project); String tabId = StringUtils.defaultIfBlank(request().getQueryString("tabId"), "readme"); return ok(home.render(getTitleMessage(tabId), project, histories, tabId)); }
From source file:de.blizzy.documentr.markdown.HtmlSerializer.java
@Override protected void printImageTag(SuperNode imageNode, String url) { String params = StringUtils.EMPTY; if (url.contains("|")) { //$NON-NLS-1$ params = StringUtils.substringAfter(url, "|").trim(); //$NON-NLS-1$ url = StringUtils.substringBefore(url, "|").trim(); //$NON-NLS-1$ }//from w w w .j a va2s.c om boolean thumbnail = params.contains(IMAGE_PARAM_THUMB); String altText = printChildrenToString(imageNode); String title = null; if (imageNode instanceof ExpImageNode) { title = StringUtils.defaultIfBlank(((ExpImageNode) imageNode).title, altText); } if (thumbnail) { printer.print("<ul class=\"thumbnails\"><li class=\"span3\"><a class=\"thumbnail\" href=\"") //$NON-NLS-1$ .print(context.getAttachmentUri(url)).print("\">"); //$NON-NLS-1$ } printer.print("<img src=\"").print(context.getAttachmentUri(url)).print("\""); //$NON-NLS-1$ //$NON-NLS-2$ if (StringUtils.isNotBlank(altText)) { printer.print(" alt=\"").printEncoded(altText).print("\""); //$NON-NLS-1$ //$NON-NLS-2$ } if (thumbnail) { printer.print(" data-lightbox=\"lightbox\" width=\"260\""); //$NON-NLS-1$ } if (StringUtils.isNotBlank(title)) { printer.print(" rel=\"tooltip\" data-title=\"").printEncoded(title).print("\""); //$NON-NLS-1$ //$NON-NLS-2$ } printer.print("/>"); //$NON-NLS-1$ if (thumbnail) { printer.print("</a></li></ul>"); //$NON-NLS-1$ } }
From source file:com.esri.geoportal.harvester.migration.MigrationDataBuilder.java
public URI createSourceUri(MigrationData data) throws URISyntaxException, UnsupportedEncodingException { String sourceuri = StringUtils.defaultIfBlank(data.sourceuri, data.docuuid); return URI.create(escapeUri(sourceuri)); }
From source file:kenh.expl.impl.BaseFunction.java
/** * Find the method with name <code>process</code> or <code>@Processing</code> *///from w w w. jav a2s . c om @Override public Object invoke(Object... params) throws UnsupportedExpressionException { Method[] methods = this.getClass().getMethods(); for (Method method : methods) { String name = method.getName(); Class[] classes = method.getParameterTypes(); Annotation a = method.getAnnotation(Processing.class); if ((name.equals(METHOD) || a != null) && params.length == classes.length) { logger.trace("Method: " + method.toGenericString()); boolean find = true; Object[] objs = new Object[params.length]; for (int i = 0; i < params.length; i++) { Class class1 = params[i].getClass(); Class class2 = classes[i]; if (class2.isAssignableFrom(class1) || class2 == Object.class) { objs[i] = params[i]; } else if (class1 == String.class) { try { Object obj = Environment.convert((String) params[i], class2); if (obj == null) { logger.trace("Failure(Convert failure[" + (i + 1) + "-" + class1 + "," + class2 + "]): " + method.toGenericString()); find = false; break; } else { objs[i] = obj; } } catch (Exception e) { logger.trace("Failure(Convert exception[" + (i + 1) + "-" + e.getMessage() + "]): " + method.toGenericString()); find = false; break; //UnsupportedExpressionException ex = new UnsupportedExpressionException(e); //throw ex; } } else { logger.trace("Failure(Class unmatched[" + (i + 1) + "]): " + method.toGenericString()); find = false; break; } } if (find) { try { return method.invoke(this, objs); } catch (Exception e) { if (e instanceof UnsupportedExpressionException) throw (UnsupportedExpressionException) e; else throw new UnsupportedExpressionException(e); } } } } String paramStr = ""; for (Object param : params) { paramStr += param.getClass().getCanonicalName() + ", "; } paramStr = StringUtils.defaultIfBlank(StringUtils.chop(StringUtils.trimToEmpty(paramStr)), "<NO PARAM>"); UnsupportedExpressionException e = new UnsupportedExpressionException( "Can't find the method to process.[" + paramStr + "]"); throw e; }
From source file:dtu.ds.warnme.model.impl.UserEntity.java
@Override public void merge(UserEntity user) { setUsername(StringUtils.defaultString(user.getUsername())); setPassword(StringUtils.defaultString(user.getPassword())); setEmail(StringUtils.defaultString(user.getEmail())); setComment(StringUtils.defaultIfBlank(user.getComment(), null)); setLocked(user.isLocked());//from w ww .j ava 2 s .c o m setDeleted(user.isDeleted()); }
From source file:ductive.console.commands.lib.LogCommands.java
@Cmd(path = { "log", "attach" }, help = "checks health of app") public void logAttach(Terminal terminal, @Arg(value = "logger", optional = true) String loggerName, @Arg(value = "level", optional = true) Level level_) throws IOException { final org.apache.logging.log4j.Logger logger; if (StringUtils.isEmpty(loggerName)) logger = org.apache.logging.log4j.LogManager.getRootLogger(); else/* w ww. j ava 2 s .c om*/ logger = org.apache.logging.log4j.LogManager.getLogger(loggerName); org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger; Configuration config = coreLogger.getContext().getConfiguration(); final Level level = level_ != null ? level_ : Level.TRACE; coreLogger.setLevel(level); PatternLayout layout = PatternLayout.newBuilder().withConfiguration(config).withPattern(logPattern).build(); RemoteTerminalAppender appender = new RemoteTerminalAppender(terminal, UUID.randomUUID().toString(), null, layout, true); appender.start(); coreLogger.addAppender(appender); try { if (log.isInfoEnabled()) log.info(String.format("terminal attached to logger '%s'", StringUtils.defaultIfBlank(logger.getName(), "ROOT"))); coreLogger.addAppender(appender); if (InteractiveTerminal.class.isInstance(terminal)) { terminal.println(new Ansi().fgBright(Color.WHITE).bold() .a(String.format("---- catching %s on logger %s. press 'q', ^D or ^C to detach ----", level, StringUtils.defaultIfBlank(logger.getName(), "ROOT"))) .reset()); terminal.flush(); InteractiveTerminal term = InteractiveTerminal.class.cast(terminal); while (true) { int c = term.readChar(10); if (c == CR) { terminal.println(""); terminal.flush(); } else if (c == CTRL_C || c == CTRL_D || c == 'q' || c == 'Q' || appender.hasIoErrors()) break; } } else { terminal.println(new Ansi().fgBright(Color.WHITE).bold() .a(String.format("---- catching %s on logger %s ----", level, StringUtils.defaultIfBlank(logger.getName(), "ROOT"))) .reset()); terminal.flush(); while (!appender.hasIoErrors()) SleepUtils.sleep(100); } } finally { coreLogger.removeAppender(appender); appender.stop(); if (log.isInfoEnabled()) log.info(String.format("terminal detached from logger '%s'", StringUtils.defaultIfBlank(logger.getName(), "ROOT"))); } }
From source file:com.neatresults.mgnltweaks.ui.action.CreateAppAction.java
@Override public void execute() throws ActionExecutionException { // First Validate validator.showValidation(true);//w w w . j a v a 2 s.com if (validator.isValid()) { // we support only JCR item adapters if (!(item instanceof JcrItemAdapter)) { return; } // don't save if no value changes occurred on adapter if (!((JcrItemAdapter) item).hasChangedProperties()) { return; } if (item instanceof AbstractJcrNodeAdapter) { // Saving JCR Node, getting updated node first AbstractJcrNodeAdapter nodeAdapter = (AbstractJcrNodeAdapter) item; try { Node node = nodeAdapter.getJcrItem(); Context originalCtx = MgnlContext.getInstance(); InputStream inputStream = null; MgnlGroovyConsoleContext groovyCtx = null; try { groovyCtx = new MgnlGroovyConsoleContext(originalCtx); groovyCtx.put("appName", item.getItemProperty("appName").getValue()); String[] pathArray = StringUtils.split(node.getPath(), "/"); if (pathArray.length < 2) { throw new ActionExecutionException( "Can't create app on selected path: " + node.getPath()); } groovyCtx.put("appLocation", pathArray[1]); groovyCtx.put("appGroup", item.getItemProperty("appGroup").getValue()); groovyCtx.put("appIcon", StringUtils .defaultIfBlank((String) item.getItemProperty("appIcon").getValue(), "icon-items")); groovyCtx.put("appRepository", StringUtils.defaultIfBlank( (String) item.getItemProperty("appRepository").getValue(), "magnolia")); groovyCtx.put("appFolderSupport", item.getItemProperty("appFolderSupport").getValue()); MgnlContext.setInstance(groovyCtx); MgnlGroovyConsole console = new MgnlGroovyConsole(new Binding()); String inputFile = "/neat-tweaks-developers/appCreationScript.groovy"; // First Check URL inFile = ClasspathResourcesUtil.getResource(inputFile); if (inFile == null) { throw new ActionExecutionException("Can't find resource file at " + inputFile); } // Get Input Stream inputStream = ClasspathResourcesUtil.getResource(inputFile).openStream(); if (inputStream == null) { throw new ActionExecutionException("Can't find resource file at " + inFile.getFile()); } Writer writer = new StringWriter(); Object result = console.evaluate(inputStream, console.generateScriptName(), writer); StringBuilder sb = new StringBuilder().append(writer.toString()).append("\n") .append(result); uiContext.openNotification(MessageStyleTypeEnum.INFO, true, sb.toString()); } finally { // close jcr sessions groovyCtx.release(); // close files IOUtils.closeQuietly(inputStream); // restore context MgnlContext.setInstance(originalCtx); } } catch (RepositoryException | IOException e) { log.error("Could not save changes to node", e); } callback.onSuccess(getDefinition().getName()); } else if (item instanceof JcrPropertyAdapter) { super.execute(); } } else { log.debug("Validation error(s) occurred. No save performed."); } }