/** * Return <code>string</code>, or <code>""</code> if <code>string</code> * is <code>null</code>. Never returns <code>null</code>. * <p>Examples:</p> * <pre> * // prints 0 * String s=null; * System.out.println(TextUtils.noNull(s).length()); * * // prints 1 * s="a"; * System.out.println(TextUtils.noNull(s).length()); * </pre> * @param string the String to check * @return a valid (non-null) string reference */ public final static String noNull(String string) { return noNull(string, ""); }
/** * Return <code>string</code>, or <code>""</code> if <code>string</code> * is <code>null</code>. Never returns <code>null</code>. * <p>Examples:</p> * <pre> * // prints 0 * String s=null; * System.out.println(TextUtils.noNull(s).length()); * * // prints 1 * s="a"; * System.out.println(TextUtils.noNull(s).length()); * </pre> * @param string the String to check * @return a valid (non-null) string reference */ public final static String noNull(String string) { return noNull(string, ""); }
public SystemNavContextLayoutBean(HttpServletRequest request) { this.request = request; this.userAgent = TextUtils.noNull(request.getHeader("USER-AGENT")); }
/** * Convert a String to an boolean. * Accepts: 1/0, yes/no, true/false - case insensitive. If the value does * not map to "true,", <code>false</code> is returned. * * @param in String to be parsed. * @return boolean representation of String. */ public final static boolean parseBoolean(String in) { in = noNull(in); if (in.length() == 0) { return false; } switch (in.charAt(0)) { case '1': case 'y': case 'Y': case 't': case 'T': return true; } return false; }
/** * Convert a String to an boolean. * Accepts: 1/0, yes/no, true/false - case insensitive. If the value does * not map to "true,", <code>false</code> is returned. * * @param in String to be parsed. * @return boolean representation of String. */ public final static boolean parseBoolean(String in) { in = noNull(in); if (in.length() == 0) { return false; } switch (in.charAt(0)) { case '1': case 'y': case 'Y': case 't': case 'T': return true; } return false; }
/** * Convert line breaks to html <code><br></code> tag. * @param s the String to convert * @return the converted string */ public final static String br(String s) { s = noNull(s); StringBuffer str = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '\n') { str.append("<br/>"); } str.append(s.charAt(i)); } return str.toString(); }
/** * Escape chars that need slashes in front of them. * @param s the String to add escape characters to * @return the converted String */ public final static String slashes(String s) { s = noNull(s); StringBuffer str = new StringBuffer(); char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { if ((chars[i] == '\\') || (chars[i] == '\"') || (chars[i] == '\'')) { str.append('\\'); } str.append(chars[i]); } return str.toString(); }
public boolean isCaptureJavascript() { return WebRequestUtils.isGoodBrowser(request) && TextUtils.noNull(request.getHeader("USER-AGENT")).indexOf("Opera") == -1; }
/** * Convert line breaks to html <code><br></code> tag. * @param s the String to convert * @return the converted string */ public final static String br(String s) { s = noNull(s); StringBuffer str = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '\n') { str.append("<br/>"); } str.append(s.charAt(i)); } return str.toString(); }
/** * Escape chars that need slashes in front of them. * @param s the String to add escape characters to * @return the converted String */ public final static String slashes(String s) { s = noNull(s); StringBuffer str = new StringBuffer(); char[] chars = s.toCharArray(); for (int i = 0; i < chars.length; i++) { if ((chars[i] == '\\') || (chars[i] == '\"') || (chars[i] == '\'')) { str.append('\\'); } str.append(chars[i]); } return str.toString(); }
/** * Returned string is non-null IFF there is a true value (ie some text) */ public static String verifyString(String s) { if (TextUtils.stringSet(TextUtils.noNull(s).trim())) { return s; } else { return null; } }
/** * Wrap paragraphs in html <code><p></code> tags. * Paragraphs are seperated by blank lines. * @param s the String to reformat * @return the reformatted string */ public final static String wrapParagraph(String s) { s = noNull(s); StringBuffer result = new StringBuffer(); result.append("<p>"); char lastC = 0; char thisC; for (int i = 0; i < s.length(); i++) { thisC = s.charAt(i); if ((thisC == '\n') && (lastC == '\n')) { result.append("</p>\n\n<p>"); } else { result.append(thisC); } lastC = thisC; } result.append("</p>"); return result.toString(); }
public void setIntroduction(String introduction) { if (TextUtils.stringSet(TextUtils.noNull(introduction).trim())) { this.introduction = TextUtils.closeTags(introduction); } else { this.introduction = null; } }
/** * Wrap paragraphs in html <code><p></code> tags. * Paragraphs are seperated by blank lines. * @param s the String to reformat * @return the reformatted string */ public final static String wrapParagraph(String s) { s = noNull(s); StringBuffer result = new StringBuffer(); result.append("<p>"); char lastC = 0; char thisC = 0; for (int i = 0; i < s.length(); i++) { thisC = s.charAt(i); if ((thisC == '\n') && (lastC == '\n')) { result.append("</p>\n\n<p>"); } else { result.append(thisC); } lastC = thisC; } result.append("</p>"); return result.toString(); }
/** * Convert all URLs and E-mail addresses in a string into hyperlinks. * * @param text The block of text to hyperlink. * @param target The target attribute to use for href (optional). * @return the text with known uri formats hyperlinked * * @see #linkEmail(String) * @see #linkURL(String) */ public final static String hyperlink(String text, String target) { text = noNull(text); StringBuffer sb = new StringBuffer((int) (text.length() * 1.1)); sb.append(text); linkEmail(sb); linkURL(sb, target); return sb.toString(); }
/** * Loops through the string and returns the issue that is found within, or null if there is no issue matching. * <p/> * It finds any string matching XXX-### and then looks it up to see if it is a valid issue. It will return the * first valid issue that exists. * * @param searchString the string to search through for issues * @return the issue that has been found, or null of one is not found. */ @Nullable public static Issue findIssueObjectInString(final String searchString) { final StringTokenizer tokenizer = new StringTokenizer(TextUtils.noNull(searchString).toUpperCase(), INVALID_ISSUEKEY_CHARS, false); String token; while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); if (JiraKeyUtils.validIssueKey(token)) { final Issue issue = getIssueObjectInternal(token); if (issue != null) { return issue; } } } return null; }
protected void doValidation() { log.debug("fullName = " + fullName); log.debug("email = " + email); // It is valid to not send a username because Crowd and LDAP do not let you edit the username // but we don't allow empty string because that is an internal user with a blank username. if (username != null && username.trim().isEmpty()) addError("username", getText("signup.error.username.required")); if (!TextUtils.stringSet(TextUtils.noNull(fullName).trim())) addError("fullName", getText("admin.errors.invalid.full.name.specified")); if (!TextUtils.verifyEmail(TextUtils.noNull(email))) addError("email", getText("admin.errors.invalid.email")); }
/** * Convert all URLs and E-mail addresses in a string into hyperlinks. * * @param text The block of text to hyperlink. * @param target The target attribute to use for href (optional). * @return the text with known uri formats hyperlinked * * @see #linkEmail(String) * @see #linkURL(String) */ public final static String hyperlink(String text, String target) { text = noNull(text); text = linkEmail(text); text = linkURL(text, target); return text; }
/** * Converts plain text to html code. * * <ul> * <li>escapes appropriate characters * <li>puts in line breaks * <li>hyperlinks link and email addresses * </ul> * * @param str - String containing the plain text. * @param target - Target for href tags (optional). * @param encodeSpecialChars - if true high characters will be encode other wise not. * @return the escaped string */ public final static String plainTextToHtml(String str, String target, boolean encodeSpecialChars) { str = noNull(str); //First, convert all the special chars... str = htmlEncode(str, encodeSpecialChars); //Convert all leading whitespaces str = leadingSpaces(str); //Then convert all line breaks... str = br(str); //Then create hyperlinks... str = hyperlink(str, target); return str; }
protected void doValidation() { // Valid name must have some content. if (!TextUtils.stringSet(getName())) { addError("name", getText("admin.errors.please.specify.a.name")); } // Confirm that the project category id actually maps to a project category. if (null == getId() || null == projectManager.getProjectCategoryObject(getId())) { addErrorMessage(getText("admin.errors.project.category.does.not.exist")); } else { // Validate that the name is not the name of another project category for (ProjectCategory projectCategory : projectManager.getAllProjectCategories()) { //cannot have two categories with a different id and the same name if (!getId().equals(projectCategory.getId()) && TextUtils.noNull(getName()).equalsIgnoreCase(projectCategory.getName())) { addError("name", getText("admin.errors.project.category.already.exists","'" + getName() + "'")); break; } } } }