Package org.ajax4jsf.resource

Examples of org.ajax4jsf.resource.InternetResource


  /* (non-Javadoc)
   * @see org.ajax4jsf.renderkit.compiler.RootElement#encode(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
   */
  public void encodeEnd(TemplateContext context) throws IOException {
    InternetResource resource = findResource(context);
    if(null !=resource){
      resource.encodeEnd(context.getFacesContext(),context.getComponent());
    }
  }
View Full Code Here


  /* (non-Javadoc)
   * @see org.ajax4jsf.renderkit.compiler.RootElement#getString(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
   */
  public String getString(TemplateContext context) throws FacesException {
    InternetResource resource = findResource(context);
    if(null !=resource){
      return resource.getUri(context.getFacesContext(),context.getComponent());
    }
    return "";
  }
View Full Code Here

    }
    return "";
  }

  private InternetResource findResource(TemplateContext context) {
    InternetResource resource;
    String path = (String) getValue(context);
    RendererBase renderer = context.getRenderer();
    if (renderer != null)  {
      resource = renderer.getResource(path);
    } else {
View Full Code Here

      InternetResource[] resources, UIComponent component) {
    if (null != resources) {
      LinkedHashSet uris = new LinkedHashSet(); // Collections.singleton(ajaxScript.getUri(context,
                            // null));
      for (int i = 0; i < resources.length; i++) {
        InternetResource resource = resources[i];
        uris.add(resource.getUri(context, component));
      }
      return uris;
    }
    return null;
  }
View Full Code Here

              path));
        }
      }
    }
    // path - is class name ?
    InternetResource res;
    try {
      Class resourceClass = Class.forName(path);
      res = createDynamicResource(path, resourceClass);
    } catch (Exception e) {
      try {
View Full Code Here

  }

  public InternetResource getResource(String path)
      throws ResourceNotFoundException {

    InternetResource internetResource = (InternetResource) resources
        .get(path);
    if (null == internetResource) {
      throw new ResourceNotFoundException("Resource not registered : "
          + path);
    } else {
View Full Code Here

   * @return
   */
  protected InternetResource createDynamicResource(String path,
      Class instatiate) throws ResourceNotFoundException {
    if (InternetResource.class.isAssignableFrom(instatiate)) {
      InternetResource resource;
      try {
        resource = (InternetResource) instatiate.newInstance();
        addResource(path, resource);
      } catch (Exception e) {
        String message = Messages.getMessage(
View Full Code Here

   * @throws FacesException
   */
  public InternetResource createUserResource(boolean cacheable,
      boolean session, String mime) throws FacesException {
    String path = getUserResourceKey(cacheable, session, mime);
    InternetResource userResource;
    try {
      userResource = getResource(path);
    } catch (ResourceNotFoundException e) {
      userResource = new UserResource(cacheable, session, mime);
      addResource(path, userResource);
View Full Code Here

    return false;
  }

  public void serviceResource(String resourceKey, HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    InternetResource resource;// getInternetResource(request);
    try {
      resource = getResourceBuilder().getResourceForKey(resourceKey);
    } catch (ResourceNotFoundException e) {
      throw new ServletException(e);
    }
    Object resourceDataForKey = getResourceBuilder().getResourceDataForKey(
        resourceKey);

    ResourceContext resourceContext = getResourceContext(resource, request,
        response);
    resourceContext.setResourceData(resourceDataForKey);
    try {

      if (resource.isCacheable(resourceContext) && this.cacheEnabled) {
        // Test for client request modification time.
        try {
          long ifModifiedSince = request
              .getDateHeader("If-Modified-Since");
          if (ifModifiedSince >= 0) {
            // Test for modification. 1000 ms due to round
            // modification
            // time to seconds.
            long lastModified = resource.getLastModified(
                resourceContext).getTime() - 1000;
            if (lastModified <= ifModifiedSince) {
              response.setStatus(304);
              return;
            }
          }
        } catch (IllegalArgumentException e) {
          log
              .warn(
                  Messages
                      .getMessage(Messages.PARSING_IF_MODIFIED_SINCE_WARNING),
                  e);
        }
        String cacheKey = resourceKey;
        CachedResourceContext cachedResourceContext = new CachedResourceContext(
            resourceContext);

        CacheContext cacheLoaderContext = new CacheContext(
            cachedResourceContext, resource);

        try {
          CacheContent content = (CacheContent) cache.get(cacheKey,
              cacheLoaderContext);
          if (log.isDebugEnabled()) {
            log
                .debug(Messages.getMessage(
                    Messages.GET_CONTENT_FROM_CACHE_INFO,
                    cacheKey));
          }
          content.sendHeaders(response);
          // Correct expires date for resource.
          Date expired = resource.getExpired(resourceContext);
          if (expired != null) {
            response.setDateHeader("Expires", expired.getTime());
          } else {
            response.setDateHeader("Expires", System
                .currentTimeMillis()
View Full Code Here

   *
   * @throws IOException - if resource not available
   */
  protected InputStream getResourceIfPresent(String path) throws IOException {
    InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
    InternetResource resource = builder.getResource(path);
    if (resource != null) {
      String uri = HTTP_PREFIX + resource.getUri(facesContext, null);
      Page page = webClient.getPage(uri);
      if (page.getWebResponse().getStatusCode() == HttpServletResponse.SC_OK) {
        return page.getWebResponse().getContentAsStream();
      }
    }
View Full Code Here

TOP

Related Classes of org.ajax4jsf.resource.InternetResource

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.