/********************************************************************************** * $URL: https://source.sakaiproject.org/svn/kernel/trunk/kernel-impl/src/main/java/org/sakaiproject/content/impl/CollectionAccessFormatter.java $ * $Id: CollectionAccessFormatter.java 51317 2008-08-24 04:38:02Z csev@umich.edu $ *********************************************************************************** * * Copyright (c) 2006, 2007, 2008 Sakai Foundation * * Licensed under the Educational Community License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.osedu.org/licenses/ECL-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * **********************************************************************************/ package org.sakaiproject.content.impl; import java.io.PrintWriter; import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.sakaiproject.component.cover.ServerConfigurationService; import org.sakaiproject.content.api.ContentCollection; import org.sakaiproject.content.api.ContentResource; import org.sakaiproject.content.cover.ContentHostingService; import org.sakaiproject.entity.api.Entity; import org.sakaiproject.entity.api.Reference; import org.sakaiproject.entity.api.ResourceProperties; import org.sakaiproject.time.api.Time; import org.sakaiproject.user.api.User; import org.sakaiproject.user.api.UserNotDefinedException; import org.sakaiproject.user.cover.UserDirectoryService; import org.sakaiproject.util.Validator; /** *
* CollectionAccessFormatter is formatter for collection access. *
*/ public class CollectionAccessFormatter { /** * Format the collection as an HTML display. */ public static void format(ContentCollection x, Reference ref, HttpServletRequest req, HttpServletResponse res, String accessPointTrue, String accessPointFalse) { // do not allow directory listings for /attachments and its subfolders if(ContentHostingService.isAttachmentResource(x.getId())) { try { res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } catch ( java.io.IOException e ) { return; } } PrintWriter out = null; // don't set the writer until we verify that // getallresources is going to work. boolean printedHeader = false; boolean printedDiv = false; String path = ref.getId(); String basedir = req.getParameter("sbasedir"); // path may have been transformed by an alias // we need origpath to check whether there was as trailing / String origpath = req.getPathInfo(); String querystring = req.getQueryString(); // set access to /access/content, must skip http://host String access = accessPointFalse; int i = access.indexOf("://"); if (i > 0) i = access.indexOf("/", i + 3); if (i > 0) access = access.substring(i); boolean sferyx = true; if (basedir == null || basedir.equals("")) { sferyx = false; basedir = req.getParameter("basedir"); } String field = req.getParameter("field"); // System.out.println("basedir " + basedir); if (field == null) field = "url"; try { List members = x.getMemberResources(); // we will need resources. getting them once makes the sort a whole lot faster // System.out.println("before sort have " + members.size()); boolean hasCustomSort = false; try { hasCustomSort = x.getProperties().getBooleanProperty(ResourceProperties.PROP_HAS_CUSTOM_SORT); } catch (Exception e) { // use false that's already there } if (sferyx || basedir != null) Collections.sort(members, new ContentHostingComparator(ResourceProperties.PROP_DISPLAY_NAME, true)); else if (hasCustomSort) Collections.sort(members, new ContentHostingComparator(ResourceProperties.PROP_CONTENT_PRIORITY, true)); else Collections.sort(members, new ContentHostingComparator(ResourceProperties.PROP_DISPLAY_NAME, true)); // System.out.println("after sort have " + members.size()); Iterator xi = members.iterator(); res.setContentType("text/html; charset=UTF-8"); out = res.getWriter(); if (sferyx) { out .println("Up one level |