001/*
002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *     <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
019 *     <a href="mailto:rspivak@nuxeo.com">Ruslan Spivak</a>
020 *     Anahide Tchertchian
021 *
022 * $Id: ActionContext.java 20218 2007-06-07 19:19:46Z sfermigier $
023 */
024
025package org.nuxeo.ecm.platform.actions;
026
027import java.io.Serializable;
028import java.util.Map;
029
030import javax.el.ELException;
031
032import org.nuxeo.ecm.core.api.CoreSession;
033import org.nuxeo.ecm.core.api.DocumentModel;
034import org.nuxeo.ecm.core.api.NuxeoPrincipal;
035
036/**
037 * Interface for action context evaluation
038 *
039 * @since 5.7.3
040 */
041public interface ActionContext extends Serializable {
042
043    /**
044     * Sets the current document to use for filter evaluation
045     */
046    void setCurrentDocument(DocumentModel doc);
047
048    /**
049     * Returns the current document to use for filter evaluation
050     */
051    DocumentModel getCurrentDocument();
052
053    /**
054     * Sets the core session to use for filter evaluation
055     */
056    void setDocumentManager(CoreSession docMgr);
057
058    /**
059     * Returns the core session to use for filter evaluation
060     */
061    CoreSession getDocumentManager();
062
063    /**
064     * Sets the current principal to use for filter evaluation
065     */
066    void setCurrentPrincipal(NuxeoPrincipal currentPrincipal);
067
068    /**
069     * Returns the current principal to use for filter evaluation
070     */
071    NuxeoPrincipal getCurrentPrincipal();
072
073    /**
074     * Sets a local variable, to put in the context so that expressions can reference it.
075     */
076    Object putLocalVariable(String key, Object value);
077
078    /**
079     * Sets local variables, to put in the context so that expressions can reference them.
080     */
081    void putAllLocalVariables(Map<String, Object> vars);
082
083    /**
084     * Returns a local variable put in the context
085     */
086    Object getLocalVariable(String key);
087
088    /**
089     * Returns the number of local variables
090     */
091    int size();
092
093    /**
094     * Returns true if given expression resolves to true in this context.
095     * <p>
096     * Returns false if expression is blank (null or empty).
097     */
098    boolean checkCondition(String expression) throws ELException;
099
100    /**
101     * Evaluates the given {@code expression} and returns the result cast to the given {@code expectedType}.
102     *
103     * @return the result of the expression evaluation
104     * @since 10.2
105     */
106    <T> T evalExpression(String expression, Class<T> expectedType) throws ELException;
107
108    /**
109     * Returns true if expressions evaluation should not be cached globally
110     */
111    boolean disableGlobalCaching();
112
113}