From cocoon-cvs-return-4294-apmail-xml-cocoon-cvs-archive=xml.apache.org@xml.apache.org Sun Dec 09 21:49:52 2001 Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 42209 invoked by uid 500); 9 Dec 2001 21:49:51 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 42200 invoked by uid 500); 9 Dec 2001 21:49:51 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 9 Dec 2001 21:30:01 -0000 Message-ID: <20011209213001.56727.qmail@icarus.apache.org> From: giacomo@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/org/apache/cocoon/transformation I18nTransformer.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 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 @@ * * *

+ * + * Note, catalogue-name, catalogue-location + * and untranslated-text can all be overridden at the + * pipeline level by specifying them as parameters to the transform statement. + * *

    *
  • gives now only the date.
  • *
  • gives the date and time.
  • @@ -173,17 +179,16 @@ * Future work coming: * *
      - *
    • Ability to override definition parameters in the pipeline *
    • Many clean ups :-) *
    * - * @author Marcus Crafter + * @author Marcus Crafter * @author Konstantin Piroumian * @author Lassi Immonen * @author Michael Enke */ 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