KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > externalizer > PropertiesTranslatorSubTask


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

5 package xdoclet.modules.externalizer;
6
7 import java.text.MessageFormat JavaDoc;
8
9 import xjavadoc.*;
10
11 import xdoclet.TemplateSubTask;
12 import xdoclet.XDocletException;
13
14 /**
15  * Creates translator classes for convenient access to externalized resource bundles.
16  *
17  * @author Konstantin Pribluda(kpriblouda@yahoo.com)
18  * @created October 5, 2002
19  * @ant.element display-name="Properties Translator" name="propertiestranslator" parent="xdoclet.DocletTask"
20  * @xdoclet.merge-file file="translator-custom.xdt" relates-to="{0}Translator.java" description="Custom Java code to
21  * be included in generated Translator classes."
22  * @version $Revision: 1.6 $
23  */

24 public class PropertiesTranslatorSubTask extends TemplateSubTask
25 {
26     public final static String JavaDoc GENERATED_FILE_NAME = "{0}Translator.java";
27     private static String JavaDoc DEFAULT_TEMPLATE_FILE = "resources/translator.xdt";
28
29
30     /**
31      * constructor for properties generator subtask
32      */

33     public PropertiesTranslatorSubTask()
34     {
35         // accept only files with message bundle attribute set
36
setHavingClassTag("msg.bundle");
37         setTemplateURL(getClass().getResource(DEFAULT_TEMPLATE_FILE));
38         setDestinationFile(GENERATED_FILE_NAME);
39
40     }
41
42
43     /**
44      * Compute file name for generated translator class bundle.
45      *
46      * @param clazz class
47      * @return filename
48      * @exception XDocletException
49      */

50     protected String JavaDoc getGeneratedFileFileName(XClass clazz) throws XDocletException
51     {
52         String JavaDoc result = MessageFormat.format(getDestinationFile(), new Object JavaDoc[]{clazz.getQualifiedName().replace('.', '/')});
53
54         return result;
55     }
56
57 }
58
Popular Tags