javax.faces.application.Resource.getRequestPath()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中javax.faces.application.Resource.getRequestPath方法的一些代码示例,展示了Resource.getRequestPath的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.getRequestPath方法的具体详情如下:
包路径:javax.faces.application.Resource
类名称:Resource
方法名:getRequestPath

Resource.getRequestPath介绍

[英]Return a path to this resource such that, when the browser resolves it against the base URI for the view that includes the resource, and issues a GET request to the resultant fully qualified URL, the bytes of the resource are returned in response.
The default implementation must implement the following algorithm. For discussion, the return result from this method will be called result.

  • Get the context-root for this web application, not ending in slash. For discussion this will be called contextRoot.
  • Discover if the FacesServlet is prefix (path) mapped, extension mapped, or exact mapped (as defined by Servlet.12.2.) and the value of the mapping (including the leading '.' in the case of extension mapping). For discussion, this will be facesServletMapping.
    If exact mapped, result must be the following if and only if the FacesServlet is mapped to the exact URL pattern ResourceHandler#RESOURCE_IDENTIFIER + #getResourceName
    result = *contextRoot* + ResourceHandler#RESOURCE_IDENTIFIER + #getResourceName

If exact mapped, and the FacesServlet is not mapped to the exact URL pattern ResourceHandler#RESOURCE_IDENTIFIER + #getResourceNamedo the following:

Retrieve the existing mappings of the FacesServlet, e.g. using ServletRegistration#getMappings(), and from those pick any prefix mapping or extension mapping. If no such mapping is found, throw an IllegalStateException. If such mapping is found remove the * character from that mapping, take that as the new facesServletMapping and continue with evaluating this mapping as specified below for if prefix mapped and for if extension mapped

If prefix mapped, result must be

result = *contextRoot* + '/' + *facesServletMapping* + ResourceHandler#RESOURCE_IDENTIFIER + '/' + #getResourceName

If extension mapped, result must be

result = *contextRoot* + ResourceHandler#RESOURCE_IDENTIFIER + #getResourceName + *facesServletMapping*

  • Build up a string, called resourceMetaData which is an & separated string of name=value pairs suitable for inclusion in a URL query string.
    If #getLibraryName returns non-null, resourceMetaData must include "ln=" + the return from #getLibraryName

If there is a localePrefix for this application, as defined in ResourceHandler#LOCALE_PREFIX, resourceMetaData must include "loc=" + the localePrefix.

If this resource is contained in a resource library contract, resourceMetaData must include "con=" + the name of the resource library contract.

Append "?" + resourceMetaData to result.

  • Make it portlet safe by passing the result through ViewHandler#getResourceURL.
    [中]返回该资源的路径,这样,当浏览器根据包含该资源的视图的基本URI解析该路径,并向生成的完全限定URL发出GET请求时,资源的字节将作为响应返回。
    默认实现必须实现以下算法。为了便于讨论,此方法的返回结果将被称为result
    获取此web应用程序的上下文根,而不是以斜杠结尾。为了便于讨论,这将被称为contextRoot*。
    发现FacesServlet是前缀(路径)映射、扩展映射还是精确映射(如Servlet.12.2所定义)以及映射的值(对于扩展映射,包括前导“.”)。为了便于讨论,这将是facesServletMapping*。
    如果精确映射,result必须为以下值当且仅当FacesServlet映射到精确的URL模式ResourceHandler#RESOURCE_IDENTIFIER+#getResourceName
    result = *contextRoot* + ResourceHandler#RESOURCE_IDENTIFIER + #getResourceName
    如果精确映射,并且FacesServlet映射到精确的URL模式ResourceHandler#RESOURCE_IDENTIFIER+#GetResourceName,请执行以下操作:
    检索FacesServlet的现有映射,例如使用ServletRegistration#getMappings(),并从这些映射中选择任何前缀映射或扩展映射。如果没有找到这样的映射,抛出一个非法状态异常。如果找到这样的映射,请从该映射中删除*字符,将其作为新的facesServletMapping,并继续按照下面为If prefix mappedIf extension mapped指定的方法计算该映射*
    如果前缀已映射,result必须为
    result = *contextRoot* + '/' + *facesServletMapping* + ResourceHandler#RESOURCE_IDENTIFIER + '/' + #getResourceName
    如果扩展映射,result必须为
    result = *contextRoot* + ResourceHandler#RESOURCE_IDENTIFIER + #getResourceName + *facesServletMapping*
    构建一个名为resourceMetaData的字符串,它是一个由名称=值对组成的&分隔字符串,适合包含在URL查询字符串中。
    如果#getLibraryName返回非-null,则resourceMetaData必须包含“ln=”+从#getLibraryName返回的值
    如果根据ResourceHandler#LOCALE_前缀中的定义,此应用程序有localePrefix,则resourceMetaData必须包含“loc=”+thelocalePrefix
    如果此资源包含在资源库合同中,resourceMetaData必须包含“con=”+资源库合同的名称。
    附加“?”+resourceMetaData
    结果*。
    *通过ViewHandler#getResourceURL传递结果,确保portlet安全。

代码示例

代码示例来源: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

String resourcePath = resource.getRequestPath();

代码示例来源:origin: primefaces/primefaces

Resource resource = context.getApplication().getResourceHandler().createResource(
    "dynamiccontent.properties", "primefaces", streamedContent.getContentType());
String resourcePath = resource.getRequestPath();

代码示例来源:origin: primefaces/primefaces

protected void encodeValidationResources(FacesContext context, boolean beanValidationEnabled) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Resource resource = context.getApplication().getResourceHandler().createResource("validation/validation.js", "primefaces");

    if (resource != null) {
      writer.startElement("script", null);
      writer.writeAttribute("type", "text/javascript", null);
      writer.writeAttribute("src", resource.getRequestPath(), null);
      writer.endElement("script");
    }

    if (beanValidationEnabled) {
      resource = context.getApplication().getResourceHandler().createResource("validation/beanvalidation.js", "primefaces");

      if (resource != null) {
        writer.startElement("script", null);
        writer.writeAttribute("type", "text/javascript", null);
        writer.writeAttribute("src", resource.getRequestPath(), null);
        writer.endElement("script");
      }
    }
  }
}

代码示例来源: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

protected void encodeCSS(FacesContext context, String library, String resource) throws IOException {
  ResponseWriter writer = context.getResponseWriter();
  Resource cssResource = context.getApplication().getResourceHandler().createResource(resource, library);
  if (cssResource == null) {
    throw new FacesException("Error loading css, cannot find \"" + resource + "\" resource of \"" + library + "\" library");
  }
  else {
    writer.startElement("link", null);
    writer.writeAttribute("type", "text/css", null);
    writer.writeAttribute("rel", "stylesheet", null);
    writer.writeAttribute("href", cssResource.getRequestPath(), null);
    writer.endElement("link");
  }
}

代码示例来源:origin: primefaces/primefaces

private void encodeScript(FacesContext context, Editor editor) throws IOException {
  String clientId = editor.getClientId(context);
  WidgetBuilder wb = getWidgetBuilder(context);
  wb.init("Editor", editor.resolveWidgetVar(), clientId)
      .attr("disabled", editor.isDisabled(), false)
      .attr("invalid", editor.isValid(), true)
      .attr("controls", editor.getControls(), null)
      .attr("width", editor.getWidth(), Integer.MIN_VALUE)
      .attr("height", editor.getHeight(), Integer.MIN_VALUE)
      .attr("maxlength", editor.getMaxlength(), Integer.MAX_VALUE)
      .callback("change", "function(e)", editor.getOnchange());
  if (AgentUtils.isIE(context)) {
    Resource resource = context.getApplication().getResourceHandler().createResource("editor/editor-ie.css", "primefaces");
    wb.attr("docCSSFile", resource.getRequestPath());
  }
  if (editor.getMaxlength() != Integer.MAX_VALUE) {
    LOGGER.info("Maxlength option is deprecated and will be removed in a future version.");
  }
  wb.finish();
}

代码示例来源:origin: com.sun.faces/jsf-api

/**
 * <p class="changed_added_2_0">Call through to {@link
 * #getRequestPath} and return the result.</p>
 *
 * @return Call through to {@link #getRequestPath} and return the
 * result.
 */
public String toString() {
  return getRequestPath();
}

代码示例来源:origin: javax/javaee-web-api

/**
 * <p class="changed_added_2_0">Call through to {@link
 * #getRequestPath} and return the result.</p>
 *
 * @return Call through to {@link #getRequestPath} and return the
 * result.
 */
@Override
public String toString() {
  return getRequestPath();
}

代码示例来源:origin: org.apache.myfaces.core/myfaces-api

@Override
public String toString()
{
  return getRequestPath();
}

代码示例来源:origin: org.glassfish/javax.faces

/**
 * <p class="changed_added_2_0">
 * Call through to {@link #getRequestPath} and return the result.
 * </p>
 *
 * @return Call through to {@link #getRequestPath} and return the result.
 */
@Override
public String toString() {
  return getRequestPath();
}

代码示例来源:origin: javax/javaee-web-api

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

代码示例来源:origin: org.apache.myfaces.core/myfaces-api

@Override
public String getRequestPath()
{
  return getWrapped().getRequestPath();
}

代码示例来源:origin: com.sun.faces/jsf-api

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

代码示例来源:origin: javax.faces/javax.faces-api

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

代码示例来源:origin: org.richfaces.ui/richfaces-components-ui

public static String getResourcePath(FacesContext context, String library, String resourceName) {
  String path = null;
  if (resourceName != null) {
    ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
    Resource resource = (library != null) ? resourceHandler.createResource(resourceName, library) : resourceHandler
        .createResource(resourceName);
    if (resource != null) {
      path = resource.getRequestPath();
    }
  }
  return path;
}

代码示例来源:origin: org.omnifaces/omnifaces

/**
 * If the given resource is not <code>null</code>, then decorate it as an unmapped resource.
 */
@Override
public Resource decorateResource(Resource resource) {
  if (resource == null) {
    return resource;
  }
  String path = resource.getRequestPath();
  return isResourceRequest(path) ? new RemappedResource(resource, unmapRequestPath(path)) : resource;
}

代码示例来源:origin: omnifaces/omnifaces

/**
 * If the given resource is not <code>null</code>, then decorate it as an unmapped resource.
 */
@Override
public Resource decorateResource(Resource resource) {
  if (resource == null) {
    return resource;
  }
  String path = resource.getRequestPath();
  return isResourceRequest(path) ? new RemappedResource(resource, unmapRequestPath(path)) : resource;
}

代码示例来源:origin: org.primefaces/primefaces

private void renderJS(FacesContext context, String name, String library) throws IOException {
  ResponseWriter writer = context.getResponseWriter();
  Resource resource = context.getApplication().getResourceHandler().createResource(name, library);
  if (resource != null) {
    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);
    writer.writeAttribute("src", resource.getRequestPath(), null);
    writer.endElement("script");
  }
}

代码示例来源:origin: org.primefaces/primefaces

private void renderCSS(FacesContext context, String name, String library) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Resource resource = context.getApplication().getResourceHandler().createResource(name, library);

    if (resource != null) {
      writer.startElement("link", null);
      writer.writeAttribute("type", "text/css", null);
      writer.writeAttribute("rel", "stylesheet", null);
      writer.writeAttribute("href", resource.getRequestPath(), null);
      writer.endElement("link");
    }
  }
}

相关文章