- import java.util.regex.Matcher;
import java.util.regex.Pattern; - /**
- * 改变javascript中 iPanel.pageWidgets.create(,,,,)函数的第二个参数
- * @author huangfei
- * @create 2008-11-23 上午11:50:48
- * @since
- * @param jsFileStr
- * @param modulType 该函数的第一个参数值等于modulType的值时才被改变
- * @param realVaule 改变后的真实值
- * @return
- */
- public String replaceParameterInJs(String jsFileStr,String modulType,String realVaule){
- // modulType="nvodFirst_ad0";
- realVaule="/""+realVaule+"/""; //"/"4584891248.htm/"";
- /**
- * regex for: iPanel.pageWidgets.create("nvodFirst_ad0", "ui://nvodFirst_ad0.htm", 3, 0)
- * is: "(iPanel.pageWidgets.create//(//s*/"([//w|_]*)/"//s*,//s*/"ui://([//w|_|//.]*)/"//s*,[^)]*//))";
- */
- String regex4function = "(iPanel.pageWidgets.create//(//s*/""+modulType+"/"//s*,//s*/"ui://([//w|_|//.]*)/"//s*,[^)]*//))";
- Pattern pattern4function = Pattern.compile(regex4function);
- Matcher matcher4function = pattern4function.matcher(jsFileStr);
- ArrayList realStrList = new ArrayList();
- while(matcher4function.find()){
- String realStr = matcher4function.group(1);
- System.out.println("find relative function:"+realStr);
- String regex4Parameter="/"ui://([//w|_|//.]*)/"";
- Pattern pattern4Parameter = Pattern.compile(regex4Parameter);
- Matcher matcher4Parameter = pattern4Parameter.matcher(realStr);
- realStr=matcher4Parameter.replaceAll(realVaule);
- realStrList.add(realStr);
- }
- matcher4function = pattern4function.matcher(jsFileStr);
- int i = 0;
- while(matcher4function.find()){
- jsFileStr = matcher4function.replaceFirst((String)realStrList.get(i));
- i++;
- matcher4function = pattern4function.matcher(jsFileStr);
- }
- return jsFileStr;
- }
替换js中函数的参数
最新推荐文章于 2022-03-10 12:29:52 发布