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:net.sf.gazpachoquest.services.core.impl.ResearchServiceImpl.java
private MailMessage composeMailMessage(final MailMessageTemplate mailMessageTemplate, final User respondent, final String surveyLinkToken) { Map<String, Object> model = new HashMap<>(); model.put("lastname", StringUtils.defaultIfBlank(respondent.getSurname(), "")); model.put("firstname", StringUtils.defaultIfBlank(respondent.getGivenNames(), "")); model.put("gender", respondent.getGender()); model.put("link", "http://localhost:8080/questionaires-ui/token=" + surveyLinkToken); Language preferredLanguage = respondent.getPreferredLanguage(); StringBuilder templateLocation = new StringBuilder().append(mailMessageTemplate.getId()); if (preferredLanguage != null) { templateLocation.append("/"); templateLocation.append(preferredLanguage); }/* www.j av a 2s.com*/ VelocityEngine velocityEngine = velocityFactory.getObject(); String body = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateLocation.toString(), "UTF-8", model); MailMessageTemplateLanguageSettings languageSettings = mailMessageTemplate.getLanguageSettings(); if (preferredLanguage != null && !preferredLanguage.equals(mailMessageTemplate.getLanguage())) { MailMessageTemplateTranslation preferedTranslation = mailMessageTemplate.getTranslations() .get(preferredLanguage); if (preferedTranslation != null) { languageSettings = preferedTranslation.getLanguageSettings(); } } MailMessage mailMessage = MailMessage.with().subject(languageSettings.getSubject()) .to(respondent.getEmail()).replyTo(mailMessageTemplate.getReplyTo()) .from(mailMessageTemplate.getFromAddress()).text(body).build(); return mailMessage; }
From source file:com.sonicle.webtop.calendar.TplHelper.java
public static String buildTplResponseUpdateBody(Locale locale, String dateFormat, String timeFormat, Event event, 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("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("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 ww w . ja va 2s . c o m*/ evt.put("location", StringUtils.defaultIfBlank(event.getLocation(), null)); evt.put("locationUrl", TplHelper.buildGoogleMapsUrl(event.getLocation())); String viewUrl = CalendarManager.buildEventPublicUrl(servicePublicUrl, event.getPublicUid()); MapItem vars = new MapItem(); vars.put("i18n", i18n); vars.put("event", evt); vars.put("viewUrl", viewUrl); return WT.buildTemplate(SERVICE_ID, "tpl/email/responseUpdate-body.html", vars); }
From source file:net.eledge.android.europeana.gui.activity.RecordActivity.java
private void handleIntent(Intent intent) { String id = null;/* w ww.j av a2 s .c o m*/ if (intent != null) { if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present id = new String(msg.getRecords()[0].getPayload()); } else if (Intent.ACTION_VIEW.equals(intent.getAction())) { id = StringUtils.defaultIfBlank(intent.getDataString(), intent.getStringExtra(RECORD_ID)); } if (StringUtils.contains(id, "europeana.eu/")) { Uri uri = Uri.parse(id); List<String> paths = uri.getPathSegments(); if ((paths != null) && (paths.size() == 4)) { String collectionId = paths.get(paths.size() - 2); String recordId = StringUtils.removeEnd(paths.get(paths.size() - 1), ".html"); id = StringUtils.join("/", collectionId, "/", recordId); } else { // invalid url/id, cancel opening record id = null; } } if (StringUtils.isNotBlank(id)) { openRecord(id); } } }
From source file:net.canadensys.dataportal.occurrence.controller.OccurrenceController.java
/** * Build and fill A OccurrenceViewModel based on a OccurrenceModel. * // w ww . j a v a2 s.c om * @param occModel * @return OccurrenceViewModel instance, never null */ public OccurrenceViewModel buildOccurrenceViewModel(OccurrenceModel occModel, DwcaResourceModel resourceModel, List<OccurrenceExtensionModel> occMultimediaExtModelList, Locale locale) { OccurrenceViewModel occViewModel = new OccurrenceViewModel(); ResourceBundle bundle = appConfig.getResourceBundle(locale); // handle multimedia first (priority over associatedmedia) if (occMultimediaExtModelList != null) { String multimediaFormat, multimediaLicense, multimediaReference, multimediaIdentifier, licenseShortname; boolean isImage; MultimediaViewModel multimediaViewModel; Map<String, String> extData; for (OccurrenceExtensionModel currMultimediaExt : occMultimediaExtModelList) { extData = currMultimediaExt.getExt_data(); multimediaFormat = StringUtils.defaultString(extData.get("format")); multimediaLicense = StringUtils.defaultString(extData.get("license")); multimediaIdentifier = extData.get("identifier"); // if reference is blank, use the identifier multimediaReference = StringUtils.defaultIfBlank(extData.get("references"), multimediaIdentifier); // check if it's an image isImage = multimediaFormat.startsWith("image"); licenseShortname = appConfig.getLicenseShortName(multimediaLicense); multimediaViewModel = new MultimediaViewModel(multimediaIdentifier, multimediaReference, extData.get("title"), multimediaLicense, extData.get("creator"), isImage, licenseShortname); occViewModel.addMultimediaViewModel(multimediaViewModel); } } // handle media (only if occMultimediaExtModelList was not provided) if ((occMultimediaExtModelList == null || occMultimediaExtModelList.isEmpty()) && StringUtils.isNotEmpty(occModel.getAssociatedmedia())) { // assumes that data are coming from harvester String[] media = occModel.getAssociatedmedia().split("; "); MultimediaViewModel multimediaViewModel; boolean isImage; String title; int imageNumber = 1, otherMediaNumber = 1; for (String currentMedia : media) { isImage = MIME_TYPE_MAP.getContentType(currentMedia).startsWith("image"); String image = bundle.getString("occ.image"); if (isImage) { title = image + " " + imageNumber; imageNumber++; } else { title = bundle.getString("occ.associatedmedia") + " " + otherMediaNumber; otherMediaNumber++; } multimediaViewModel = new MultimediaViewModel(currentMedia, currentMedia, title, null, null, isImage, null); occViewModel.addMultimediaViewModel(multimediaViewModel); } } // handle associated sequences handleAssociatedSequence(occModel, occViewModel); // handle data source page URL (url to the resource page) if (resourceModel != null) { if (StringUtils.contains(resourceModel.getArchive_url(), IPT_ARCHIVE_PATTERN)) { occViewModel.setDataSourcePageURL(StringUtils.replace(resourceModel.getArchive_url(), IPT_ARCHIVE_PATTERN, IPT_RESOURCE_PATTERN)); } } // handle Recommended Citation String datasourcePageUrl = occViewModel.getDataSourcePageURL(); if (datasourcePageUrl != null) occViewModel.setRecommendedCitation( Formatter.buildRecommendedCitation(occModel, datasourcePageUrl, bundle)); return occViewModel; }
From source file:ca.on.oicr.pde.deciders.GenomicAlignmentNovoalignDecider.java
@Override protected boolean checkFileDetails(ReturnValue returnValue, FileMetadata fm) { Log.debug("CHECK FILE DETAILS:" + fm); if (this.options.has("template-type")) { if (!returnValue.getAttribute(Header.SAMPLE_TAG_PREFIX.getTitle() + "geo_library_source_template_type") .equals(this.options.valueOf("template-type"))) { return false; }//from ww w . jav a 2 s . c o m } //Get additional metadata if (null != this.ius_accession) { this.ius_accession = this.ius_accession + "," + returnValue.getAttribute(Header.IUS_SWA.getTitle()); } else { this.ius_accession = returnValue.getAttribute(Header.IUS_SWA.getTitle()); } if (null != this.sequencer_run_name) { this.sequencer_run_name = this.sequencer_run_name + "," + returnValue.getAttribute(Header.SEQUENCER_RUN_NAME.getTitle()); } else { this.sequencer_run_name = returnValue.getAttribute(Header.SEQUENCER_RUN_NAME.getTitle()); } if (null != this.lane) { this.lane = this.lane + "," + returnValue.getAttribute(Header.LANE_NUM.getTitle()); } else { this.lane = returnValue.getAttribute(Header.LANE_NUM.getTitle()); } FileAttributes rv = new FileAttributes(returnValue, returnValue.getFiles().get(0)); String groupId = StringUtils.defaultIfBlank(rv.getLimsValue(Lims.GROUP_ID), ""); this.rg_library = rv.getLibrarySample() + groupId; this.rg_platform = "illumina"; this.rg_sample_name = rv.getDonor() + groupId; return super.checkFileDetails(returnValue, fm); }
From source file:com.sonicle.webtop.calendar.TplHelper.java
public static String buildTplEventReminderBody(Locale locale, String dateFormat, String timeFormat, Event event) 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)); 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("location", StringUtils.defaultIfBlank(event.getLocation(), null)); evt.put("locationUrl", TplHelper.buildGoogleMapsUrl(event.getLocation())); evt.put("organizer", StringUtils.defaultIfBlank(event.getOrganizerCN(), event.getOrganizerAddress())); MapItemList evtAtts = new MapItemList(); for (EventAttendee attendee : event.getAttendees()) { MapItem item = new MapItem(); String cn = attendee.getCN(); String address = attendee.getAddress(); item.put("cn", StringUtils.isBlank(cn) ? null : cn); item.put("address", StringUtils.isBlank(address) ? null : address); evtAtts.add(item);//from ww w .j ava 2 s .c o m } MapItem vars = new MapItem(); vars.put("i18n", i18n); vars.put("event", evt); vars.put("eventAttendees", evtAtts); return WT.buildTemplate(SERVICE_ID, "tpl/email/eventInvitation-body.html", vars); }
From source file:net.sf.jsignpdf.BasicSignerOptions.java
/** * Returns output file name if filled or input file name with default output * suffix ("_signed")// w w w.j a v a2 s . co m * * @return */ public String getOutFileX() { String tmpOut = StringUtils.defaultIfBlank(outFile, null); if (tmpOut == null) { String tmpExtension = ""; String tmpNameBase = StringUtils.defaultIfBlank(getInFile(), null); if (tmpNameBase == null) { tmpOut = "signed.pdf"; } else { if (tmpNameBase.toLowerCase().endsWith(".pdf")) { final int tmpBaseLen = tmpNameBase.length() - 4; tmpExtension = tmpNameBase.substring(tmpBaseLen); tmpNameBase = tmpNameBase.substring(0, tmpBaseLen); } tmpOut = tmpNameBase + Constants.DEFAULT_OUT_SUFFIX + tmpExtension; } } return tmpOut; }
From source file:com.ericsson.eiffel.remrem.semantics.SemanticsService.java
@Override public String generateRoutingKey(JsonObject eiffelMessage, String tag, String domain, String userDomainSuffix) { String family = getFamily(eiffelMessage); String type = getType(eiffelMessage); if (StringUtils.isNotEmpty(family) && StringUtils.isNotEmpty(type)) { if (StringUtils.isNotBlank(tag) && (tag.contains(".") || StringUtils.deleteWhitespace(tag).length() > 16)) { log.error("tag must not contain any dots and must not exceed 16 characters"); return null; }/*from w w w.j ava 2s .co m*/ String domainId = getDomainId(eiffelMessage); // If domainId from input message is null then configured domain // will be considered domainId = StringUtils.defaultIfBlank(domainId, domain); if (StringUtils.isNotBlank(domainId)) { if (StringUtils.isNotBlank(userDomainSuffix)) { domainId = domainId + DOT + userDomainSuffix; } return StringUtils.deleteWhitespace(PROTOCOL + DOT + family + DOT + type + DOT + StringUtils.defaultIfBlank(tag, "notag") + DOT + domainId); } log.error( "domain needed for Routing key generation in the format <protocol>.<family>.<type>.<tag>.<domain> is not provided in either input message or configuration"); } return null; }
From source file:chat.viska.xmpp.HandshakerPipe.java
private void consumeResourceBinding(final Document document) { if (!resourceBindingIqId.equals(document.getDocumentElement().getAttribute("id"))) { sendStreamError(new StreamErrorException(StreamErrorException.Condition.NOT_AUTHORIZED)); } else if ("error".equals(document.getDocumentElement().getAttribute("type"))) { try {//w ww .j ava 2 s . co m handshakeResult.onError(StanzaErrorException.fromXml(document)); } catch (StreamErrorException ex) { sendStreamError(ex); } } else if ("result".equals(document.getDocumentElement().getAttribute("type"))) { final Optional<Element> bindElement = DomUtils .convertToList(document.getDocumentElement().getChildNodes()).stream() .filter(it -> "bind".equals(it.getLocalName())) .filter(it -> CommonXmlns.RESOURCE_BINDING.equals(it.getNamespaceURI())).map(it -> (Element) it) .findFirst(); if (!bindElement.isPresent()) { sendStreamError( new StreamErrorException(StreamErrorException.Condition.INVALID_XML, "Empty result.")); return; } final String[] results = DomUtils.convertToList(bindElement.get().getChildNodes()).stream() .map(it -> (Element) it).filter(it -> "jid".equals(it.getLocalName())) .filter(it -> CommonXmlns.RESOURCE_BINDING.equals(it.getNamespaceURI())) .map(it -> StringUtils.defaultIfBlank(it.getTextContent(), "").split(" ")).findFirst() .orElse(new String[0]); switch (results.length) { case 1: this.negotiatedJid = new Jid(results[0]); break; case 2: if (new Jid(results[0]).equals(this.loginJid)) { this.negotiatedJid = new Jid(this.loginJid.getLocalPart(), this.loginJid.getDomainPart(), results[1]); } else { sendStreamError(new StreamErrorException(StreamErrorException.Condition.INVALID_XML, "Resource Binding result contains incorrect JID.")); } break; default: sendStreamError(new StreamErrorException(StreamErrorException.Condition.INVALID_XML, "Malformed JID syntax.")); break; } } if (!this.negotiatedJid.isEmpty()) { if (this.negotiatedFeatures.add(this.negotiatingFeature)) { this.eventStream.onNext(new FeatureNegotiatedEvent(this, StreamFeature.RESOURCE_BINDING)); } this.negotiatingFeature = null; } }
From source file:com.pidoco.juri.JURI.java
/** * @return true if a path is set: http://a.com/ : true, http://a.com : false. *///from www . ja va 2 s . co m public boolean isHavingPath() { String rawPath = StringUtils.defaultIfBlank(getRawPath(), ""); return rawPath.length() > 0; }