-
Notifications
You must be signed in to change notification settings - Fork 12
/
OutputBuilder.java
98 lines (90 loc) · 4.28 KB
/
OutputBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.ndx.aadarchi.base;
import org.apache.commons.vfs2.FileObject;
import com.structurizr.model.Element;
public interface OutputBuilder {
public static interface HandledFormat {
/**
* get the used extension for this format, as declared in {@link OutputBuilder#outputFor(AgileArchitectureSection, Element, Enhancer, String)}
* @return file extension for that formt
*/
String getExtension();
/**
* Creates the comment documenting which enhancer generated that file.
* @param enhancer the enhabcer for which an asciidoc comment will be written
* @return a comment in the format specified indicating which enhancer generated the file
*/
String createCommentForEnhancer(Enhancer enhancer);
default String encoding() {
return "UTF-8";
}
}
/**
* This enum defines the formats we're able to write.
* It exists to ease things out for aadarchi developers, because the outputFor method
* using this enum as parameter is able to write comments for each enhancer, which is cool, believe me)
*/
public static enum Format implements HandledFormat {
adoc("adoc") {
@Override
public String createCommentForEnhancer(Enhancer enhancer) {
return String.format("// Generated by %s\n",
enhancer.getClass().getName());
}
};
private final String extension;
public String getExtension() {
return extension;
}
private Format(String extension) {
this.extension = extension;
}
}
/**
* Provide an output file for the given section and the given model element.
* @param section the section in which we want to add some content
* @param element the element to which we want to add some content
* @param format file format (without the dot!). Typically it will be "adoc"
* @param enhancer the enhancer producing that content
* @return a path, relative to base
* @deprecated prefer the version using the Format enum
*/
FileObject outputFor(AgileArchitectureSection section, Element element, Enhancer enhancer, String format);
/**
* Provide an output file for the given section and the given model element
* @param section the section in which we want to add some content
* @param element the element to which we want to add some content
* @param format file format. For asciidoc, one should use {@link Format#adoc}
* @param enhancer the enhancer producing that content
* @return a path, relative to base
*/
FileObject outputFor(AgileArchitectureSection section, Element element, Enhancer enhancer, HandledFormat format);
/**
* Write the given text in the output file for the given enhancer.
* BEWARE: This is not append. Content of file will be replaced.
* @param section the section in which we want to add some content
* @param element the element to which we want to add some content
* @param format file format. For asciidoc, one should use {@link Format#adoc}
* @param enhancer the enhancer producing that content
* @param text text to output
* @return the file in which content has been written, for later reference (typically useful for generating links)
*/
FileObject writeToOutput(AgileArchitectureSection section, Element element, Enhancer enhancer, HandledFormat format, CharSequence text);
/**
* Write the given text in the output file for the given enhancer.
* BEWARE: This is pure append. Any preexisting content will be kept.
* @param section the section in which we want to add some content
* @param element the element to which we want to add some content
* @param format file format. For asciidoc, one should use {@link Format#adoc}
* @param enhancer the enhancer producing that content
* @param text text to output
* @return the file in which content has been written, for later reference (typically useful for generating links)
*/
FileObject appendToOutput(AgileArchitectureSection section, Element element, Enhancer enhancer, HandledFormat format, CharSequence text);
/**
* Get the output directory in which all output is to be written.
* @param section the section in which we want to add some content
* @param element the element to which we want to add some content
* @return a file in which to write content
*/
FileObject outputDirectoryFor(AgileArchitectureSection section, Element element);
}