Example usage for org.springframework.web.context.support WebApplicationContextUtils findWebApplicationContext

List of usage examples for org.springframework.web.context.support WebApplicationContextUtils findWebApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.context.support WebApplicationContextUtils findWebApplicationContext.

Prototype

@Nullable
public static WebApplicationContext findWebApplicationContext(ServletContext sc) 

Source Link

Document

Find a unique WebApplicationContext for this web app: either the root web app context (preferred) or a unique WebApplicationContext among the registered ServletContext attributes (typically coming from a single DispatcherServlet in the current web application).

Usage

From source file:org.unitedinternet.cosmo.dav.provider.CalendarCollectionProvider.java

/**
 * @param collectionItem//from w ww  .j a v  a  2  s .co m
 * @return
 */
private Calendar getCalendarFromCollection(DavRequest req, CollectionItem collectionItem) {
    Calendar result = new Calendar();

    if (productId == null) {
        synchronized (this) {
            if (productId == null) {
                Environment environment = WebApplicationContextUtils
                        .findWebApplicationContext(req.getServletContext()).getEnvironment();
                productId = environment.getProperty(PRODUCT_ID_KEY);
            }
        }
    }

    result.getProperties().add(new ProdId(productId));
    result.getProperties().add(Version.VERSION_2_0);
    result.getProperties().add(CalScale.GREGORIAN);

    for (Item item : collectionItem.getChildren()) {
        if (!NoteItem.class.isInstance(item)) {
            continue;
        }
        for (Stamp s : item.getStamps()) {
            if (BaseEventStamp.class.isInstance(s)) {
                BaseEventStamp baseEventStamp = BaseEventStamp.class.cast(s);
                result.getComponents().add(baseEventStamp.getEvent());
            }
        }
    }
    return result;
}