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.OracleDialect.java
/** * Oracle?DateTimestamp??getString()?????load-data??? <br /> * ??????????//ww w. j av a 2 s . c o m */ @Override public String convertLoadData(ResultSet resultSet, int columnIndex, String columnLabel, int sqlType) throws SQLException { String value = null; switch (sqlType) { case Types.DATE: Date date = resultSet.getDate(columnLabel); if (date != null) { value = sdfDate.format(date); } break; default: value = super.convertLoadData(resultSet, columnIndex, columnLabel, sqlType); break; } // null to blank. value = StringUtils.defaultIfEmpty(value, ""); return value; }
From source file:com.healthcit.cacure.businessdelegates.GeneratedModuleDataManager.java
/** * Takes a GeneratedFormDataDetail object and uses it to generate random CouchDb data * (a JSON object) for a module.//from www. j av a 2 s . c o m */ @SuppressWarnings("unchecked") private JSONObject generateModuleData(GeneratedModuleDataDetail form, Map<String, JSONObject> uniqueKey, Map<String, JSONObject> lastUniqueKey, String entityId) { JSONObject jsonForm = new JSONObject(); // set up entity ID jsonForm.put(ENTITY_ID, entityId); // set up module ID (random string) jsonForm.put(MODULE_ID, UUID.randomUUID().toString()); // set up the updatedDate (current timestamp) jsonForm.put(UPDATED_DATE, DateUtils.formatDateUTC(DateUtils.now())); // set up questions JSONObject questions = new JSONObject(); for (Map<String, Object> obj : form.getQuestionFields()) { JSONObject jsonQuestion = new JSONObject(); if (GeneratedModuleDataDetail.isSelected(obj)) { Map<String, Object> selectedQuestion = obj; // debugging JSONObject debugObj = new JSONObject(); debugObj.putAll(selectedQuestion); log.debug("Selected question..." + debugObj); // question UUID String questionUUID = (String) selectedQuestion.get(UUID_VALUE); // set "questionId" jsonQuestion.put(QUESTION_ID, questionUUID); // set "linkId" jsonQuestion.put(LINK_ID, selectedQuestion.get(LINK_ID)); // set "questionSn" jsonQuestion.put(QUESTION_SN, selectedQuestion.get(SHORTNAME)); // set "questionText" jsonQuestion.put(QUESTION_TEXT, selectedQuestion.get(TEXT)); // set "answer values" jsonQuestion.put(ANSWERVALUES, selectedQuestion.get(ANSWERVALUES)); // set "form name" - temporary value which will be used to generate CouchDB-ready documents later jsonQuestion.put(FORM_NAME, selectedQuestion.get(FORM_NAME)); // set "module name" - temporary value which will be used to generate CouchDB-ready documents later jsonQuestion.put(MODULE_NAME, selectedQuestion.get(MODULE_NAME)); // check if this is one of the unique key questions boolean isUniqueKeyQuestion = uniqueKey.containsKey(questionUUID); // set up answer values // NOTE: Currently we will only generate one answer value for each question // JSONArray jsonAnswerValuesArray = new JSONArray(); JSONArray randomQuestionAnswerValues = new JSONArray(); // If this question is one of the "unique-per-entity", "unique-per-entity-modules" or "unique-per-all-modules" questions, // then get the answer value from the uniqueKey map; // else, generate a random answer value object. Object lastRandomQuestionAnswerValue = lastUniqueKey.get(questionUUID) == null ? null : getAnswerValue(lastUniqueKey.get(questionUUID)); Map randomQuestionAnswerValue = isUniqueKeyQuestion ? uniqueKey.get(questionUUID) : generateRandomAnswerValue(selectedQuestion, lastRandomQuestionAnswerValue, Algorithm.PSEUDORANDOM); randomQuestionAnswerValues.add(randomQuestionAnswerValue); for (Object obj2 : randomQuestionAnswerValues) { JSONObject answerValue = (JSONObject) obj2; JSONObject jsonAnswer = new JSONObject(); // get answer value text String answerValueText = (String) answerValue.get(ANSWERVALUE_TEXT); // get answer value value String answerValueValue = answerValue.get(ANSWERVALUE_VALUE).toString(); // answer value id jsonAnswer.put(ANSWERVALUE_ID, answerValue.get(ANSWERVALUE_ID)); // answer value shortname jsonAnswer.put(ANSWERVALUE_SN, answerValue.get(ANSWERVALUE_SN)); // answer value text jsonAnswer.put(ANSWERVALUE_TEXT, answerValueText); // answer value value jsonAnswer.put(ANSWERVALUE_VALUE, answerValueValue); jsonAnswerValuesArray.add(jsonAnswer); // track this answer for future frequency analysis form.trackQuestionAndAnswer(questionUUID, StringUtils.defaultIfEmpty(answerValueText, answerValueValue)); } jsonQuestion.put(ANSWERVALUES, jsonAnswerValuesArray); questions.put(questionUUID, jsonQuestion); } } jsonForm.put(QUESTIONS, questions); return jsonForm; }
From source file:com.eyeq.pivot4j.ui.html.HtmlRenderer.java
/** * @see com.eyeq.pivot4j.ui.AbstractPivotRenderer#getCellLabel(com.eyeq.pivot4j.ui.RenderContext) *///from w ww . j a v a 2 s . c o m @Override protected String getCellLabel(RenderContext context) { return StringUtils.defaultIfEmpty(super.getCellLabel(context), " "); }
From source file:com.fiveamsolutions.nci.commons.util.HibernateHelper.java
/** * Set name of the resource bundle to be used by validator. * @param bundleName the name of the bundle. If null or empty, the default bundle is used. *//*from ww w.ja va 2s . c o m*/ public void setBundleName(String bundleName) { bundle = ResourceBundle.getBundle(StringUtils.defaultIfEmpty(bundleName, DEFAULT_BUNDLE)); INTERPOLATOR.setBundle(bundle); }
From source file:com.manydesigns.portofino.actions.admin.page.PageAdminAction.java
public Resolution deletePage() { PageInstance pageInstance = getPageInstance(); PageInstance parentPageInstance = pageInstance.getParent(); if (parentPageInstance == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.delete.the.root.page")); } else {//from w w w . ja v a 2 s .c o m Dispatcher dispatcher = DispatcherUtil.get(context.getRequest()); String contextPath = context.getRequest().getContextPath(); String landingPagePath = portofinoConfiguration.getString(PortofinoProperties.LANDING_PAGE); Dispatch landingPageDispatch = dispatcher.getDispatch(landingPagePath); if (landingPageDispatch != null && landingPageDispatch.getLastPageInstance().getDirectory() .equals(pageInstance.getDirectory())) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.delete.the.landing.page")); return new RedirectResolution(originalPath); } try { String pageName = pageInstance.getName(); File childPageDirectory = parentPageInstance.getChildPageDirectory(pageName); Layout parentLayout = parentPageInstance.getLayout(); Iterator<ChildPage> it = parentLayout.getChildPages().iterator(); while (it.hasNext()) { if (pageName.equals(it.next().getName())) { it.remove(); DispatcherLogic.savePage(parentPageInstance.getDirectory(), parentPageInstance.getPage()); break; } } FileUtils.deleteDirectory(childPageDirectory); } catch (Exception e) { logger.error("Error deleting page", e); } return new RedirectResolution(StringUtils.defaultIfEmpty(parentPageInstance.getPath(), "/")); } return new RedirectResolution(originalPath); }
From source file:com.openshift.internal.restclient.DefaultClient.java
private Map<String, String> getTypeMappings(String apiVersion) { if (typeMappings.isEmpty()) { //OpenShift endpoints final String version = StringUtils.defaultIfEmpty(apiVersion, getOpenShiftAPIVersion()); final String osEndpoint = String.format("%s/%s", OS_API_ENDPOINT, version); typeMappings.put(ResourceKind.BUILD, osEndpoint); typeMappings.put(ResourceKind.BUILD_CONFIG, osEndpoint); typeMappings.put(ResourceKind.DEPLOYMENT_CONFIG, osEndpoint); typeMappings.put(ResourceKind.IMAGE_STREAM, osEndpoint); typeMappings.put(ResourceKind.IMAGE_STREAM_TAG, osEndpoint); typeMappings.put(ResourceKind.OAUTH_ACCESS_TOKEN, osEndpoint); typeMappings.put(ResourceKind.OAUTH_AUTHORIZE_TOKEN, osEndpoint); typeMappings.put(ResourceKind.OAUTH_CLIENT, osEndpoint); typeMappings.put(ResourceKind.OAUTH_CLIENT_AUTHORIZATION, osEndpoint); typeMappings.put(ResourceKind.POLICY, osEndpoint); typeMappings.put(ResourceKind.POLICY_BINDING, osEndpoint); typeMappings.put(ResourceKind.PROJECT, osEndpoint); typeMappings.put(ResourceKind.PROJECT_REQUEST, osEndpoint); typeMappings.put(ResourceKind.ROLE, osEndpoint); typeMappings.put(ResourceKind.ROLE_BINDING, osEndpoint); typeMappings.put(ResourceKind.ROUTE, osEndpoint); typeMappings.put(ResourceKind.TEMPLATE, osEndpoint); typeMappings.put(ResourceKind.USER, osEndpoint); //not real kinds typeMappings.put(ResourceKind.PROCESSED_TEMPLATES, osEndpoint); //Kubernetes endpoints final String k8eApiVersion = StringUtils.defaultIfEmpty(apiVersion, getKubernetesVersion()); final String k8eEndpoint = String.format("%s/%s", API_ENDPOINT, k8eApiVersion); typeMappings.put(ResourceKind.EVENT, k8eEndpoint); typeMappings.put(ResourceKind.POD, k8eEndpoint); typeMappings.put(ResourceKind.PVC, k8eEndpoint); typeMappings.put(ResourceKind.PERSISTENT_VOLUME, k8eEndpoint); typeMappings.put(ResourceKind.LIMIT_RANGE, k8eEndpoint); typeMappings.put(ResourceKind.REPLICATION_CONTROLLER, k8eEndpoint); typeMappings.put(ResourceKind.RESOURCE_QUOTA, k8eEndpoint); typeMappings.put(ResourceKind.SERVICE, k8eEndpoint); typeMappings.put(ResourceKind.SECRET, k8eEndpoint); typeMappings.put(ResourceKind.SERVICE_ACCOUNT, k8eEndpoint); }/* w ww .j a v a2 s . c o m*/ return typeMappings; }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns the virtual machine's Class object for the named primitive type.<br/> * If the type is not a primitive type, {@code null} is returned. * * @param name the name of the type/*w ww . j a va 2 s .c o m*/ * @return the Class instance representing the primitive type */ private static Class<?> getPrimitiveType(String name) { name = StringUtils.defaultIfEmpty(name, ""); if (name.equals("int")) return Integer.TYPE; if (name.equals("short")) return Short.TYPE; if (name.equals("long")) return Long.TYPE; if (name.equals("float")) return Float.TYPE; if (name.equals("double")) return Double.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("void")) return Void.TYPE; return null; }
From source file:gtu._work.ui.RegexCatchReplacer.java
private void exeucteActionPerformed(ActionEvent evt) { String loadFromFileSbStr = loadFromFileSb == null ? "" : loadFromFileSb.toString(); String replaceText = StringUtils.defaultIfEmpty(replaceArea.getText(), loadFromFileSbStr); String fromPattern = repFromText.getText(); String toFormat = repToText.getText(); Validate.notEmpty(replaceText, "source can't empty"); Validate.notEmpty(fromPattern, "replace regex can't empty"); replacer(fromPattern, toFormat, replaceText); }
From source file:com.gst.portfolio.client.domain.Client.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(9); if (command.isChangeInIntegerParameterNamed(ClientApiConstants.statusParamName, this.status)) { final Integer newValue = command.integerValueOfParameterNamed(ClientApiConstants.statusParamName); actualChanges.put(ClientApiConstants.statusParamName, ClientEnumerations.status(newValue)); this.status = ClientStatus.fromInt(newValue).getValue(); }//from w w w . ja v a 2 s . c om if (command.isChangeInStringParameterNamed(ClientApiConstants.accountNoParamName, this.accountNumber)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName); actualChanges.put(ClientApiConstants.accountNoParamName, newValue); this.accountNumber = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.externalIdParamName); actualChanges.put(ClientApiConstants.externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.mobileNoParamName, this.mobileNo)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.mobileNoParamName); actualChanges.put(ClientApiConstants.mobileNoParamName, newValue); this.mobileNo = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.firstnameParamName, this.firstname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName); actualChanges.put(ClientApiConstants.firstnameParamName, newValue); this.firstname = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.middlenameParamName, this.middlename)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.middlenameParamName); actualChanges.put(ClientApiConstants.middlenameParamName, newValue); this.middlename = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.lastnameParamName, this.lastname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.lastnameParamName); actualChanges.put(ClientApiConstants.lastnameParamName, newValue); this.lastname = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.fullnameParamName, this.fullname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.fullnameParamName); actualChanges.put(ClientApiConstants.fullnameParamName, newValue); this.fullname = newValue; } if (command.isChangeInLongParameterNamed(ClientApiConstants.staffIdParamName, staffId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName); actualChanges.put(ClientApiConstants.staffIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.genderIdParamName, genderId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.genderIdParamName); actualChanges.put(ClientApiConstants.genderIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.savingsProductIdParamName, savingsProductId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.savingsProductIdParamName); actualChanges.put(ClientApiConstants.savingsProductIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.genderIdParamName, genderId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.genderIdParamName); actualChanges.put(ClientApiConstants.genderIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.clientTypeIdParamName, clientTypeId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.clientTypeIdParamName); actualChanges.put(ClientApiConstants.clientTypeIdParamName, newValue); } if (command.isChangeInLongParameterNamed(ClientApiConstants.clientClassificationIdParamName, clientClassificationId())) { final Long newValue = command .longValueOfParameterNamed(ClientApiConstants.clientClassificationIdParamName); actualChanges.put(ClientApiConstants.clientClassificationIdParamName, newValue); } if (command.isChangeInIntegerParameterNamed(ClientApiConstants.legalFormIdParamName, this.getLegalForm())) { final Integer newValue = command.integerValueOfParameterNamed(ClientApiConstants.legalFormIdParamName); if (newValue != null) { LegalForm legalForm = LegalForm.fromInt(newValue); if (legalForm != null) { actualChanges.put(ClientApiConstants.legalFormIdParamName, ClientEnumerations.legalForm(newValue)); this.setLegalForm(legalForm.getValue()); } else { actualChanges.put(ClientApiConstants.legalFormIdParamName, null); this.setLegalForm(null); } } else { actualChanges.put(ClientApiConstants.legalFormIdParamName, null); this.setLegalForm(null); } } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.activationDateParamName, getActivationLocalDate())) { final String valueAsInput = command .stringValueOfParameterNamed(ClientApiConstants.activationDateParamName); actualChanges.put(ClientApiConstants.activationDateParamName, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(ClientApiConstants.activationDateParamName); this.activationDate = newValue.toDate(); this.officeJoiningDate = this.activationDate; } if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.dateOfBirthParamName, dateOfBirthLocalDate())) { final String valueAsInput = command .stringValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName); actualChanges.put(ClientApiConstants.dateOfBirthParamName, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName); this.dateOfBirth = newValue.toDate(); } if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.submittedOnDateParamName, getSubmittedOnDate())) { final String valueAsInput = command .stringValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName); actualChanges.put(ClientApiConstants.submittedOnDateParamName, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName); this.submittedOnDate = newValue.toDate(); } validateUpdate(); deriveDisplayName(); return actualChanges; }
From source file:ch.admin.suis.msghandler.config.ClientConfigurationFactory.java
private void setupTransparentApps(String defaultSenderCronValue, String baseDir, ReceiverConfiguration receiverConfiguration, StatusCheckerConfiguration statusCheckerConfiguration) throws ConfigurationException { // ************** transparent applications LOG.info("Configure the transparent applications..."); final List transparent = xmlConfig.configurationsAt("transparentApp"); for (Iterator i = transparent.iterator(); i.hasNext();) { HierarchicalConfiguration sub = (HierarchicalConfiguration) i.next(); // the sedex ID of this application final String sedexId = sub.getString(".[@participantId]"); final String outboxDir = sub.getString("outbox[@dirPath]"); // the outbox if (null != outboxDir) { final String cronValue = sub.getString("outbox[@cron]"); // the outbox exists final SenderConfiguration senderConfiguration = new SenderConfiguration( StringUtils.defaultIfEmpty(cronValue, defaultSenderCronValue)); senderConfiguration.addOutbox(new Outbox(FileUtils.createPath(baseDir, outboxDir))); clientConfiguration.addTransparentSenderConfiguration(senderConfiguration); // MANTIS 5023 LOG.info("transparent sender added, " + senderConfiguration); }//from w w w . ja va 2s . co m // inboxes final List inboxes = sub.configurationsAt(".inbox"); for (Iterator j = inboxes.iterator(); j.hasNext();) { final HierarchicalConfiguration inboxSub = (HierarchicalConfiguration) j.next(); String inboxDir = inboxSub.getString("[@dirPath]"); File tmpDir = FileUtils.createPath(baseDir, inboxDir); Inbox inbox = new TransparentInbox(tmpDir, sedexId, MessageType.from(inboxSub.getString(MSG_TYPES))); checkSedexIdMsgTypes(inbox); receiverConfiguration.addInbox(inbox); } // receipt folder if (sub.getString("receipts[@dirPath]") != null) { String receiptsDir = sub.getString("receipts[@dirPath]"); File tmpDir = FileUtils.createPath(baseDir, receiptsDir); statusCheckerConfiguration.addReceiptFolder(new ReceiptsFolder(tmpDir, sedexId, MessageType.from(sub.getString("receipts[@msgTypes]")))); } } // wrap-up for MANTIS 5023 clientConfiguration.setReceiverConfiguration(receiverConfiguration); LOG.info("receiver added, " + receiverConfiguration); clientConfiguration.setStatusCheckerConfiguration(statusCheckerConfiguration); LOG.info("status checker added, " + statusCheckerConfiguration); // **************** status database settings clientConfiguration.setLogServiceConfiguration(createLogServiceConfig(xmlConfig)); // the localRecipients (replacement from targetDirectoryResolver) final List<HierarchicalConfiguration> localRecipients = xmlConfig .configurationsAt("messageHandler.localRecipients.localRecipient"); for (HierarchicalConfiguration lr : localRecipients) { final String recipientId = lr.getString("[@recipientId]"); final String msgTypes = lr.getString(MSG_TYPES); LocalRecipient localRecipient = new LocalRecipient(recipientId, msgTypes); LOG.info("LocalRecipient: " + localRecipient); clientConfiguration.addLocalRecipient(localRecipient); } // if the protocol files should be created ProtocolWriter.getInstance() .setActive(xmlConfig.getBoolean("messageHandler.protocol[@createPerMessageProtocols]", false)); LOG.info(ProtocolWriter.getInstance().isActive() ? "protocol writer configured" : "protocol writer not configured"); }