001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * vpasquier <vpasquier@nuxeo.com> 018 */ 019package org.nuxeo.ecm.automation.core.exception; 020 021import org.apache.commons.lang.StringEscapeUtils; 022import org.nuxeo.ecm.automation.AutomationFilter; 023import org.nuxeo.ecm.automation.core.AutomationFilterDescriptor; 024import org.nuxeo.ecm.automation.core.scripting.Expression; 025import org.nuxeo.ecm.automation.core.scripting.Scripting; 026 027/** 028 * @since 5.7.3 029 */ 030public class ChainExceptionFilter implements AutomationFilter { 031 032 protected String id; 033 034 protected Expression value; 035 036 @Override 037 public Expression getValue() { 038 return value; 039 } 040 041 @Override 042 public String getId() { 043 return id; 044 } 045 046 public ChainExceptionFilter(String id, String value) { 047 this.id = id; 048 if (value.startsWith("expr:")) { 049 value = value.substring(5).trim(); 050 // Unescape xml checking 051 value = StringEscapeUtils.unescapeXml(value); 052 if (value.contains("@{")) { 053 this.value = Scripting.newTemplate(value); 054 } else { 055 this.value = Scripting.newExpression(value); 056 } 057 } 058 } 059 060 public ChainExceptionFilter(AutomationFilterDescriptor automationFilterDescriptor) { 061 id = automationFilterDescriptor.getId(); 062 String value = automationFilterDescriptor.getValue(); 063 if (value.startsWith("expr:")) { 064 value = value.substring(5).trim(); 065 // Unescape xml checking 066 value = StringEscapeUtils.unescapeXml(value); 067 if (value.contains("@{")) { 068 this.value = Scripting.newTemplate(value); 069 } else { 070 this.value = Scripting.newExpression(value); 071 } 072 } 073 } 074 075}