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:jp.co.tis.gsp.tools.dba.dialect.Dialect.java
/** * load-data???????????/*from w w w. j a v a 2 s . c om*/ * * @param resultSet * @param columnIndex * @param columnLabel * @param sqlType * @return * @throws SQLException */ public String convertLoadData(ResultSet resultSet, int columnIndex, String columnLabel, int sqlType) throws SQLException { String value = resultSet.getString(columnLabel); // null to blank. value = StringUtils.defaultIfEmpty(value, ""); return value; }
From source file:com.eviware.soapui.support.components.SimpleForm.java
public JButton appendButton(String label, String tooltip) { JButton button = new JButton(); button.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null)); button.getAccessibleContext().setAccessibleDescription(tooltip); append(label, button);//from w ww. j a v a2 s. c o m return button; }
From source file:com.cyberway.issue.crawler.extractor.JerichoExtractorHTML.java
protected void processForm(CrawlURI curi, Element element) { String action = element.getAttributeValue("action"); String name = element.getAttributeValue("name"); String queryURL = ""; final boolean ignoreFormActions = ((Boolean) getUncheckedAttribute(curi, ATTR_IGNORE_FORM_ACTION_URLS)) .booleanValue();// w ww. ja va2s . co m if (ignoreFormActions) { return; } // method-sensitive extraction String method = StringUtils.defaultIfEmpty(element.getAttributeValue("method"), "GET"); if (((Boolean) getUncheckedAttribute(curi, ATTR_EXTRACT_ONLY_FORM_GETS)).booleanValue() && !"GET".equalsIgnoreCase(method)) { return; } numberOfFormsProcessed++; // get all form fields FormFields formFields = element.findFormFields(); for (Iterator fieldsIter = formFields.iterator(); fieldsIter.hasNext();) { // for each form field FormField formField = (FormField) fieldsIter.next(); // for each form control for (Iterator controlIter = formField.getFormControls().iterator(); controlIter.hasNext();) { FormControl formControl = (FormControl) controlIter.next(); // get name of control element (and URLEncode it) String controlName = formControl.getName(); // retrieve list of values - submit needs special handling Collection controlValues; if (!(formControl.getFormControlType() == FormControlType.SUBMIT)) { controlValues = formControl.getValues(); } else { controlValues = formControl.getPredefinedValues(); } if (controlValues.size() > 0) { // for each value set for (Iterator valueIter = controlValues.iterator(); valueIter.hasNext();) { String value = (String) valueIter.next(); queryURL += "&" + controlName + "=" + value; } } else { queryURL += "&" + controlName + "="; } } } // clean up url if (action == null) { queryURL = queryURL.replaceFirst("&", "?"); } else { if (!action.contains("?")) queryURL = queryURL.replaceFirst("&", "?"); queryURL = action + queryURL; } CharSequence context = Link.elementContext(element.getName(), "name=" + name); processLink(curi, queryURL, context); }
From source file:com.smartitengineering.cms.ws.resources.content.FieldResource.java
protected Collection<Entry> getEntries(final FieldValue value, final Date lastModifiedDate, String... id) throws IllegalArgumentException { final List<Entry> entries = new ArrayList<Entry>(); final String mimeType = getFieldValueDefaultMimeType(fieldDef.getValueDef()).toString(); switch (fieldDef.getValueDef().getType()) { case BOOLEAN: BooleanFieldValue booleanFieldValue = (BooleanFieldValue) value; Entry entry = getEntry("value", "Value", lastModifiedDate); entry.setContent(Boolean.toString(booleanFieldValue.getValue()), mimeType); entries.add(entry);//from w w w . j av a2s. com break; case COLLECTION: CollectionFieldValue collectionFieldValue = (CollectionFieldValue) value; int index = 0; for (FieldValue fieldValue : collectionFieldValue.getValue()) { entries.addAll(getEntries(fieldValue, lastModifiedDate, new StringBuilder("value-").append(index++).toString())); } break; case CONTENT: ContentFieldValue contentFieldValue = (ContentFieldValue) value; entry = getEntry(StringUtils.defaultIfEmpty(id[0], "value"), "Value", lastModifiedDate, getLink(ContentResource.getContentUri(getRelativeURIBuilder(), contentFieldValue.getValue()), Link.REL_ALTERNATE, mimeType)); entries.add(entry); break; case DATE_TIME: DateTimeFieldValue dateTimeFieldValue = (DateTimeFieldValue) value; entry = getEntry("value", "Value", lastModifiedDate); entry.setContent(Utils.getFormattedDate(dateTimeFieldValue.getValue()), mimeType); entries.add(entry); break; case DOUBLE: case INTEGER: case LONG: NumberFieldValue numberFieldValue = (NumberFieldValue) value; entry = getEntry("value", "Value", lastModifiedDate); entry.setContent(numberFieldValue.getValue().toString(), mimeType); entries.add(entry); break; case STRING: case OTHER: OtherDataType otherDataType = (OtherDataType) fieldDef.getValueDef(); entry = getEntry("value", "Value", lastModifiedDate); entry.setContent(String.valueOf(value), mimeType); entries.add(entry); break; } return entries; }
From source file:de.csdev.ebus.cfg.std.EBusConfigurationReader.java
/** * @param template// w ww. j a v a 2 s. co m * @param templateMap * @param commandMethod * @return * @throws EBusConfigurationReaderException */ protected Collection<EBusCommandValue> parseValueConfiguration(EBusValueDTO template, Map<String, EBusCommandValue> templateMap, EBusCommandMethod commandMethod) throws EBusConfigurationReaderException { Collection<EBusCommandValue> result = new ArrayList<EBusCommandValue>(); String typeStr = template.getType(); String collectionId = null; // check if really set if (commandMethod != null && commandMethod.getParent() != null && commandMethod.getParent().getParentCollection() != null) { collectionId = commandMethod.getParent().getParentCollection().getId(); } if (typeStr.equals("template-block")) { Collection<EBusCommandValue> templateCollection = null; if (StringUtils.isNotEmpty(template.getName())) { logger.warn("Property 'name' is not allowed for type 'template-block', ignore property !"); } // use the global or local id as template block, new with alpha 15 String id = (String) template.getProperty("id"); String globalId = collectionId + "." + id; if (StringUtils.isNotEmpty(id)) { templateCollection = templateBlockRegistry.get(id); if (templateCollection == null) { // try to convert the local id to a global id logger.trace("Unable to find a template with id {}, second try with {} ...", id, globalId); templateCollection = templateBlockRegistry.get(globalId); if (templateCollection == null) { throw new EBusConfigurationReaderException("Unable to find a template-block with id {0}!", id); } } } else if (templateMap != null) { // return the complete template block from within command block templateCollection = templateMap.values(); } else { throw new EBusConfigurationReaderException( "No additional information for type 'template-block' defined!"); } if (templateCollection != null) { for (EBusCommandValue commandValue : templateCollection) { // clone the original value EBusCommandValue clone = commandValue.clone(); clone.setParent(commandMethod); overwritePropertiesFromTemplate(clone, template); result.add(clone); } } return result; } else if (typeStr.equals("template")) { String id = (String) template.getProperty("id"); String globalId = collectionId + "." + id; Collection<EBusCommandValue> templateCollection = null; if (StringUtils.isEmpty(id)) { throw new EBusConfigurationReaderException( "No additional information for type 'template' defined!"); } if (templateValueRegistry.containsKey(id)) { templateCollection = templateValueRegistry.get(id); } else if (templateValueRegistry.containsKey(globalId)) { templateCollection = templateValueRegistry.get(globalId); } else if (templateMap != null && templateMap.containsKey(id)) { // return the complete template block from within command block templateCollection = new ArrayList<EBusCommandValue>(); templateCollection.add(templateMap.get(id)); } else { throw new EBusConfigurationReaderException("Unable to find a template for id {0}!", id); } if (templateCollection != null && !templateCollection.isEmpty()) { for (EBusCommandValue commandValue : templateCollection) { EBusCommandValue clone = commandValue.clone(); clone.setParent(commandMethod); overwritePropertiesFromTemplate(clone, template); // allow owerwrite for single names clone.setName(StringUtils.defaultIfEmpty(template.getName(), clone.getName())); result.add(clone); } } else { throw new EBusConfigurationReaderException("Internal template collection is empty!"); } return result; } else if (typeStr.equals("static")) { // convert static content to bytes byte[] byteArray = EBusUtils.toByteArray(template.getDefault()); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("length", byteArray.length); final IEBusType<?> typeByte = registry.getType(EBusTypeBytes.TYPE_BYTES, properties); EBusCommandValue commandValue = EBusCommandValue.getInstance(typeByte, byteArray); commandValue.setParent(commandMethod); result.add(commandValue); return result; } EBusCommandValue ev = null; // value is a nested value if (template.getChildren() != null) { EBusCommandNestedValue evc = new EBusCommandNestedValue(); ev = evc; int pos = 0; for (EBusValueDTO childElem : template.getChildren()) { // add pos information from list childElem.setPos(pos); // parse child value for (EBusCommandValue childValue : parseValueConfiguration(childElem, templateMap, commandMethod)) { evc.add(childValue); } pos++; } } else { // default value ev = new EBusCommandValue(); } Map<String, Object> map = template.getAsMap(); IEBusType<?> type = registry.getType(typeStr, map); ev.setType(type); ev.setName(template.getName()); ev.setLabel(template.getLabel()); ev.setFactor(template.getFactor()); ev.setMin(template.getMin()); ev.setMax(template.getMax()); ev.setMapping(template.getMapping()); ev.setFormat(template.getFormat()); ev.setParent(commandMethod); result.add(ev); return result; }
From source file:com.thinkbiganalytics.spark.datavalidator.Validator.java
protected String toSelectFields(FieldPolicy[] policies1) { List<String> fields = new ArrayList<>(); log.info("Building select statement for # of policies {}", policies1.length); for (int i = 0; i < policies1.length; i++) { if (policies1[i].getField() != null) { log.info("policy [{}] name {} feedName {}", i, policies1[i].getField(), policies1[i].getFeedField()); String feedField = StringUtils.defaultIfEmpty(policies1[i].getFeedField(), policies1[i].getField()); fields.add("`" + feedField + "` as `" + policies1[i].getField() + "`"); }/*w w w .j av a 2s.co m*/ } fields.add("`processing_dttm`"); return StringUtils.join(fields.toArray(new String[0]), ","); }
From source file:com.eviware.soapui.support.components.SimpleForm.java
public JPasswordField appendPasswordField(String label, String tooltip) { JPasswordField textField = new JPasswordField(); textField.setColumns(defaultTextFieldColumns); textField.setToolTipText(StringUtils.defaultIfEmpty(tooltip, null)); textField.getAccessibleContext().setAccessibleDescription(tooltip); append(label, textField);/*from ww w . j a va 2 s. c om*/ return textField; }
From source file:com.adobe.acs.commons.replication.status.impl.JcrPackageReplicationStatusEventHandler.java
/** * Extracts relevant event information from a Granite Replication Event OR a Day CQ Replication event. * @param event the Osgi Event// w w w. ja v a2 s. c o m * @return a Map containing the relevant data points. */ protected final Map<String, Object> getInfoFromEvent(Event event) { final Map<String, Object> eventConfig = new HashMap<>(); final ReplicationEvent replicationEvent = ReplicationEvent.fromEvent(event); if (replicationEvent != null) { // Granite event final ReplicationAction replicationAction = replicationEvent.getReplicationAction(); eventConfig.put(PROPERTY_PATHS, replicationAction.getPaths()); eventConfig.put(PROPERTY_REPLICATED_BY, replicationAction.getUserId()); } else { // CQ event String[] paths = (String[]) event.getProperty(ReplicationAction.PROPERTY_PATHS); if (paths == null) { paths = ArrayUtils.EMPTY_STRING_ARRAY; } String userId = (String) event.getProperty(ReplicationAction.PROPERTY_USER_ID); if (StringUtils.isBlank(userId)) { userId = StringUtils.defaultIfEmpty(this.replicatedByOverride, FALLBACK_REPLICATION_USER_ID); } eventConfig.put(PROPERTY_PATHS, paths); eventConfig.put(PROPERTY_REPLICATED_BY, userId); } return eventConfig; }
From source file:com.ning.killbill.zuora.zuora.ZuoraApi.java
private String getFirstName(com.ning.billing.account.api.Account account) { final Integer firstNameLength = Objects.firstNonNull(account.getFirstNameLength(), 0); return StringUtils.defaultIfEmpty(StringUtils.substring(account.getName(), 0, firstNameLength), ""); }
From source file:com.funambol.LDAP.admin.LDAPSyncSourceConfigPanel.java
/** * Load the current syncSource showing the name, uri and type in the panel's * fields.//from ww w. j ava 2 s . c om */ public void updateForm() { if (!(getSyncSource() instanceof LDAPContactsSyncSource)) { notifyError(new AdminException("This is not an " + LDAPContactsSyncSource.class.getName() + " Unable to process SyncSource values (" + getSyncSource() + ").")); return; } LDAPContactsSyncSource syncSource = (LDAPContactsSyncSource) getSyncSource(); if (getState() == STATE_INSERT) { confirmButton.setText("Add"); } else if (getState() == STATE_UPDATE) { confirmButton.setText("Save"); } syncSource.setInfo(new SyncSourceInfo(supportedTypes, typeValue.getSelectedIndex())); sourceUriValue.setText(syncSource.getSourceURI()); nameValue.setText(syncSource.getName()); typeValue.setSelectedIndex(syncSource.getInfo().getPreferred()); if (syncSource.getServerTimeZone() != null) { timeZoneValue.setSelectedItem(syncSource.getServerTimeZone().getID()); } else { timeZoneValue.setSelectedItem(TimeZone.getDefault().getID()); } daoNameValue.setSelectedItem(syncSource.getDaoName()); followReferralValue.setSelected(syncSource.isFollowReferral()); connectionPoolingValue.setSelected(syncSource.isConnectionPooling()); providerUrlValue.setText(syncSource.getProviderUrl()); // bindAsUserValue.setSelected(syncSource.getBindAsUser()); ldapBaseValue.setText(syncSource.getLdapBase()); entryFilterValue.setText(syncSource.getEntryFilter()); ldapUserValue.setText(syncSource.getLdapUser()); ldapPassValue.setText(syncSource.getLdapPass()); dbNameValue.setText(StringUtils.defaultIfEmpty(syncSource.getDbName(), "fnblds")); if (syncSource.getSourceURI() != null) { sourceUriValue.setEditable(false); } ldapServerValue.setSelectedItem(syncSource.getLdapInterfaceClassName()); }