com.service.impl

时间:2022-09-12 10:56:01
package com.service.impl;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import com.domain.bean.TmpBean;
import com.ulitis.www.JUtils; public class CodeSericeImpl implements CodeServiceDao {
// For layout public static final String LEFT = "<h2>#if(";
public static final String RIGHT = ")";
public static final String END = "#end</h2>"; // for variable
// public String valDes = "";
// public static String varLEFT = "#set($";
// public static String varMIDLE = "=\"";
// public static String varRIGHT = "\") "; public static final String varLEFT = "#set($";
public static final String varRIGHT = ")"; /*
* (non-Javadoc)
*
* @see com.service.impl.StrServerDao#StrAppend(java.lang.String)
*/ // ***********************Context
// function**************************************
public String StrAppend(String str) {
int placeholder = 1;
String Strdes = "";
int i = 0;
while (str != null && i < str.length()) {
char ch = str.charAt(i);
if (ch == '[') {
Strdes += LEFT;
Strdes += JUtils.getFormat(placeholder);
placeholder++;
Strdes += RIGHT; }
if (ch == ']') {
Strdes += END; }
Strdes += ch;
i++; }
return Strdes;
} // do for string replace
public String formatString(String str) {
return str.replace("[", "").replace("]", "").replace("#if(", "#if($");
} public LinkedHashMap<String, String> varAdd2Map(List<String> varlist) {
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
for (int varIndex = 0; varIndex < varlist.size(); varIndex++) {
String[] str = varlist.get(varIndex).split("=");
map.put(str[0].trim(), str[1].trim()); }
return map;
} public String removeRuleNumber(String str) { Pattern pattern = Pattern.compile("\\([^s{1,3}]\\)");
Matcher matcher = pattern.matcher(str);
String strValue = matcher.replaceAll("");
return strValue; } // ************************Variable fucntion****************
public String varAppend(List<String> varlist) {
String arr = null;
for (int varIndex = 0; varIndex < varlist.size(); varIndex++) {
arr += varLEFT + varlist.get(varIndex) + varRIGHT;
} return arr;
} public List<String> splitVariable2list(String str) {
List<String> list = new ArrayList<String>(); String[] varlist = str.split(",");
for (int varIndex = 0; varIndex < varlist.length; varIndex++) {
String val = varlist[varIndex].trim();
list.add(val);
} return list;
} public String TestPattern(String str) {
// TODO Auto-generated method stub
return null;
} }
package com.service.impl;

import java.util.LinkedHashMap;
import java.util.List; import com.domain.bean.TmpBean; public interface CodeServiceDao { public abstract String StrAppend(String str); public List<String> splitVariable2list(String str); public String varAppend(List<String> varlist); public String formatString(String str); public LinkedHashMap<String, String> varAdd2Map(List<String> varlist); public String TestPattern(String str); public abstract String removeRuleNumber(String mscript);
}

相关文章