public static ClassLoader getCurrentClassLoader(Class clazz) { ClassLoader cl = getContextClassLoader(); if (cl == null && clazz != null) { cl = clazz.getClassLoader(); } return cl; }
public boolean isValueBlank(String value) { return LangUtils.isValueBlank(value); }
@Override public boolean applies(Object value, Object filter, Locale locale) { String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase(locale); if (LangUtils.isValueEmpty(filterText)) { return true; } if (value == null) { return false; } return value.toString().toLowerCase(locale).equalsIgnoreCase(filterText); } }
if (LangUtils.isValueBlank(fileUpload.getAccept())) { 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");
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; }
public static Class tryToLoadClassForName(String name) { try { return loadClassForName(name); } catch (ClassNotFoundException e) { return null; } }
protected void decodeMultiple(FacesContext context, AutoComplete ac) { Map<String, String[]> paramValues = context.getExternalContext().getRequestParameterValuesMap(); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = ac.getClientId(context); String[] hinputValues = paramValues.get(clientId + "_hinput"); String[] submittedValues = (hinputValues != null) ? hinputValues : new String[]{}; String inputValue = params.get(clientId + "_input"); if (!isValueBlank(inputValue)) { submittedValues = LangUtils.concat(submittedValues, new String[]{inputValue}); } if (submittedValues.length > 0) { ac.setSubmittedValue(submittedValues); } else { ac.setSubmittedValue(""); } }
if (LangUtils.contains(submittedValues, selectItemVal) && !LangUtils.contains(oldValues, selectItemVal)) { else if (LangUtils.contains(oldValues, selectItemVal)) { validSubmittedValues.add(selectItemVal); if (LangUtils.contains(submittedValues, selectItemVal)) { validSubmittedValues.add(selectItemVal);
String userBundleName = application.getMessageBundle(); ResourceBundle bundle = null; ClassLoader currentClassLoader = LangUtils.getCurrentClassLoader(application.getClass());
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; }
/** * Gets the {@link Class} from the {@link TagAttribute}. * * @param attribute The {@link TagAttribute}. * @param ctx The {@link FaceletContext}. * @return The {@link Class}. */ protected Class<?> getClassFromAttribute(TagAttribute attribute, FaceletContext ctx) { String type = attribute.getValue(ctx); try { return LangUtils.loadClassForName(type); } catch (ClassNotFoundException e) { throw new FacesException("Class " + type + " not found.", e); } }
@Override public void decode(FacesContext context, UIComponent component) { Chips chips = (Chips) component; String clientId = chips.getClientId(context); if (!shouldDecode(chips)) { return; } Map<String, String> params = context.getExternalContext().getRequestParameterMap(); Map<String, String[]> paramValues = context.getExternalContext().getRequestParameterValuesMap(); String[] hInputValues = paramValues.get(clientId + "_hinput"); String[] submittedValues = (hInputValues != null) ? hInputValues : new String[]{}; String inputValue = params.get(clientId + "_input"); if (!isValueBlank(inputValue)) { submittedValues = LangUtils.concat(submittedValues, new String[]{inputValue}); } if (submittedValues.length > chips.getMax()) { return; } if (submittedValues.length > 0) { chips.setSubmittedValue(submittedValues); } else { chips.setSubmittedValue(""); } decodeBehaviors(context, chips); }
public CSVBuilder update(UIComponent component, String expressions) { if (!LangUtils.isValueBlank(expressions)) { String resolvedExpressions = SearchExpressionFacade.resolveClientIds( context, component, expressions, SearchExpressionHint.VALIDATE_RENDERER); buffer.append(",u:'").append(resolvedExpressions).append("'"); } return this; }
@Override public boolean applies(Object value, Object filter, Locale locale) { String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase(locale); if (LangUtils.isValueEmpty(filterText)) { return true; } if (value == null) { return false; } return value.toString().toLowerCase(locale).startsWith(filterText); } }
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); } } }
/** * Gets the {@link Class} from the {@link TagAttribute}. * * @param attribute The {@link TagAttribute}. * @param ctx The {@link FaceletContext}. * @return The {@link Class}. */ protected Class<?> getClassFromAttribute(TagAttribute attribute, FaceletContext ctx) { String type = attribute.getValue(ctx); try { return LangUtils.loadClassForName(type); } catch (ClassNotFoundException e) { throw new FacesException("Class " + type + " not found.", e); } }
public static Class loadClassForName(String name) throws ClassNotFoundException { try { return Class.forName(name, false, LangUtils.class.getClassLoader()); } catch (ClassNotFoundException e) { try { return Class.forName(name, false, getContextClassLoader()); } catch (ClassNotFoundException e2) { throw e2; } } }
private AjaxRequestBuilder addExpressions(UIComponent component, String expressions, String key, int options) { if (!LangUtils.isValueBlank(expressions)) { String resolvedExpressions = SearchExpressionFacade.resolveClientIds(context, component, expressions, options); buffer.append(",").append(key).append(":\"").append(resolvedExpressions).append("\""); } return this; }
@Override public boolean applies(Object value, Object filter, Locale locale) { String filterText = (filter == null) ? null : filter.toString().trim().toLowerCase(locale); if (LangUtils.isValueEmpty(filterText)) { return true; } if (value == null) { return false; } return value.toString().toLowerCase(locale).endsWith(filterText); } }
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()); } }