List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:org.LexGrid.LexBIG.Impl.helpers.graph.GHolder.java
/** * Constructs a new container to hold concept graph representations. * /*from w w w . j a v a 2s .c o m*/ * @param internalCodingSchemeName * The coding scheme name for associated nodes; not null. * @param internalVersionString * The coding scheme version for associated nodes; not null. * @param focusNode * The starting point for resolved relations; null for absolute * root. * @param resolveForward * Whether relations are to be resolved in the forward direction. * @param resolveReverse * Whether relations are to be resolved in the reverse direction. */ public GHolder(String internalCodingSchemeName, String internalVersionString, ConceptReference focusNode, boolean resolveForward, boolean resolveReverse) { internalCodingSchemeName_ = internalCodingSchemeName; internalVersionString_ = internalVersionString; focusConceptReference_ = focusNode; resolveForward_ = resolveForward; resolveReverse_ = resolveReverse; allNodes_ = new Hashtable<String, GNode>(); allAssociations_ = new Hashtable<String, GAssociationInfo>(); if (focusConceptReference_ != null) focusConceptReference_.setCodingSchemeName(StringUtils .defaultIfEmpty(focusConceptReference_.getCodingSchemeName(), internalCodingSchemeName)); }
From source file:org.lfs.common.entity.FileSet.java
public void setSourceDir(String sourceDir) { this.sourceDir = StringUtils.defaultIfEmpty(sourceDir, this.DEFAULT_SOURCE_DIR); }
From source file:org.lfs.common.entity.FileSet.java
public void setDestDir(String destDir) { this.destDir = StringUtils.defaultIfEmpty(destDir, this.DEFAULT_DEST_DIR); }
From source file:org.linagora.linshare.core.service.impl.MailBuildingServiceImpl.java
private MailContainerWithRecipient buildMailContainer(MailConfig cfg, User sender, final MailContainerWithRecipient input, String pm, MailContentType type, MailContainerBuilder builder) throws BusinessException { Language lang = input.getLanguage(); MailContainerWithRecipient container = new MailContainerWithRecipient(input); MailContent mailContent = cfg.findContent(lang, type); String subject = StringUtils.defaultIfEmpty(formatSubject(input.getSubject(), lang), mailContent.getSubject());/* ww w . j ava 2 s . c o m*/ String greetings = mailContent.getGreetings(); String body = mailContent.getBody(); MailFooter f = cfg.findFooter(lang); String footer = formatFooter(cfg.findFooter(lang).getFooter(), lang); String layout = cfg.getMailLayoutHtml().getLayout(); pm = formatPersonalMessage(pm, lang); subject = builder.getSubjectChain().build(subject); greetings = builder.getGreetingsChain().build(greetings); body = builder.getBodyChain().build(body); footer = builder.getFooterChain().build(footer); layout = builder.getLayoutChain().add("image", displayLogo ? LINSHARE_LOGO : "").add("personalMessage", pm) .add("greetings", greetings).add("body", body).add("footer", footer).build(layout); container.setSubject(subject); container.setContentHTML(layout); container.setContentTXT(container.getContentHTML()); container.setInReplyTo(input.getInReplyTo()); container.setReferences(input.getReferences()); return container; }
From source file:org.localmatters.serializer.serialization.NameSerialization.java
/** * @see org.localmatters.serializer.serialization.Serialization#serialize(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.lang.Object, org.localmatters.serializer.SerializationContext) *///from w w w. j ava 2 s . com public void serialize(Serialization ser, String aName, Object object, SerializationContext ctx) throws SerializationException { getDelegate().serialize(ser, StringUtils.defaultIfEmpty(getName(), aName), object, ctx); }
From source file:org.localmatters.serializer.util.SerializationUtils.java
/** * Returns the singular value for the given term * @param term The term//w ww .j a v a 2 s .com * @param def The default value to return if no singular could be found * @return The singular value for this term or */ public static String getSingular(String term, String def) { String result = ""; String str = StringUtils.reverse(term); // first, lets clean the List or Map at the end Matcher m = COLLECTION_PATTERN.matcher(str); if (m.matches()) { str = m.group(1); result = StringUtils.reverse(str); } // then we look for plural m = PLURAL_PATTERN.matcher(str); if (m.matches()) { result = ""; result += StringUtils.defaultString(StringUtils.reverse(m.group(3))); if (m.group(2) != null) { if ("ei".equals(m.group(2))) { result += "y"; } else { result += StringUtils.reverse(m.group(2)); } } if (m.group(1) != null) { result += StringUtils.reverse(m.group(1)); } } return StringUtils.defaultIfEmpty(result, def); }
From source file:org.localmatters.serializer.writer.JSONWriter.java
/** * @see org.localmatters.serializer.writer.Writer#writeValue(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.lang.Object, org.localmatters.serializer.SerializationContext) *///w w w .ja v a 2s .co m public void writeValue(Serialization ser, String name, Object value, SerializationContext ctx) throws SerializationException { ctx.nextLevel(StringUtils.defaultIfEmpty(name, VALUE_LEVEL)); String prefix = getPrefix(ctx); String str = String.valueOf(value); if ((value != null) && StringUtils.isNotEmpty(str)) { write(ctx, prefix); if (StringUtils.isNotBlank(name)) { write(ctx, QUOTE_BYTES).write(ctx, name).write(ctx, QUOTE_COLUMN_BYTES); } if (ReflectionUtils.isNumeric(value.getClass()) || ReflectionUtils.isBoolean(value.getClass())) { write(ctx, str); } else { write(ctx, QUOTE_BYTES).write(ctx, EscapeUtils.escapeJson(str)).write(ctx, QUOTE_BYTES); } } else if (ser.isWriteEmpty()) { write(ctx, prefix); if (StringUtils.isNotBlank(name)) { write(ctx, QUOTE_BYTES).write(ctx, name).write(ctx, QUOTE_COLUMN_BYTES); } write(ctx, NULL_BYTES); } ctx.previousLevel(); }
From source file:org.localmatters.serializer.writer.JSONWriter.java
/** * @see org.localmatters.serializer.writer.Writer#writeComplex(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.lang.Object, java.util.Collection, java.util.Collection, java.util.Collection, org.localmatters.serializer.SerializationContext) *//*w w w. j av a2 s . co m*/ public void writeComplex(Serialization ser, String name, Object object, Collection<Serialization> attributes, Collection<Serialization> elements, Collection<String> comments, SerializationContext ctx) throws SerializationException { ctx.nextLevel(StringUtils.defaultIfEmpty(name, COMPLEX_LEVEL)); boolean empty = true; String prefix = getPrefix(ctx); if (CollectionUtils.isNotEmpty(attributes) || CollectionUtils.isNotEmpty(elements)) { if (StringUtils.isEmpty(name)) { ctx.pushPrefix(prefix + LEFT_CURLY); } else { ctx.pushPrefix(prefix + QUOTE + name + QUOTE_COLUMN_LEFT_CURLY); } byte[] sep = new byte[] {}; if (CollectionUtils.isNotEmpty(attributes)) { for (Serialization attribute : attributes) { ctx.pushPrefix(sep); attribute.serialize(attribute, null, object, ctx); if (ctx.consomePrefix() == null) { sep = COMMA_BYTES; } } } if (CollectionUtils.isNotEmpty(elements)) { for (Serialization element : elements) { ctx.pushPrefix(sep); element.serialize(element, null, object, ctx); if (ctx.consomePrefix() == null) { sep = COMMA_BYTES; } } } if (ctx.consomePrefix() == null) { write(ctx, prefix).write(ctx, RIGHT_CURLY_BYTES); empty = false; } } if (empty && ser.isWriteEmpty()) { write(ctx, prefix).write(ctx, QUOTE_BYTES).write(ctx, name).write(ctx, QUOTE_COLUMN_CLOSED_CURLY_BYTES); } ctx.previousLevel(); }
From source file:org.localmatters.serializer.writer.JSONWriter.java
/** * @see org.localmatters.serializer.writer.Writer#writeIterator(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.util.Iterator, java.lang.String, org.localmatters.serializer.serialization.Serialization, java.util.Collection, org.localmatters.serializer.SerializationContext) *///from w w w . j a va2s . c o m public void writeIterator(Serialization ser, String name, Iterator<?> itr, String elementName, Serialization element, Collection<String> comments, SerializationContext ctx) throws SerializationException { ctx.nextLevel(StringUtils.defaultIfEmpty(name, ITERATOR_LEVEL)); boolean empty = true; String prefix = getPrefix(ctx); if (itr.hasNext()) { if (StringUtils.isEmpty(name)) { ctx.pushPrefix(prefix + LEFT_SQUARE); } else { ctx.pushPrefix(prefix + QUOTE + name + QUOTE_COLUMN_LEFT_SQUARE); } byte[] sep = new byte[] {}; while (itr.hasNext()) { ctx.pushPrefix(sep); element.serialize(element, null, itr.next(), ctx); if (ctx.consomePrefix() == null) { sep = COMMA_BYTES; } } if (ctx.consomePrefix() == null) { write(ctx, prefix).write(ctx, RIGHT_SQUARE_BYTES); empty = false; } } if (empty && ser.isWriteEmpty()) { write(ctx, prefix).write(ctx, QUOTE_BYTES).write(ctx, name).write(ctx, QUOTE_COLUMN_CLOSED_SQUARE_BYTES); } ctx.previousLevel(); }
From source file:org.localmatters.serializer.writer.JSONWriter.java
/** * @see org.localmatters.serializer.writer.Writer#writeMap(org.localmatters.serializer.serialization.Serialization, java.lang.String, java.util.Collection, java.lang.String, org.localmatters.serializer.serialization.Serialization, java.util.Collection, org.localmatters.serializer.SerializationContext) */// w w w . jav a 2s . c o m @SuppressWarnings("rawtypes") public void writeMap(Serialization ser, String name, Collection<Map.Entry> entries, String key, Serialization value, Collection<String> comments, SerializationContext ctx) throws SerializationException { ctx.nextLevel(StringUtils.defaultIfEmpty(name, MAP_LEVEL)); boolean empty = true; String prefix = getPrefix(ctx); if (CollectionUtils.isNotEmpty(entries)) { if (StringUtils.isEmpty(name)) { ctx.pushPrefix(prefix + LEFT_CURLY); } else { ctx.pushPrefix(prefix + QUOTE + name + QUOTE_COLUMN_LEFT_CURLY); } byte[] sep = new byte[] {}; for (Map.Entry entry : entries) { ctx.pushPrefix(sep); value.serialize(value, resolvesMapKey(key, entry, ctx), entry.getValue(), ctx); if (ctx.consomePrefix() == null) { sep = COMMA_BYTES; } } if (ctx.consomePrefix() == null) { write(ctx, prefix).write(ctx, RIGHT_CURLY_BYTES); empty = false; } } if (empty && ser.isWriteEmpty()) { write(ctx, prefix).write(ctx, QUOTE_BYTES).write(ctx, name).write(ctx, QUOTE_COLUMN_CLOSED_CURLY_BYTES); } ctx.previousLevel(); }