Package org.apache.jetspeed.capabilities

Examples of org.apache.jetspeed.capabilities.CapabilityMap


    }

    public void invoke( RequestContext request, ValveContext context ) throws PipelineException
    {
        CapabilityMap cm = request.getCapabilityMap();

        if (cm != null && this.clientToMediaTypeMap != null)
        {
            Client client = cm.getClient();
            String mediaTypeName = (String) this.clientToMediaTypeMap.get(client.getName());
           
            if (mediaTypeName != null)
            {
                MediaType mediaType = this.capabilities.getMediaType(mediaTypeName);
                cm.setPreferredMediaType(mediaType);
                request.setMediaType(mediaTypeName);
            }
        }

        // Pass control to the next Valve in the Pipeline
View Full Code Here


     * @throws TemplateLocatorException
     */
    protected LocatorDescriptor getTemplateLocatorDescriptor(RenderRequest request) throws TemplateLocatorException
    {
        RequestContext requestContext = getRequestContext(request);
        CapabilityMap capabilityMap = requestContext.getCapabilityMap();
        Locale locale = requestContext.getLocale();

        LocatorDescriptor templateLocatorDescriptor = templateLocator.createLocatorDescriptor(null);
        templateLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName());
        templateLocatorDescriptor.setCountry(locale.getCountry());
        templateLocatorDescriptor.setLanguage(locale.getLanguage());
        return templateLocatorDescriptor;    
    }
View Full Code Here

     * @throws TemplateLocatorException
     */
    protected LocatorDescriptor getDecoratorLocatorDescriptor(RenderRequest request) throws TemplateLocatorException
    {
        RequestContext requestContext = getRequestContext(request);
        CapabilityMap capabilityMap = requestContext.getCapabilityMap();
        Locale locale = requestContext.getLocale();
 
        LocatorDescriptor decorationLocatorDescriptor = decorationLocator.createLocatorDescriptor(null);
        decorationLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName());
        decorationLocatorDescriptor.setCountry(locale.getCountry());
        decorationLocatorDescriptor.setLanguage(locale.getLanguage());
       
        return decorationLocatorDescriptor;
    }
View Full Code Here

                Page page = requestContext.getPage();
                layoutDecoration = page.getEffectiveDefaultDecorator(layoutType);
            }
           
            // get layout capabilites and locale
            CapabilityMap capabilityMap = requestContext.getCapabilityMap();
            Locale locale = requestContext.getLocale();
            String layoutMediaType = capabilityMap.getPreferredMediaType().getName();
            String layoutLanguage = locale.getLanguage();
            String layoutCountry = locale.getCountry();
           
            // lookup cache config based on decoration cache key
            String cacheKey = layoutDecoration + ":" + layoutType + ":" + layoutMediaType + ":" + layoutLanguage + ":" + layoutCountry;
View Full Code Here

     * @throws UnableToBuildCapabilityMapException
     * @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
     */
    public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException
    {       
        CapabilityMap map = null;
        boolean bClientFound = false;
        String defaultAgent = null;

        if (userAgent == null)
        {
            userAgent = DEFAULT_AGENT;
        }

        // Check the cache if we have already a capability map for
        // the given Agent
        map = (CapabilityMap) capabilityMapCache.get(userAgent);

        if (map != null)
        {
            // Entry found
            return map;
        }

        while (!bClientFound)
        {
            Client entry = findClient(userAgent);

            if (entry == null)
            {
                if (userAgent.equals(DEFAULT_AGENT))
                {
                    log.error(
                        "CapabilityMap: Default agent not found in Client Registry !");

                    // Stop searching -- event the default userAgent can't be found
                    bClientFound = true;
                } else
                {
                    // Retry with the default Agent
                    if (log.isDebugEnabled())
                    {
                        log.debug(
                            "CapabilityMap: useragent "
                                + userAgent
                                + "unknown, falling back to default");
                    }

                    // Use default Client
                    defaultAgent = userAgent;
                    userAgent = DEFAULT_AGENT;
                }
            } else
            {
                // Found Client entry start populating the capability map.
                map = new CapabilityMapImpl();

                // Add client to CapabilityMap
                map.setClient(entry);

                // Add capabilities
                Iterator capabilities = entry.getCapabilities().iterator();
                while (capabilities.hasNext())
                {
                    map.addCapability((Capability) capabilities.next());
                }

                Collection mediatypes =
                    getMediaTypesForMimeTypes(entry.getMimetypes().iterator());

                // Add Mimetypes to map
                Iterator mimetypes = entry.getMimetypes().iterator();
                while (mimetypes.hasNext())
                {
                    map.addMimetype((MimeType) mimetypes.next());
                }

                Iterator media = mediatypes.iterator();
                while (media.hasNext())
                {
                    map.addMediaType((MediaType) media.next());
                }

                //Set preferred Mimetype
                MediaType mtEntry =
                    getMediaTypeForMimeType(map.getPreferredType().getName());

                map.setPreferredMediaType(mtEntry);

                // Add map to cache
                capabilityMapCache.put(userAgent, map);
                if (defaultAgent != null)
                    capabilityMapCache.put(defaultAgent, map);
View Full Code Here

     * @throws TemplateLocatorException
     */
    protected LocatorDescriptor getTemplateLocatorDescriptor(RenderRequest request) throws TemplateLocatorException
    {
        RequestContext requestContext = getRequestContext(request);
        CapabilityMap capabilityMap = requestContext.getCapabilityMap();
        Locale locale = requestContext.getLocale();

        LocatorDescriptor templateLocatorDescriptor = templateLocator.createLocatorDescriptor(null);
        templateLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName());
        templateLocatorDescriptor.setCountry(locale.getCountry());
        templateLocatorDescriptor.setLanguage(locale.getLanguage());
        return templateLocatorDescriptor;    
    }
View Full Code Here

     * @throws TemplateLocatorException
     */
    protected LocatorDescriptor getDecoratorLocatorDescriptor(RenderRequest request) throws TemplateLocatorException
    {
        RequestContext requestContext = getRequestContext(request);
        CapabilityMap capabilityMap = requestContext.getCapabilityMap();
        Locale locale = requestContext.getLocale();
 
        LocatorDescriptor decorationLocatorDescriptor = decorationLocator.createLocatorDescriptor(null);
        decorationLocatorDescriptor.setMediaType(capabilityMap.getPreferredMediaType().getName());
        decorationLocatorDescriptor.setCountry(locale.getCountry());
        decorationLocatorDescriptor.setLanguage(locale.getLanguage());
       
        return decorationLocatorDescriptor;
    }
View Full Code Here

                ContentPage page = requestContext.getPage();
                layoutDecoration = page.getEffectiveDefaultDecorator(layoutType);
            }
           
            // get layout capabilites and locale
            CapabilityMap capabilityMap = requestContext.getCapabilityMap();
            Locale locale = requestContext.getLocale();
            String layoutMediaType = capabilityMap.getPreferredMediaType().getName();
            String layoutLanguage = locale.getLanguage();
            String layoutCountry = locale.getCountry();
           
            // lookup cache config based on decoration cache key
            String cacheKey = layoutDecoration + ":" + layoutType + ":" + layoutMediaType + ":" + layoutLanguage + ":" + layoutCountry;
View Full Code Here

     * @throws UnableToBuildCapabilityMapException
     * @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
     */
    public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException
    {       
        CapabilityMap map = null;
        boolean bClientFound = false;
        String defaultAgent = null;

        if (userAgent == null)
        {
            userAgent = DEFAULT_AGENT;
        }

        // Check the cache if we have already a capability map for
        // the given Agent
        synchronized (capabilityMapCache)
        {
            map = (CapabilityMap) capabilityMapCache.get(userAgent);
            if (map != null)
            {
                capabilityMapCacheKeyList.remove(userAgent);
                capabilityMapCacheKeyList.addFirst(userAgent);
            }
        }

        if (map != null)
        {
            // Entry found
            return map;
        }

        while (!bClientFound)
        {
            Client entry = findClient(userAgent);

            if (entry == null)
            {
                if (userAgent.equals(DEFAULT_AGENT))
                {
                    log.error(
                        "CapabilityMap: Default agent not found in Client Registry !");

                    // Stop searching -- event the default userAgent can't be found
                    bClientFound = true;
                } else
                {
                    // Retry with the default Agent
                    if (log.isDebugEnabled())
                    {
                        log.debug(
                            "CapabilityMap: useragent "
                                + userAgent
                                + "unknown, falling back to default");
                    }

                    // Use default Client
                    defaultAgent = userAgent;
                    userAgent = DEFAULT_AGENT;
                }
            } else
            {
                bClientFound = true;

                try
                {
                    // Found Client entry start populating the capability map.
                    map = new CapabilityMapImpl();

                    // Add client to CapabilityMap
                    map.setClient(entry);

                    // Add capabilities
                    Iterator capabilities = entry.getCapabilities().iterator();
                    while (capabilities.hasNext())
                    {
                        map.addCapability((Capability) capabilities.next());
                    }

                    // Add Mimetypes to map
                    Iterator mimetypes = entry.getMimetypes().iterator();
                    while (mimetypes.hasNext())
                    {
                        map.addMimetype((MimeType) mimetypes.next());
                    }

                    // Add Mediatypes for Mimetype to map
                    Collection mediatypes =
                        getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
                    Iterator media = mediatypes.iterator();
                    while (media.hasNext())
                    {
                        map.addMediaType((MediaType) media.next());
                    }

                    // Validate preferred Mimetype
                    MimeType mimeTypeEntry = map.getPreferredType();
                    if (mimeTypeEntry == null)
                    {
                        throw new RuntimeException("Unable to get preferred Mimetype for client: "+entry.getName());                       
                    }

                    // Set preferred Mediatype for Mimetype
                    MediaType mediaTypeEntry = getMediaTypeForMimeType(mimeTypeEntry.getName());
                    if (mediaTypeEntry == null)
                    {
                        throw new RuntimeException("Unable to find preferred Mediatype for Mimetype/client: "+mimeTypeEntry.getName()+"/"+entry.getName());
                    }
                    map.setPreferredMediaType(mediaTypeEntry);

                    // Add map to cache
                    synchronized (capabilityMapCache)
                    {
                        if (capabilityMapCache.put(userAgent, map) != null)
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.capabilities.CapabilityMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.