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:com.gst.infrastructure.configuration.domain.ExternalServicesProperties.java
public Map<String, Object> update(final JsonCommand command, String paramName) { final Map<String, Object> actualChanges = new LinkedHashMap<>(2); final String valueParamName = EXTERNALSERVICEPROPERTIES_JSON_INPUT_PARAMS.VALUE.getValue(); if (command.isChangeInStringParameterNamed(paramName, this.value)) { final String newValue = command.stringValueOfParameterNamed(paramName); if (paramName.equals(SMTP_JSON_INPUT_PARAMS.PASSWORD.getValue()) && newValue.equals("XXXX")) { // If Param Name is Password and ParamValue is XXXX that means // the password has not been changed. } else {//from ww w.j a va2 s . co m actualChanges.put(valueParamName, newValue); } this.value = StringUtils.defaultIfEmpty(newValue, null); } return actualChanges; }
From source file:com.gst.accounting.glaccount.domain.GLAccount.java
private GLAccount(final GLAccount parent, final String name, final String glCode, final boolean disabled, final boolean manualEntriesAllowed, final Integer type, final Integer usage, final String description, final CodeValue tagId) { this.name = StringUtils.defaultIfEmpty(name, null); this.glCode = StringUtils.defaultIfEmpty(glCode, null); this.disabled = BooleanUtils.toBooleanDefaultIfNull(disabled, false); this.manualEntriesAllowed = BooleanUtils.toBooleanDefaultIfNull(manualEntriesAllowed, true); this.usage = usage; this.type = type; this.description = StringUtils.defaultIfEmpty(description, null); this.parent = parent; this.tagId = tagId; }
From source file:com.cognifide.slice.persistence.impl.serializer.RecursiveSerializer.java
private String retrievePropertyName(Field field) { final JcrProperty jcrPropAnnotation = field.getAnnotation(JcrProperty.class); final String overridingPropertyName = jcrPropAnnotation.value(); final String fieldName = field.getName(); return StringUtils.defaultIfEmpty(overridingPropertyName, fieldName); }
From source file:com.widen.valet.Route53Driver.java
/** * Submit ordered list of commands to Route53. * * @param zone//from w w w .j ava 2s .c om * @param comment * @param updateActions * @return * @thorws * ValetException if Route53 rejects the transaction block */ public ZoneChangeStatus updateZone(final Zone zone, final String comment, final List<ZoneUpdateAction> updateActions) { if (updateActions.isEmpty()) { return new ZoneChangeStatus(zone.getExistentZoneId(), "no-change-submitted", ZoneChangeStatus.Status.INSYNC, new Date()); } String commentXml = StringUtils.defaultIfEmpty(comment, String.format("Modify %s records.", updateActions.size())); XMLTag xml = XMLDoc.newDocument(false).addDefaultNamespace(ROUTE53_XML_NAMESPACE) .addRoot("ChangeResourceRecordSetsRequest").addTag("ChangeBatch").addTag("Comment") .addText(commentXml).addTag("Changes"); String ns = xml.getPefix(ROUTE53_XML_NAMESPACE); for (ZoneUpdateAction updateAction : updateActions) { updateAction.addChangeTag(xml); xml.gotoTag("//%s:Changes", ns); } String payload = xml.toString(); log.trace("Update Zone Post Payload:\n{}", payload); String responseText = pilot.executeResourceRecordSetsPost(zone.getExistentZoneId(), payload); XMLTag result = XMLDoc.from(responseText, true); log.trace("Update Zone Response:\n{}", result); if (result.hasTag("Error")) { throw parseErrorResponse(result); } return parseChangeResourceRecordSetsResponse(zone.getExistentZoneId(), result); }
From source file:esun.org.apache.flume.plugins.KafkaSink.java
/** * Process status.//from ww w . ja va 2 s.c om * * @return the status * @throws EventDeliveryException * the event delivery exception */ @Override public Status process() throws EventDeliveryException { Status status = null; // Start transaction Channel ch = getChannel(); Transaction txn = ch.getTransaction(); txn.begin(); try { // This try clause includes whatever Channel operations you want to do Event event = ch.take(); String partitionKey = (String) parameters.get(KafkaFlumeConstans.PARTITION_KEY_NAME); String encoding = StringUtils.defaultIfEmpty( (String) this.parameters.get(KafkaFlumeConstans.ENCODING_KEY_NAME), KafkaFlumeConstans.DEFAULT_ENCODING); String topic = Preconditions.checkNotNull( (String) this.parameters.get(KafkaFlumeConstans.CUSTOME_TOPIC_KEY_NAME), "custom.topic.name is required"); String eventData = new String(event.getBody(), encoding); String includeHeader = this.parameters.getProperty(KafkaFlumeConstans.INCLUDE_HEADER, "true"); if ("true".equals(includeHeader)) { String header = ""; Map<String, String> headerMap = event.getHeaders(); if (headerMap != null) { for (Map.Entry<String, String> entry : headerMap.entrySet()) { header += String.format("%s:%s,", entry.getKey(), entry.getValue()); } header = header.substring(0, Math.max(0, header.length() - 1)); } eventData = String.format("%s<fh[%s]>", eventData, header); } KeyedMessage<String, String> data; // if partition key does'nt exist if (StringUtils.isEmpty(partitionKey)) { data = new KeyedMessage<String, String>(topic, eventData); } else { data = new KeyedMessage<String, String>(topic, partitionKey, eventData); } if (LOGGER.isInfoEnabled()) { LOGGER.info( "Send Message to Kafka : [" + eventData + "] -- [" + EventHelper.dumpEvent(event) + "]"); } producer.send(data); txn.commit(); status = Status.READY; } catch (Throwable t) { txn.rollback(); status = Status.BACKOFF; // re-throw all Errors if (t instanceof Error) { throw (Error) t; } } finally { txn.close(); } return status; }
From source file:elaborate.editor.publish.SearchConfig.java
private String fieldOf(String level) { return StringUtils.defaultIfEmpty(level, ""); }
From source file:com.gst.accounting.rule.domain.AccountingRule.java
private AccountingRule(final Office office, final GLAccount accountToDebit, final GLAccount accountToCredit, final String name, final String description, final boolean systemDefined, final boolean allowMultipleCreditEntries, final boolean allowMultipleDebitEntries) { this.accountToDebit = accountToDebit; this.accountToCredit = accountToCredit; this.name = name; this.office = office; this.description = StringUtils.defaultIfEmpty(description, null); if (this.description != null) { this.description = this.description.trim(); }//from w w w . java 2 s. c o m this.systemDefined = systemDefined; this.allowMultipleCreditEntries = allowMultipleCreditEntries; this.allowMultipleDebitEntries = allowMultipleDebitEntries; }
From source file:info.magnolia.importexport.PropertiesImportExport.java
public void createContent(Content root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream);/*www .j a v a 2s .c o m*/ properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, ItemType.CONTENTNODE.getSystemName()); Content c = ContentUtil.createPath(root, path, new ItemType(type)); populateContent(c, propertyName, valueStr); } }
From source file:com.baidu.cc.web.filter.LoginFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; String path = request.getServletPath(); if (request.getParameter("method") != null) { path = path + "?method=" + request.getParameter("method"); }//from ww w .ja va 2 s .c om // exclude path ??? if (UrlUtils.urlMatch(excludePathv, path)) { filterChain.doFilter(request, response); return; } CookieHelper cookieHelper = new CookieHelper(request, response); Long uid = NumberUtils.toLong(cookieHelper.getCookieVal("rcc_uid")); String name = cookieHelper.getCookieVal("rcc_name"); String token = cookieHelper.getCookieVal("rcc_token"); if (uid > 0L && StringUtils.isNotEmpty(name) && SysUtils.genCookieToken(uid, name).equals(token)) { ThreadLocalInfo.setThreadUuid(uid.toString()); User user = new User(); user.setId(uid); user.setName(name); SysUtils.addLoginCookie(request, response, user); filterChain.doFilter(request, response); } else { response.sendRedirect(StringUtils.defaultIfEmpty(request.getContextPath(), "/")); } }
From source file:com.adobe.acs.commons.replication.status.impl.ReplicatedByWorkflowProcess.java
@Override public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException { final WorkflowData workflowData = workItem.getWorkflowData(); final String type = workflowData.getPayloadType(); // Check if the payload is a path in the JCR if (!StringUtils.equals(type, "JCR_PATH")) { return;//from w w w . j a va2s . co m } // Get the path to the JCR resource from the payload final String payloadPath = workflowData.getPayload().toString(); // Get ResourceResolver final Map<String, Object> authInfo = new HashMap<String, Object>(); authInfo.put(AUTHENTICATION_INFO_SESSION, workflowSession.getSession()); final ResourceResolver resourceResolver; try { resourceResolver = resourceResolverFactory.getResourceResolver(authInfo); // Get replicated by value final String replicatedBy = StringUtils.defaultIfEmpty(workItem.getWorkflow().getInitiator(), "Unknown Workflow User"); final List<String> paths = workflowPackageManager.getPaths(resourceResolver, payloadPath); for (final String path : paths) { // For each item in the WF Package, or if not a WF Package, path = payloadPath Resource resource = replStatusManager.getReplicationStatusResource(path, resourceResolver); final ModifiableValueMap mvm = resource.adaptTo(ModifiableValueMap.class); if (StringUtils .isNotBlank(mvm.get(ReplicationStatus.NODE_PROPERTY_LAST_REPLICATED_BY, String.class))) { mvm.put(ReplicationStatus.NODE_PROPERTY_LAST_REPLICATED_BY, replicatedBy); resourceResolver.commit(); log.trace("Set replicateBy to [ {} ] on resource [ {} ]", replicatedBy, resource.getPath()); } else { log.trace("Skipping; Resource does not have replicateBy property set [ {} ]", resource.getPath()); } } } catch (LoginException e) { log.error("Could not acquire a ResourceResolver object from the Workflow Session's JCR Session: {}", e); } catch (PersistenceException e) { log.error("Could not save replicateBy property for payload [ {} ] due to: {}", payloadPath, e); } catch (RepositoryException e) { log.error("Could not collect Workflow Package items for payload [ {} ] due to: {}", payloadPath, e); } }