List of usage examples for org.apache.commons.lang StringUtils defaultString
public static String defaultString(String str)
Returns either the passed in String, or if the String is null
, an empty String ("").
From source file:mitm.common.postfix.PostfixMainConfigBuilder.java
public void writeConfig(Writer writer) throws IOException { for (Map.Entry<String, String> entry : values.entrySet()) { String name = entry.getKey(); String value = entry.getValue(); if (name.startsWith(PostfixMainConfigParser.OTHER_LINE_NAME)) { writer.write(value);// w ww .j a v a 2 s . c o m } else { writer.write(name); writer.write(" = "); writer.write(StringUtils.defaultString(value)); } writer.write("\n"); } }
From source file:gtu._work.etc.EnglishAdd.java
void scanWord() { String word = StringUtils.defaultString(showwordText.getText()); word = StringUtils.trim(word);//w w w.j a va 2s . c om if (StringUtils.isBlank(word) || StringUtils.equals(currentWord, word)) { //showChineseLabel.setText(""); return; } if (netChkBox.isSelected()) { currentWord = word; WordInfo wordInfo = null; try { wordInfo = diectory.parseToWordInfo(word); } catch (Exception ex) { showChineseArea.setText(word + " ?!!!"); return; } showChineseArea.setText(word + " " + wordInfo.getPronounce() + "\n" + wordInfo.getMeaning()); showwordText.setText(""); } else { showChineseArea.setText(word + "\n" + "=> ?"); showwordText.setText(""); } addWordTable(word); }
From source file:mitm.common.util.MiscStringUtils.java
/** * If input does not end with endsWith it will append endsWith and return the result. If input does end with * endsWith input will be returned.//from w ww.ja v a2s . co m */ public static String ensureEndsWith(String input, String endsWith) { return StringUtils.endsWith(input, endsWith) ? StringUtils.defaultString(input) : StringUtils.defaultString(input) + StringUtils.defaultString(endsWith); }
From source file:mitm.common.util.MiscStringUtils.java
/** * Replaces the last chars with replaceCharWith * //from w ww. j a v a 2 s.c om * Example: * * replaceLastChars("abc123", 3, "mn") returns "abcmnmnmn" */ public static String replaceLastChars(String input, int lastChars, String replaceCharWith) { input = StringUtils.defaultString(input); int maxLength = input.length() - lastChars; if (maxLength < 0) { maxLength = 0; } String dots = StringUtils.repeat(StringUtils.defaultString(replaceCharWith), input.length() - maxLength); return StringUtils.substring(input, 0, maxLength) + dots; }
From source file:com.redhat.rhn.frontend.xmlrpc.user.UserHandler.java
/** * Gets details for a given user. These details include first names, last name, email, * prefix, last login date, and created on date. * @param loggedInUser The current user//ww w . ja v a 2s . c om * @param login The login for the user you want the details for * @return Returns a Map containing the details for the given user. * @throws FaultException A FaultException is thrown if the user doesn't have access * to lookup the user corresponding to login or if the user does not exist. * * @xmlrpc.doc Returns the details about a given user. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("string", "login", "User's login name.") * @xmlrpc.returntype * #struct("user details") * #prop_desc("string", "first_names", "deprecated, use first_name") * #prop("string", "first_name") * #prop("string", "last_name") * #prop("string", "email") * #prop("int", "org_id") * #prop("string", "org_name") * #prop("string", "prefix") * #prop("string", "last_login_date") * #prop("string", "created_date") * #prop_desc("boolean", "enabled", "true if user is enabled, * false if the user is disabled") * #prop_desc("boolean", "use_pam", "true if user is configured to use * PAM authentication") * #prop_desc("boolean", "read_only", "true if user is readonly") * #prop_desc("boolean", "errata_notification", "true if errata e-mail notification * is enabled for the user") * #struct_end() */ public Map getDetails(User loggedInUser, String login) throws FaultException { User target = XmlRpcUserHelper.getInstance().lookupTargetUser(loggedInUser, login); LocalizationService ls = LocalizationService.getInstance(); Map ret = new HashMap(); ret.put("first_names", StringUtils.defaultString(target.getFirstNames())); ret.put("first_name", StringUtils.defaultString(target.getFirstNames())); ret.put("last_name", StringUtils.defaultString(target.getLastName())); ret.put("email", StringUtils.defaultString(target.getEmail())); ret.put("prefix", StringUtils.defaultString(target.getPrefix())); //Last login date String lastLoggedIn = target.getLastLoggedIn() == null ? "" : ls.formatDate(target.getLastLoggedIn()); ret.put("last_login_date", lastLoggedIn); //Created date String created = target.getCreated() == null ? "" : ls.formatDate(target.getCreated()); ret.put("created_date", created); ret.put("org_id", loggedInUser.getOrg().getId()); ret.put("org_name", loggedInUser.getOrg().getName()); if (target.isDisabled()) { ret.put("enabled", Boolean.FALSE); } else { ret.put("enabled", Boolean.TRUE); } ret.put("use_pam", target.getUsePamAuthentication()); ret.put("read_only", target.isReadOnly()); ret.put("errata_notification", target.getEmailNotify() == 1); return ret; }
From source file:com.redhat.rhn.frontend.action.systems.SystemSearchAction.java
protected DataResult performSearch(RequestContext context) { HttpServletRequest request = context.getRequest(); String searchString = (String) request.getAttribute(SEARCH_STR); String viewMode = (String) request.getAttribute(VIEW_MODE); String whereToSearch = (String) request.getAttribute(WHERE_TO_SEARCH); Boolean invertResults = StringUtils.defaultString((String) request.getAttribute(INVERT_RESULTS)) .equals("on"); Boolean isFineGrained = (Boolean) request.getAttribute(FINE_GRAINED); ActionErrors errs = new ActionErrors(); DataResult dr = null;// w ww . j a va2s . c o m try { dr = SystemSearchHelper.systemSearch(context, searchString, viewMode, invertResults, whereToSearch, isFineGrained); } catch (MalformedURLException e) { log.error("Caught Exception :" + e, e); errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.connection_error")); } catch (XmlRpcFault e) { log.info("Caught Exception :" + e + ", code [" + e.getErrorCode() + "]", e); if (e.getErrorCode() == 100) { log.error("Invalid search query", e); errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.could_not_parse_query", searchString)); } else if (e.getErrorCode() == 200) { log.error("Index files appear to be missing: ", e); errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.index_files_missing", searchString)); } else { errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.could_not_execute_query", searchString)); } } catch (XmlRpcException e) { log.error("Caught Exception :" + e, e); errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("packages.search.connection_error")); } if (dr == null) { ActionMessages messages = new ActionMessages(); messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("systemsearch_no_matches_found")); getStrutsDelegate().saveMessages(request, messages); } if (!errs.isEmpty()) { addErrors(request, errs); } return dr; }
From source file:fr.paris.lutece.plugins.directory.business.EntryTypeArray.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s.c o m*/ */ @Override public String getEntryData(HttpServletRequest request, Locale locale) { String strTitle = request.getParameter(PARAMETER_TITLE); String strHelpMessage = (request.getParameter(PARAMETER_HELP_MESSAGE) != null) ? request.getParameter(PARAMETER_HELP_MESSAGE).trim() : null; String strHelpMessageSearch = (request.getParameter(PARAMETER_HELP_MESSAGE_SEARCH) != null) ? request.getParameter(PARAMETER_HELP_MESSAGE_SEARCH).trim() : null; String strComment = request.getParameter(PARAMETER_COMMENT); String strIndexed = request.getParameter(PARAMETER_INDEXED); String strIndexedAsTitle = request.getParameter(PARAMETER_INDEXED_AS_TITLE); String strIndexedAsSummary = request.getParameter(PARAMETER_INDEXED_AS_SUMMARY); String strShowInAdvancedSearch = request.getParameter(PARAMETER_SHOWN_IN_ADVANCED_SEARCH); String strShowInResultList = request.getParameter(PARAMETER_SHOWN_IN_RESULT_LIST); String strShowInResultRecord = request.getParameter(PARAMETER_SHOWN_IN_RESULT_RECORD); String strMultipleSearchFields = request.getParameter(PARAMETER_MULTIPLE_SEARCH_FIELDS); String strShowInHistory = request.getParameter(PARAMETER_SHOWN_IN_HISTORY); String strFieldError = DirectoryUtils.EMPTY_STRING; String strShowInExport = request.getParameter(PARAMETER_SHOWN_IN_EXPORT); String strShowInCompleteness = request.getParameter(PARAMETER_SHOWN_IN_COMPLETENESS); String strNumberRows = request.getParameter(PARAMETER_NUMBER_ROWS); String strNumberColumns = request.getParameter(PARAMETER_NUMBER_COLUMNS); if ((strTitle == null) || strTitle.trim().equals(DirectoryUtils.EMPTY_STRING)) { strFieldError = FIELD_TITLE; } else if (StringUtils.isEmpty(strNumberRows)) { strFieldError = FIELD_NUMBER_ROWS; } else if (StringUtils.isEmpty(strNumberColumns)) { strFieldError = FIELD_NUMBER_COLUMNS; } if (!strFieldError.equals(DirectoryUtils.EMPTY_STRING)) { Object[] tabRequiredFields = { I18nService.getLocalizedString(strFieldError, locale) }; return AdminMessageService.getMessageUrl(request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP); } else if (!isValid(strNumberRows)) { Object[] tabRequiredFields = { I18nService.getLocalizedString(FIELD_NUMBER_ROWS, locale) }; return AdminMessageService.getMessageUrl(request, MESSAGE_NUMERIC_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP); } else if (!isValid(strNumberColumns)) { Object[] tabRequiredFields = { I18nService.getLocalizedString(FIELD_NUMBER_COLUMNS, locale) }; return AdminMessageService.getMessageUrl(request, MESSAGE_NUMERIC_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP); } int row = Integer.valueOf(strNumberRows); int column = Integer.valueOf(strNumberColumns); this.setTitle(strTitle); this.setHelpMessage(strHelpMessage); this.setHelpMessageSearch(strHelpMessageSearch); this.setComment(strComment); this.setMandatory(false); this.setIndexed(strIndexed != null); this.setIndexedAsTitle(strIndexedAsTitle != null); this.setIndexedAsSummary(strIndexedAsSummary != null); this.setShownInAdvancedSearch(strShowInAdvancedSearch != null); this.setShownInResultList(strShowInResultList != null); this.setShownInResultRecord(strShowInResultRecord != null); this.setMultipleSearchFields(strMultipleSearchFields != null); this.setShownInHistory(strShowInHistory != null); this.setShownInExport(strShowInExport != null); this.setShownInCompleteness(strShowInCompleteness != null); this.setNumberColumn(column); this.setNumberRow(row); ArrayList<Field> listFields = new ArrayList<Field>(); List<Field> fields = FieldHome.getFieldListByIdEntry(this.getIdEntry(), PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME)); for (int i = 1; i <= (row + 1); i++) { for (int j = 1; j <= (column + 1); j++) { Field existingFields = null; for (Field f : fields) { if (f.getValue().equals(i + "_" + j)) { existingFields = f; break; } } String strTitleRow = request.getParameter("field_" + i + "_" + j); if ((i == 1) && (j != 1)) { Field field = new Field(); if (existingFields != null) { field = existingFields; } field.setEntry(this); field.setValue(i + "_" + j); field.setTitle(StringUtils.defaultString(strTitleRow)); listFields.add(field); } else if ((i != 1) && (j == 1)) { Field field = new Field(); if (existingFields != null) { field = existingFields; } field.setEntry(this); field.setValue(i + "_" + j); field.setTitle(StringUtils.defaultString(strTitleRow)); listFields.add(field); } else { Field field = new Field(); field.setEntry(this); field.setValue(i + "_" + j); listFields.add(field); } } } this.setFields(listFields); return null; }
From source file:com.haulmont.cuba.web.gui.components.presentations.TablePresentations.java
protected void buildPresentationsList() { menuBar.removeItems();// w ww .j a v a 2 s. c o m presentationsMenuMap = new HashMap<>(); final Presentations p = table.getPresentations(); for (final Object presId : p.getPresentationIds()) { final MenuBar.MenuItem item = menuBar.addItem(StringUtils.defaultString(p.getCaption(presId)), new com.vaadin.ui.MenuBar.Command() { @Override public void menuSelected(com.vaadin.ui.MenuBar.MenuItem selectedItem) { table.applyPresentation(presId); } }); final Presentation current = p.getCurrent(); if (current != null && presId.equals(current.getId())) { setCurrentItemStyle(item); } final Presentation defaultPresentation = p.getDefault(); if (defaultPresentation != null && presId.equals(defaultPresentation.getId())) { setDefaultItemStyle(item); } presentationsMenuMap.put(presId, item); } }
From source file:mitm.common.pdf.MessagePDFBuilder.java
private void addTextPart(String text, Phrase bodyPhrase, FontSelector fontSelector) { if (StringUtils.isNotEmpty(text)) { bodyPhrase.add(fontSelector.process(StringUtils.defaultString(text))); }// w w w . j a va 2 s.co m }
From source file:net.sf.groovyMonkey.GroovyMonkeyPlugin.java
public static void log(final int severity, final String message, final Throwable throwable) { if (getDefault() == null) return;//from ww w .j a v a 2 s . c om getDefault().getLog() .log(new Status(severity, PLUGIN_ID, 0, StringUtils.defaultString(message), throwable)); }