/** * @return ApplicationContext instance. */ public PrimeApplicationContext getApplicationContext() { if (this.applicationContext == null) { this.applicationContext = PrimeApplicationContext.getCurrentInstance(context); } return applicationContext; }
@Override public void processEvent(SystemEvent event) throws AbortProcessingException { PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(FacesContext.getCurrentInstance()); if (applicationContext != null) { applicationContext.release(); } } }
public AjaxRequestBuilder partialSubmit(boolean value, boolean partialSubmitSet, String partialSubmitFilter) { PrimeConfiguration config = PrimeApplicationContext.getCurrentInstance(context).getConfig(); //component can override global setting boolean partialSubmit = partialSubmitSet ? value : config.isPartialSubmitEnabled(); if (partialSubmit) { buffer.append(",ps:true"); if (partialSubmitFilter != null) { buffer.append(",psf:\"").append(partialSubmitFilter).append("\""); } } return this; }
@SuppressWarnings("deprecation") // the default constructor is deprecated in JSF 2.3 public PrimeResource(final Resource resource) { super(); wrapped = resource; version = "&v=" + PrimeApplicationContext.getCurrentInstance(FacesContext.getCurrentInstance()).getEnvironment().getBuildVersion(); }
public AjaxRequestBuilder resetValues(boolean value, boolean resetValuesSet) { PrimeConfiguration config = PrimeApplicationContext.getCurrentInstance(context).getConfig(); //component can override global setting boolean resetValues = resetValuesSet ? value : config.isResetValuesEnabled(); if (resetValues) { buffer.append(",rv:true"); } return this; }
/** * Get all constants of the given {@link Class}. * * @param facesContext The {@link FacesContext}. * @param type The class which includes the constants. * @return A {@link Map} with the constants. */ protected Map<String, Object> getConstants(FacesContext facesContext, Class<?> type) { boolean cacheEnabled = facesContext.isProjectStage(ProjectStage.Production); Map<Class<?>, Map<String, Object>> cache = PrimeApplicationContext.getCurrentInstance(FacesContext.getCurrentInstance()).getConstantsCacheMap(); Map<String, Object> constants; if (cacheEnabled && cache.containsKey(type)) { constants = cache.get(type); } else { constants = Collections.unmodifiableMap(collectConstants(type)); if (cacheEnabled) { cache.put(type, constants); } } return constants; }
@Override public void processEvent(SystemEvent event) throws AbortProcessingException { try { if (event instanceof PreRenderComponentEvent) { PreRenderComponentEvent preRenderComponentEvent = (PreRenderComponentEvent) event; execute(PrimeApplicationContext.getCurrentInstance(FacesContext.getCurrentInstance()), preRenderComponentEvent.getComponent()); } } catch (IOException e) { throw new FacesException(e); } }
public static boolean isSkipIteration(VisitContext visitContext, FacesContext context) { if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf21()) { return visitContext.getHints().contains(VisitHint.SKIP_ITERATION); } else { Boolean skipIterationHint = (Boolean) visitContext.getFacesContext().getAttributes().get(SKIP_ITERATION_HINT); return skipIterationHint != null && skipIterationHint.booleanValue() == true; } }
public static void performVirusScan(FacesContext facesContext, FileUpload fileUpload, InputStream inputStream) throws VirusException { if (fileUpload.isPerformVirusScan()) { PrimeApplicationContext.getCurrentInstance(facesContext).getVirusScannerService().performVirusScan(inputStream); } }
protected void renderDynamicPassThruAttributes(FacesContext context, UIComponent component) throws IOException { if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf22()) { Jsf22Helper.renderPassThroughAttributes(context, component); } }
protected boolean isBeanValidationDefined(UIInput input, FacesContext context) { try { PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); Set<ConstraintDescriptor<?>> constraints = BeanValidationMetadataExtractor.extractDefaultConstraintDescriptors(context, applicationContext,
protected NavigationCase findNavigationCase(FacesContext context, UIOutcomeTarget outcomeTarget) { ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); String outcome = outcomeTarget.getOutcome(); if (outcome == null) { outcome = context.getViewRoot().getViewId(); } if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf22()) { if (outcomeTarget instanceof UIComponent) { String toFlowDocumentId = (String) ((UIComponent) outcomeTarget).getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME); if (toFlowDocumentId != null) { return navigationHandler.getNavigationCase(context, null, outcome, toFlowDocumentId); } } } return navigationHandler.getNavigationCase(context, null, outcome); }
@Override public void decode(FacesContext context, UIComponent component) { if (!context.getExternalContext().getRequestContentType().toLowerCase().startsWith("multipart/")) { return; } FileUpload fileUpload = (FileUpload) component; if (!fileUpload.isDisabled()) { PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); String uploader = applicationContext.getConfig().getUploader(); boolean isAtLeastJSF22 = applicationContext.getEnvironment().isAtLeastJsf22(); String inputToDecodeId = getSimpleInputDecodeId(fileUpload, context); if (uploader.equals("auto")) { if (isAtLeastJSF22) { NativeFileUploadDecoder.decode(context, fileUpload, inputToDecodeId); } else { CommonsFileUploadDecoder.decode(context, fileUpload, inputToDecodeId); } } else if (uploader.equals("native")) { if (!isAtLeastJSF22) { throw new FacesException("native uploader requires at least a JSF 2.2 runtime"); } NativeFileUploadDecoder.decode(context, fileUpload, inputToDecodeId); } else if (uploader.equals("commons")) { CommonsFileUploadDecoder.decode(context, fileUpload, inputToDecodeId); } } }
protected void renderPassThruAttributes(FacesContext context, UIComponent component, String[] attrs, String[] ignoredAttrs) throws IOException { ResponseWriter writer = context.getResponseWriter(); //pre-defined attributes for (String attribute : attrs) { if (isIgnoredAttribute(attribute, ignoredAttrs)) { continue; } Object value = component.getAttributes().get(attribute); if (shouldRenderAttribute(value)) { writer.writeAttribute(attribute, value.toString(), attribute); } } //dynamic attributes if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf22()) { Jsf22Helper.renderPassThroughAttributes(context, component); } }
/** * Finds appropriate converter for a given value holder * * @param context FacesContext instance * @param component ValueHolder instance to look converter for * @return Converter */ public static Converter getConverter(FacesContext context, UIComponent component) { if (!(component instanceof ValueHolder)) { return null; } Converter converter = ((ValueHolder) component).getConverter(); if (converter != null) { return converter; } ValueExpression valueExpression = component.getValueExpression("value"); if (valueExpression == null) { return null; } Class<?> converterType = valueExpression.getType(context.getELContext()); if (converterType == null || converterType == Object.class) { // no conversion is needed return null; } if (converterType == String.class && !PrimeApplicationContext.getCurrentInstance(context).getConfig().isStringConverterAvailable()) { return null; } return context.getApplication().createConverter(converterType); }
public static ValueExpression getExpression(ELContext elContext, ValueExpression expression) { if (expression == null) { return null; } // Unwrapping is required e.g. for p:graphicImage to support nested expressions in composites // The unwrapping requires EL 2.2 if (PrimeApplicationContext.getCurrentInstance(FacesContext.getCurrentInstance()).getEnvironment().isAtLeastEl22()) { ValueReference reference = toValueReference(expression, elContext); // check for a CC expression if (reference != null && isCompositeComponentReference(reference)) { ValueExpression unwrapped = unwrapCompositeComponentReference(reference); if (unwrapped != null) { // check for nested CC expressions if (isCompositeComponentReference(toValueReference(unwrapped, elContext))) { return getExpression(elContext, unwrapped); } else { return unwrapped; } } } } return expression; }
@Override public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); // we only need to collect resources on ajax requests // for non ajax, the head will always be rendered again if (context.getViewRoot() == null || !context.getPartialViewContext().isAjaxRequest()) { return; } // we can also skip non-postback ajax requests, which occurs e.g. without a form if (!context.isPostback()) { return; } // skip update=@all as the head, with all resources, will already be rendered if (context.getPartialViewContext().isRenderAll()) { return; } // JSF 2.3 contains a own dynamic resource handling if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf23()) { return; } // collect all current resources before new components can be added to the view in later phases List<ResourceUtils.ResourceInfo> initialResources = ResourceUtils.getComponentResources(context); putInitialResources(context, initialResources); }
@Override public void decode(FacesContext context, UIComponent component) { TextEditor editor = (TextEditor) component; if (!shouldDecode(editor)) { return; } decodeBehaviors(context, editor); String inputParam = editor.getClientId(context) + "_input"; Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String value = params.get(inputParam); if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isHtmlSanitizerAvailable()) { value = HtmlSanitizer.sanitizeHtml(value, editor.isAllowBlocks(), editor.isAllowFormatting(), editor.isAllowLinks(), editor.isAllowStyles(), editor.isAllowImages()); } else { if (!editor.isAllowBlocks() || !editor.isAllowFormatting() || !editor.isAllowLinks() || !editor.isAllowStyles() || !editor.isAllowImages()) { LOGGER.warning("HTML sanitizer not available - skip sanitizing...."); } } if (value != null && value.equals("<br/>")) { value = ""; } editor.setSubmittedValue(value); }
@Override public Converter getConverter() { Converter converter = super.getConverter(); if (converter == null && PrimeApplicationContext.getCurrentInstance(getFacesContext()).getConfig().isClientSideValidationEnabled()) { DateTimeConverter con = new DateTimeConverter(); con.setPattern(calculatePattern()); con.setTimeZone(CalendarUtils.calculateTimeZone(this.getTimeZone())); con.setLocale(calculateLocale(getFacesContext())); return con; } return converter; } }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); Growl growl = (Growl) component; String clientId = growl.getClientId(context); String widgetVar = growl.resolveWidgetVar(); writer.startElement("span", growl); writer.writeAttribute("id", clientId, "id"); if (PrimeApplicationContext.getCurrentInstance(context).getConfig().isClientSideValidationEnabled()) { writer.writeAttribute("class", "ui-growl-pl", null); writer.writeAttribute(HTML.WIDGET_VAR, widgetVar, null); writer.writeAttribute("data-global", growl.isGlobalOnly(), null); writer.writeAttribute("data-summary", growl.isShowSummary(), null); writer.writeAttribute("data-detail", growl.isShowDetail(), null); writer.writeAttribute("data-severity", getClientSideSeverity(growl.getSeverity()), null); writer.writeAttribute("data-redisplay", String.valueOf(growl.isRedisplay()), null); } writer.endElement("span"); WidgetBuilder wb = getWidgetBuilder(context); wb.init("Growl", growl.resolveWidgetVar(), clientId) .attr("sticky", growl.isSticky()) .attr("life", growl.getLife()) .attr("escape", growl.isEscape()) .attr("keepAlive", growl.isKeepAlive()); writer.write(",msgs:"); encodeMessages(context, growl); wb.finish(); }