Package javax.faces.application

Examples of javax.faces.application.Resource


    }

    private void verifyResourcesPresent(Resource... expectedResources) {
        for (Resource expectedResource : expectedResources) {
            ResourceFactory resourceFactory = new ResourceFactoryImpl(null);
            Resource resource = resourceFactory.createResource(expectedResource.getResourceName(),
                    expectedResource.getLibraryName(), null);

            assertNotNull(
                    "resource is not present: " + expectedResource.getLibraryName() + ":" + expectedResource.getResourceName(),
                    resource);
            assertThat(resource.getRequestPath(), equalTo(expectedResource.getRequestPath()));
        }
    }
View Full Code Here


    }

    private void verifyResourceNotPresent(Resource... nonPresentResources) {
        for (Resource notPresentResource : nonPresentResources) {
            ResourceFactory resourceFactory = new ResourceFactoryImpl(null);
            Resource resource = resourceFactory.createResource(notPresentResource.getResourceName(),
                    notPresentResource.getLibraryName(), null);

            assertNull(resource);
        }
    }
View Full Code Here

    private interface Location {
        String getRequestPath();
    }

    private Resource resource(String library, String name, final Location location) {
        Resource resource = Mockito.mock(Resource.class);
        when(resource.getLibraryName()).thenReturn(library);
        when(resource.getResourceName()).thenReturn(name);
        when(resource.getRequestPath()).thenAnswer(new Answer<String>() {
            @Override
            public String answer(InvocationOnMock invocation) throws Throwable {
                return location.getRequestPath();
            }
        });
View Full Code Here

        if ((resourceName == null) || (resourceName.length() == 0)) {
            return null;
        }

        String libraryName = resourceData.getLibraryName();
        Resource resource = createDynamicResource(new ResourceKey(resourceName, libraryName), false);

        if (resource == null) {
            logMissingResource(context, resourceData.getResourceKey());
            return null;
        }
View Full Code Here

    }

    public Resource createResource(String resourceName, String libraryName, String contentType) {
        ResourceKey resourceKey = new ResourceKey(resourceName, libraryName);

        Resource resource = createMappedResource(resourceKey);

        if (resource != null) {
            return resource;
        } else {
            return createDynamicResource(resourceKey, true);
View Full Code Here

        // do not map resources for ResourceServlet requests (they should be already mapped)
        if (context.getExternalContext().getRequestMap().get(ResourceServlet.RESOURCE_SERVLET_REQUEST_FLAG) == Boolean.TRUE) {
            return null;
        }

        Resource mappedResource = resolveMappedResource(context, resourceKey);

        if (mappedResource == null) {
            return null;
        }

        resourceTracker.markResourceRendered(context, resourceKey);
        ResourcePath path = new ResourcePath(mappedResource.getRequestPath());
        Set<ResourceKey> aggregatedResources = mappedResourceFactory.getAggregatedResources(path);
        for (ResourceKey key : aggregatedResources) {
            resourceTracker.markResourceRendered(context, key);
        }
View Full Code Here

        }
        return list;
    }

    protected Resource createDynamicResource(ResourceKey resourceKey, boolean useDependencyInjection) {
        Resource result = null;

        Map<String, String> params = null;

        MappedResourceData mappedResourceData = mappedResourceDataMap.get(resourceKey);
        ResourceKey actualKey;
        if (mappedResourceData != null) {
            actualKey = mappedResourceData.getResourceKey();
            if (useDependencyInjection) {
                params = mappedResourceData.getParams();
            }
        } else {
            actualKey = resourceKey;
            if (useDependencyInjection) {
                params = Collections.<String, String>emptyMap();
            }
        }

        if (Strings.isNullOrEmpty(resourceKey.getResourceName())) {
            return null;
        }

        if (actualKey.getResourceName().endsWith(".ecss")) {
            // TODO nick - params?
            result = createCompiledCSSResource(actualKey);
        } else {
            result = createHandlerDependentResource(actualKey, params);
        }

        if (result != null) {
            result.setLibraryName(resourceKey.getLibraryName());
            result.setResourceName(resourceKey.getResourceName());
        } else if (mappedResourceData != null) {
            result = defaultHandler.createResource(actualKey.getResourceName(), actualKey.getLibraryName());
        }

        return result;
View Full Code Here

                if (skin != null) {
                    faces.setSkin(skin);
                }

                Resource resource = createResource(facesContext, resourceKey);
                CurrentResourceContext.getInstance(facesContext).setResource(resource);
                // TODO check content type

                if (shouldCheckForEL(resource) && containsELExpression(resource)) {
                    log.info(MessageFormat.format("Skipping {0} because it contains EL-expressions", resourceKey));
View Full Code Here

            log.debug("checking " + resourceKey);
            try {
                FacesContext facesContext = faces.startRequest();
                faces.setSkin("DEFAULT");

                Resource resource = createResource(facesContext, resourceKey);
                if (resource == null) {
                    // TODO log null resource
                    log.warn("null resource for resource key " + resourceKey + " (resource rendering will be skipped)");
                    skipped = true;
                    return;
                }

                if (!filter.apply(resource)) {
                    log.debug("filtered out resource: " + resourceKey + " (resource rendering will be skipped)");
                    log.debug(" - content-type: " + resource.getContentType() + ", qualifier: " + ResourceUtil.getResourceQualifier(resource));
                    skipped = true;
                    return;
                }

                String contentType = resource.getContentType();
                if (contentType == null) {
                    // TODO log null content type
                    log.warn("null content type for resource key " + resourceKey + " (resource rendering will be skipped)");
                    skipped = true;
                    return;
                }

                skinDependent = ResourceSkinUtils.isSkinDependent(resource.getRequestPath());
            } catch (Exception e) {
                throw (RuntimeException) e;
            } finally {
                log.debug("checked " + resourceKey + ": skinDependent: " + skinDependent + ", skipped: " + skipped);
                faces.setSkin(null);
View Full Code Here

        checkBaseAndProperty(base, property);

        if (base instanceof ResourceHandler) {
            ResourceHandler handler = (ResourceHandler) base;
            String prop = (String) property;
            Resource resource;
            if (!prop.contains(":")) {
                resource = handler.createResource(prop);
            } else {
                String[] parts = prop.split(":");
                if (parts.length != 2) {
                    throw new ELException(MessageFormat.format(
                            "Invalid resource format. Property {0} contains more than one colon (:)", prop));
                }
                resource = handler.createResource(parts[1], parts[0]);
            }

            context.setPropertyResolved(true);

            if (resource != null) {
                String requestPath = resource.getRequestPath();
                FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
                Resource contextResource = CurrentResourceContext.getInstance(facesContext).getResource();
                if (contextResource != null) {
                    requestPath = relativize(requestPath, contextResource.getRequestPath());
                }

                return requestPath;
            }
        }
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.