KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > tagshandler > TranslatorTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.tagshandler;
6
7 import java.util.Properties JavaDoc;
8
9 import xdoclet.XDocletException;
10 import xdoclet.XDocletTagSupport;
11 import xdoclet.util.DocletUtil;
12 import xdoclet.util.Translator;
13
14 /**
15  * Wrapper around the {@link xdoclet.util.Translator}, allowing text in generated files to be localised using the
16  * resource bundles generated by the {@link xdoclet.modules.externalizer.ExternalizerSubTask externalizer} subtask.
17  *
18  * @author <a HREF="mailto:stevensa@users.sourceforge.net">Andrew Stevens</a>
19  * @created Jan 24, 2002
20  * @xdoclet.taghandler namespace="I18n"
21  * @version $Revision: 1.10 $
22  */

23 public class TranslatorTagsHandler extends XDocletTagSupport
24 {
25     /**
26      * Returns a localized text string.
27      *
28      * @param attributes The attributes of the template tag
29      * @return The localized string
30      * @exception XDocletException Description of Exception
31      * @see xdoclet.util.Translator#getString(String,String,String[])
32      * @doc.tag type="content"
33      * @doc.param name="bundle" optional="true" description="The base name of the resource bundle to
34      * use e.g. xdoclet.modules.ejb (corresponding to
35      * modules/ejb/src/xdoclet/modules/ejb/resources/Messages.properties) etc. It defaults to xdoclet"
36      * @doc.param name="resource" optional="false" description="The resource key to look up in the
37      * bundle."
38      * @doc.param name="arguments" optional="true" description="An optional list of arguments to be
39      * substituted for any placeholders ({0}, {1} etc.) in the resource value string."
40      * @doc.param name="delimiter" optional="true" description="The arguments parameter is delimited
41      * by the string specified in the delimiter parameter (default is a comma)."
42      */

43     public String JavaDoc getString(Properties JavaDoc attributes) throws XDocletException
44     {
45         String JavaDoc bundleKey = attributes.getProperty("bundle");
46         String JavaDoc resourceKey = attributes.getProperty("resource");
47         String JavaDoc argumentsStr = attributes.getProperty("arguments");
48         String JavaDoc delimiter = attributes.getProperty("delimiter");
49
50         String JavaDoc[] arguments = null;
51
52         if (argumentsStr != null) {
53             if (delimiter == null) {
54                 delimiter = PARAMETER_DELIMITER;
55             }
56
57             arguments = DocletUtil.tokenizeDelimitedToArray(argumentsStr, delimiter);
58         }
59         if (bundleKey == null) {
60             bundleKey = "xdoclet.XDocletMessages";
61         }
62
63         return Translator.getString(bundleKey + "Messages", resourceKey, arguments);
64     }
65
66 }
67
Popular Tags