package org.argeo.slc.web.ajaxplorer.file; import java.io.File; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.web.ajaxplorer.AjxpDriverException; public class AjxpFile { private final static Log log = LogFactory.getLog(AjxpFile.class); // FIXME: more generic modif time format? private final static SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy hh:mm"); private final File file; private final String parentPath; private final String filePath; private final String ext; private final FileType type; public AjxpFile(File file, String parentPath) { this.file = file; this.parentPath = parentPath; if (parentPath.equals("/")) { this.filePath = "/" + file.getName(); } else { this.filePath = parentPath + "/" + file.getName(); } this.ext = file.isDirectory() ? null : file.getName().substring( file.getName().indexOf('.') + 1); this.type = FileType.findType(ext); } public String toXml(final LsMode mode, final String encoding) { try { StringBuffer buf = new StringBuffer(); buf.append(""); if (log.isTraceEnabled()) log.trace(buf.toString()); return buf.toString(); } catch (Exception e) { throw new AjxpDriverException("Could not serialize file " + file, e); } } private String formatModifTime() { return sdf.format(new Date(file.lastModified())); } private String formatFileSize() { return (file.length() / 1024) + " Kb"; } protected void addAttr(String attrName, String attrValue, StringBuffer buf) { buf.append(" ").append(attrName).append("=\"").append(attrValue) .append("\""); } /** To be overridden, do nothing by default. */ protected void addAdditionalAttrs(final StringBuffer buf, final LsMode mode, final String encoding) { } }