KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openuss > presentation > enhydra > framework > multilanguage > PageTranslatorFactory


1 /**
2  * Title: OpenUSS - Open Source University Support System
3  * Description: Page Translator Factory for Presentation
4  * Copyright: Copyright (c) B. Lofi Dewanto
5  * Company: University of Muenster
6  * @author B. Lofi Dewanto
7  * @version 1.0
8  */

9 package org.openuss.presentation.enhydra.framework.multilanguage;
10
11 import com.lutris.appserver.server.httpPresentation.*;
12
13 import java.lang.reflect.*;
14
15 import java.util.*;
16
17 import org.enhydra.xml.xmlc.html.*;
18
19
20 /**
21  * Page Translator Factory for the presentation objects in Enhydra.
22  *
23  * @author B. Lofi Dewanto
24  * @version 1.0
25  */

26 public class PageTranslatorFactory {
27     // Static variables
28
private static String JavaDoc TRANSLATION_SUFFIX = "Translator";
29
30     /**
31      * Translate the page with its respective translation.
32      */

33     public static HTMLObjectImpl createAndTranslate(HttpPresentationComms comms,
34                                                     Locale locale,
35                                                     String JavaDoc fullClassName)
36                                              throws Exception JavaDoc {
37         // The name of the translation class is
38
// Page Name Class + Translator
39
// Example:
40
// - Page name : LoginApplicationDetailOfAssistant.java
41
// - Translation name : LoginApplicationDetailOfAssistantTranslator.java
42
String JavaDoc translationFullClassName = new String JavaDoc(fullClassName.concat(
43                                                              TRANSLATION_SUFFIX));
44
45         // Create the page and translate it
46
Class JavaDoc objectClass = Class.forName(translationFullClassName);
47
48         // Get the constructor
49
Class JavaDoc myHttpPresentationComms = Class.forName(
50                                                 "com.lutris.appserver.server.httpPresentation.HttpPresentationComms");
51         Class JavaDoc myLocale = Class.forName("java.util.Locale");
52         Class JavaDoc[] parameterTypes = new Class JavaDoc[2];
53         parameterTypes[0] = myHttpPresentationComms;
54         parameterTypes[1] = myLocale;
55
56         Constructor objectConstructor = objectClass.getConstructor(
57                                                 parameterTypes);
58
59         // Create the object with the constructor
60
// Translate the page and return it
61
Object JavaDoc[] initArgs = new Object JavaDoc[2];
62         initArgs[0] = comms;
63         initArgs[1] = locale;
64
65         BasePageTranslator translator = (BasePageTranslator) objectConstructor.newInstance(
66                                                 initArgs);
67
68         try {
69             translator.translatePage();
70         } catch (Exception JavaDoc ex) {
71             // Error on translation, just ignore
72
System.out.println("Error on translating the page: " +
73                                translator + " - " + ex);
74         }
75
76         return translator.getPage();
77     }
78 }
Popular Tags