Skip to content

Commit

Permalink
date format implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Mar 27, 2015
1 parent afce471 commit 5dc85aa
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -103,13 +103,21 @@ private StringBuilder getContentXMLOfFileSystemDirectory(String path) throws Exc
StringBuilder sb = new StringBuilder();
sb.append("<dir:directory yanel:path=\"" + getPath() + "\" dir:name=\"" + new File(path).getName() + "\" dir:path=\"" + path + "\" xmlns:dir=\"http://apache.org/cocoon/directory/2.0\" xmlns:yanel=\"http://www.wyona.org/yanel/resource/directory/1.0\">");

// TODO: Make ordering/sorting configurable!
log.warn("TODO: Make order/sorting configurable!");
File[] children = new File(path).listFiles();
Calendar calendar = Calendar.getInstance();
if (children != null) {
for (int i = 0; i < children.length; i++) {
if (children[i].isFile()) {
calendar.setTimeInMillis(children[i].lastModified());
String lastModified = DateUtil.format(calendar.getTime());
log.warn("DEBUG: File last modified: " + lastModified);
if (getResourceConfigProperty("date-format") != null) {
java.text.DateFormat df = new java.text.SimpleDateFormat(getResourceConfigProperty("date-format"));
lastModified = df.format(children[i].lastModified());
log.warn("DEBUG: File last modified (formatted): " + lastModified);
}
sb.append("<dir:file path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\" lastModified=\"" + children[i].lastModified() + "\" date=\"" + lastModified + "\" size=\"" + children[i].length() + "\"/>");
} else if (children[i].isDirectory()) {
calendar.setTimeInMillis(children[i].lastModified());
Expand Down Expand Up @@ -170,6 +178,12 @@ private StringBuilder getContentXMLOfYarepNode(String path) throws Exception {
if (children[i].isResource()) {
calendar.setTimeInMillis(children[i].getLastModified());
String lastModified = DateUtil.format(calendar.getTime());
log.warn("DEBUG: File last modified: " + lastModified);
if (getResourceConfigProperty("date-format") != null) {
java.text.DateFormat df = new java.text.SimpleDateFormat(getResourceConfigProperty("date-format"));
lastModified = df.format(children[i].getLastModified());
log.warn("DEBUG: File last modified (formatted): " + lastModified);
}
sb.append("<dir:file path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\" lastModified=\"" + children[i].getLastModified() + "\" date=\"" + lastModified + "\" size=\"" + children[i].getSize() + "\"/>");
} else if (children[i].isCollection()) {
sb.append("<dir:directory path=\"" + children[i].getPath() + "\" name=\"" + children[i].getName() + "\"/>");
Expand Down Expand Up @@ -249,6 +263,7 @@ private StreamSource getXSLTStreamSource() throws Exception {
return new StreamSource(getRealm().getRepository().getNode(customDefaultXSLT).getInputStream());
}

// INFO: If no property 'default-xslt' set, then fallback to XSLT part of this resource
File defaultXSLTFile = org.wyona.commons.io.FileUtil.file(rtd.getConfigFile().getParentFile().getAbsolutePath(), "xslt" + File.separator + "dir2xhtml.xsl");
if (log.isDebugEnabled()) log.debug("XSLT file: " + defaultXSLTFile);
return new StreamSource(defaultXSLTFile);
Expand Down

0 comments on commit 5dc85aa

Please sign in to comment.