-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathShared.java
More file actions
228 lines (192 loc) · 5.26 KB
/
Shared.java
File metadata and controls
228 lines (192 loc) · 5.26 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package writers;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.sun.javadoc.Doc;
import com.sun.javadoc.ProgramElementDoc;
public class Shared {
// what we're looking for
private static Shared instance;
private String webrefTagName = "webref";
private String seeAlsoTagName = "see_external";
private String coreClassName = "PApplet";
private ArrayList<String> descriptionSets;
//where things go
private String outputDirectory = "web_reference";
private String localOutputDirectory = "local_reference";
private String imageDirectory = "images";
private String fileExtension = ".html";
//where things come from
private String templateDirectory = "templates";
private String exampleDirectory = "web_examples";
private String includeDirectory = "include";
boolean noisy = false;
public ArrayList<String> corePackages;
public ArrayList<String> rootClasses;
private Shared(){
corePackages = new ArrayList<String>();
rootClasses = new ArrayList<String>();
descriptionSets = new ArrayList<String>();
addDescriptionTag("description");
}
public static Shared i()
{
if(instance == null)
{
instance = new Shared();
}
return instance;
}
public String getWebrefTagName(){
return webrefTagName;
}
public String getSeeAlsoTagName()
{
return seeAlsoTagName;
}
public void setIncludeDirectory( String s )
{
includeDirectory = s;
}
public String getIncludeDirectory()
{
return includeDirectory + "/";
}
public void setWebrefTagName(String webrefTagName)
{
this.webrefTagName = webrefTagName;
}
public void setCoreClassName(String coreClassName)
{
this.coreClassName = coreClassName;
}
public String getCoreClassName()
{
return coreClassName;
}
public void addDescriptionTag(String s) {
System.out.println( "Added description tag: " + s );
descriptionSets.add( "/root/"+s );
descriptionSets.add( "/root/js_mode/"+s );
}
public ArrayList<String> getDescriptionSets() {
return descriptionSets;
}
public void setOutputDirectory(String outputDirectory) {
this.outputDirectory = outputDirectory;
}
public String getOutputDirectory() {
return outputDirectory;
}
public void setFileExtension(String fileExtension) {
this.fileExtension = fileExtension;
}
public String getFileExtension() {
return fileExtension;
}
public void setTemplateDirectory(String templateDirectory) {
this.templateDirectory = templateDirectory;
}
public String getTemplateDirectory() {
return templateDirectory;
}
public String TEMPLATE_DIRECTORY(){
return templateDirectory + "/";
}
public void setExampleDirectory(String exampleDirectory) {
this.exampleDirectory = exampleDirectory;
}
public String getExampleDirectory() {
return exampleDirectory;
}
public String getXMLDirectory(){
return exampleDirectory + "/";
}
public void setImageDirectory(String imageDirectory) {
this.imageDirectory = imageDirectory;
}
public String getImageDirectory(){
return imageDirectory + "/";
}
public void setLocalOutputDirectory(String localOutputDirectory) {
this.localOutputDirectory = localOutputDirectory;
}
public String getLocalOutputDirectory()
{
return localOutputDirectory + "/";
}
public String OUTPUT_DIRECTORY()
{
return outputDirectory + "/";
}
public boolean isCore(ProgramElementDoc doc){
return corePackages.contains(doc.containingPackage().name());
}
public boolean isWebref(ProgramElementDoc doc){
return doc.tags(webrefTagName).length > 0;
}
public boolean isRootLevel(ProgramElementDoc doc){
if(doc.isClass() || doc.isInterface()){
return rootClasses.contains(doc.name());
} else {
return rootClasses.contains(doc.containingClass().name());
}
}
public boolean isNoisy(){
return noisy;
}
public void setNoisy(boolean b){
noisy = b;
}
public void createOutputDirectory(String dir){
System.out.println("Creating output directory: " + dir );
File f = new File(getLocalOutputDirectory() + dir);
f.mkdirs();
f = new File(OUTPUT_DIRECTORY() + dir);
f.mkdirs();
}
public static Document loadXmlDocument( String path )
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder;
Document doc = null;
try {
builder = factory.newDocumentBuilder();
doc = builder.parse( path );
} catch (ParserConfigurationException e) {
System.out.println("Failed to parse " + path );
System.out.println( e.getLocalizedMessage() );
} catch (SAXException e) {
System.out.println("Failed to parse " + path );
System.out.println( e.getLocalizedMessage() );
} catch (IOException e) {
System.out.println("Failed to parse " + path );
System.out.println( e.getLocalizedMessage() );
}
return doc;
}
public void createBaseDirectories(){
File f = new File(getLocalOutputDirectory());
f.mkdirs();
f = new File(OUTPUT_DIRECTORY());
f.mkdirs();
}
public boolean shouldOmit(Doc doc){
if( doc.tags("nowebref").length > 0 )
{
return true;
}
if( doc.tags("notWebref").length > 0 )
{
return true;
}
// if none found, we should include
return false;
}
}