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.sonicle.webtop.core.app.shiro.WTFormAuthFilter.java
private void writeAuthLog(UsernamePasswordDomainToken token, HttpServletRequest request, String action) { WebTopApp wta = WebTopApp.getInstance(); if (wta != null) { String domainId = StringUtils.defaultIfBlank(token.getDomain(), "?"); String userId = StringUtils.defaultIfBlank(token.getUsername(), "?"); UserProfileId pid = new UserProfileId(domainId, userId); wta.getLogManager().write(pid, CoreManifest.ID, action, null, request, request.getRequestedSessionId(), null);/*from www .ja v a 2 s. co m*/ } }
From source file:com.sonicle.webtop.core.io.input.XlsRecordsProcessor.java
@Override public void processRecord(Record record) { int thisRow = -1; int thisCol = -1; cellValue = null;/*from w w w. ja va 2 s . co m*/ switch (record.getSid()) { case BoundSheetRecord.sid: BoundSheetRecord bsr = (BoundSheetRecord) record; if (!sheetFound) { if (StringUtils.equals(bsr.getSheetname(), sheetName)) { sheetFound = true; columnNames = new LinkedHashMap<>(); columnIndexes = new HashMap<>(); } } else { close(); } break; case SSTRecord.sid: sstRecord = (SSTRecord) record; break; case BlankRecord.sid: BlankRecord br = (BlankRecord) record; thisRow = br.getRow(); thisCol = br.getColumn(); cellValue = ""; break; case BoolErrRecord.sid: BoolErrRecord ber = (BoolErrRecord) record; thisRow = ber.getRow(); thisCol = ber.getColumn(); cellValue = ""; break; case FormulaRecord.sid: FormulaRecord fr = (FormulaRecord) record; thisRow = fr.getRow(); thisCol = fr.getColumn(); if (Double.isNaN(fr.getValue())) { // Formula result is a string that is stored in the next record! findNextStringRecord = true; nextRow = fr.getRow(); nextCol = fr.getColumn(); cellValue = null; } else { cellValue = formatTrackingListener.formatNumberDateCell(fr); } break; case StringRecord.sid: if (findNextStringRecord) { // String for formula StringRecord sr = (StringRecord) record; cellValue = sr.getString(); thisRow = nextRow; thisCol = nextCol; // Resets markers... findNextStringRecord = false; nextRow = -1; nextCol = -1; } break; case LabelRecord.sid: LabelRecord lr = (LabelRecord) record; thisRow = lr.getRow(); thisCol = lr.getColumn(); cellValue = lr.getValue(); break; case LabelSSTRecord.sid: LabelSSTRecord lsstr = (LabelSSTRecord) record; thisRow = lsstr.getRow(); thisCol = lsstr.getColumn(); if (sstRecord == null) { cellValue = "#ERROR(undefined string)"; } else { cellValue = sstRecord.getString(lsstr.getSSTIndex()).toString(); } break; case NoteRecord.sid: NoteRecord nr = (NoteRecord) record; thisRow = nr.getRow(); thisCol = nr.getColumn(); // TODO: Find object to match nrec.getShapeId() cellValue = "#ERROR(TODO)"; break; case NumberRecord.sid: NumberRecord rn = (NumberRecord) record; thisRow = rn.getRow(); thisCol = rn.getColumn(); cellValue = formatTrackingListener.formatNumberDateCell(rn); break; case RKRecord.sid: RKRecord rkr = (RKRecord) record; thisRow = rkr.getRow(); thisCol = rkr.getColumn(); cellValue = "#ERROR(TODO)"; break; default: cellValue = null; } // Handle new row if ((thisRow != -1) && (thisRow != row)) { row = -1; isNewRow = true; } else { isNewRow = false; } if (thisRow > -1) row = thisRow; if (thisCol > -1) col = thisCol; isInRange = ((row >= firstDataRow) && ((lastDataRow == -1) || (row <= lastDataRow))); // Handle end of row if (record instanceof LastCellOfRowDummyRecord) { isDummyEndRow = true; col = -1; // We're nearly onto a new row } else { isDummyEndRow = false; } if (!isDummyEndRow && (row == headersRow)) { String cellReference = CellReference.convertNumToColString(col); String name = (headersRow == firstDataRow) ? cellReference : StringUtils.defaultIfBlank(cellValue, cellReference); columnNames.put(name.toLowerCase(), name); columnIndexes.put(name, col); } }
From source file:com.contentful.vault.compiler.Processor.java
private void parseSpace(TypeElement element, Map<TypeElement, SpaceInjection> spaces, Map<TypeElement, ModelInjection> models) { Space annotation = element.getAnnotation(Space.class); String id = annotation.value(); if (id.isEmpty()) { error(element, "@%s id may not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return;//from ww w .j av a 2 s . c o m } TypeMirror spaceMirror = elementUtils.getTypeElement(Space.class.getName()).asType(); List<ModelInjection> includedModels = new ArrayList<>(); for (AnnotationMirror mirror : element.getAnnotationMirrors()) { if (typeUtils.isSameType(mirror.getAnnotationType(), spaceMirror)) { Set<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> items = mirror .getElementValues().entrySet(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : items) { if ("models".equals(entry.getKey().getSimpleName().toString())) { List l = (List) entry.getValue().getValue(); if (l.size() == 0) { error(element, "@%s models must not be empty. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } Set<String> modelIds = new LinkedHashSet<>(); for (Object model : l) { TypeElement e = (TypeElement) ((Type) ((Attribute) model).getValue()).asElement(); ModelInjection modelInjection = models.get(e); if (modelInjection == null) { return; } else { String rid = modelInjection.remoteId; if (!modelIds.add(rid)) { error(element, "@%s includes multiple models with the same id \"%s\". (%s)", Space.class.getSimpleName(), rid, element.getQualifiedName()); return; } includedModels.add(modelInjection); } } } } } } List<String> locales = Arrays.asList(annotation.locales()); Set<String> checked = new HashSet<>(); for (int i = locales.size() - 1; i >= 0; i--) { String code = locales.get(i); if (!checked.add(code)) { error(element, "@%s contains duplicate locale code '%s'. (%s)", Space.class.getSimpleName(), code, element.getQualifiedName()); return; } else if (code.contains(" ") || code.isEmpty()) { error(element, "Invalid locale code '%s', must not be empty and may not contain spaces. (%s)", code, element.getQualifiedName()); return; } } if (checked.size() == 0) { error(element, "@%s at least one locale must be configured. (%s)", Space.class.getSimpleName(), element.getQualifiedName()); return; } ClassName injectionClassName = getInjectionClassName(element, SUFFIX_SPACE); String dbName = "space_" + SqliteUtils.hashForId(id); String copyPath = StringUtils.defaultIfBlank(annotation.copyPath(), null); spaces.put(element, new SpaceInjection(id, injectionClassName, element, includedModels, dbName, annotation.dbVersion(), copyPath, locales)); }
From source file:controllers.PullRequestApp.java
@AnonymousCheck(requiresLogin = true, displaysFlashMessage = true) @IsCreatable(ResourceType.FORK)//from w w w.ja va 2 s . c o m public static Result mergeResult(String userName, String projectName) throws IOException, GitAPIException { final Project project = Project.findByOwnerAndProjectName(userName, projectName); ValidationResult validation = validateBeforePullRequest(project); if (validation.hasError()) { return validation.getResult(); } final Project fromProject = getSelectedProject(project, request().getQueryString("fromProjectId"), false); final Project toProject = getSelectedProject(project, request().getQueryString("toProjectId"), true); final List<GitBranch> fromBranches = new GitRepository(fromProject).getBranches(); final List<GitBranch> toBranches = new GitRepository(toProject).getBranches(); final PullRequest pullRequest = PullRequest.createNewPullRequest(fromProject, toProject, StringUtils.defaultIfBlank(request().getQueryString("fromBranch"), fromBranches.get(0).getName()), StringUtils.defaultIfBlank(request().getQueryString("toBranch"), toBranches.get(0).getName())); PullRequestMergeResult mergeResult = pullRequest.getPullRequestMergeResult(); response().setHeader("Cache-Control", "no-cache, no-store"); return ok(partial_merge_result.render(project, pullRequest, mergeResult.getGitCommits(), mergeResult.conflicts())); }
From source file:com.sonicle.webtop.calendar.TplHelper.java
public static String buildTplEventInvitationBody(Locale locale, String dateFormat, String timeFormat, Event event, String crud, String recipientEmail, String servicePublicUrl) throws IOException, TemplateException, AddressException { DateTimeZone etz = DateTimeZone.forID(event.getTimezone()); MapItem i18n = new MapItem(); i18n.put("whenStart", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHEN_START)); i18n.put("whenEnd", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHEN_END)); i18n.put("where", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHERE)); i18n.put("whereMap", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHERE_MAP)); i18n.put("organizer", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_ORGANIZER)); i18n.put("who", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_WHO)); i18n.put("going", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_GOING)); i18n.put("goingToAll", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_GOINGTOALL)); i18n.put("goingYes", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_GOING_YES)); i18n.put("goingMaybe", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_GOING_MAYBE)); i18n.put("goingNo", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_GOING_NO)); i18n.put("view", WT.lookupResource(SERVICE_ID, locale, CalendarLocale.TPL_EMAIL_INVITATION_VIEW)); DateTimeFormatter fmt = DateTimeUtils.createFormatter(dateFormat + " " + timeFormat, etz); MapItem evt = new MapItem(); evt.put("title", StringUtils.defaultIfBlank(event.getTitle(), "")); evt.put("description", StringUtils.defaultIfBlank(event.getDescription(), null)); evt.put("timezone", event.getTimezone()); evt.put("startDate", fmt.print(event.getStartDate())); evt.put("endDate", fmt.print(event.getEndDate())); evt.put("occurs", null); if (!StringUtils.isEmpty(event.getRecurrenceRule())) { RRuleStringify.Strings strings = WT.getRRuleStringifyStrings(locale); RRuleStringify rrs = new RRuleStringify(strings, etz); evt.put("occurs", rrs.toHumanReadableTextQuietly(event.getRecurrenceRule())); }/*from w ww . j a va2s .c o m*/ evt.put("location", StringUtils.defaultIfBlank(event.getLocation(), null)); evt.put("locationUrl", TplHelper.buildGoogleMapsUrl(event.getLocation())); evt.put("organizer", StringUtils.defaultIfBlank(event.getOrganizerCN(), event.getOrganizerAddress())); String recipientAttendeeId = null; MapItemList evtAtts = new MapItemList(); for (EventAttendee attendee : event.getAttendees()) { MapItem item = new MapItem(); String cn = attendee.getCN(); String address = attendee.getAddress(); if (StringUtils.equals(address, recipientEmail)) recipientAttendeeId = attendee.getAttendeeId(); item.put("cn", StringUtils.isBlank(cn) ? null : cn); item.put("address", StringUtils.isBlank(address) ? null : address); evtAtts.add(item); } String viewUrl = CalendarManager.buildEventPublicUrl(servicePublicUrl, event.getPublicUid()); MapItem vars = new MapItem(); vars.put("i18n", i18n); vars.put("event", evt); vars.put("eventAttendees", evtAtts); if (!StringUtils.equals(crud, "delete")) { vars.put("replyYesUrl", (recipientAttendeeId == null) ? null : CalendarManager.buildEventReplyPublicUrl(servicePublicUrl, event.getPublicUid(), recipientAttendeeId, "yes")); vars.put("replyMaybeUrl", (recipientAttendeeId == null) ? null : CalendarManager.buildEventReplyPublicUrl(servicePublicUrl, event.getPublicUid(), recipientAttendeeId, "maybe")); vars.put("replyNoUrl", (recipientAttendeeId == null) ? null : CalendarManager.buildEventReplyPublicUrl(servicePublicUrl, event.getPublicUid(), recipientAttendeeId, "no")); vars.put("viewUrl", viewUrl); } return WT.buildTemplate(SERVICE_ID, "tpl/email/eventInvitation-body.html", vars); }
From source file:com.xpn.xwiki.tool.backup.ImportMojo.java
private void toExtension(DefaultLocalExtension extension, Model model, ComponentManager componentManager) throws ComponentLookupException { extension.setName(getPropertyString(model, MPNAME_NAME, model.getName())); extension.setSummary(getPropertyString(model, MPNAME_SUMMARY, model.getDescription())); extension.setWebsite(getPropertyString(model, MPNAME_WEBSITE, model.getUrl())); // authors/* w ww. j ava 2 s.co m*/ for (Developer developer : (List<Developer>) model.getDevelopers()) { URL authorURL = null; if (developer.getUrl() != null) { try { authorURL = new URL(developer.getUrl()); } catch (MalformedURLException e) { // TODO: log ? } } extension.addAuthor(new DefaultExtensionAuthor( StringUtils.defaultIfBlank(developer.getName(), developer.getId()), authorURL)); } // licenses if (!model.getLicenses().isEmpty()) { ExtensionLicenseManager licenseManager = componentManager.getInstance(ExtensionLicenseManager.class); for (License license : (List<License>) model.getLicenses()) { extension.addLicense(getExtensionLicense(license, licenseManager)); } } // features String featuresString = getProperty(model, MPNAME_FEATURES); if (StringUtils.isNotBlank(featuresString)) { featuresString = featuresString.replaceAll("[\r\n]", ""); ConverterManager converter = componentManager.getInstance(ConverterManager.class); extension.setFeatures(converter.<Collection<String>>convert(List.class, featuresString)); } // dependencies for (Dependency mavenDependency : (List<Dependency>) model.getDependencies()) { if (!mavenDependency.isOptional() && (mavenDependency.getScope().equals("compile") || mavenDependency.getScope().equals("runtime"))) { extension.addDependency(new DefaultExtensionDependency( mavenDependency.getGroupId() + ':' + mavenDependency.getArtifactId(), new DefaultVersionConstraint(mavenDependency.getVersion()))); } } }
From source file:alfio.manager.AdminReservationRequestManager.java
private Stream<AdminReservationModification> spread(AdminReservationModification src, boolean single) { if (single) { return Stream.of(src); }/*w ww . j a va2 s . c om*/ return src.getTicketsInfo().stream() .flatMap(ti -> ti.getAttendees().stream() .map(a -> Pair.of(a, new AdminReservationModification.TicketsInfo(ti.getCategory(), singletonList(a), ti.isAddSeatsIfNotAvailable(), ti.isUpdateAttendees())))) .map(p -> { AdminReservationModification.Attendee attendee = p.getLeft(); String language = StringUtils.defaultIfBlank(attendee.getLanguage(), src.getLanguage()); CustomerData cd = new CustomerData(attendee.getFirstName(), attendee.getLastName(), attendee.getEmailAddress(), null, language); return new AdminReservationModification(src.getExpiration(), cd, singletonList(p.getRight()), language, src.isUpdateContactData(), src.getNotification()); }); }
From source file:chat.viska.xmpp.Connection.java
/** * Constructs a {@link Connection} with full server URI. * @param port Use {@code -1} to indicate no port. * @throws IllegalArgumentException If {@link Protocol#TCP} is specified. *//*from w ww . jav a 2 s . co m*/ public Connection(final Protocol protocol, final String scheme, final String domain, final int port, @Nullable final String path) { Objects.requireNonNull(protocol, "`protocol` is absent."); if (protocol == Protocol.TCP) { throw new IllegalArgumentException("TCP protocol is not suitable for this constructor."); } this.protocol = protocol; Validate.notBlank(scheme, "`scheme` is absent."); this.scheme = StringUtils.isAllLowerCase(scheme) ? scheme : scheme.toLowerCase(); Validate.notBlank(domain, "`domain` is absent."); this.domain = domain; this.port = port; this.path = StringUtils.defaultIfBlank(path, ""); this.tlsMethod = TlsMethod.NONE; }
From source file:com.sonicle.webtop.core.app.WebTopManager.java
public static String generateSecretKey() { return StringUtils.defaultIfBlank(IdentifierUtils.generateSecretKey(), "0123456789101112"); }
From source file:com.xwikisas.xcs.tools.dependenciespackager.PackageExtensionsMojo.java
private void toExtension(DefaultLocalExtension extension, Model model) throws ComponentLookupException { extension.setName(getPropertyString(model, MPNAME_NAME, model.getName())); extension.setSummary(getPropertyString(model, MPNAME_SUMMARY, model.getDescription())); extension.setWebsite(getPropertyString(model, MPNAME_WEBSITE, model.getUrl())); // authors/*w w w.j ava 2 s .c om*/ for (Developer developer : model.getDevelopers()) { URL authorURL = null; if (developer.getUrl() != null) { try { authorURL = new URL(developer.getUrl()); } catch (MalformedURLException e) { // TODO: log ? } } extension.addAuthor(new DefaultExtensionAuthor( StringUtils.defaultIfBlank(developer.getName(), developer.getId()), authorURL)); } // licenses if (!model.getLicenses().isEmpty()) { ExtensionLicenseManager licenseManager = xwikiComponentManager .getInstance(ExtensionLicenseManager.class); for (License license : model.getLicenses()) { extension.addLicense(getExtensionLicense(license, licenseManager)); } } // features String featuresString = getProperty(model, MPNAME_FEATURES); if (StringUtils.isNotBlank(featuresString)) { featuresString = featuresString.replaceAll("[\r\n]", ""); ConverterManager converter = xwikiComponentManager.getInstance(ConverterManager.class); extension.setFeatures(converter.<Collection<String>>convert(List.class, featuresString)); } // dependencies for (Dependency mavenDependency : model.getDependencies()) { if (!mavenDependency.isOptional() && (mavenDependency.getScope().equals("compile") || mavenDependency.getScope().equals("runtime"))) { extension.addDependency(new DefaultExtensionDependency( mavenDependency.getGroupId() + ':' + mavenDependency.getArtifactId(), new DefaultVersionConstraint(mavenDependency.getVersion()))); } } }