2525import com .yanglb .codegen .exceptions .CodeGenException ;
2626import com .yanglb .codegen .utils .Infos ;
2727import com .yanglb .codegen .utils .StringUtil ;
28+ import org .apache .commons .text .StringEscapeUtils ;
2829
2930public class MsgAndroidTranslatorImpl extends BaseMsgTranslator {
3031 @ Override
@@ -66,21 +67,22 @@ protected void onTranslate() throws CodeGenException {
6667 Map <String , List <String >> arrays = new HashMap <String , List <String >>();
6768 for (TableModel tblModel : this .model ) {
6869 for (Map <String , String > itm : tblModel .toList ()) {
69- String id = itm .get ("id" );
70+ String id = escape ( itm .get ("id" ) );
7071 if (StringUtil .isNullOrEmpty (id )) continue ;
7172 if (!arrays .containsKey (id )) {
7273 arrays .put (id , new ArrayList <String >());
7374 }
7475
7576 // 对字符串进行转换
76- String value = this . convert2CSCode (itm .get (this .msgLang ));
77+ String value = escape (itm .get (this .msgLang ));
7778 List <String > items = arrays .get (id );
7879 items .add (value );
7980 }
8081 }
8182
8283 for (String key :arrays .keySet ()) {
8384 List <String > items = arrays .get (key );
85+
8486 if (items .size () > 1 ) {
8587 // list
8688 sb .append (String .format (" <string-array name=\" %s\" >\r \n " , key ));
@@ -97,14 +99,11 @@ protected void onTranslate() throws CodeGenException {
9799
98100 this .writableModel .setData (sb );
99101 }
100-
101- private String convert2CSCode (String value ) {
102+
103+ private String escape (String value ) {
102104 if (value == null ) return null ;
103-
104- // 先替换\r\n,防止有文档只有\r或\n 后面再替换一次
105- value = value .replaceAll ("\r \n " , "\\ \\ r\\ \\ n" );
106- value = value .replaceAll ("\r " , "\\ \\ r\\ \\ n" );
107- value = value .replaceAll ("\n " , "\\ \\ r\\ \\ n" );
105+
106+ value = StringEscapeUtils .escapeXml10 (value );
108107 return value ;
109108 }
110109}
0 commit comments