JAVA Pattern和Matcher 的用法

 String上可使用正则表达式的操作,实际上是利用了java.util.regex.Pattern与java.util.regex.Matcher的功能。当调用String的matches()方法时,实际上是调用Pattern的静态方法matches(),这个方法会返回boolean值,表示字符串是否符合正则表达式。
如果想要将正则表达式视为一个对象来重复使用,可以使用Pattern的静态方法compile()进行编译。compile()方法会返回一个Pattern的实例,这个实例代表正则表达式,之后就可以重复使用Pattern实例的matcher()方法来返回一个Matcher的实例,代表符合正则式的实例,这个实例上有一些寻找符合正则式条件的方法可供操作。

function ajaxExportExcel(formName){
		var type = "${isBranch}";
		
		//if(type=="0"){
		//	Ext.MessageBox.alert("警告", "没有数据!");
		//	return;
		//}
		
		var agentName = "agentName:" + Ext.getCmp("agentName").getValue();
		
		var system = "system:" + Ext.getCmp("system_id").getValue();
		
		if (Ext.getCmp("system_id").getRawValue()=='') {
		    system = "system:";
		}
		
		var officeNo = "officeNo:" + Ext.getCmp("officeNo").getValue();
		var status = "status:" + Ext.getCmp("status_id").getValue();
		if (Ext.getCmp("status_id").getRawValue()=='') {
		    status = "status:";
		}
		var startTime = "startTime:" + Ext.getCmp("startTime_index_1").getRawValue();
		var endTime = "endTime:" + Ext.getCmp("startTime_index_2").getRawValue();
		var zData = "zData:" + Ext.getCmp("zData").getValue();

		var params = agentName + "_@_" + system + "_@_" + officeNo + "_@_" 
		+ status + "_@_"+ startTime + "_@_" + endTime + "_@_" + zData;
		
		var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"请稍候..."});
		myMask.show();
		
		Ext.Ajax.request({
			url: "./report!exportqueryHistorysReport.action",
			timeout: 900000,  
		    method: 'post',
			params: {queryInfo: params},
			success:function(action){
				var response = action.responseText;
				if(response.indexOf('file:')==-1){
					myMask.hide();
					Ext.MessageBox.show({
	   					title: "导出报表失败",
		           		msg: response,
		           		buttons: Ext.MessageBox.OK,
		           		icon: Ext.MessageBox.INFO
		       		});
				}else{
					var reportFileName = response.substring(5);
					var newWindow = new Ext.Window({
		                	id: 'winExportReport',
		                	title: this.title,
		                	width: 850,
		                	layout: 'fit',
		                	collapsible: true,
		                	height: this.height,
		                	frame: true,
		                	modal: true,
		                	html: '<iframe id="iframe1" src="../report/download?filePath='+reportFileName+'" width="100%" height="500"/>'
						});
		            newWindow.addListener("show", function(){delayCloseWindow(myMask);}); 
		            newWindow.addListener("close", function(){myMask.hide();});
	                newWindow.show();
	            }
            },
		    failure: function(action){ 
				var response = action.responseText;
		       	myMask.hide(); 
		       	Ext.MessageBox.show({
					title: "导出报表失败",
		           	msg: response,
		           	buttons: Ext.MessageBox.OK,
		           	icon: Ext.MessageBox.INFO
		       	});
			}
		});
	}

 

private static Pattern configSummaryQueryParameterPatternhy = 
		Pattern.compile("^agentName:(.*)_@_system:(.*)_@_officeNo:(.*)_@_status:(.*)_@_startTime:(.*)_@_endTime:(.*)_@_zData:(.*)$");


public String exportqueryHistorysReport()throws Exception{
		//数据渲染器选择标记
		ServletActionContext.getRequest().setAttribute(
				com.travelsky.bravo.core.ui.Constants.AJAX_HANDLE_KEY,
				com.travelsky.bravo.core.ui.Constants.AJAX_HANDLE_VALUE);
		try{
	        String queryInfo = ServletActionContext.getRequest().getParameter("queryInfo").trim();
			Matcher matcher = configSummaryQueryParameterPatternhy.matcher(queryInfo);
			if (!matcher.find()) {
				throw new RuntimeException("wrong parameters:" + queryInfo);
			}
			SecUser currentUser = RequestHandler.getContextRequestHandler().getCurrentUser();
			String islocaluse=currentUser.getBranchId().getIslocaluse();
			String fileName = reportManager.generateConfigHistorysReport(
					StringUtils.trim(matcher.group(1)), 
					StringUtils.trim(matcher.group(2)), 
					StringUtils.trim(matcher.group(3)), 
					StringUtils.trim(matcher.group(4)), 
					StringUtils.trim(matcher.group(5)), 
					StringUtils.trim(matcher.group(6)),
					StringUtils.trim(matcher.group(7)),islocaluse); 
			
			ServletActionContext.getRequest().setAttribute(
					Constants.AJAX_HANDLE_STATUS,  "Y");
			ServletActionContext.getRequest().setAttribute(
					Constants.AJAX_HANDLE_MSG,  "file:" + fileName);
		}catch(Exception e){
			logger.error(e.getMessage(), e);
			ServletActionContext.getRequest().setAttribute(
					Constants.FORM_AJAX_SUBMIT_STATUS,
					Constants.FORM_AJAX_SUBMIT_FAILURE);
			ServletActionContext.getRequest().setAttribute(
					Constants.FORM_AJAX_SUBMIT_MSG,
					e.getMessage());
		}
		return JSON_DATA_RENDER_CHAIN;
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值