01: /*
02: * Translator.java February 2006
03: *
04: * Copyright (C) 2006, Niall Gallagher <niallg@users.sf.net>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General
16: * Public License along with this library; if not, write to the
17: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18: * Boston, MA 02111-1307 USA
19: */
20:
21: package simple.page.translate;
22:
23: import simple.page.Workspace;
24:
25: /**
26: * The <code>Translator</code> object is used to translate a JSP source
27: * file to a Java or Groovy source file. The translation process can be
28: * brokwn up into two phases, these are the build phase and the
29: * generation phase. In the build phase the document is parsed and a
30: * document definition is created as a <code>Definition</code> object.
31: * <p>
32: * The generation pahse uses the document definition constructed by the
33: * build phase to generate the Java or Groovy source required to
34: * compile the page into a usable, loadable object.,
35: *
36: * @author Niall Gallagher
37: *
38: * @see simple.page.compile.Compiler
39: */
40: public class Translator {
41:
42: /**
43: * This is used to generate a source file from the definition.
44: */
45: private Generator generator;
46:
47: /**
48: * This is used to build the document definition from the JSP.
49: */
50: private Builder builder;
51:
52: /**
53: * Constructor for the <code>Translator</code> object. This needs
54: * a workspace configuration in order to gather and compile the
55: * JSP sources. All JSP sources will be gathered from the workspace
56: * and written to a build path provided by the workspace.
57: *
58: * @param project this provides a workspace for translation
59: */
60: public Translator(Workspace project) {
61: this .generator = new Generator(project);
62: this .builder = new Builder(project);
63: }
64:
65: /**
66: * This method performs the translation of the JSP source file. The
67: * source file is translated as part of a two phase process. First
68: * the JSP file is build into a collection or code segments. Then
69: * the source is generated in the runtime language required. The
70: * possible runtime languages are Groovy and Java.
71: *
72: * @param target this is the JSP source file to be translated
73: */
74: public Source translate(String target) throws Exception {
75: Definition source = builder.build(target);
76: generator.generate(source);
77: return source;
78: }
79: }
|