directory listing builder implementation
This commit is contained in:
parent
a8d0393194
commit
92d9a14057
@ -29,7 +29,7 @@
|
|||||||
//Send default directory.
|
//Send default directory.
|
||||||
CreateRequest(client,"200","OK","testfile.html");
|
CreateRequest(client,"200","OK","testfile.html");
|
||||||
} else {
|
} else {
|
||||||
CreateRequest(client,"200","OK",requestloc.replace("/",""));
|
CreateRequest(client,"200","OK",requestloc.replaceFirst("/",""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.CopyOption;
|
import java.nio.file.CopyOption;
|
||||||
import java.nio.file.DirectoryNotEmptyException;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -13,15 +12,14 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class sigPlace {
|
public class sigPlace {
|
||||||
|
|
||||||
final static String ROOTDIR = "sitefiles";
|
final static String ROOTDIR = "sitefiles";
|
||||||
final static String REFDIR = "ref";
|
final static String REFDIR = "ref";
|
||||||
final static String OUTDIR = "out";
|
final static String OUTDIR = "out";
|
||||||
|
final static String DIRECTORYLISTING_FILENAME = "DIRECTORY_LISTING";
|
||||||
static int PORT = 8080;
|
static int PORT = 8080;
|
||||||
|
|
||||||
final static HashMap<String,String> map = new HashMap<>(Map.ofEntries(
|
final static HashMap<String,String> map = new HashMap<>(Map.ofEntries(
|
||||||
@ -108,7 +106,19 @@ public class sigPlace {
|
|||||||
}
|
}
|
||||||
}catch (IOException e) {
|
}catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
System.err.println("Copying files over failed!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Building directory listings...");
|
||||||
|
try {
|
||||||
|
buildDirectoryListings();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("Failed to build directory listings!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Site has been built into the "+OUTDIR+" directory.");
|
System.out.println("Site has been built into the "+OUTDIR+" directory.");
|
||||||
|
|
||||||
ExportCodeFile();
|
ExportCodeFile();
|
||||||
@ -133,6 +143,21 @@ public class sigPlace {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
static void buildDirectoryListings()
|
||||||
|
throws IOException {
|
||||||
|
String startingPath=Paths.get(sigPlace.OUTDIR).toAbsolutePath().toString();
|
||||||
|
HashMap<String,List<Path>> map = new HashMap<>();
|
||||||
|
Iterator<Path> it = Files.walk(Paths.get(sigPlace.OUTDIR)).iterator();
|
||||||
|
map.put("/",new ArrayList<Path>());
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Path f = it.next();
|
||||||
|
String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),"");
|
||||||
|
System.out.println(myKey+","+f);
|
||||||
|
map.putIfAbsent(myKey,new ArrayList<Path>());
|
||||||
|
map.get(myKey).add(f);
|
||||||
|
}
|
||||||
|
System.out.println(map);
|
||||||
|
}
|
||||||
private static boolean isArticleFile(Path f) {
|
private static boolean isArticleFile(Path f) {
|
||||||
return f.getFileName().toString().contains(".article");
|
return f.getFileName().toString().contains(".article");
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class sigServer {
|
|||||||
//Send default directory.
|
//Send default directory.
|
||||||
CreateRequest(client,"200","OK","testfile.html");
|
CreateRequest(client,"200","OK","testfile.html");
|
||||||
} else {
|
} else {
|
||||||
CreateRequest(client,"200","OK",requestloc.replace("/",""));
|
CreateRequest(client,"200","OK",requestloc.replaceFirst("/",""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -83,11 +83,16 @@ public class sigServer {
|
|||||||
OutputStream clientOutput = client.getOutputStream();
|
OutputStream clientOutput = client.getOutputStream();
|
||||||
if (statusCode.equals("200")) {
|
if (statusCode.equals("200")) {
|
||||||
if (Files.exists(file)) {
|
if (Files.exists(file)) {
|
||||||
|
if (Files.isDirectory(file)) {
|
||||||
|
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html",Files.readAllBytes(Paths.get(sigPlace.OUTDIR,string,sigPlace.DIRECTORYLISTING_FILENAME)));
|
||||||
|
clientOutput.write(("<div class=\"generateTime\">Webpage generated in "+(System.currentTimeMillis()-startTime)+"ms</div>\r\n").getBytes());
|
||||||
|
} else {
|
||||||
CreateRawRequest(clientOutput,statusCode,statusMsg,Files.probeContentType(file),Files.readAllBytes(file));
|
CreateRawRequest(clientOutput,statusCode,statusMsg,Files.probeContentType(file),Files.readAllBytes(file));
|
||||||
String contentType = Files.probeContentType(file);
|
String contentType = Files.probeContentType(file);
|
||||||
if (contentType!=null&&contentType.equals("text/html")) {
|
if (contentType!=null&&contentType.equals("text/html")) {
|
||||||
clientOutput.write(("<div class=\"generateTime\">Webpage generated in "+(System.currentTimeMillis()-startTime)+"ms</div>\r\n").getBytes());
|
clientOutput.write(("<div class=\"generateTime\">Webpage generated in "+(System.currentTimeMillis()-startTime)+"ms</div>\r\n").getBytes());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage is in another castle!".getBytes());
|
CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage is in another castle!".getBytes());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user