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

How to use
Resource
in
javax.faces.application

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

Refine searchRefine arrow

  • Application
  • FacesContext
  • ResourceHandler
  • UIComponent
  • ExternalContext
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

if (resource != null && !"RES_NOT_FOUND".equals(resource.toString())) {
  inputStream = resource.getInputStream();
  contentType = resource.getContentType();
    ExternalContext externalContext = context.getExternalContext();
    File file = new File(externalContext.getRealPath("") + imagePath);
    inputStream = new FileInputStream(file);
origin: primefaces/primefaces

@Override
public String getResourceName() {
  return getWrapped().getResourceName();
}
origin: TheCoder4eu/BootsFaces-OSP

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

  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: primefaces/primefaces

public static String getResourceRequestPath(FacesContext context, String resourceName) {
  Resource resource = context.getApplication().getResourceHandler().createResource(resourceName, "primefaces");
  return resource.getRequestPath();
}
origin: org.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.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: com.sun.faces/jsf-impl

private void handleHeaders(FacesContext ctx,
              Resource resource) {
  ExternalContext extContext = ctx.getExternalContext();
  for (Map.Entry<String, String> cur :
     resource.getResponseHeaders().entrySet()) {
      extContext.setResponseHeader(cur.getKey(), cur.getValue());
  }
}
origin: org.icefaces/icefaces

public InputStream getInputStream() throws IOException {
  ArrayList<InputStream> streams = new ArrayList();
  for (Info next : resourceInfos.resources) {
    ResourceHandler handler = FacesContext.getCurrentInstance().getApplication().getResourceHandler();
    Resource resource = handler.createResource(next.name, next.library);
    streams.add(new SkipBOMInputStream(resource.getInputStream()));
    streams.add(new ByteArrayInputStream("\n\r".getBytes("UTF-8")));
  }
  return new SequenceInputStream(Collections.enumeration(streams));
}
origin: org.icefaces/icefaces

private Resource getDynamicResourceViaDummyFile(String actualResourceName){
  FacesContext fc = FacesContext.getCurrentInstance();
  ResourceHandler handler = fc.getApplication().getResourceHandler();
  Resource rez = handler.createResource("coalesced.txt",getLibraryName(),getContentType());
  rez.setResourceName(getResourceName());
  return rez;
}
origin: org.omnifaces/omnifaces

private Resource createGraphicResourceByName(FacesContext context, String name, boolean dataURI) throws IOException {
  String library = (String) getAttributes().get("library");
  Resource resource = context.getApplication().getResourceHandler().createResource(name, library);
  if (resource != null && dataURI && resource.getContentType().startsWith("image")) {
    resource = new GraphicResource(resource.getInputStream(), resource.getContentType());
  }
  return resource;
}
origin: org.icefaces/icefaces

public void handleResourceRequest(FacesContext facesContext) throws IOException {
  ExternalContext externalContext = facesContext.getExternalContext();

  if ( getTokenResource().getRequestPath().equals(
    getResourcePath(facesContext)) )  {
    storeParts(externalContext);
    externalContext.setResponseContentType("text/plain");
    OutputStream out = externalContext.getResponseOutputStream();
    out.write("handled by AuxUploadResourceHandler".getBytes());
    return;
  }
  
  wrapped.handleResourceRequest(facesContext);
  
}
origin: org.glassfish/jakarta.faces

private ResourceBundle findResourceBundleAsResource(FacesContext context) {
  
  if (getAttributes().containsKey(COMPONENT_RESOURCE_KEY)) {
    Resource ccResource = (Resource) this.getAttributes().get(COMPONENT_RESOURCE_KEY);
    
    if (ccResource != null) {
      
      ccResource = findComponentResourceBundleLocaleMatch(context, ccResource.getResourceName(), ccResource.getLibraryName());
      
      if (ccResource  != null) {
        try (InputStream propertiesInputStream = ccResource.getInputStream()) {
          return new PropertyResourceBundle(propertiesInputStream);
        } catch (IOException ex) {
          Logger.getLogger(UIComponent.class.getName()).log(SEVERE, null, ex);
        }
      }
    }
  }
  
  return null;
}
origin: org.glassfish/javax.faces

private String getCompositeComponentName(UIComponent compositeComponent) {
  Resource resource =
     (Resource) compositeComponent.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY);
  String name = resource.getResourceName();
  String library = resource.getLibraryName();
  if (library != null) {
    return "Composite Component: " + name + ", library: " + library;
  } else {
    return "Composite Component: " + name;
  }
}
origin: org.icefaces/icefaces

VersionedResource(Resource wrapped) {
  this.wrapped = wrapped;
  //Not sure why this is necessary but if we don't do this, the
  //Content-Type response header may not make it back to the browser.
  setResourceName(wrapped.getResourceName());
  setLibraryName(wrapped.getLibraryName());
  setContentType(wrapped.getContentType());
}
origin: com.github.albfernandez.richfaces/richfaces-core

public void initialize(Resource resource) throws IOException {
  setResourceName(resource.getResourceName());
  setContentType(resource.getContentType());
  this.headers = resource.getResponseHeaders();
  initializeFromHeaders();
  this.content = readContent(resource.getInputStream());
}
origin: javax/javaee-web-api

/**
 * <p class="changed_added_2_0">The default behavior of this method
 * is to call {@link Resource#userAgentNeedsUpdate} on the wrapped {@link
 * ResourceHandler} object.</p>
 */
@Override
public boolean userAgentNeedsUpdate(FacesContext context) {
  return getWrapped().userAgentNeedsUpdate(context);
}
javax.faces.applicationResource

Javadoc

An instance of Resource is a Java object representation of the artifact that is served up in response to a resource request from the client. Instances of Resource are normally created and initialized via calls to ResourceHandler#createResource. See the documentation for ResourceHandler for more information.

Most used methods

  • getRequestPath
    Return a path to this resource such that, when the browser resolves it against the base URI for the
  • getContentType
    Return the MIME content-type for this resource.
  • getResourceName
    Return the resourceName for this resource. Will never be null. All Resource instances must have a
  • getLibraryName
    Return the libraryName for this resource. May be null. The libraryName for a resource is an optiona
  • getInputStream
    If the current request is a resource request, (that is, ResourceHandler#isResourceRequest returns tr
  • getResponseHeaders
    Returns a mutable Map whose entries will be sent as response headers during Resourc
  • userAgentNeedsUpdate
    Return true if the user-agent requesting this resource needs an update. If the If-Modified-Since HTT
  • setResourceName
    Set the resourceName for this resource.
  • getURL
    Return an actual URL instance that refers to this resource instance.
  • setContentType
    Set the MIME content-type for this resource. The default implementation performs no validation on t
  • setLibraryName
    Set the libraryName for this resource.
  • toString
    Call through to #getRequestPath and return the result.
  • setLibraryName,
  • toString

Popular in Java

  • Creating JSON documents from java classes using gson
  • onCreateOptionsMenu (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • ImageIO (javax.imageio)
  • JTextField (javax.swing)
  • Top 12 Jupyter Notebook extensions
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