View Javadoc

1   // Copyright 2006 Daniel Gredler
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package net.sf.beanform.util;
16  
17  /***
18   * Utility class that can determine the version of Tapestry being used in the current
19   * runtime environment, providing version-specific data to the rest of the library.
20   *
21   * @author Daniel Gredler
22   */
23  public final class TapestryCompat {
24  
25      private final static boolean IS_TAPESTRY_41 = isTapestry41();
26  
27      final static String TAPESTRY_41_CANCEL_JS = "tapestry.form.cancel(this.form)";
28      final static String TAPESTRY_40_CANCEL_JS = "this.form.events.cancel()";
29  
30      final static String TAPESTRY_41_REFRESH_JS = "tapestry.form.refresh(this.form)";
31      final static String TAPESTRY_40_REFRESH_JS = "this.form.events.refresh()";
32  
33      TapestryCompat() {
34          // Empty.
35      }
36  
37      public static String getCancelJavaScript() {
38          if( IS_TAPESTRY_41 ) return TAPESTRY_41_CANCEL_JS;
39          else return TAPESTRY_40_CANCEL_JS;
40      }
41  
42      public static String getRefreshJavaScript() {
43          if( IS_TAPESTRY_41 ) return TAPESTRY_41_REFRESH_JS;
44          else return TAPESTRY_40_REFRESH_JS;
45      }
46  
47      private static boolean isTapestry41() {
48          boolean isTapestry41;
49          try {
50              Class.forName( "org.apache.tapestry.IJSONRender" );
51              isTapestry41 = true;
52          }
53          catch( Throwable t ) {
54              isTapestry41 = false;
55          }
56          return isTapestry41;
57      }
58  
59  }