List of usage examples for org.apache.commons.lang3 StringUtils defaultString
public static String defaultString(final String str, final String defaultStr)
Returns either the passed in String, or if the String is null , the value of defaultStr .
StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"
From source file:org.apache.struts2.views.java.simple.SubmitHandler.java
public void generate() throws IOException { Map<String, Object> params = context.getParameters(); Attributes attrs = new Attributes(); String type = StringUtils.defaultString((String) params.get("type"), "input"); if ("button".equals(type)) { attrs.addIfExists("name", params.get("name")).add("type", "submit") .addIfExists("value", params.get("nameValue")).addIfTrue("disabled", params.get("disabled")) .addIfExists("tabindex", params.get("tabindex")).addIfExists("id", params.get("id")) .addIfExists("class", params.get("cssClass")).addIfExists("style", params.get("cssStyle")); start("button", attrs); } else if ("image".equals(type)) { attrs.addIfExists("src", params.get("src")).add("type", "image").addIfExists("alt", params.get("label")) .addIfExists("id", params.get("id")).addIfExists("class", params.get("cssClass")) .addIfExists("style", params.get("cssStyle")); start("input", attrs); } else {/*from ww w . j a v a 2 s .c o m*/ attrs.addIfExists("name", params.get("name")).add("type", "submit") .addIfExists("value", params.get("nameValue")).addIfTrue("disabled", params.get("disabled")) .addIfExists("tabindex", params.get("tabindex")).addIfExists("id", params.get("id")) .addIfExists("class", params.get("cssClass")).addIfExists("style", params.get("cssStyle")); start("input", attrs); } }
From source file:org.apache.zeppelin.markdown.PegdownWebSequencelPlugin.java
public static String createWebsequenceUrl(String style, String content) { style = StringUtils.defaultString(style, "default"); OutputStreamWriter writer = null; BufferedReader reader = null; String webSeqUrl = ""; try {/*from w ww. ja v a 2 s .c om*/ String query = new StringBuilder().append("style=").append(style).append("&message=") .append(URLEncoder.encode(content, "UTF-8")).append("&apiVersion=1").toString(); URL url = new URL(WEBSEQ_URL); URLConnection conn = url.openConnection(); conn.setDoOutput(true); writer = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8); writer.write(query); writer.flush(); StringBuilder response = new StringBuilder(); reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); String line; while ((line = reader.readLine()) != null) { response.append(line); } writer.close(); reader.close(); String json = response.toString(); int start = json.indexOf("?png="); int end = json.indexOf("\"", start); if (start != -1 && end != -1) { webSeqUrl = WEBSEQ_URL + "/" + json.substring(start, end); } } catch (IOException e) { throw new RuntimeException("Failed to get proper response from websequencediagrams.com", e); } finally { IOUtils.closeQuietly(writer); IOUtils.closeQuietly(reader); } return webSeqUrl; }
From source file:org.docx4j.template.WordprocessingMLDocxTemplate.java
public WordprocessingMLDocxTemplate() { //??// w ww.j av a 2s.co m this.inputEncoding = StringUtils.defaultString(this.inputEncoding, Docx4jProperties.getProperty("docx4j.docx.input.encoding", Docx4jConstants.DEFAULT_CHARSETNAME)); this.outputEncoding = StringUtils.defaultString(this.outputEncoding, Docx4jProperties.getProperty("docx4j.docx.output.encoding", Docx4jConstants.DEFAULT_CHARSETNAME)); this.placeholderStart = StringUtils.defaultString(this.placeholderStart, Docx4jProperties.getProperty("docx4j.docx.placeholderStart", "${")); this.placeholderEnd = StringUtils.defaultString(this.placeholderEnd, Docx4jProperties.getProperty("docx4j.docx.placeholderEnd", "}")); this.autoDelete = Docx4jProperties.getProperty("docx4j.docx.source.delete", false); }