Java Code Examples for javax.faces.application.ResourceHandler#createResource()

The following examples show how to use javax.faces.application.ResourceHandler#createResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalIE8CompatiblityLinks.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
@Override
  public void encodeBegin(FacesContext context) throws IOException {
      Application app = context.getApplication();
      ResourceHandler rh = app.getResourceHandler();
  	ResponseWriter responseWriter = context.getResponseWriter();
Resource h5s = rh.createResource("js/html5shiv.js", C.BSF_LIBRARY);
Resource rjs = rh.createResource("js/respond.js", C.BSF_LIBRARY);

responseWriter.write("<!--[if lt IE 9]>");
responseWriter.startElement("script", null);
responseWriter.writeAttribute("src", h5s.getRequestPath(), null);
responseWriter.endElement("script");
responseWriter.startElement("script", null);
responseWriter.writeAttribute("src", rjs.getRequestPath(), null);
responseWriter.endElement("script");
responseWriter.write("<![endif]-->");
  }
 
Example 2
Source File: Datepicker.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
public Datepicker() {
	setRendererType(null); // this component renders itself

	AddResourcesListener.addThemedCSSResource("core.css");
	AddResourcesListener.addExtCSSResource("jq.ui.core.css");
	AddResourcesListener.addExtCSSResource("jq.ui.theme.css");
	AddResourcesListener.addExtCSSResource("jq.ui.datepicker.css");

	AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/core.js");
	AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, "jq/ui/datepicker.js");
	FacesContext context = FacesContext.getCurrentInstance();
	Application app = context.getApplication();
	ResourceHandler rh = app.getResourceHandler();
	Resource rdp;
	Iterator<Locale> preferredLanguages = context.getExternalContext().getRequestLocales();
	while (preferredLanguages.hasNext()) {
		String language = preferredLanguages.next().getLanguage();
		if ("en".equals(language)) {
			break;
		}
		final String jsl = "jq/ui/i18n/datepicker-" + language + ".js";
		rdp = rh.createResource(jsl, C.BSF_LIBRARY);
		if (rdp != null) { // rdp is null if the language .js is not present
							// in jar
			AddResourcesListener.addResourceToHeadButAfterJQuery(C.BSF_LIBRARY, jsl);
			break;
		}

	}
	Tooltip.addResourceFiles();
}
 
Example 3
Source File: ImageRenderer.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Determine the path value of an image value.
 * </p>
 *
 * @param context
 *            the {@link FacesContext} for the current request.
 * @param component
 *            the component to obtain the image information from
 * @return the encoded path to the image source
 */
public static String getImageSource(FacesContext context, UIComponent component) {
	Image image = (Image) component;
	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));
		}
	}

	String library = image.getLibrary();
	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 "RES_NOT_FOUND";
	} else {
		return (context.getExternalContext().encodeResourceURL(res.getRequestPath()));
	}
}