/*
(non-Javadoc)

@see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext,
javax.faces.component.UIComponent)
18247
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        VariableMapper orig = ctx.getVariableMapper();
        AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
        actx.pushClient(this);

        if (_params != null)
        {
            VariableMapper vm = new VariableMapperWrapper(orig);
            ctx.setVariableMapper(vm);
            for (int i = 0; i < _params.length; i++)
            {
                _params[i].apply(ctx, parent);
            }
        }

        FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
        String path;
        boolean markInitialState = false;
        if (!_template.isLiteral())
        {
            String uniqueId = actx.generateUniqueFaceletTagId(fcc.startComponentUniqueIdSection(), tagId);
            //path = getTemplateValue(actx, fcc, parent, uniqueId);
            String restoredPath = (String) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId);
            if (restoredPath != null)
            {
                // If is not restore view phase, the path value should be
                // evaluated and if is not equals, trigger markInitialState stuff.
                if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
                {
                    path = this._template.getValue(ctx);
                    if (path == null || path.length() == 0)
                    {
                        return;
                    }
                    if (!path.equals(restoredPath))
                    {
                        markInitialState = true;
                    }
                }
                else
                {
                    path = restoredPath;
                }
            }
            else
            {
                //No state restored, calculate path
                path = this._template.getValue(ctx);
            }
            ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, path);
        }
        else
        {
            path = _template.getValue(ctx);
        }
        try
        {
            try
            {
                boolean oldMarkInitialState = false;
                Boolean isBuildingInitialState = null;
                if (markInitialState)
                {
                    //set markInitialState flag
                    oldMarkInitialState = fcc.isMarkInitialState();
                    fcc.setMarkInitialState(true);
                    isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
                            StateManager.IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
                }
                try
                {
                    ctx.includeFacelet(parent, path);
                }
                finally
                {
                    if (markInitialState)
                    {
                        //unset markInitialState flag
                        if (isBuildingInitialState == null)
                        {
                            ctx.getFacesContext().getAttributes().remove(
                                    StateManager.IS_BUILDING_INITIAL_STATE);
                        }
                        else
                        {
                            ctx.getFacesContext().getAttributes().put(
                                    StateManager.IS_BUILDING_INITIAL_STATE, isBuildingInitialState);
                        }
                        fcc.setMarkInitialState(oldMarkInitialState);
                    }
                }
            }
            finally
            {
                ctx.setVariableMapper(orig);
                actx.popClient(this);
            }
        }
        finally
        {
            if (!_template.isLiteral())
            {
                fcc.endComponentUniqueIdSection();
            }
        }
        if (!_template.isLiteral() && fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() &&
            !fcc.isRefreshingTransientBuild())
        {
            //Mark the parent component to be saved and restored fully.
            ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
        }
        if (!_template.isLiteral() && fcc.isDynamicComponentSection())
        {
            ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
        }
    }
1342430
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WFieldLayout fieldLayout = (WFieldLayout) component;
		XmlStringBuilder xml = renderContext.getWriter();
		int labelWidth = fieldLayout.getLabelWidth();
		String title = fieldLayout.getTitle();

		xml.appendTagOpen("ui:fieldlayout");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendOptionalAttribute("hidden", fieldLayout.isHidden(), "true");
		xml.appendOptionalAttribute("labelWidth", labelWidth > 0, labelWidth);
		xml.appendAttribute("layout", fieldLayout.getLayoutType());
		xml.appendOptionalAttribute("title", title);
		// Ordered layout
		if (fieldLayout.isOrdered()) {
			xml.appendAttribute("ordered", fieldLayout.getOrderedOffset());
		}
		xml.appendClose();

		// Render margin
		MarginRendererUtil.renderMargin(fieldLayout, renderContext);

		// Paint Fields
		paintChildren(fieldLayout, renderContext);

		xml.appendEndTag("ui:fieldlayout");
	}
774855
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        if (_template != null)
        {
            VariableMapper orig = ctx.getVariableMapper();
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
            actx.extendClient(this);
            if (_params != null)
            {
                VariableMapper vm = new VariableMapperWrapper(orig);
                ctx.setVariableMapper(vm);
                for (int i = 0; i < _params.length; i++)
                {
                    _params[i].apply(ctx, parent);
                }
            }

            try
            {
                ctx.includeFacelet(parent, _template.getValue(ctx));
            }
            finally
            {
                actx.popExtendedClient(this);
                ctx.setVariableMapper(orig);
            }
        }
        else
        {
            this.nextHandler.apply(ctx, parent);
        }
    }
392835
@Override
    public void decode(FacesContext context, UIComponent component) {
        Tree tree = (Tree) component;
        super.decode(context, tree);

        final TreeNodeEventListener nodeSelectionListener = tree.getNodeSelectionListener();
        String params = context.getExternalContext().getRequestParameterMap().get("params");

        if (params != null) {
            params = params.replace("BsFEvent=", "");
            String[] pair = params.split(":", 2);
            String key = pair[0];
            Integer value = null;
            if (pair.length == 2)
                value = Integer.valueOf(pair[1]);
            
            if (value != null) {
                Node n = TreeModelUtils.searchNodeById(tree.getValue(), value);

                if (nodeSelectionListener != null && n != null) {
                    // execute listener only for listened events
                    if ("nodeSelected".equals(key)) {
                        n.setSelected(true);
                        nodeSelectionListener.processValueSelected(new TreeNodeSelectionEvent(n, true));
                    } else if ("nodeUnselected".equals(key)) {
                        n.setSelected(false);
                        nodeSelectionListener.processValueSelected(new TreeNodeSelectionEvent(n, false));
                    } else if ("nodeChecked".equals(key)) {
                        n.setChecked(true);
                        nodeSelectionListener.processValueChecked(new TreeNodeCheckedEvent(n, true));
                    } else if ("nodeUnchecked".equals(key)) {
                        n.setChecked(false);
                        nodeSelectionListener.processValueChecked(new TreeNodeCheckedEvent(n, false));
                    } else if ("nodeExpanded".equals(key)) {
                        n.setExpanded(true);
                        nodeSelectionListener.processValueExpanded(new TreeNodeExpandedEvent(n, true));
                    } else if ("nodeCollapsed".equals(key)) {
                        n.setExpanded(false);
                        nodeSelectionListener.processValueExpanded(new TreeNodeExpandedEvent(n, false));
                    }
                }
            }
        }
    }
1183169
public void focus(String expression, UIComponent base) {
        if (LangUtils.isValueBlank(expression)) {
            return;
        }

        FacesContext facesContext = getFacesContext();

        String clientId = SearchExpressionFacade.resolveClientId(facesContext,
                base,
                expression);
        executeScript("PrimeFaces.focus('" + clientId + "');");
    }
1051242
@Override
    public T apply(T entity) {

        switch (this.mode) {
            case NEW_VALUE_MODE:
                return value(entity, this.element, this.value, false);
            case MIN_MODE:
                return min(entity, this.element);
            case MAX_MODE:
                return max(entity, this.element);
            case FLOOR_MODE:
                return floor(entity, this.element);
            case CEILING_MODE:
                return ceiling(entity, this.element);
            case LENIENT_MODE:
                return value(entity, this.element, this.value, true);
            case DECREMENTING_MODE:
                return this.move(entity, false);
            case INCREMENTING_MODE:
                return this.move(entity, true);
            default:
                throw new UnsupportedOperationException(
                    "Unknown mode: " + this.mode);
        }

    }
206581
@Override
    public Object apply(Object value, Object... params) {

        return super.asString(super.get(0, params)) + super.asString(value);
    }
873366
public void validate(FacesContext context,
                         UIComponent  component,
                         Object       value) throws ValidatorException {
	if (null == context || null == component) {
	    throw new NullPointerException();
	}
        try {
            methodBinding.invoke(context, new Object[] {context, component, 
							value});
        } 
	catch (EvaluationException ee) {
	    Throwable cause = this.getExpectedCause(ValidatorException.class,
						    ee);
	    if (cause instanceof ValidatorException) {
		throw ((ValidatorException) cause);
	    }
	    if (cause instanceof RuntimeException) {
		throw ((RuntimeException) cause);
	    }
	    throw new IllegalStateException(ee);
        }
	
	
    }
964768
public static void apply(Annotated member, Schema property) {
        if (member.hasAnnotation(XmlElementWrapper.class) || member.hasAnnotation(XmlElement.class)) {
            applyElement(member, property);
        } else if (member.hasAnnotation(XmlAttribute.class) && isAttributeAllowed(property)) {
            applyAttribute(member, property);
        }
    }
1306192
private final UIComponent createComponent(FacesContext facesContext, 
            final String componentType) throws FacesException
    {
        checkNull(componentType, "componentType");
        checkEmpty(componentType, "componentType");

        final Class<? extends UIComponent> componentClass =
                getObjectFromClassMap(componentType, _componentClassMap);
        if (componentClass == null)
        {
            log.log(Level.SEVERE, "Undefined component type " + componentType);
            throw new FacesException("Undefined component type " + componentType);
        }

        try
        {
            UIComponent component = componentClass.newInstance();
            _handleAnnotations(facesContext, component, component);
            return component;
        }
        catch (Exception e)
        {
            log.log(Level.SEVERE, "Could not instantiate component componentType = " + componentType, e);
            throw new FacesException("Could not instantiate component componentType = " + componentType, e);
        }
    }
396959
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
            ELException
    {
        if (_template != null)
        {
            //VariableMapper orig = ctx.getVariableMapper();
            //if (_params != null)
            //{
            //    VariableMapper vm = new VariableMapperWrapper(orig);
            //    ctx.setVariableMapper(vm);
            //    for (int i = 0; i < _params.length; i++)
            //    {
            //        _params[i].apply(ctx, parent);
            //    }
            //}
            AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
            FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
            actx.extendClient(this);
            if (_params != null)
            {
                String uniqueId = fcc.generateUniqueComponentId();
                //VariableMapper vm = new VariableMapperWrapper(orig);
                //ctx.setVariableMapper(vm);
                for (int i = 0; i < _params.length; i++)
                {
                    _params[i].apply(ctx, parent, _params[i].getName(ctx), _params[i].getValue(ctx), uniqueId);
                }
            }

            try
            {
                ctx.includeFacelet(parent, _template.getValue(ctx));
            }
            finally
            {
                actx.popExtendedClient(this);
                //ctx.setVariableMapper(orig);
            }
        }
        else
        {
            this.nextHandler.apply(ctx, parent);
        }
    }
1218442
public void addComponent(Object screenField)
    {
        if (this.getNextConverter() != null)
            this.getNextConverter().addComponent(screenField);
        else
            super.addComponent(screenField);
    }
434488
private static void applyAllRecursively(ViewGroup viewGroup, AssetManager assets) {
        for (int i = 0, size = viewGroup.getChildCount(); i < size; i++) {
            final View childView = viewGroup.getChildAt(i);
            if (childView instanceof TextView) {
                setTypeface((TextView) childView, assets, false);
            } else if (childView instanceof ViewGroup) {
                applyAllRecursively((ViewGroup) childView, assets);
            }
        }
    }
353317
public void apply(Object target) throws InvalidOrderingException {
        /*
         * Note that some subclasses of Ordering override apply(). The Sorter
         * subclass of Ordering overrides apply() to apply the sort (this is
         * done because sorting is more efficient than ordering).
         */
        if (target instanceof Orderable) {
            Orderable orderable = (Orderable) target;
            orderable.order(new Orderer(this));
        }
    }
290128
public void apply() {
        if (element != null) {
            String uid = DOM.createUniqueId();
            element.setId(uid);
            JsScrollfire.apply("#" + uid, offset, callback::call);
        } else {
            GWT.log("You must set the element before applying the scrollfire", new IllegalStateException());
        }
    }
1193144
public void setValue(FacesContext context, Object value)
            throws EvaluationException, PropertyNotFoundException {
            
        if (context == null) {
	        throw new NullPointerException("FacesContext -> null");
        }
        try {
            valueExpression.setValue(context.getELContext(), value);
        } catch (javax.el.PropertyNotFoundException pnfe) {
            throw new PropertyNotFoundException(pnfe);
        } catch (javax.el.PropertyNotWritableException pnwe) {
            throw new PropertyNotFoundException(pnwe);
        } catch (ELException elex) {
            throw new EvaluationException(elex);
        }
    }
566110
@Override
	public CharSequence apply( final Object computedContext, final Options options ) throws IOException {

		// Get parameters
		Object context = options.context.model();
		String componentPath = null;
		if( computedContext instanceof String )
			componentPath = (String) computedContext;

		if( Utils.isEmptyOrWhitespaces( componentPath ))
			componentPath = InstanceFilter.JOKER;

		// Process them
		CharSequence result = StringUtils.EMPTY;
		if (context instanceof ApplicationContextBean) {
			// Implicit: all instances of the application.
			result = safeApply(((ApplicationContextBean) context).getInstances(), options, componentPath );

		} else if (context instanceof InstanceContextBean) {
			// Implicit: all descendants of the instance.
			result = safeApply( descendantInstances((InstanceContextBean) context), options, componentPath );

		} else {
			this.logger.warning( "An unexpected context was received: " + (context == null ? null : context.getClass()));
		}

		return result;
	}