1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.script.internal.safe

File AbstractNoExceptionSafeObject.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

0
6
4
1
97
31
4
0.67
1.5
4
1

Classes

Class Line # Actions
AbstractNoExceptionSafeObject 37 6 0% 4 4
0.660%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.script.internal.safe;
21   
22    import javax.inject.Inject;
23   
24    import org.xwiki.context.Execution;
25    import org.xwiki.extension.script.ExtensionManagerScriptService;
26    import org.xwiki.script.internal.safe.AbstractSafeObject;
27    import org.xwiki.script.internal.safe.ScriptSafeProvider;
28   
29    /**
30    * Encapsulate {@link AbstractSafeObject} with tools to make easier to use the wrapped API with script language not
31    * supporting exceptions.
32    *
33    * @param <T> the type of the wrapped object
34    * @version $Id: 45786ce6310cce9635c0df80846d7ab20494a60b $
35    * @since 4.0M2
36    */
 
37    public abstract class AbstractNoExceptionSafeObject<T> extends AbstractSafeObject<T>
38    {
39    /**
40    * Indicate of the object should behave as if the caller scripts had programming right.
41    *
42    * @since 4.2M1
43    */
44    protected boolean hasProgrammingRight;
45   
46    /**
47    * Provides access to the current context.
48    */
49    @Inject
50    private Execution execution;
51   
52    /**
53    * @param wrapped the wrapped object
54    * @param safeProvider the provider of instances safe for public scripts
55    * @param execution provide access to the current context
56    */
 
57  0 toggle public AbstractNoExceptionSafeObject(T wrapped, ScriptSafeProvider< ? > safeProvider, Execution execution)
58    {
59  0 this(wrapped, safeProvider, execution, false);
60    }
61   
62    /**
63    * @param wrapped the wrapped object
64    * @param safeProvider the provider of instances safe for public scripts
65    * @param execution provide access to the current context
66    * @param hasProgrammingRight does the caller script has programming right
67    */
 
68  1620 toggle public AbstractNoExceptionSafeObject(T wrapped, ScriptSafeProvider< ? > safeProvider, Execution execution,
69    boolean hasProgrammingRight)
70    {
71  1620 super(wrapped, safeProvider);
72   
73  1619 this.execution = execution;
74  1619 this.hasProgrammingRight = hasProgrammingRight;
75    }
76   
77    /**
78    * Get the error generated while performing the previously called action.
79    *
80    * @return an eventual exception or {@code null} if no exception was thrown
81    */
 
82  0 toggle public Exception getLastError()
83    {
84  0 return (Exception) this.execution.getContext().getProperty(ExtensionManagerScriptService.EXTENSIONERROR_KEY);
85    }
86   
87    /**
88    * Store a caught exception in the context, so that it can be later retrieved using {@link #getLastError()}.
89    *
90    * @param e the exception to store, can be {@code null} to clear the previously stored exception
91    * @see #getLastError()
92    */
 
93  654 toggle protected void setError(Exception e)
94    {
95  654 this.execution.getContext().setProperty(ExtensionManagerScriptService.EXTENSIONERROR_KEY, e);
96    }
97    }