/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * See LICENSE.txt included in this distribution for the specific * language governing permissions and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at LICENSE.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * * Portions Copyright 2011 Jens Elkner. */ package org.opensolaris.opengrok.web; import java.io.File; import java.io.IOException; import java.io.Writer; import java.text.Format; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; import org.opensolaris.opengrok.configuration.RuntimeEnvironment; import org.opensolaris.opengrok.history.HistoryException; import org.opensolaris.opengrok.history.HistoryGuru; import org.opensolaris.opengrok.index.IgnoredNames; /** * Generates HTML listing of a Directory */ public class DirectoryListing { private final EftarFileReader desc; private final long now; public DirectoryListing() { desc = null; now = System.currentTimeMillis(); } public DirectoryListing(EftarFileReader desc) { this.desc = desc; now = System.currentTimeMillis(); } /** * Write part of HTML code which contains file/directory last * modification time and size. * * @param out write destination * @param child the file or directory to use for writing the data * @param modTime the time of the last commit that touched {@code child}, * or {@code null} if unknown * @param dateFormatter the formatter to use for pretty printing dates * * @throws NullPointerException if a parameter is {@code null} */ private void printDateSize(Writer out, File child, Date modTime, Format dateFormatter) throws IOException { long lastm = modTime == null ? child.lastModified() : modTime.getTime(); out.write("
\n"); out.write(" | Name | \n"); out.write("\n"); out.write(" | Date | \n"); out.write("Size | \n"); if (offset > 0) { out.write("Description | \n"); } out.write("
---|---|---|---|---|---|
"); out.write(".. | "); printDateSize(out, dir.getParentFile(), null, dateFormatter); out.write(" | ||||
"); out.write(""); out.write(" | "); out.write(file); out.write("/"); } else { out.write("\">"); out.write(file); out.write(""); } out.write(" | "); Util.writeHAD(out, contextPath, path + file, isDir); printDateSize(out, child, modTimes.get(file), dateFormatter); if (offset > 0) { String briefDesc = desc.getChildTag(parentFNode, file); if (briefDesc == null) { out.write(""); } else { out.write(" | "); out.write(briefDesc); out.write(" | "); } } out.write("