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

File AbstractFilterScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

0
4
4
1
92
31
4
1
1
4
1

Classes

Class Line # Actions
AbstractFilterScriptService 34 4 0% 4 4
0.550%
 

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.filter.script;
21   
22    import javax.inject.Inject;
23   
24    import org.xwiki.context.Execution;
25    import org.xwiki.script.internal.safe.ScriptSafeProvider;
26    import org.xwiki.script.service.ScriptService;
27   
28    /**
29    * Base class for all FilterStream related script services.
30    *
31    * @version $Id: 123c0b7138ea17548bdad058d51381783260eeeb $
32    * @since 6.2M1
33    */
 
34    public abstract class AbstractFilterScriptService implements ScriptService
35    {
36    /**
37    * The key under which the last encountered error is stored in the current execution context.
38    */
39    public static final String EXTENSIONERROR_KEY = "scriptservice.filter.error";
40   
41    @Inject
42    @SuppressWarnings("rawtypes")
43    protected ScriptSafeProvider scriptProvider;
44   
45    /**
46    * Provides access to the current context.
47    */
48    @Inject
49    protected Execution execution;
50   
51    /**
52    * @param <T> the type of the object
53    * @param unsafe the unsafe object
54    * @return the safe version of the passed object
55    */
 
56  0 toggle @SuppressWarnings("unchecked")
57    protected <T> T safe(T unsafe)
58    {
59  0 return (T) this.scriptProvider.get(unsafe);
60    }
61   
62    // Error management
63   
64    /**
65    * Get the error generated while performing the previously called action.
66    *
67    * @return an eventual exception or {@code null} if no exception was thrown
68    */
 
69  0 toggle public Exception getLastError()
70    {
71  0 return (Exception) this.execution.getContext().getProperty(EXTENSIONERROR_KEY);
72    }
73   
74    /**
75    * Reset error status.
76    */
 
77  39 toggle protected void resetError()
78    {
79  39 setError(null);
80    }
81   
82    /**
83    * Store a caught exception in the context, so that it can be later retrieved using {@link #getLastError()}.
84    *
85    * @param e the exception to store, can be {@code null} to clear the previously stored exception
86    * @see #getLastError()
87    */
 
88  41 toggle protected void setError(Exception e)
89    {
90  41 this.execution.getContext().setProperty(EXTENSIONERROR_KEY, e);
91    }
92    }