From: <jbo...@li...> - 2005-08-11 15:48:53
|
Author: adamw Date: 2005-08-11 11:47:30 -0400 (Thu, 11 Aug 2005) New Revision: 822 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/XmlInputFactory.java Log: Downloads extensions Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java 2005-08-11 12:54:04 UTC (rev 821) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadsDescriptor.java 2005-08-11 15:47:30 UTC (rev 822) @@ -9,6 +9,8 @@ package org.jboss.forge.common.projects; import java.io.IOException; +import java.text.DateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -262,6 +264,12 @@ public void fillContextShallow(PropertiesMap properties, DelegateContext context) { String id = properties.get("id").getFirstValue(); + String pathToFile = separator + projectId + + separator + componentDir + separator + + pathCategoryContext + separator + id; + + boolean outsideFile = false; + /* * Checking if this is the link to a file is not an absolute * one; if it is not, then we prepend the prefix that was @@ -272,14 +280,31 @@ if ((id.startsWith("http://")) || (id.startsWith("ftp://"))) { context.put("link", id); context.put("size", properties.get("size").getFirstValue()); + outsideFile = true; } else { context.put("link", downloadPrefix + pathCategoryContext + separator + id); - context.put("size", getFileSize(isf, separator + projectId - + separator + componentDir + separator - + pathCategoryContext + separator + id)); + context.put("size", getFileSize(isf, pathToFile)); } + + context.put("license", properties.get("license").getFirstValue()); + + /* + * Adding release date information - trying to read it from the + * properties, and if there is no such info, auto-generating it. + */ + if (properties.hasValues("release")) + context.put("release", properties.get("release").getFirstValue()); + else + /* + * If this is an outside file, then we cannot determine its + * release date. + */ + if (!outsideFile) + context.put("release", DateFormat.getDateInstance( + DateFormat.SHORT).format( + getFileModification(isf, pathToFile))); } public void fillContext(PropertiesMap properties, @@ -296,6 +321,19 @@ } /** + * Computes the last modification time of the given file. + * + * @param isf + * A factory of XML files. + * @param file + * Name of the file which last modification time should be computed. + * @return A date holding last modification of the given file. + */ + private Date getFileModification(XmlInputFactory isf, String file) { + return new Date(isf.getLastModification(file)); + } + + /** * Computes the length of the given file and returns it in a short form as a * string with a proper suffix (MB, KB, B). * @@ -307,7 +345,7 @@ * given file. */ private String getFileSize(XmlInputFactory isf, String file) { - long length = isf.getFileLength(file); + long length = isf.getLength(file); String suffix = "B"; if (length >= 1048576) { suffix = "MB"; Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/XmlInputFactory.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/XmlInputFactory.java 2005-08-11 12:54:04 UTC (rev 821) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/XmlInputFactory.java 2005-08-11 15:47:30 UTC (rev 822) @@ -63,16 +63,28 @@ } /** - * Gets the file length of a resource with the given identifier. Needed for + * Gets the length of a resource with the given identifier. Needed for * the downloads descriptor. * * @param identifier * Identifier of the resource to check. * @return Length of the given resource. */ - public long getFileLength(String identifier) { + public long getLength(String identifier) { return cm.getLength(identifier); } + + /** + * Gets the last modification time of a resource with the given identifier. + * Needed for the downloads descriptor. + * + * @param identifier + * Identifier of the resource to check. + * @return Last modification time of the given resource. + */ + public long getLastModification(String identifier) { + return cm.getLastModification(identifier); + } public static XmlInputFactory getContentReadingInstance(ContentManager cm) { return new XmlInputFactory(cm); |