cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/transformation I18nTransformer.java
Date Sun, 09 Dec 2001 21:30:01 GMT
giacomo     01/12/09 13:30:01

  Modified:    src/org/apache/cocoon/transformation I18nTransformer.java
  Log:
  Patched I18nTransformer to support transform
  time configuration changes.
  Submitted by:	Marcus Crafter <crafterm@fztig938.bank.dresdner.net>
  
  Revision  Changes    Path
  1.24      +52 -8     xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java
  
  Index: I18nTransformer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/I18nTransformer.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- I18nTransformer.java	2001/10/25 20:15:38	1.23
  +++ I18nTransformer.java	2001/12/09 21:30:01	1.24
  @@ -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:Marcus.Crafter@osa.de">Marcus Crafter</a>
  + * @author <a href="mailto:Marcus.Crafter@managesoft.com">Marcus Crafter</a>
    * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
    * @author <a href="mailto:lassi.immonen@valkeus.com">Lassi Immonen</a>
    * @author <a href="mailto:Michael.Enke@wincor-nixdorf.com">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
  +                    );
   
               //FIXME(DIMS): Why should i do this explicitly? Is there an alternative?
               dictionary.compose( this.manager );
  @@ -433,7 +466,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 =
  @@ -453,8 +487,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"
);
  @@ -1158,4 +1192,14 @@
        }
        */
   
  +    public void recycle() {
  +
  +        // restore untranslated-text if necessary
  +        if ( globalUntranslated != null &&
  +             !untranslated.equals( globalUntranslated )
  +        ) {
  +            untranslated = globalUntranslated;
  +            debug( "untranslated-text restored to " + untranslated );
  +        }
  +    }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message