01: /*
02: * This file is part of "SnipSnap Radeox Rendering Engine".
03: *
04: * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
05: * All Rights Reserved.
06: *
07: * Please visit http://radeox.org/ for updates and contact.
08: *
09: * --LICENSE NOTICE--
10: * Licensed under the Apache License, Version 2.0 (the "License");
11: * you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software
17: * distributed under the License is distributed on an "AS IS" BASIS,
18: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19: * See the License for the specific language governing permissions and
20: * limitations under the License.
21: * --LICENSE NOTICE--
22: */
23:
24: package examples;
25:
26: import groovy.lang.GroovyClassLoader;
27: import org.radeox.macro.Macro;
28:
29: import java.io.ByteArrayInputStream;
30: import java.io.InputStream;
31:
32: // cut:start-1
33: public class GroovyMacroCompiler {
34: public Macro compileMacro(String macroSource) {
35: Macro macro = null;
36: try {
37: GroovyClassLoader gcl = new GroovyClassLoader();
38: InputStream is = new ByteArrayInputStream(macroSource
39: .getBytes());
40: Class clazz = gcl.parseClass(is, "Macro.groovy");
41: Object aScript = clazz.newInstance();
42: macro = (Macro) aScript;
43: } catch (Exception e) {
44: System.err.println("Cannot compile groovy macro.");
45: }
46: return macro;
47: }
48: }
49: // cut:end-1
|