org.apache.jackrabbit.webdav.DavResource Java Examples

The following examples show how to use org.apache.jackrabbit.webdav.DavResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The DELETE method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doDelete(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {

	log.debug("doDelete");
	try {
		if (log.isDebugEnabled())
			log.debug("[DELETE] {} {}", (resource.isCollection() ? " FOLDER" : " DOCUMENT"),
					resource.getDisplayName());

		DavResource parent = resource.getCollection();
		if (parent != null) {
			parent.removeMember(resource);
			response.setStatus(DavServletResponse.SC_NO_CONTENT);
		} else {
			response.sendError(DavServletResponse.SC_FORBIDDEN, "Cannot remove the root resource.");
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #2
Source File: VersionControlledResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Modify the labels present with the versions of this resource.
 * 
 * @param labelInfo details of the label
 * 
 * @throws org.apache.jackrabbit.webdav.DavException error in the DAV communication
 * @see VersionControlledResource#label(LabelInfo)
 * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String,
 *      boolean)
 * @see javax.jcr.version.VersionHistory#removeVersionLabel(String)
 */
public void label(LabelInfo labelInfo) throws DavException {
	if (labelInfo == null) {
		throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required.");
	}
	if (!exists()) {
		throw new DavException(DavServletResponse.SC_NOT_FOUND);
	}

	try {
		if (!isVersionControlled()) {
			throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED,
					"A LABEL request may only be applied to a version-controlled, checked-in resource.");
		}
		DavResource[] resArr = this.getReferenceResources(CHECKED_IN);
		if (resArr.length == 1 && resArr[0] instanceof VersionResource) {
			((VersionResource) resArr[0]).label(labelInfo);
		} else {
			throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:checked-in property on '"
					+ getHref() + "' did not point to a single VersionResource.");
		}
	} catch (Exception e) {

	}
}
 
Example #3
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The REPORT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doReport(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doReport");

	ReportInfo info = request.getReportInfo();
	Report report;
	if (resource instanceof DeltaVResource) {
		report = ((DeltaVResource) resource).getReport(info);
	} else if (resource instanceof AclResource) {
		report = ((AclResource) resource).getReport(info);
	} else {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}

	int statusCode = (report.isMultiStatusReport()) ? DavServletResponse.SC_MULTI_STATUS : DavServletResponse.SC_OK;
	response.sendXmlResponse(report, statusCode);
}
 
Example #4
Source File: DavResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds a new member to this resource.
 * 
 * @see DavResource#addMember(DavResource,
 *      org.apache.jackrabbit.webdav.io.InputContext)
 */
public void addMember(DavResource member, InputContext inputContext) throws DavException {
	if (!exists()) {
		throw new DavException(DavServletResponse.SC_CONFLICT);
	}
	if (isLocked(this) || isLocked(member)) {
		throw new DavException(DavServletResponse.SC_LOCKED);
	}

	try {
		String memberName = Text.getName(member.getLocator().getResourcePath());

		ImportContext ctx = getImportContext(inputContext, memberName);

		if (!config.getIOManager().importContent(ctx, member)) {
			// any changes should have been reverted in the importer
			throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
Example #5
Source File: DavResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see DavResource#removeMember(DavResource)
 */
public void removeMember(DavResource member) throws DavException {
	if (!exists() || !member.exists()) {
		throw new DavException(DavServletResponse.SC_NOT_FOUND);
	}
	if (isLocked(this) || isLocked(member)) {
		throw new DavException(DavServletResponse.SC_LOCKED);
	}

	try {
		Resource resource = resourceService.getResource(member.getLocator().getResourcePath(), session);
		// set the requesting person
		resource.setRequestedPerson(this.resource.getRequestedPerson());

		resourceService.deleteResource(resource, session);
	} catch (DavException de) {
		throw de;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #6
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistantResourceShould404()
    throws Exception
{
    Path dir = baseDir.resolve( "testdir" );
    try
    {
        DavResource directoryResource = getDavResource( "/testdir", dir );
        directoryResource.getCollection().removeMember( directoryResource );
        fail( "Did not throw DavException" );
    }
    catch ( DavException e )
    {
        assertEquals( DavServletResponse.SC_NOT_FOUND, e.getErrorCode() );
    }
}
 
Example #7
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
	try {
		DavResource resource = getFromCache(session, locator.getResourcePath());
		if (resource != null)
			return resource;

		Resource res = resourceService.getResource(locator.getResourcePath(), session);
		resource = createResource(locator, session, res);

		putInCache(session, resource);
		return resource;
	} catch (Throwable e) {
		log.error(e.getMessage(), e);
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #8
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The OPTION method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 */
protected void doOptions(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doOptions");

	response.addHeader(DavConstants.HEADER_DAV, resource.getComplianceClass());
	response.addHeader("Allow", resource.getSupportedMethods());
	response.addHeader("MS-Author-Via", DavConstants.HEADER_DAV);
	if (resource instanceof SearchResource) {
		String[] langs = ((SearchResource) resource).getQueryGrammerSet().getQueryLanguages();
		for (int i = 0; i < langs.length; i++) {
			response.addHeader(SearchConstants.HEADER_DASL, "<" + langs[i] + ">");
		}
	}
	// with DeltaV the OPTIONS request may contain a Xml body.
	OptionsResponse oR = null;
	OptionsInfo oInfo = request.getOptionsInfo();
	if (oInfo != null && resource instanceof DeltaVResource) {
		oR = ((DeltaVResource) resource).getOptionResponse(oInfo);
	}
	if (oR == null) {
		response.setStatus(DavServletResponse.SC_OK);
	} else {
		response.sendXmlResponse(oR, DavServletResponse.SC_OK);
	}
}
 
Example #9
Source File: IOManagerImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean exportContent(ExportContext context, DavResource resource) throws IOException {
	boolean success = false;
	if (context != null && resource != null) {

		IOHandler[] ioHandlers = getIOHandlers();
		for (int i = 0; i < ioHandlers.length && !success; i++) {
			IOHandler ioh = ioHandlers[i];
			if (ioh.canExport(context, resource)) {

				success = ioh.exportContent(context, resource);

			}
		}
		context.informCompleted(success);
	}
	return success;
}
 
Example #10
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The COPY method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doCopy(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doCopy");
	// only depth 0 and infinity is allowed
	int depth = request.getDepth(DEPTH_INFINITY);
	if (!(depth == DEPTH_0 || depth == DEPTH_INFINITY)) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	DavResource destResource = null;
	try {
		destResource = getResourceFactory().createResource(request.getDestinationLocator(), request);
	} catch (Throwable e) {
		destResource = resource.getCollection();
	}
	int status = validateDestination(destResource, request);
	if (status > DavServletResponse.SC_NO_CONTENT) {
		response.sendError(status);
		return;
	}

	resource.copy(destResource, depth == DEPTH_0);
	response.setStatus(status);
}
 
Example #11
Source File: DeltaVResourceImpl.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
	DavProperty prop = getProperty(hrefPropertyName);
	List resources = new ArrayList();
	if (prop != null && prop instanceof HrefProperty) {
		HrefProperty hp = (HrefProperty) prop;
		// process list of hrefs
		List hrefs = hp.getHrefs();
		for (Iterator iter = hrefs.iterator(); iter.hasNext();) {
			String href = (String) iter.next();
			DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(),
					href);
			resources.add(createResourceFromLocator(locator));
		}
	} else {
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
	}
	return (DavResource[]) resources.toArray(new DavResource[0]);
}
 
Example #12
Source File: DavResourceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCollection()
    throws Exception
{
    Path dir = baseDir.resolve( "testdir" );
    try
    {
        assertNotNull( Files.createDirectories(dir) );
        DavResource directoryResource = getDavResource( "/testdir", dir );
        directoryResource.getCollection().removeMember( directoryResource );
        assertFalse( Files.exists(dir) );
    }
    finally
    {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory( dir );
    }
}
 
Example #13
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * The PROPPATCH method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 */
@SuppressWarnings("rawtypes")
protected void doPropPatch(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws IOException, DavException {
	log.debug("doPropPatch");

	List changeList = request.getPropPatchChangeList();
	if (changeList.isEmpty()) {
		response.sendError(DavServletResponse.SC_BAD_REQUEST);
		return;
	}

	MultiStatus ms = new MultiStatus();
	MultiStatusResponse msr = resource.alterProperties(changeList);
	ms.addResponse(msr);
	response.sendMultiStatus(ms);
}
 
Example #14
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public DavResourceIterator getMembers()
{
    List<DavResource> list;
    if ( exists() && isCollection() )
    {
        list = asset.list().stream().filter( m -> !m.getName().startsWith( HIDDEN_PATH_PREFIX ) )
            .map(m -> {
                String path = locator.getResourcePath( ) + '/' + m.getName();
                DavResourceLocator resourceLocator =
                    locator.getFactory( ).createResourceLocator( locator.getPrefix( ), path );
                try
                {
                    return factory.createResource( resourceLocator, session );
                }
                catch ( DavException e )
                {
                    return null;
                }

            }).filter( Objects::nonNull ).collect( Collectors.toList());
    } else {
        list = Collections.emptyList( );
    }
    return new DavResourceIteratorImpl( list );
}
 
Example #15
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public DavResource getCollection()
{
    DavResource parent = null;
    if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
    {
        String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
        if ( parentPath.equals( "" ) )
        {
            parentPath = "/";
        }
        DavResourceLocator parentloc =
            locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
        try
        {
            parent = factory.createResource( parentloc, session );
        }
        catch ( DavException e )
        {
            // should not occur
        }
    }
    return parent;
}
 
Example #16
Source File: ArchivaVirtualDavResource.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public DavResource getCollection()
{
    DavResource parent = null;
    if ( getResourcePath() != null && !getResourcePath().equals( "/" ) )
    {
        String parentPath = Text.getRelativeParent( getResourcePath(), 1 );
        if ( parentPath.equals( "" ) )
        {
            parentPath = "/";
        }
        DavResourceLocator parentloc =
            locator.getFactory().createResourceLocator( locator.getPrefix(), parentPath );
        try
        {
            // go back to ArchivaDavResourceFactory!
            parent = factory.createResource( parentloc, null );
        }
        catch ( DavException e )
        {
            // should not occur
        }
    }
    return parent;
}
 
Example #17
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavSession session)
		throws DavException {

	try {
		String resourcePath = locator.getResourcePath();
		Matcher matcher = versionRequestPattern.matcher(locator.getResourcePath());

		String version = null;
		if (matcher.matches() == true) {
			version = matcher.group(1);
			resourcePath = resourcePath.replaceFirst("/vstore/" + version, "");
		}

		DavResource resource;

		Resource repositoryResource = resourceService.getResource(resourcePath, session);

		if (repositoryResource == null) {
			boolean isCollection = DavMethods.isCreateCollectionRequest(request);
			resource = createNullResource(locator, session, isCollection);
		} else {
			repositoryResource.setVersionLabel(version);
			repositoryResource.setRequestedPerson(Long.parseLong(session.getObject("id").toString()));
			resource = new VersionControlledResourceImpl(locator, this, session, resourceConfig, repositoryResource);
		}

		putInCache(session, resource);
		return resource;
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
	}
}
 
Example #18
Source File: IOManagerImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean importContent(ImportContext context, DavResource resource) throws IOException {
	boolean success = false;
	if (context != null && resource != null) {

		IOHandler[] ioHandlers = getIOHandlers();
		for (int i = 0; i < ioHandlers.length && !success; i++) {
			IOHandler ioh = ioHandlers[i];
			if (ioh.canImport(context, resource)) {
				success = ioh.importContent(context, resource);
			}
		}
		context.informCompleted(success);
	}
	return success;
}
 
Example #19
Source File: DavResourceTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public DavResource createResource( DavResourceLocator locator, DavServletRequest request,
                                   DavServletResponse response )
    throws DavException
{
    throw new UnsupportedOperationException( "Not supported yet." );
}
 
Example #20
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Puts an entry in the cache
 * 
 * @param session The curent DAV session
 * @param resource The entry to be cached
 */
public void putInCache(DavSession session, DavResource resource) {
	try {
		ContextProperties config = Context.get().getProperties();
		if ("true".equals(config.getProperty("webdav.usecache"))) {
			// Initialize the collection of children
			Cache cache = ((CacheManager) Context.get().getBean("DavCacheManager"))
					.getCache("dav-resources");
			Element element = new Element(session.getObject("id") + ";" + resource.getResourcePath(), resource);
			cache.put(element);
		}
	} catch (Throwable t) {

	}
}
 
Example #21
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void doVersionControl(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doVersionControl");
	if (!(resource instanceof VersionableResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionableResource) resource).addVersionControl();
}
 
Example #22
Source File: AbstractWebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The EVENT_UNCHECKOUT method
 * 
 * @param request the HTTP request
 * @param response the server's response
 * @param resource the DAV resource
 * 
 * @throws IOException generic I/O error
 * @throws DavException error in the DAV communication
 */
protected void doUncheckout(WebdavRequest request, WebdavResponse response, DavResource resource)
		throws DavException, IOException {
	log.debug("doUncheckout(" + resource.getDisplayName() + ")");
	if (!(resource instanceof VersionControlledResource)) {
		response.sendError(DavServletResponse.SC_METHOD_NOT_ALLOWED);
		return;
	}
	((VersionControlledResource) resource).uncheckout();
	response.setStatus(DavServletResponse.SC_OK);
}
 
Example #23
Source File: DavResourceFactoryImpl.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DavResource createResource(DavResourceLocator locator, DavSession session, Resource resource)
		throws DavException {
	DavResource res = getFromCache(session, locator.getResourcePath());
	if (res != null)
		return res;

	res = new VersionControlledResourceImpl(locator, this, session, resourceConfig, resource);
	putInCache(session, res);
	return res;
}
 
Example #24
Source File: WebdavServlet.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
protected boolean isPreconditionValid(WebdavRequest request, DavResource resource) {
	if (resource.getDisplayName().toLowerCase().equals("thumbs.db"))
		return false;

	return !resource.exists() || request.matchesIfHeader(resource);
}
 
Example #25
Source File: DavResourceTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public DavResource createResource( DavResourceLocator locator, DavSession session )
    throws DavException
{
    try
    {
        return new ArchivaDavResource( new FilesystemAsset(repository, "/" , baseDir.toAbsolutePath()), "/", repository, session, resourceLocator,
                                       resourceFactory, mimeTypes, Collections.<AuditListener> emptyList(),
                                       null );
    }
    catch ( LayoutException e )
    {
        throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
    }
}
 
Example #26
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void move( DavResource destination )
    throws DavException
{
    if ( !exists() )
    {
        throw new DavException( HttpServletResponse.SC_NOT_FOUND, "Resource to copy does not exist." );
    }

    try
    {
        ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( destination );
        if ( isCollection() )
        {
            this.asset = repositoryStorage.moveAsset( asset, destination.getResourcePath() );
            triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_DIRECTORY );
        }
        else
        {
            this.asset = repositoryStorage.moveAsset( asset, destination.getResourcePath() );
            triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_FILE );
        }

        log.debug( "{}{}' moved to '{}' (current user '{}')", ( isCollection() ? "Directory '" : "File '" ),
                   asset.getPath(), destination, this.principal );

    }
    catch ( IOException e )
    {
        throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
    }
}
 
Example #27
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void triggerAuditEvent( DavResource member, String action )
    throws DavException
{
    String path = logicalResource + "/" + member.getDisplayName();

    ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member );
    AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, action );
    auditEvent.setRemoteIP( resource.remoteAddr );

    for ( AuditListener listener : auditListeners )
    {
        listener.auditEvent( auditEvent );
    }
}
 
Example #28
Source File: ArchivaDavResource.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void removeMember( DavResource member )
    throws DavException
{
    StorageAsset resource = checkDavResourceIsArchivaDavResource( member ).getAsset( );

    if ( resource.exists() )
    {
        try
        {
            if ( resource.isContainer() )
            {
                repositoryStorage.removeAsset( resource );
                triggerAuditEvent( member, AuditEvent.REMOVE_DIR );
            }
            else
            {
                repositoryStorage.removeAsset( resource );
                triggerAuditEvent( member, AuditEvent.REMOVE_FILE );
            }

            log.debug( "{}{}' removed (current user '{}')", ( resource.isContainer() ? "Directory '" : "File '" ),
                       member.getDisplayName(), this.principal );

        }
        catch ( IOException e )
        {
            throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
        }
    }
    else
    {
        throw new DavException( HttpServletResponse.SC_NOT_FOUND );
    }
}
 
Example #29
Source File: DavContentBase.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public DavResourceIterator getMembers() {
    // while it would be ideal to throw an UnsupportedOperationException,
    // MultiStatus tries to add a MultiStatusResponse for every member
    // of a WebDavResource regardless of whether or not it's a collection,
    // so we need to return an empty iterator.
    return new DavResourceIteratorImpl(new ArrayList<DavResource>());
}
 
Example #30
Source File: ArchivaDavResourceFactory.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void setHeaders( DavServletResponse response, DavResourceLocator locator, DavResource resource,
                         boolean group )
{
    // [MRM-503] - Metadata file need Pragma:no-cache response
    // header.
    if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || ( resource instanceof ArchivaDavResource
        && ( ArchivaDavResource.class.cast( resource ).getAsset().isContainer() ) ) )
    {
        response.setHeader( "Pragma", "no-cache" );
        response.setHeader( "Cache-Control", "no-cache" );
        response.setDateHeader( "Last-Modified", new Date().getTime() );
    }
    // if the resource is a directory don't cache it as new groupId deployed will be available
    // without need of refreshing browser
    else if ( locator.getResourcePath().endsWith( "/maven-metadata.xml" ) || (
        resource instanceof ArchivaVirtualDavResource && ( Files.isDirectory(Paths.get(
            ArchivaVirtualDavResource.class.cast( resource ).getLogicalResource() )) ) ) )
    {
        response.setHeader( "Pragma", "no-cache" );
        response.setHeader( "Cache-Control", "no-cache" );
        response.setDateHeader( "Last-Modified", new Date().getTime() );
    }
    else if ( group )
    {
        if ( resource instanceof ArchivaVirtualDavResource )
        {
            //MRM-1854 here we have a directory so force "Last-Modified"
            response.setDateHeader( "Last-Modified", new Date().getTime() );
        }
    }
    else
    {
        // We need to specify this so connecting wagons can work correctly
        response.setDateHeader( "Last-Modified", resource.getModificationTime() );
    }
    // TODO: [MRM-524] determine http caching options for other types of files (artifacts, sha1, md5, snapshots)
}