{"id":1444,"date":"2009-07-30T01:10:42","date_gmt":"2009-07-29T16:10:42","guid":{"rendered":"http:\/\/fukata.org\/?p=1444"},"modified":"2017-08-11T23:07:14","modified_gmt":"2017-08-11T23:07:14","slug":"jc-tag-library-br-tag","status":"publish","type":"post","link":"https:\/\/blog.fukata.org\/archives\/1444\/","title":{"rendered":"[JC]\u6539\u884c\u30b3\u30fc\u30c9\u3092br\u30bf\u30b0\u306b\u7f6e\u63db\u3059\u308b\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f"},"content":{"rendered":"
\u306f\u3044\u3002\u30bf\u30a4\u30c8\u30eb\u901a\u308a\u306e\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u5f53\u521d\u666e\u901a\u306eJSP\u306e\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5024\u3092\u6e21\u3059\u4e88\u5b9a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3058\u3083\u6e21\u305b\u306a\u3044\u3058\u3083\u3093\u3068\u3044\u3046\u3053\u3068\u306b\u4f5c\u6210\u3057\u7d42\u308f\u3063\u305f\u5f8c\u306b\u6c17\u3065\u3044\u3066\u4f5c\u6210\u3057\u306a\u304a\u3057\u307e\u3057\u305f\u3002\u3068\u3044\u3046\u304b\u3001\u30c7\u30d0\u30c3\u30b0\u306e\u59cb\u307e\u308a\u3067\u3057\u305fw<\/p>\n
\r\n<\/jc>\r\n<\/pre>\n\u4eca\u56de\u4f5c\u6210\u3057\u305f\u306e\u306f\u4e0b\u8a18\u306e4\u70b9\u3067\u3059\u3002<\/p>\n
\n- Text2BrTag.java\uff1a\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u30af\u30e9\u30b9<\/li>\n
- Text2Br.java\uff1a\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8<\/li>\n
- HtmlUtils.java\uff1aHTML\u51fa\u529b\u7528\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3<\/li>\n
- jcommunity.tld\uff1a\u30ab\u30b9\u30bf\u30e0\u30bf\u30b0\u5b9a\u7fa9\u30d5\u30a1\u30a4\u30eb<\/li>\n<\/ul>\n
\u307e\u305f\u4eca\u56de\u3082\u919c\u3044\u304b\u3068\u306f\u601d\u3044\u307e\u3059\u304c\u3001\u4f55\u304b\u306e\u5f79\u306b\u7acb\u3066\u3070\u3068\u601d\u3044\u3001\u30bd\u30fc\u30b9\u3092\u8cbc\u308a\u4ed8\u3051\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n
<\/p>\n
\u25a0Text2BrTag.java<\/p>\n
\r\npackage org.fukata.jc_common.view.taglib;\r\n\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport org.apache.struts2.components.Component;\r\nimport org.apache.struts2.views.jsp.ComponentTagSupport;\r\nimport org.fukata.jc_common.view.component.Text2Br;\r\n\r\nimport com.opensymphony.xwork2.util.ValueStack;\r\n\r\n\/**\r\n * \u30c6\u30ad\u30b9\u30c8\u306e\u6539\u884c\u30b3\u30fc\u30c9\u3092
\u306b\u7f6e\u63db\u3059\u308b\r\n * \r\n * @author tatsuya\r\n *\r\n *\/\r\npublic class Text2BrTag extends ComponentTagSupport {\r\n\t\r\n\tprivate static final long serialVersionUID = 1L;\r\n\t\r\n\t\/\/ \u7f6e\u63db\u3059\u308b\u6587\u5b57\u5217\r\n\tprivate String value;\r\n\t\r\n\tpublic String getValue() {\r\n\t\treturn value;\r\n\t}\r\n\r\n\tpublic void setValue(String value) {\r\n\t\tthis.value = value;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Component getBean(ValueStack stack, HttpServletRequest req,\r\n\t\t\tHttpServletResponse res) {\r\n\t\treturn new Text2Br(stack);\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected void populateParams() {\r\n\t\tsuper.populateParams();\r\n\t\t\r\n\t\tText2Br text2Br = (Text2Br) component;\r\n\t\ttext2Br.setValue(this.value);\r\n\t}\r\n\r\n\t\r\n}\r\n<\/pre>\n\u25a0Text2Br.java<\/p>\n
\r\npackage org.fukata.jc_common.view.component;\r\n\r\nimport java.io.IOException;\r\nimport java.io.Writer;\r\n\r\nimport org.apache.struts2.components.Component;\r\nimport org.fukata.jc_common.utils.HtmlUtils;\r\n\r\nimport com.opensymphony.xwork2.util.ValueStack;\r\n\r\npublic class Text2Br extends Component {\r\n\r\n\tprivate String value;\r\n\t\r\n\tpublic Text2Br(ValueStack stack) {\r\n\t\tsuper(stack);\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic boolean start(Writer writer) {\r\n\t\tboolean result = super.start(writer);\r\n\t\t\r\n\t\tif (this.value!=null) {\r\n\t\t\tthis.value = findString(this.value);\r\n\t\t\t\/\/ \u6539\u884c\u30b3\u30fc\u30c9\u3092br\u30bf\u30b0\u306b\u7f6e\u63db\r\n\t\t\tthis.value = HtmlUtils.getTxt2Br(this.value);\r\n\t\t}\r\n\t\t\r\n\t\treturn result;\r\n\t}\r\n\t\r\n\t@Override\r\n\tprotected boolean end(Writer writer, String body, boolean popComponentStack) {\r\n\t\tboolean result = super.end(writer, body, popComponentStack);\r\n\t\t\r\n\t\ttry {\r\n\t\t\t\/\/ \u753b\u9762\u306b\u66f8\u304d\u51fa\u3059\r\n\t\t\twriter.write(this.value);\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\t\r\n\t\treturn result;\r\n\t}\r\n\r\n\tpublic String getValue() {\r\n\t\treturn value;\r\n\t}\r\n\r\n\tpublic void setValue(String value) {\r\n\t\tthis.value = value;\r\n\t}\r\n\r\n\t\r\n}\r\n<\/pre>\n\u25a0HtmlUtils.java<\/p>\n
\r\npackage org.fukata.jc_common.utils;\r\n\r\npublic class HtmlUtils {\r\n\t\r\n\tprivate static final String BKREAK_REGEX = \"(\\r\\n|\\r|\\n)\"; \r\n\tprivate static final String HTML_BREAK = \"
\"; \r\n\t\r\n\tprivate HtmlUtils() {\r\n\t}\r\n\t\r\n\tpublic static String getTxt2Br(String txt) {\r\n\t\treturn txt.replaceAll(BKREAK_REGEX, HTML_BREAK);\r\n\t}\r\n}\r\n<\/pre>\n\u25a0jcommunity.tld<\/p>\n
\r\n< ?xml version=\"1.0\" ?>\r\n< !DOCTYPE taglib PUBLIC \"-\/\/Sun Microsystems, Inc.\/\/DTD JSP Tag Library 1.1\/\/EN\" \"https:\/\/java.sun.com\/j2ee\/dtds\/web-jsptaglibrary_1_1.dtd\">\r\n\r\n\r\n 1.0<\/tlibversion>\r\n 2.0<\/jspversion>\r\n jcommunity<\/shortname>\r\n JCommunity tab library<\/info>\r\n\r\n \r\n txt2br<\/name>\r\n org.fukata.jc_common.view.taglib.Text2BrTag<\/tagclass>\r\n empty<\/bodycontent>\r\n text to html br tag<\/info>\r\n \r\n \tvalue<\/name>\r\n \ttrue<\/required>\r\n \ttrue<\/rtexprvalue>\r\n \t< ![CDATA[Value expression for Parameter to set]]><\/description>\r\n <\/attribute>\r\n <\/tag>\r\n<\/taglib>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u306f\u3044\u3002\u30bf\u30a4\u30c8\u30eb\u901a\u308a\u306e\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u5f53\u521d\u666e\u901a\u306eJSP\u306e\u30bf\u30b0\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f5c\u6210\u3057\u305f\u306e\u3067\u3059\u304c\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5024\u3092\u6e21\u3059\u4e88\u5b9a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u308c\u3058\u3083\u6e21\u305b\u306a\u3044\u3058\u3083\u3093\u3068\u3044\u3046\u3053\u3068\u306b\u4f5c\u6210\u3057\u7d42\u308f\u3063\u305f\u5f8c\u306b\u6c17 … \u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":2,"featured_media":9223372036854775807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1980],"tags":[341,346,358],"_links":{"self":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1444"}],"collection":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/comments?post=1444"}],"version-history":[{"count":0,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/posts\/1444\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media\/9223372036854775807"}],"wp:attachment":[{"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/media?parent=1444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/categories?post=1444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fukata.org\/wp-json\/wp\/v2\/tags?post=1444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}