2424
2525import org .ocpsoft .common .util .Assert ;
2626import org .ocpsoft .rewrite .bind .Binding ;
27+ import org .ocpsoft .rewrite .config .Operation ;
2728import org .ocpsoft .rewrite .context .EvaluationContext ;
2829import org .ocpsoft .rewrite .event .Rewrite ;
29- import org .ocpsoft .rewrite .exception .RewriteException ;
3030import org .ocpsoft .rewrite .param .Parameter ;
3131import org .ocpsoft .rewrite .param .Parameters ;
3232import org .ocpsoft .rewrite .param .Transposition ;
@@ -50,6 +50,8 @@ public class LocaleTransposition implements Transposition<String>
5050
5151 private final String languageParam ;
5252 private final String bundleName ;
53+
54+ private Operation onFailureOperation ;
5355
5456 private LocaleTransposition (final String languageParam , final String bundleName )
5557 {
@@ -60,6 +62,7 @@ private LocaleTransposition(final String languageParam, final String bundleName)
6062
6163 this .languageParam = languageParam ;
6264 this .bundleName = bundleName ;
65+
6366 }
6467
6568 /**
@@ -95,6 +98,18 @@ public static LocaleTransposition bundle(final String bundleName, final String l
9598 {
9699 return new LocaleTransposition (localeParam , bundleName );
97100 }
101+
102+ /**
103+ * Specify an Operation to perform in case the transposition failed.
104+ * Failure occurs when no resource bundle can be found for the requested language.
105+ * @param onFailureOperation
106+ * @return
107+ */
108+ public LocaleTransposition onFailure (Operation onFailureOperation )
109+ {
110+ this .onFailureOperation = onFailureOperation ;
111+ return this ;
112+ }
98113
99114 @ Override
100115 public String transpose (Rewrite event , EvaluationContext context , String value )
@@ -117,8 +132,10 @@ public String transpose(Rewrite event, EvaluationContext context, String value)
117132 }
118133 catch (MissingResourceException e )
119134 {
120- throw new RewriteException ("Error occurred during Locale transposition of parameter value [" + value
121- + "] via bundle [" + bundleName + "_" + targetLang + "]" , e );
135+ if (onFailureOperation != null )
136+ {
137+ onFailureOperation .perform (event , context );
138+ }
122139 }
123140 }
124141
0 commit comments