1 /*
2 * Copyright 2006 Outsource Cafe, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the 'License')
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an 'AS IS' BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.javagen.agile.core.emitter;
17
18 import java.io.File;
19
20 import org.javagen.agile.core.context.Context;
21 import org.javagen.agile.core.util.NanoTemplate;
22
23 /***
24 * Output file name and path are bound using passed in context and NanoTemplate engine.
25 *
26 * @author Richard Easterling
27 */
28 public class DefaultArtifact implements Artifact {
29
30 protected String outputDirectoryProperty;
31 protected String fileNameProperty;
32
33 public DefaultArtifact() {
34 }
35
36 public DefaultArtifact(String outputDirectoryProperty, String fileNameProperty) {
37 this.outputDirectoryProperty = outputDirectoryProperty;
38 this.fileNameProperty = fileNameProperty;
39 }
40
41 public File outputFileName(Context context) {
42 if (fileNameProperty==null) {
43 throw new IllegalArgumentException("fileNameProperty not set");
44 }
45 String path = NanoTemplate.bindVariables(fileNameProperty, context);
46 return new File(path);
47 }
48
49 public File outputDirectory(Context context) {
50 if (outputDirectoryProperty==null) {
51 throw new IllegalArgumentException("outputDirectoryProperty not set");
52 }
53 String path = NanoTemplate.bindVariables(outputDirectoryProperty, context);
54 return new File(path);
55 }
56
57
58 //
59 // protected String outputDirectoryTemplateKey;
60 // protected String fileNameTemplateKey;
61 //
62 // public DefaultArtifact() {
63 // this(Keys.OUTPUT_DIRECTORY_TEMPLATE.toString(), Keys.FILE_NAME_TEMPLATE.toString());
64 // }
65 //
66 // public DefaultArtifact(String outputDirectoryTemplateKey) {
67 // this(outputDirectoryTemplateKey, Keys.FILE_NAME_TEMPLATE.toString());
68 // }
69 //
70 // public DefaultArtifact(String outputDirectoryTemplateKey, String fileNameTemplateKey) {
71 // this.outputDirectoryTemplateKey = outputDirectoryTemplateKey;
72 // this.fileNameTemplateKey = fileNameTemplateKey;
73 // }
74 //
75 // public File outputFileName(Context context) {
76 // String template = (String)context.get(fileNameTemplateKey);
77 // if (template==null) {
78 // throw new IllegalArgumentException("no artifact key found in context under: "+fileNameTemplateKey);
79 // }
80 // String path = NanoTemplate.bindVariables(template, context);
81 // return new File(path);
82 // }
83 //
84 // public File outputDirectory(Context context) {
85 // String template = (String)context.get(outputDirectoryTemplateKey);
86 // if (template==null) {
87 // throw new IllegalArgumentException("no artifact key found in context under: "+outputDirectoryTemplateKey);
88 // }
89 // String path = NanoTemplate.bindVariables(template, context);
90 // return new File(path);
91 // }
92 //
93
94 }