Hi All,

        Hope all is well.

        Attached is a patch to the I18nTransformer to support transform
        time configuration changes. The parameters given at definition time
        can now also be overridden as map:parameter's to change the defaults
        specified at definition time (all except the cache-at-startup option).

        eg.

<map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer">
        <catalogue-name>messages</catalogue-name>
        <catalogue-location>translations</catalogue-location>
</map:transformer>

...
...
...

<map:transform type="i18n">
        <map:parameter name="catalogue-name" value="msg"/>
</map:transform>

        Hope it's all ok. Hope everyone has a great weekend.

        Cheers,

        Marcus
-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'     Email : [EMAIL PROTECTED]
          &&&&.        Business Hours : +49 69 9757 200
    &&&&&&&:
Index: src/org/apache/cocoon/transformation/I18nTransformer.java
===================================================================
RCS file: 
/home/cvspublic/xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java,v
retrieving revision 1.8.2.13
diff -u -r1.8.2.13 I18nTransformer.java
--- src/org/apache/cocoon/transformation/I18nTransformer.java   2001/10/26 15:32:52    
 1.8.2.13
+++ src/org/apache/cocoon/transformation/I18nTransformer.java   2001/12/07 17:56:08
@@ -17,6 +17,7 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.excalibur.pool.Recyclable;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.ResourceNotFoundException;
 import org.apache.cocoon.acting.LocaleAction;
@@ -150,6 +151,11 @@
  * </pre>
  *
  * <p/>
+ *
+ * Note, <strong>catalogue-name</strong>, <strong>catalogue-location</strong>
+ * and <strong>untranslated-text</strong> can all be overridden at the
+ * pipeline level by specifying them as parameters to the transform statement.
+ *
  * <ul>
  *  <li><strong><i18n:date/></strong> gives now only the date.</li>
  *  <li><strong><i18n:date-time/></strong> gives the date and time.</li>
@@ -173,17 +179,16 @@
  * Future work coming:
  *
  * <ul>
- *  <li>Ability to override definition parameters in the pipeline
  *  <li>Many clean ups :-)
  * </ul>
  *
- * @author <a href="mailto:[EMAIL PROTECTED]";>Marcus Crafter</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Marcus Crafter</a>
  * @author <a href="mailto:[EMAIL PROTECTED]";>Konstantin Piroumian</a>
  * @author <a href="mailto:[EMAIL PROTECTED]";>Lassi Immonen</a>
  * @author <a href="mailto:[EMAIL PROTECTED]";>Michael Enke</a>
  */
 public class I18nTransformer extends AbstractTransformer
-        implements Composable, Poolable, Configurable {
+        implements Composable, Poolable, Configurable, Recyclable {
 
     private static final String FILE = "file:";
 
@@ -339,6 +344,7 @@
     private String catalogueName;
     private String catalogueLocation;
     private String untranslated;
+    private String globalUntranslated;
     private boolean cacheAtStartup;
 
     /**
@@ -394,11 +400,35 @@
 
         try {
 
+            // check parameters to see if anything has been locally overloaded
+            String localCatLocation = null;
+            String localCatName = null;
+            String localUntranslated = null;
+
+            if ( parameters != null ) {
+                localCatLocation =
+                    parameters.getParameter( I18N_CATALOGUE_LOCATION, null );
+                localCatName =
+                    parameters.getParameter( I18N_CATALOGUE_NAME, null );
+                localUntranslated =
+                    parameters.getParameter( I18N_UNTRANSLATED, null );
+            }
+
+            // if untranslated-text has been overridden, save the original 
+            // value so it can be restored when this object is recycled.
+            if ( localUntranslated != null ) {
+                globalUntranslated = untranslated;
+                untranslated = localUntranslated;
+            }
+
             // Set current language and locale
             String lc = LocaleAction.getLocale( objectModel );
 
             // configure the factory
-            _setup( resolver );
+            _setup( resolver,
+                    localCatLocation == null
+                       ? catalogueLocation : localCatLocation
+            );
 
             // setup everything for the current locale
             String[] matches = new RE( "_" ).split( lc );
@@ -412,7 +442,10 @@
             debug( "using locale " + locale.toString() );
 
             dictionary =
-                    (XMLResourceBundle) factory.select( catalogueName, locale );
+                    (XMLResourceBundle) factory.select( 
+                       localCatName == null ? catalogueName : localCatName,
+                       locale
+                    );
 
             debug( "selected dictionary " + dictionary );
 
@@ -430,7 +463,8 @@
      * REVISIT: when we can get the resolver anywhere, we can pass the
      * configuration object directly to XMLResourceBundle.
      */
-    private void _setup( SourceResolver resolver ) throws Exception {
+    private void _setup( SourceResolver resolver, String location )
+             throws Exception {
 
         // configure the factory to log correctly and cache catalogues
         DefaultConfiguration configuration =
@@ -450,8 +484,8 @@
                         "location"
                 );
 
-        debug( "catalog location:" + catalogueLocation );
-        Source source = resolver.resolve( catalogueLocation );
+        debug( "catalog location:" + location );
+        Source source = resolver.resolve( location );
         String systemId = source.getSystemId();
         if ( !systemId.startsWith( FILE ) ) {
             throw new ResourceNotFoundException( systemId + " does not denote a 
directory" );
@@ -1155,4 +1189,14 @@
      }
      */
 
+    public void recycle() {
+
+        // restore untranslated-text if necessary
+        if ( globalUntranslated != null &&
+             !untranslated.equals( globalUntranslated )
+        ) {
+            untranslated = globalUntranslated;
+            debug( "untranslated-text restored to " + untranslated );
+        }
+    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to