litesoft
@ 821
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.GWT.forms.server; import java.util.*; import org.litesoft.core.typeutils.*; import org.litesoft.ui_1_5.*; public class InterceptingProxyExternalization implements ExternalizationInterface { private ExternalizationInterface mProxied; protected Handler mCommons = new Handler(); protected Handler mLabelAndInputs = new Handler(); protected Handler mActions = new Handler(); protected Handler mErrors = new Handler(); private InterceptingProxyExternalization( ExternalizationInterface pProxied, Handler pCommons, // Handler pLabelAndInputs, Handler pAction, Handler pError ) { this( pProxied ); mCommons.addAll( pCommons ); mLabelAndInputs.addAll( pLabelAndInputs ); mActions.addAll( pAction ); mErrors.addAll( pError ); } public InterceptingProxyExternalization( ExternalizationInterface pProxied ) { mProxied = (pProxied != null) ? pProxied : UnresolvedExternalization.INSTANCE; } public InterceptingProxyExternalization( ExternalizationInterface pProxied, String... pKeyResolvedPairs ) { this( pProxied ); add( pKeyResolvedPairs ); } public InterceptingProxyExternalization( ExternalizationInterface pProxied, Map<String, String> pKeyResolvedPairs ) { this( pProxied ); add( pKeyResolvedPairs ); } public InterceptingProxyExternalization add( String pKey, String pResolved ) { mCommons.add( pKey, pResolved ); return this; } public InterceptingProxyExternalization addTooltip( String pKey, String pResolved ) { mCommons.addTooltip( pKey, pResolved ); return this; } public InterceptingProxyExternalization add( String... pKeyResolvedPairs ) { mCommons.add( pKeyResolvedPairs ); return this; } public InterceptingProxyExternalization add( Map<String, String> pKeyResolvedPairs ) { mCommons.add( pKeyResolvedPairs ); return this; } public InterceptingProxyExternalization addCommon( Entry pEntry ) { mCommons.add( pEntry ); return this; } public InterceptingProxyExternalization add( Label pEntry ) { mLabelAndInputs.add( pEntry ); return this; } public InterceptingProxyExternalization add( Action pEntry ) { mActions.add( pEntry ); return this; } public InterceptingProxyExternalization add( Input pEntry ) { mLabelAndInputs.add( pEntry ); return this; } public InterceptingProxyExternalization add( Error pEntry ) { mErrors.add( pEntry ); return this; } public InterceptingProxyExternalization add( String pKey, String pResolved, String pTooltip ) { addCommon( new Common( pKey, pResolved, pTooltip ) ); return this; } public InterceptingProxyExternalization addLabel( String pLabelID, String pResolved ) { add( new Label( pLabelID, pResolved ) ); return this; } public InterceptingProxyExternalization addAction( String pActionID, String pResolved ) { add( new Action( pActionID, pResolved ) ); return this; } public InterceptingProxyExternalization addAction( String pActionID, String pResolved, String pTooltip ) { add( new Action( pActionID, pResolved, pTooltip ) ); return this; } public InterceptingProxyExternalization addInput( String pInputID, String pResolved ) { add( new Input( pInputID, pResolved ) ); return this; } public InterceptingProxyExternalization addInput( String pInputID, String pResolved, String pTooltip ) { add( new Input( pInputID, pResolved, pTooltip ) ); return this; } public InterceptingProxyExternalization addError( String pErrorID, String pResolved ) { add( new Error( pErrorID, pResolved ) ); return this; } public InterceptingProxyExternalization addAll( Collector pCollector ) { if ( pCollector != null ) { for ( Entry entry : pCollector.getEntries() ) { switch ( entry.getType() ) { case Common: mCommons.add( entry ); break; case Label: mLabelAndInputs.add( entry ); break; case Action: mActions.add( entry ); break; case Input: mLabelAndInputs.add( entry ); break; case Error: mErrors.add( entry ); break; default: throw new IllegalStateException( "What is a Entry Type: " + entry.getType() ); } } } return this; } private class Handler implements ExternalizationSupport { public synchronized void addAll( Handler pEntries ) { mEntries.putAll( pEntries.mEntries ); } private Map<String, String> mEntries = new HashMap<String, String>(); private void LLadd( String pKey, String pResolved ) { mEntries.put( pKey, Entry.normalizeResolved( pResolved ) ); } public synchronized String getEntry( String pKey ) { return mEntries.get( Strings.deNull( pKey ).trim() ); } public String getTooltip( String pKey ) { return getEntry( Strings.deNull( pKey ).trim() + TOOLTIP ); } public String getEntry( String pKey, Handler pCommon ) { String rv = getEntry( pKey ); return (rv != null) ? rv : pCommon.getEntry( pKey ); } public String getTooltip( String pKey, Handler pCommon ) { String rv = getTooltip( pKey ); return (rv != null) ? rv : pCommon.getTooltip( pKey ); } public synchronized void add( String pKey, String pResolved ) { LLadd( Strings.assertNotNullNotEmpty( "Key", pKey ), pResolved ); } public synchronized void addTooltip( String pKey, String pResolved ) { LLadd( Strings.assertNotNullNotEmpty( "Key", pKey ) + TOOLTIP, pResolved ); } public synchronized void add( Entry pEntry ) { if ( pEntry != null ) { add( pEntry.getKey(), pEntry.getResolved() ); String tip = pEntry.getTooltip(); if ( tip != null ) { addTooltip( pEntry.getKey(), tip ); } } } public synchronized void add( String... pKeyResolvedPairs ) { if ( pKeyResolvedPairs != null ) { if ( (pKeyResolvedPairs.length & 1) != 0 ) { throw new IllegalArgumentException( "KeyResolvedPairs not Pairs, length: " + pKeyResolvedPairs.length ); } for ( int i = 0; i < pKeyResolvedPairs.length; i++ ) { String key = Strings.noEmpty( pKeyResolvedPairs[i] ); if ( key == null ) { throw new IllegalArgumentException( "KeyResolvedPair[" + i + "] was null or empty" ); } LLadd( key, pKeyResolvedPairs[++i] ); } } } public synchronized void add( Map<String, String> pKeyResolvedPairs ) { if ( pKeyResolvedPairs != null ) { for ( String keyEntry : pKeyResolvedPairs.keySet() ) { String key = Strings.noEmpty( keyEntry ); if ( key == null ) { throw new IllegalArgumentException( "KeyResolvedPair contained a null or empty key" ); } LLadd( key, pKeyResolvedPairs.get( keyEntry ) ); } } } } public ExternalizationInterface addContext( String pRootType ) { ExternalizationInterface newEI = mProxied.addContext( pRootType ); return (mProxied == newEI) ? this : // new InterceptingProxyExternalization( newEI, mCommons, mLabelAndInputs, mActions, mErrors ); } public String resolveLabel( String pLabelID ) { String entry = mLabelAndInputs.getEntry( pLabelID, mCommons ); return (entry != null) ? entry : mProxied.resolveLabel( pLabelID ); } public String resolveAction( String pActionID ) { String entry = mActions.getEntry( pActionID, mCommons ); return (entry != null) ? entry : mProxied.resolveAction( pActionID ); } public String resolveActionTooltip( String pActionID ) { String entry = mActions.getTooltip( pActionID, mCommons ); return (entry != null) ? entry : mProxied.resolveActionTooltip( pActionID ); } public String resolveInputTooltip( String pInputID ) { String entry = mLabelAndInputs.getTooltip( pInputID, mCommons ); return (entry != null) ? entry : mProxied.resolveInputTooltip( pInputID ); } public String resolveError( String pErrorID ) { String entry = mErrors.getEntry( pErrorID, mCommons ); return (entry != null) ? entry : mProxied.resolveError( pErrorID ); } } |
Commits for litesoft/trunk/Java/GWT/OldServer/src/org/litesoft/GWT/forms/server/InterceptingProxyExternalization.java
Revision | Author | Commited | Message |
---|---|---|---|
821 Diff | GeorgeS | Sun 19 Aug, 2012 00:08:41 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
60 Diff | GeorgeS | Tue 24 Aug, 2010 00:37:36 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |