Skip to content

Commit a5b8b44

Browse files
committed
Standardized logic comparing "content" folders in the WebSite class
1 parent 6b432ff commit a5b8b44

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/javaxt/express/cms/WebSite.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ public abstract class WebSite extends HttpServlet {
3535
".html", ".txt"
3636
};
3737

38-
private String[] DefaultFileNames = new String[]{
39-
"home", "index", "Overview"
38+
/** */
39+
private String[] defaultFileNames = new String[]{
40+
"home", "index", "Overview"
4041
};
4142

43+
private String[] contentFolders = new String[]{
44+
"content",
45+
"documentation", //javaxt.com
46+
"wiki" //legacy
47+
};
4248

4349

4450
//**************************************************************************
@@ -204,10 +210,15 @@ public void processRequest(HttpServletRequest request, HttpServletResponse respo
204210
}
205211
else if (ext.equals("txt")){
206212

207-
//Don't send text files from the wiki directory
213+
//Don't send text files from any of the content folders (e.g. wiki directory)
208214
String filePath = file.getDirectory().toString();
209-
int idx = filePath.indexOf("/wiki/");
210-
sendFile = (idx==-1);
215+
for (String folderName : contentFolders){
216+
int idx = filePath.indexOf("/" + folderName + "/");
217+
if (idx>-1){
218+
sendFile = false;
219+
break;
220+
}
221+
}
211222
}
212223

213224
if (sendFile){
@@ -392,7 +403,7 @@ private void sendHTML(HttpServletRequest request, HttpServletResponse response)
392403
else{
393404
if (file!=null){
394405
title = file.getName(false);
395-
for (String fileName : DefaultFileNames){
406+
for (String fileName : defaultFileNames){
396407
if (title.equalsIgnoreCase(fileName)){
397408
title = file.getDirectory().getName();
398409
break;
@@ -679,7 +690,7 @@ private javaxt.io.File getHtmlFile(java.net.URL url){
679690

680691
//If we are still here, check whether the url is missing a content folder
681692
//in its path (e.g. "documentation", "wiki").
682-
String[] contentFolders = new String[]{"documentation", "wiki"};
693+
683694
for (String folderName : contentFolders){
684695

685696
folderPath = web + folderName + "/";
@@ -716,7 +727,7 @@ private javaxt.io.File getFile(String path, String folderPath){
716727
javaxt.io.Directory dir = new javaxt.io.Directory(folderPath + path);
717728
//System.out.println("Search: " + dir + " <--" + dir.exists());
718729
if (dir.exists()){
719-
for (String fileName : DefaultFileNames){
730+
for (String fileName : defaultFileNames){
720731
for (String fileExtension : fileExtensions){
721732

722733
javaxt.io.File file = new javaxt.io.File(dir, fileName + fileExtension);

0 commit comments

Comments
 (0)