Refine search
private void logResourceProblem(FacesContext context, Throwable throwable, String messagePattern, Object... arguments) { boolean isProductionStage = context.isProjectStage(ProjectStage.Production); if (LOGGER.isWarnEnabled() || (!isProductionStage && LOGGER.isInfoEnabled())) { String formattedMessage = MessageFormat.format(messagePattern, arguments); if (throwable != null) { LOGGER.warn(formattedMessage, throwable); } else { if (isProductionStage) { LOGGER.info(formattedMessage); } else { LOGGER.warn(formattedMessage); } } } }
private boolean checkResourceMarker(String resourceName) { ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); URL resourceMarkerUrl = contextClassLoader.getResource("META-INF/" + resourceName + ".resource.properties"); boolean result = (resourceMarkerUrl != null); if (LOGGER.isDebugEnabled()) { if (result) { LOGGER.debug(MessageFormat.format("Marker file for {0} resource found in classpath", resourceName)); } else { LOGGER.debug(MessageFormat.format("Marker file for {0} resource does not exist", resourceName)); } } return result; }
private Resource lookupInCache(Cache cache, String resourceKey) { 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 { LOGGER.debug("Resource was located in cache"); } } return resource; }
@Override public Map<String, String> getResponseHeaders() { Map<String, String> headers = new HashMap<String, String>(); FacesContext facesContext = FacesContext.getCurrentInstance(); if (isResourceRequest()) { int contentLength = getContentLength(facesContext); if (contentLength >= 0) { headers.put("Content-Length", String.valueOf(contentLength)); } String contentType = getContentType(); if (contentType != null) { headers.put("Content-Type", contentType); } Date lastModified = getLastModified(facesContext); if (lastModified != null) { headers.put("Last-Modified", ResourceUtils.formatHttpDate(lastModified)); } headers.put("Date", ResourceUtils.formatHttpDate(getCurrentTime())); addCacheControlResponseHeaders(facesContext, headers); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Created set of response headers"); // TODO - security - can we log header values? for (Entry<String, String> entry : headers.entrySet()) { LOGGER.debug(MessageFormat.format("\t{0}={1}", entry.getKey(), entry.getValue())); } } } return headers; }
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 })); if (LOGGER.isDebugEnabled()) { LOGGER.debug("User agent needs resource update, encoding resource"); ExternalContext externalContext = context.getExternalContext(); Map<String, String> headers = resource.getResponseHeaders(); is.close(); } catch (IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Resource succesfully encoded"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Passing request to the next resource handler in chain");
private Date getLastModifiedBySource() { ClassLoader classLoader = getClassLoader(); if (classLoader == null) { return null; } URL classResource = classLoader.getResource(getClass().getName().replace('.', '/') + ".class"); if (classResource != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(MessageFormat.format("Located source for the resource class: {0}", classResource)); } try { URLConnection connection = classResource.openConnection(); connection.setUseCaches(false); long classLastModifiedDate = connection.getLastModified(); if (classLastModifiedDate > 0) { lastModified = new Date(classLastModifiedDate); if (LOGGER.isDebugEnabled()) { LOGGER.debug(MessageFormat.format("Last source modification date is: {0,date}", lastModified)); } } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Source for the resource class has not been located"); } } return null; }
private Resource createDynamicResourceInstance(Class<?> loadedClass) throws Exception, LinkageError { String resourceName = loadedClass.getName(); boolean checkResult = false; DynamicResource annotation = loadedClass.getAnnotation(DynamicResource.class); if (annotation != null) { LOGGER.debug(MessageFormat.format("Dynamic resource annotation is present on resource class {0}", resourceName)); checkResult = true; } else { LOGGER.debug(MessageFormat.format("Dynamic resource annotation is not present on resource class {0}", resourceName)); } if (!checkResult) { checkResult = checkResourceMarker(resourceName); } if (!checkResult) { return null; } Class<? extends Resource> resourceClass = loadedClass.asSubclass(Resource.class); Resource result = (Resource) resourceClass.newInstance(); return result; }
private void logException(CSSParseException e) { String formattedMessage = MessageFormat.format("Problem parsing ''{0}'' resource: {1}", getResourceLocator(), e.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(formattedMessage, e); } else { LOGGER.warn(formattedMessage); } }
private synchronized File createOutputFile(String path) throws IOException { File outFile = new File(resourceContentsDir, path); outFile.getParentFile().mkdirs(); if (outFile.exists()) { if (outFile.lastModified() > currentTime) { log.debug(MessageFormat.format("File {0} already exists and will be overwritten", outFile.getPath())); } outFile.delete(); } if (!outFile.createNewFile()) { log.warn(MessageFormat.format("Could not create {0} file", outFile.getPath())); } return outFile; }
@Override public InputStream getInputStream() throws IOException { FacesContext ctx = FacesContext.getCurrentInstance(); InputStream stream = null; CSSStyleSheet styleSheet = null; ErrorHandlerImpl errorHandler = new ErrorHandlerImpl(this, ctx.isProjectStage(ProjectStage.Production)); LOGGER.error(e.getMessage(), e); } finally { if (stream != null) { stream.close(); } catch (IOException e) { LOGGER.warn(e.getMessage(), e); String encoding = ctx.getExternalContext().getResponseCharacterEncoding(); CSSVisitorImpl cssVisitor = new CSSVisitorImpl(ctx); cssVisitor.setEncoding(encoding != null ? encoding : "UTF-8"); } else { if (!ctx.isProjectStage(ProjectStage.Production)) { LOGGER.info(MessageFormat.format(NULL_STYLESHEET, getLibraryName(), getResourceName()));
/** * Initializes {@link org.richfaces.application.push.PushContext} on startup as it is a time when {@link FacesContext} is available */ private void initializePushContext() { try { LOGGER.info("Startup initialization of PushContext"); ServiceTracker.getService(PushContextFactory.class).getPushContext(); } catch (Exception e) { LOGGER.error(MessageFormat.format("There were problems initializing PushContext on startup: {0}", e.getMessage())); } }
loaded = true; } catch (IOException e) { LOGGER.warn(MessageFormat.format("Failure loading properties from URL: {0}", url.toExternalForm()), e); if (LOGGER.isInfoEnabled()) { LOGGER.warn(MessageFormat.format("Failure loading properties from location: {0}", location), e);
private void renderResource(String skin) { log.debug("rendering " + resourceKey + " (" + skin + ")"); log.info(MessageFormat.format("Skipping {0} because it contains EL-expressions", resourceKey)); return; resourceWriter.writeResource(skin, resource); log.debug("rendered " + resourceKey + " (" + skin + ")"); } catch (Exception e) { log.debug("not rendered " + resourceKey + " (" + skin + ") - cought exception"); if (skin != null) { log.error( MessageFormat.format("Exception rendering resorce {0} using skin {1}: {2}", resourceKey, skin, e.getMessage()), e); } else { log.error(MessageFormat.format("Exception rendering resorce {0}: {1}", resourceKey, e.getMessage()), e);
@Override public void focus(String componentId) { FacesContext context = FacesContext.getCurrentInstance(); if (context == null) { throw new IllegalStateException(FocusManager.class.getSimpleName() + " can't be used without FacesContext available"); } if (componentId == null) { setContextAttribute(context, null); } else { UIComponent currentComponent = UIComponent.getCurrentComponent(context); if (currentComponent == null) { currentComponent = context.getViewRoot(); } currentComponent.findComponent(componentId); UIComponent component = RendererUtils.getInstance().findComponentFor(currentComponent, componentId); if (component == null) { String message = FocusManager.class.getSimpleName() + ": Component with ID '" + componentId + "' was not found"; LOG.warn(message); context.addMessage(null, new FacesMessage(message)); } else { String clientId = component.getClientId(context); setContextAttribute(context, clientId); JavaScriptService javaScriptService = ServiceTracker.getService(context, JavaScriptService.class); javaScriptService.addPageReadyScript(context, new JSLiteral(String.format(SCRIPT, clientId))); } } }
@Override public void encodeChildren(FacesContext context, UIComponent component) throws IOException { // Test for correct parameters. checkForCorrectParams(context, component, "encodeBegin"); if (LOG.isDebugEnabled()) { LOG.debug(Messages.getMessage(Messages.CHILDREN_ENCODING_COMPONENT_INFO, component.getClientId(context), component .getClass().getName())); } if (component.isRendered()) { ResponseWriter writer = context.getResponseWriter(); doEncodeChildren(writer, context, component); } }
protected boolean isSubmitted(FacesContext facesContext, UIComponent uiComponent) { if (getUtils().isBooleanAttribute(uiComponent, "disabled")) { return false; } String clientId = uiComponent.getClientId(facesContext); Map<String, String> paramMap = facesContext.getExternalContext().getRequestParameterMap(); Object value = paramMap.get(clientId); /* * RF-13559, RF-13018, prevent commandButton with @type="button" or "reset" from executing its action if it didn't * submit the form */ boolean preventButtonExecution = false; if (uiComponent instanceof AbstractCommandButton) { AbstractCommandButton button = (AbstractCommandButton) uiComponent; String type = ((String) button.getAttributes().get("type")).toLowerCase(); String source = paramMap.get(SOURCE_ID); if ((type.equals("button") || type.equals("reset")) && !button.getClientId().equals(source)) { preventButtonExecution = true; } } boolean submitted = null != value && !preventButtonExecution; if (submitted && LOG.isDebugEnabled()) { LOG.debug("Decode submit of the Ajax component " + clientId); } return submitted; }
private Resource createMappedResource(ResourceKey resourceKey) { final FacesContext context = FacesContext.getCurrentInstance(); // 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); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Resource '%s' is redirected to following resource path: %s", resourceKey, path)); if (aggregatedResources.size() >= 1) { LOGGER.debug(String.format("Following resources are marked as rendered: %s", resourceKey, aggregatedResources)); } } return mappedResource; }
public String imageUrl(String resourceName) { if ("plain".equals(getName())){ return "none"; } FacesContext facesContext = FacesContext.getCurrentInstance(); Resource resource = facesContext.getApplication().getResourceHandler().createResource(resourceName, IMAGE_LIBRARY); String resourcePath; if (resource != null) { resourcePath = resource.getRequestPath(); } else { resourcePath = "RES_NOT_FOUND"; LOG.warn("Unable to find or serve resource '" + ResourceKey.create(resourceName, IMAGE_LIBRARY) + "'"); } return String.format("url(%s)", resourcePath); }