<%
// first get the working dir
// String workingDir = System.getProperty("user.dir");
String workingDir = "/usr/local/apache/htdocs";
// this is the users directory
File userDir = new File(workingDir + "/webapps/MMAPI/deviceblog/users");
// a list of users
File users[] = userDir.listFiles();
if(!userDir.exists() || users.length == 0) {
out.println("No entries are present at this point");
return;
} else {
// and a sorted map of entries
TreeMap entryList = new TreeMap();
// traverse the users directories and look for the entries
// folder in each, which will contain a list of entries
for(int i = 0; i < users.length; i++) {
File entriesFolder = new File(users[i], "entries");
if(!entriesFolder.exists()) continue;
File[] entries = entriesFolder.listFiles();
for(int j = 0; j < entries.length; j++) {
entryList.put(entries[j].getName(), entries[j].getPath());
}
}
Collection entryFiles = entryList.values();
Iterator itr = entryFiles.iterator();
String title = "";
String str = "";
String user = "";
String postedOn = "";
String fileName = "";
String mediaFileName = "";
String mediaFilePath = "";
boolean image = false;
boolean audio = false;
boolean video = false;
while(itr.hasNext()) {
BufferedReader in = null;
String message = "";
try {
String path = (String)itr.next();
File file = new File(path);
if(file.isDirectory()) continue;
user = path.substring(
path.indexOf("users/") + 6,
path.indexOf("/entries"));
fileName = file.getName();
postedOn = fileName.substring(0, fileName.indexOf("."));
// read each entry file
in = new BufferedReader(new FileReader(file));
// the first line is the title
title = in.readLine();
// the second line is the media file, blank if no media file is there
mediaFileName = in.readLine();
// the next lines are the message
while ((str = in.readLine()) != null) {
message += str;
}
if(mediaFileName.length() != 0) { // means that this entry has media data
if(mediaFileName.startsWith("image")) image = true;
else if(mediaFileName.startsWith("audio")) audio = true;
else video = true;
mediaFilePath = "users/" + user + "/entries/" + mediaFileName;
}
%>