public PrimeEnvironment() { atLeastEl22 = LangUtils.tryToLoadClassForName("javax.el.ValueReference") != null; atLeastJsf23 = LangUtils.tryToLoadClassForName("javax.faces.component.UIImportConstants") != null; atLeastJsf22 = LangUtils.tryToLoadClassForName("javax.faces.flow.Flow") != null; atLeastJsf21 = LangUtils.tryToLoadClassForName("javax.faces.component.TransientStateHolder") != null; atLeastBv11 = LangUtils.tryToLoadClassForName("javax.validation.executable.ExecutableValidator") != null; beanValidationAvailable = checkIfBeanValidationIsAvailable(); buildVersion = resolveBuildVersion(); // This should only happen if PF + the webapp is openend and started in the same netbeans instance // Fallback to a UID to void a empty version in the resourceUrls if (buildVersion == null || buildVersion.trim().isEmpty()) { buildVersion = UUID.randomUUID().toString().replace("-", "").substring(0, 10); } htmlSanitizerAvailable = LangUtils.tryToLoadClassForName("org.owasp.html.PolicyFactory") != null; }
protected boolean checkIfBeanValidationIsAvailable() { boolean available = LangUtils.tryToLoadClassForName("javax.validation.Validation") != null; if (available) { // Trial-error approach to check for Bean Validation impl existence. // If any Exception occurs here, we assume that Bean Validation is not available. // The cause may be anything, i.e. NoClassDef, config error... try { Validation.buildDefaultValidatorFactory().getValidator(); } catch (Throwable t) { LOGGER.log(Level.FINE, "BV not available - Could not build default ValidatorFactory."); available = false; } } return available; }
protected void addAttachedObjectHandlerToMyFaces(UIComponent component, FaceletContext ctx) { try { if (myfacesGetCompositionContextInstance == null || myfacesAddAttachedObjectHandler == null) { Class<?> clazz = LangUtils.tryToLoadClassForName("org.apache.myfaces.view.facelets.FaceletCompositionContext"); myfacesGetCompositionContextInstance = clazz.getDeclaredMethod("getCurrentInstance", FaceletContext.class); myfacesAddAttachedObjectHandler = clazz.getDeclaredMethod("addAttachedObjectHandler", UIComponent.class, AttachedObjectHandler.class); } Object faceletCompositionContextInstance = myfacesGetCompositionContextInstance.invoke(null, ctx); myfacesAddAttachedObjectHandler.invoke(faceletCompositionContextInstance, component, this); } catch (Exception ex) { Logger.getLogger(AjaxBehaviorHandler.class.getName()).log(Level.SEVERE, "Could not add AttachedObjectHandler to MyFaces!", ex); } } }
public PrimeEnvironment(FacesContext context) { this(); this.mojarra = context.getExternalContext().getApplicationMap().containsKey("com.sun.faces.ApplicationAssociate"); Class<?> portletContext = LangUtils.tryToLoadClassForName("javax.portlet.PortletContext"); if (portletContext != null) { portlet = portletContext.isInstance(context.getExternalContext().getContext()); } }
@SuppressWarnings("deprecation") // the default constructor is deprecated in JSF 2.3 public PrimeResourceHandler(ResourceHandler wrapped) { this.wrapped = wrapped; handlers = new HashMap<>(); handlers.put(DynamicContentType.STREAMED_CONTENT.toString(), new StreamedContentHandler()); if (LangUtils.tryToLoadClassForName("org.krysalis.barcode4j.output.AbstractCanvasProvider") != null) { handlers.put(DynamicContentType.BARCODE.toString(), new BarcodeHandler()); } if (LangUtils.tryToLoadClassForName("net.glxn.qrgen.QRCode") != null) { handlers.put(DynamicContentType.QR_CODE.toString(), new QRCodeHandler()); } }
boolean tika = LangUtils.tryToLoadClassForName("org.apache.tika.filetypedetector.TikaFileTypeDetector") != null; if (!tika && LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("Could not find Apache Tika in classpath which is recommended for reliable content type checking");