congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ResourceHandler
Code IndexAdd Tabnine to your IDE (free)

How to use
ResourceHandler
in
javax.faces.application

Best Java code snippets using javax.faces.application.ResourceHandler (Showing top 20 results out of 441)

Refine searchRefine arrow

  • Application
  • FacesContext
  • Resource
  • ExternalContext
  • UIComponent
origin: primefaces/primefaces

    Resource resource = context.getApplication().getResourceHandler().createResource(
        "dynamiccontent.properties", "primefaces", streamedContent.getContentType());
    String resourcePath = resource.getRequestPath();
    Map<String, Object> session = context.getExternalContext().getSessionMap();
    Map<String, String> dynamicResourcesMapping = (Map) session.get(Constants.DYNAMIC_RESOURCES_MAPPING);
    if (dynamicResourcesMapping == null) {
        context.getELContext(), component.getValueExpression("value"));
        .append("&").append(Constants.DYNAMIC_CONTENT_TYPE_PARAM).append("=").append(type.toString());
    for (int i = 0; i < component.getChildCount(); i++) {
      UIComponent child = component.getChildren().get(i);
      if (child instanceof UIParameter) {
        UIParameter param = (UIParameter) child;
return context.getExternalContext().encodeResourceURL(src);
origin: primefaces/primefaces

public static void addComponentResource(FacesContext context, String name, String library, String target) {
  Application application = context.getApplication();
  UIComponent componentResource = application.createComponent(UIOutput.COMPONENT_TYPE);
  componentResource.setRendererType(application.getResourceHandler().getRendererTypeForResourceName(name));
  componentResource.getAttributes().put("name", name);
  componentResource.getAttributes().put("library", library);
  componentResource.getAttributes().put("target", target);
  context.getViewRoot().addComponentResource(context, componentResource, target);
}
origin: com.sun.faces/jsf-impl

private List<String> getResourceLibraryContracts(FacesContext context) {
  UIViewRoot viewRoot = context.getViewRoot();
  if(viewRoot == null) {
    if(context.getApplication().getResourceHandler().isResourceRequest(context)) {
      // it is a resource request. look at the parameter con=.
      String param = context.getExternalContext().getRequestParameterMap().get("con");
      if(!nameContainsForbiddenSequence(param) && param != null && param.trim().length() > 0) {
        return Arrays.asList(param);
      }
    }
    // PENDING(edburns): calculate the contracts!
    return Collections.emptyList();
  }
  return context.getResourceLibraryContracts();
}
origin: net.bootsfaces/bootsfaces

ResourceHandler handler = context.getApplication().getResourceHandler();
String resourceName = image.getName();
String value = image.getValue();
if (value != null && value.length() > 0) {
  if (resourceName != null && image.getLibrary() != null) {
    if (FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development)) {
      LOGGER.warning(
          "Please use either the 'value' attribute of b:image, or the 'name' and 'library' attribute pair. If all three attributes are provided, BootsFaces uses the 'value' attributes, ignoring both 'name' and 'library'.");
  if (handler.isResourceURL(value)) {
    return value;
  } else {
    value = context.getApplication().getViewHandler().getResourceURL(context, value);
    return (context.getExternalContext().encodeResourceURL(value));
Resource res = handler.createResource(resourceName, library);
if (res == null) {
  if (context.isProjectStage(ProjectStage.Development)) {
    String msg = "Unable to find resource " + resourceName;
    FacesMessages.error(component.getClientId(context), msg, msg);
  return (context.getExternalContext().encodeResourceURL(res.getRequestPath()));
origin: org.apache.myfaces.core/myfaces-shaded-impl

public static void writeScriptInline(FacesContext facesContext, ResponseWriter writer, String libraryName, String resourceName) throws IOException
{
  if (!ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName))
  {
    if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isRiImplAvailable())
    {
      //Use more compatible way.
      UIComponent outputScript = facesContext.getApplication().
        createComponent(facesContext, JAVAX_FACES_OUTPUT_COMPONENT_TYPE, DEFAULT_SCRIPT_RENDERER_TYPE);
      outputScript.getAttributes().put(JSFAttr.NAME_ATTR, resourceName);
      outputScript.getAttributes().put(JSFAttr.LIBRARY_ATTR, libraryName);
      outputScript.encodeAll(facesContext);
    }
    else
    {
      //Fast shortcut, don't create component instance and do what HtmlScriptRenderer do.
      Resource resource = facesContext.getApplication().getResourceHandler().createResource(resourceName, libraryName);
      markScriptAsRendered(facesContext, libraryName, resourceName);
      writer.startElement(HTML.SCRIPT_ELEM, null);
      writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT , null);
      writer.writeURIAttribute(HTML.SRC_ATTR, resource.getRequestPath(), null);
      writer.endElement(HTML.SCRIPT_ELEM);
    }
  }
}

origin: primefaces/primefaces

public static String getResourceRequestPath(FacesContext context, String resourceName) {
  Resource resource = context.getApplication().getResourceHandler().createResource(resourceName, "primefaces");
  return resource.getRequestPath();
}
origin: primefaces/primefaces

  protected String getImageSrc(FacesContext context, GraphicImage image) throws Exception {
    String name = image.getName();

    if (name != null) {
      String libName = image.getLibrary();
      ResourceHandler handler = context.getApplication().getResourceHandler();
      Resource res = handler.createResource(name, libName);

      if (res == null) {
        return "RES_NOT_FOUND";
      }
      else {
        String requestPath = res.getRequestPath();
        return context.getExternalContext().encodeResourceURL(requestPath);
      }
    }
    else {
      return DynamicContentSrcBuilder.build(context, image.getValue(), image, image.isCache(), DynamicContentType.STREAMED_CONTENT, image.isStream());
    }
  }
}
origin: primefaces/primefaces

@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
  ResponseWriter writer = context.getResponseWriter();
  Barcode barcode = (Barcode) component;
  String clientId = barcode.getClientId(context);
    Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent.properties", "primefaces", "image/png");
    String resourcePath = resource.getRequestPath();
    Map<String, Object> session = context.getExternalContext().getSessionMap();
    Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING);
    if (barcodeMapping == null) {
  writer.writeAttribute("src", context.getExternalContext().encodeResourceURL(src), null);
origin: de.beyondjava/angularFaces-core

public void encodeScript(FacesContext context, UIComponent component, String name, String library)
   throws IOException {
  Map<Object, Object> contextMap = context.getAttributes();
  Resource resource = context.getApplication().getResourceHandler()
     .createResource(name, library);
  ResponseWriter writer = context.getResponseWriter();
  writer.startElement("script", component);
  writer.writeAttribute("type", "text/javascript", "type");
    if (context.isProjectStage(ProjectStage.Development)) {
      String msg = "Unable to find resource " + (library == null ? "" : library + ", ") + name;
      context.addMessage(component.getClientId(context),
              new FacesMessage(FacesMessage.SEVERITY_ERROR,
                      msg,
    resourceSrc = resource.getRequestPath();
    if (query != null) {
      resourceSrc = resourceSrc +
          query;
    resourceSrc = context.getExternalContext().encodeResourceURL(resourceSrc);
origin: org.omnifaces/omnifaces

private static Resource createResource(FacesContext context) {
  if (Hacks.isPrimeFacesDynamicResourceRequest(context)) {
    return null;
  }
  String pathInfo = context.getExternalContext().getRequestPathInfo();
  String resourceName = (pathInfo != null) ? pathInfo.substring(1) : "";
  if (resourceName.isEmpty()) {
    return null;
  }
  String libraryName = context.getExternalContext().getRequestParameterMap().get("ln");
  return context.getApplication().getResourceHandler().createResource(resourceName, libraryName);
}
origin: com.sun.faces/jsf-impl

private boolean isResourceRequest() {
  FacesContext ctx = FacesContext.getCurrentInstance();
  return (ctx.getApplication().getResourceHandler().isResourceRequest(ctx));
}
origin: org.icefaces/icefaces-mobi

protected void writeJavascriptFile(FacesContext facesContext, 
    UIComponent component, String JS_NAME, String JS_MIN_NAME, 
    String JS_LIBRARY) throws IOException {
  ResponseWriter writer = facesContext.getResponseWriter();
  String clientId = component.getClientId(facesContext);
  writer.startElement(HTML.SPAN_ELEM, null);
  writer.writeAttribute(HTML.ID_ATTR, clientId+"_libJS", HTML.ID_ATTR);
  writer.writeAttribute(HTML.CLASS_ATTR, "mobi-hidden", null);
  if (!isScriptLoaded(facesContext, JS_NAME)) {
    String jsFname = JS_NAME;
    if (facesContext.isProjectStage(ProjectStage.Production)){
      jsFname = JS_MIN_NAME;
    }
    //set jsFname to min if development stage
    Resource jsFile = facesContext.getApplication().getResourceHandler().createResource(jsFname, JS_LIBRARY);
    String src = jsFile.getRequestPath();
    writer.startElement("script", component);
    writer.writeAttribute("type", "text/javascript", null);
    writer.writeAttribute("src", src, null);
    writer.endElement("script");
    setScriptLoaded(facesContext, JS_NAME);
  } 
  writer.endElement(HTML.SPAN_ELEM);
}
origin: omnifaces/omnifaces

/**
 * Obtain the resource, construct a {@link Reader} around it using the character encoding as obtained from the
 * response writer and then invoke {@link #startElement(ResponseWriter, UIComponent)},
 * {@link #writeResource(Reader, ResponseWriter)} and {@link #endElement(ResponseWriter)} in sequence.
 */
@Override
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
  ResponseWriter writer = context.getResponseWriter();
  String name = (String) component.getAttributes().get("name");
  String library = (String) component.getAttributes().get("library");
  Resource resource = context.getApplication().getResourceHandler().createResource(name, library);
  startElement(writer, component);
  try (Reader reader = new InputStreamReader(resource.getInputStream(), writer.getCharacterEncoding())) {
    writeResource(reader, writer);
  }
  endElement(writer);
}
origin: org.glassfish/javax.faces

private void renderComponentResources(FacesContext context, UIViewRoot viewRoot) throws IOException {
  ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
  PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
  boolean updateStarted = false;
  for (UIComponent resource : viewRoot.getComponentResources(context)) {
    String name = (String) resource.getAttributes().get("name");
    String library = (String) resource.getAttributes().get("library");
    if (resource.getChildCount() == 0 
     && resourceHandler.getRendererTypeForResourceName(name) != null 
     && !resourceHandler.isResourceRendered(context, name, library)) 
    {
      if (!updateStarted) {
        writer.startUpdate("javax.faces.Resource");
        updateStarted = true;
      }
      resource.encodeAll(context);
    }
  }
  if (updateStarted) {
    writer.endUpdate();
  }
}

origin: org.apache.myfaces.core/myfaces-shaded-impl

public boolean containsNamespace(String ns)
{
  if (ns != null && ns.startsWith(NAMESPACE_PREFIX))
  {
    ResourceHandler resourceHandler = 
      FacesContext.getCurrentInstance().getApplication().getResourceHandler();
    
    if (ns.length() > NAMESPACE_PREFIX.length())
    {
      String libraryName = ns.substring(NAMESPACE_PREFIX.length());
      return resourceHandler.libraryExists(libraryName);
    }
  }        
  return false;
}
origin: org.glassfish/javax.faces

@Override
public URL resolveUrl(String path) {
  ViewResource faceletResource = resourceHandler.createViewResource(FacesContext.getCurrentInstance(), path);
  if (faceletResource != null) {
    return faceletResource.getURL();
  }
  
  return null;
}
origin: com.github.albfernandez.richfaces/richfaces-core

public String getRendererType(FacesContext context) {
  ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
  return resourceHandler.getRendererTypeForResourceName(getName());
}
origin: com.liferay.faces/liferay-faces-bridge-impl

protected void handleJSF2ResourceRequest(FacesContext facesContext) throws IOException {
  ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler();
  resourceHandler.handleResourceRequest(facesContext);
}
origin: primefaces/primefaces

Application application = facesContext.getApplication();
ResourceHandler resourceHandler = application.getResourceHandler();
  resource = resourceHandler.createResource(resourceName, resourceLibrary);
  resource = resourceHandler.createResource(resourceName);
origin: org.icefaces/icefaces

public boolean isResourceRequest(FacesContext context) {
  EnvUtils.createSessionOnPageLoad(context);
  if (EnvUtils.isSessionInvalid(context)) {
    //make sure dispose window requests are treated as submit requests even if the session has expired
    if (WindowScopeManager.isDisposeWindowRequest(context.getExternalContext().getRequestParameterMap())) {
      return false;
    } else {
      return getWrapped().isResourceRequest(context);
    }
  } else {
    return isSessionAwareResourceRequest(context);
  }
}
javax.faces.applicationResourceHandler

Javadoc

ResourceHandler is the run-time API by which javax.faces.component.UIComponent and javax.faces.render.Rendererinstances, and the javax.faces.view.ViewDeclarationLanguage can reference Resource instances. An implementation of this class must be thread-safe.

Packaging Resources

ResourceHandler defines a path based packaging convention for resources. The default implementation of ResourceHandler must support packaging resources in the classpath or in the web application root. See section JSF.2.6.1 of the spec prose document linked in the overview summary for the normative specification of packaging resources.

Briefly, The default implementation must support packaging resources in the web application root under the path

resources/<resourceIdentifier>

relative to the web app root. "resources" is the default location, but this location can be changed by the value of the #WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME <context-param>.

For the default implementation, resources packaged in the classpath must reside under the JAR entry name

META-INF/resources/<resourceIdentifier>

In the case of Faces Flows packaged within jar files, resources packaged in the classpath must reside under the jar entry name

META-INF/flows/<resourceIdentifier>

<resourceIdentifier> consists of several segments, specified as follows.

[localePrefix/][libraryName/][libraryVersion/]resourceName[/resourceVersion]

None of the segments in the resourceIdentifier may be relative paths, such as ‘../otherLibraryName’. The implementation is not required to support the libraryVersion and resourceVersion segments for the JAR packaging case.

Note that resourceName is the only required segment.

Encoding Resources

During the handling of view requests, the JSF run-time may be called upon to encode a resource in such a way as to instruct the user-agent to make a subsequent resource request. This behavior is orchestrated by one of the resource renderers (ScriptRenderer, StylesheetRenderer, ImageRenderer), which all call Resource#getRequestPath to obtain the encoded URI for the resource. See Resource#getRequestPath and the Standard HTML RenderKit specification for the complete specification.

This usage of resources does not apply for resources that correspond to VDL resources.

Decoding Resources

During the handling of resource requests, the JSF run-time will be called upon to decode a resource in such a way as to serve up the bytes of the resource to the user-agent. This behavior is orchestrated by #handleResourceRequest, which calls Resource#getInputStream to obtain bytes of the resource. See #handleResourceRequest for the complete specification.

This usage of resources does not apply for resources that correspond to VDL resources.

Most used methods

  • createResource
    Create an instance ofResource with a resourceName given by the value of the argument resourceName th
  • isResourceRequest
    Return true if the current request is a resource request. This method is called by javax.faces.webap
  • getRendererTypeForResourceName
    Return the renderer-type for a javax.faces.render.Renderer that is capable of rendering this resourc
  • handleResourceRequest
    This method specifies the contract for satisfying resource requests. This method is called from java
  • libraryExists
    Return true if the resource library named by the argument libraryName can be found.
  • createViewResource
  • isResourceURL
    Return true if the argument urlcontains the string given by the value of the constant ResourceHandle
  • createResourceFromId
  • isResourceRendered
  • markResourceRendered
  • getViewResources
  • getRenderedResources
    Return a set of already rendered resources by this renderer on the current request.
  • getViewResources,
  • getRenderedResources

Popular in Java

  • Making http requests using okhttp
  • setRequestProperty (URLConnection)
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • Notification (javax.management)
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now