Package javax.faces.application

Examples of javax.faces.application.Resource


                String[] split = resourceName.split(":", 2);
                libraryName = split[0];
                resourceName = split[1];
            }
        }
        Resource imported = facesContext.getApplication().getResourceHandler().createResource(resourceName, libraryName);
        if (imported == null) {
            LOGGER.error("Resource with name " + resourceName + " can't be found.");
            return;
        }
        String toAdd = null;
        try {
            toAdd = convertStreamToString(imported.getInputStream(), this.getEncoding());
        } catch (IOException e) {
            LOGGER.error("Error while importing nested resource with name " + resourceName);
        }
        if (toAdd != null && toAdd.length() > 0) {
            buffer.append(toAdd);
View Full Code Here


            ResourceRequestData data = resourceCodec.decodeResource(context, resourcePath);
            assert (data != null);

            Cache cache = ServiceTracker.getService(context, Cache.class);
            Resource resource = lookupInCache(cache, data.getResourceKey());

            if (resource == null) {
                resource = resourceFactory.createResource(context, data);
            }

            if (resource == null) {
                sendResourceNotFound(context);
                return;
            }

            if (resource instanceof CacheableResource) {
                CacheableResource cacheableResource = (CacheableResource) resource;

                if (cacheableResource.isCacheable(context)) {

                    // TODO - we could move this part of code to ConcurrentMap so that
                    // only single thread does resource put
                    CachedResourceImpl cachedResource = new CachedResourceImpl();

                    cachedResource.initialize(resource);

                    // someone may provided this resource for us
                    // while we were reading it, check once again
                    resource = lookupInCache(cache, data.getResourceKey());

                    if (resource == null) {
                        // don't cache it on Development stage
                        if (!ProjectStage.Development.equals(context.getApplication().getProjectStage())) {
                            Date cacheExpirationDate = cachedResource.getExpired(context);
                            if (LOGGER.isDebugEnabled()) {
                                LOGGER.debug(new MessageFormat(
                                        "Storing {0} resource in cache until {1,date,dd MMM yyyy HH:mm:ss zzz}", Locale.US)
                                        .format(new Object[] { data.getResourceKey(), cacheExpirationDate }));
                            }
                            cache.put(data.getResourceKey(), cachedResource, cacheExpirationDate);
                        }
                        resource = cachedResource;
                    }
                }
            }

            if (resource.userAgentNeedsUpdate(context)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("User agent needs resource update, encoding resource");
                }

                ExternalContext externalContext = context.getExternalContext();
                Map<String, String> headers = resource.getResponseHeaders();

                for (Entry<String, String> headerEntry : headers.entrySet()) {
                    String headerName = headerEntry.getKey();
                    String headerValue = headerEntry.getValue();

                    // TODO should external context handles this itself?
                    if ("content-length".equals(headerName.toLowerCase(Locale.US))) {
                        try {
                            externalContext.setResponseContentLength(Integer.parseInt(headerValue));
                        } catch (NumberFormatException e) {

                            // TODO: handle exception
                        }
                    } else {
                        externalContext.setResponseHeader(headerName, headerValue);
                    }
                }

                // TODO null content type?
                String contentType = resource.getContentType();

                if (contentType != null) {
                    externalContext.setResponseContentType(contentType);
                }

                if (resource instanceof ContentProducerResource) {
                    ContentProducerResource contentProducerResource = (ContentProducerResource) resource;
                    contentProducerResource.encode(context);
                } else {
                    // TODO setup output buffer size according to configuration parameter
                    InputStream is = resource.getInputStream();
                    OutputStream os = externalContext.getResponseOutputStream();

                    try {
                        ResourceUtils.copyStreamContent(is, os);
                    } finally {
View Full Code Here

        if (cache == null) {
            LOGGER.debug("No cache was provided");
            return null;
        }

        Resource resource = (Resource) cache.get(resourceKey);

        if (LOGGER.isDebugEnabled()) {
            if (resource == null) {
                LOGGER.debug("Resource was not located in cache");
            } else {
View Full Code Here

     * (non-Javadoc)
     * @see javax.faces.application.ResourceHandlerWrapper#createResource(java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public Resource createResource(String resourceName, String libraryName, String contentType) {
        Resource resource = resourceFactory.createResource(resourceName, libraryName, contentType);
        if (resource == null) {
            resource = defaultHandler.createResource(resourceName, libraryName, contentType);
        }

        return resource;
View Full Code Here

            return dim;
        }
    }

    public String getCKEditorRequestPath(FacesContext facesContext) {
        Resource resource = facesContext.getApplication().getResourceHandler()
                .createResource("ckeditor.js", "org.richfaces.ckeditor");
        return resource.getRequestPath();
    }
View Full Code Here

                .createResource("ckeditor.js", "org.richfaces.ckeditor");
        return resource.getRequestPath();
    }

    public String getECSSQueryString(FacesContext facesContext, String resourceName) {
        Resource resource = facesContext.getApplication().getResourceHandler()
                .createResource(resourceName, "org.richfaces.ckeditor");
        String requestPath = resource.getRequestPath();

        Matcher matcher = DB_PATTERN.matcher(requestPath);
        if (matcher.matches()) {
            return "?" + matcher.group(2);
        } else {
View Full Code Here

    public static String getResourcePath(FacesContext context, String library, String resourceName) {
        String path = null;
        if (resourceName != null) {
            ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
            Resource resource = (library != null) ? resourceHandler.createResource(resourceName, library) : resourceHandler
                    .createResource(resourceName);
            if (resource != null) {
                path = resource.getRequestPath();
            }
        }
        return path;
    }
View Full Code Here

        {
            if (ns.length() > NAMESPACE_PREFIX.length())
            {
                String libraryName = ns.substring(NAMESPACE_PREFIX.length());
                String resourceName = localName + ".xhtml";
                Resource compositeComponentResource = _resourceHandler.createResource(resourceName, libraryName);
                if (compositeComponentResource != null)
                {
                    URL url = compositeComponentResource.getURL();
                    return (url != null);
                }
            }
        }
        return false;
View Full Code Here

                // the Resource and if it does not exists, it just returns null.
                // The intention of this code is just create an instance and pass to
                // CompositeComponentResourceTagHandler. Then, its values
                // (resourceName, libraryName) will be used to derive the real instance
                // to use in a view, based on the locale used.
                Resource compositeComponentResource = new CompositeResouceWrapper(
                    _resourceHandler.createResource(resourceName, libraryName));
                if (compositeComponentResource != null)
                {
                    ComponentConfig componentConfig = new ComponentConfigWrapper(tag,
                            "javax.faces.NamingContainer", null);
View Full Code Here

        {
            additionalQueryParams = resourceName.substring(index + 1);
            resourceName = resourceName.substring(0, index);
        }

        Resource resource;
        if (libraryName == null)
        {
            if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName))
            {
                //Resource already founded
                return;
            }
            resource = facesContext.getApplication().getResourceHandler()
                    .createResource(resourceName);
        }
        else
        {
            if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName))
            {
                //Resource already founded
                return;
            }
            resource = facesContext.getApplication().getResourceHandler()
                    .createResource(resourceName, libraryName);

        }

        if (resource == null)
        {
            //no resource found
            log.warning("Resource referenced by resourceName " + resourceName +
                    (libraryName == null ? "" : " and libraryName " + libraryName) +
                    " not found in call to ResourceHandler.createResource." +
                    " It will be silenty ignored.");
            return;
        }
        else
        {
            if (ResourceUtils.isRenderedScript(facesContext, resource.getLibraryName(), resource.getResourceName()))
            {
                //Resource already founded
                return;
            }

            // Rendering resource
            ResourceUtils.markScriptAsRendered(facesContext, libraryName, resourceName);
            ResourceUtils.markStylesheetAsRendered(facesContext, resource.getLibraryName(), resource.getResourceName());
            ResponseWriter writer = facesContext.getResponseWriter();
            writer.startElement(HTML.SCRIPT_ELEM, component);
// We can't render the content type, because usually it returns "application/x-javascript"
// and this is not compatible with IE. We should force render "text/javascript".
            writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
            String path = resource.getRequestPath();
            if (additionalQueryParams != null)
            {
                path = path + ( (path.indexOf('?') >= 0) ? "&amp;" : "?" ) + additionalQueryParams;
            }
            writer.writeURIAttribute(HTML.SRC_ATTR, path, null);
View Full Code Here

TOP

Related Classes of javax.faces.application.Resource

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.