001 // Copyright 2006-2007 Daniel Gredler 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package net.sf.beanform.util; 016 017 /** 018 * Utility class that can determine the version of Tapestry being used in the current 019 * runtime environment, providing version-specific data to the rest of the library. 020 * 021 * @author Daniel Gredler 022 */ 023 public final class TapestryCompat { 024 025 private final static boolean IS_TAPESTRY_41 = isTapestry41(); 026 027 final static String TAPESTRY_41_CANCEL_JS = "tapestry.form.cancel(this.form)"; 028 final static String TAPESTRY_40_CANCEL_JS = "this.form.events.cancel()"; 029 030 final static String TAPESTRY_41_REFRESH_JS = "tapestry.form.refresh(this.form)"; 031 final static String TAPESTRY_40_REFRESH_JS = "this.form.events.refresh()"; 032 033 TapestryCompat() { 034 // Empty. 035 } 036 037 public static String getCancelJavaScript() { 038 if( IS_TAPESTRY_41 ) return TAPESTRY_41_CANCEL_JS; 039 else return TAPESTRY_40_CANCEL_JS; 040 } 041 042 public static String getRefreshJavaScript() { 043 if( IS_TAPESTRY_41 ) return TAPESTRY_41_REFRESH_JS; 044 else return TAPESTRY_40_REFRESH_JS; 045 } 046 047 private static boolean isTapestry41() { 048 boolean isTapestry41; 049 try { 050 Class.forName( "org.apache.tapestry.IJSONRender" ); 051 isTapestry41 = true; 052 } 053 catch( Throwable t ) { 054 isTapestry41 = false; 055 } 056 return isTapestry41; 057 } 058 059 }