1 package com.teamkonzept.webman; 2 3 import com.teamkonzept.web.*; 4 import com.teamkonzept.webman.db.*; 5 import com.teamkonzept.webman.db.queries.*; 6 import com.teamkonzept.db.*; 7 import com.teamkonzept.lib.*; 8 9 import java.sql.*; 10 11 public class TKWMContentSelectorReg extends TKClassRegistry { 12 13 protected TKHashtable resultTypes = new TKHashtable(); 14 15 public void registerClass( String selectionType, String selectionClass, int resultType ) 16 { 17 super.registerClass( selectionType, selectionClass ); 18 resultTypes.put( selectionType, Integer.toString( resultType ) ); 19 } 20 21 public final TKWMContentSelector getSelector( String selectionType ) 22 { 23 try { 24 return (TKWMContentSelector) get( selectionType ); 25 } 26 catch( Throwable t ) { 27 throw new Error ( t.getMessage() ); 28 } 29 } 30 31 public void _edit( TKHTMLTemplate t, String selectionType, int contentNodeId, String selectionData ) 32 { 33 String resultType = (String ) resultTypes.get( selectionType ); 34 TKHashtable dummyParams = new TKHashtable(4); 35 dummyParams.put( "SEL_TYPE", selectionType ); 36 dummyParams.put( "RES_TYPE", resultType ); 37 dummyParams.put( "NODE_ID", Integer.toString( contentNodeId ) ); 38 if( selectionData != null ) dummyParams.put( "SEL_DATA", selectionData ); 39 40 _modify( t, selectionType, TKWMContentSelector.ACTION_INIT, dummyParams ); 41 } 42 43 public void _modify( TKHTMLTemplate t, String selectionType, String action, TKHashtable params ) 44 { 45 getSelector( selectionType ).modifySelection( t, action, params ); 46 } 47 48 public String _getData( String selectionType, TKHashtable params ) 49 { 50 return getSelector( selectionType ).getSelectionData( params ); 51 } 52 53 public TKVector _select( String selectionType, String selectionData, int contentNodeId ) 54 { 55 return getSelector( selectionType ).doSelection( selectionData, contentNodeId ); 56 } 57 58 protected static TKWMContentSelectorReg registry = null; 60 protected static boolean initialized = false; 61 62 public static final void edit( TKHTMLTemplate t, String selectionType, int contentNodeId, String selectionData ) 63 { 64 if( !initialized ) initialize(); 65 registry._edit( t, selectionType, contentNodeId, selectionData ); 66 } 67 68 public static final void edit( TKHTMLTemplate t, String selectionType, int contentNodeId ) 69 { 70 edit( t, selectionType, contentNodeId, null ); 71 } 72 73 public static final void modify( TKHTMLTemplate t, String selectionType, String action, TKHashtable params ) 74 { 75 if( !initialized ) initialize(); 76 registry._modify( t, selectionType, action, params ); 77 } 78 79 public static final String getData( String selectionType, TKHashtable params ) 80 { 81 if( !initialized ) initialize(); 82 return registry._getData( selectionType, params ); 83 } 84 85 public static final TKVector select( String selectionType, String selectionData, int contentNodeId ) 86 { 87 if( !initialized ) initialize(); 88 return registry._select( selectionType, selectionData, contentNodeId ); 89 } 90 91 public static final synchronized void initialize() 92 { 93 if( initialized ) return; 94 95 initialized = true; 96 registry = new TKWMContentSelectorReg(); 97 98 try { 99 TKQuery q = TKWebmanDBManager.newQuery(TKDBContSelClassGetAll.class); 100 q.execute(); 101 ResultSet rs = q.fetchResultSet(); 102 103 while( rs.next() ) { 104 registry.registerClass( 105 rs.getString("SELECTION_TYPE"), 106 rs.getString("SELECTION_CLASS"), 107 rs.getInt("RESULT_TYPE") 108 ); 109 } 110 } 111 catch( SQLException e ) { 112 throw new TKSQLError( e.getMessage(), e ); 113 } 114 } 115 } | Popular Tags |