public class Utils extends Object
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
LOGGER |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
arePlaceholdersEnabled(XWikiContext context)
Check if placeholders are enabled in the current context.
|
static String |
createPlaceholder(String value,
XWikiContext context)
Create a placeholder key for a string that should be protected from further processing.
|
static String |
decode(String text,
XWikiContext context)
Deprecated.
replaced by
Util.decodeURI(String, XWikiContext) since 1.3M2 |
static void |
disablePlaceholders(XWikiContext context)
Disable placeholder support in the current request context.
|
static void |
enablePlaceholders(XWikiContext context)
Enable placeholder support in the current request context.
|
static String |
encode(String text,
XWikiContext context)
Deprecated.
replaced by
Util.encodeURI(String, XWikiContext) since 1.3M2 |
static String |
formEncode(String value)
Deprecated.
starting with 2.7 use
$services.xml.escape(content) |
static <T> T |
getComponent(Class<T> role)
Deprecated.
since 4.0M1 use
getComponent(Type) instead |
static <T> T |
getComponent(Class<T> role,
String hint)
Deprecated.
since 4.0M1 use
getComponent(Type, String) instead |
static <T> T |
getComponent(Type roleType)
Deprecated.
starting with 4.1M2 use the Component Script Service instead
|
static <T> T |
getComponent(Type roleType,
String roleHint)
Deprecated.
starting with 4.1M2 use the Component Script Service instead
|
static <T> List<T> |
getComponentList(Class<T> role)
Deprecated.
since 4.0M1 use
getComponentManager() instead |
static org.xwiki.component.manager.ComponentManager |
getComponentManager()
Deprecated.
since 6.1M1, use
getContextComponentManager() instead |
static byte[] |
getContent(List<org.apache.commons.fileupload.FileItem> filelist,
String name)
Get the content of an uploaded file, corresponding to the specified form field.
|
static XWikiContext |
getContext()
Helper method for obtaining a valid xcontext from the execution context.
|
static org.xwiki.component.manager.ComponentManager |
getContextComponentManager()
Deprecated.
last resort way of accessing the
ComponentManager , make sure you cannot do it any other way
possible since it add a strong dependency to a static to your code |
static String |
getFileName(List<org.apache.commons.fileupload.FileItem> filelist,
String name)
Get the name of an uploaded file, corresponding to the specified form field.
|
static String |
getPage(XWikiRequest request,
String defaultpage)
Retrieve the name of the velocity template which should be used to generate the response.
|
static String |
getRedirect(String action,
String queryString,
String... redirectParameters)
Retrieve the URL to which the client should be redirected after the successful completion of the requested
action.
|
static String |
getRedirect(String action,
String queryString,
XWikiContext context)
Retrieve the URL to which the client should be redirected after the successful completion of the requested
action.
|
static String |
getRedirect(String action,
XWikiContext context)
Retrieve the URL to which the client should be redirected after the successful completion of the requested
action.
|
static String |
getRedirect(XWikiRequest request,
String defaultRedirect)
Retrieve the URL to which the client should be redirected after the successful completion of the requested
action.
|
static org.xwiki.component.manager.ComponentManager |
getRootComponentManager()
Deprecated.
last resort way of accessing the
ComponentManager , make sure you cannot do it any other way
possible since it add a strong dependency to a static to your code |
static FileUploadPlugin |
handleMultipart(javax.servlet.http.HttpServletRequest request,
XWikiContext context)
Process a multi-part request, extracting all the uploaded files.
|
static Boolean |
isAjaxRequest(XWikiContext context)
Verify if the current request is an AJAX request.
|
static Map<String,String[]> |
parseParameters(byte[] data,
String encoding)
Parse the request parameters from the specified byte array using the specified encoding.
|
static Map<String,String[]> |
parseParameters(String data,
String encoding)
Parse the request parameters from the specified String using the specified encoding.
|
static void |
parseTemplate(String template,
boolean write,
XWikiContext context)
Generate the response by parsing a velocity template and (optionally) printing the result to the
Response . |
static void |
parseTemplate(String template,
XWikiContext context)
Generate the response by parsing a velocity template and printing the result to the
Response . |
static XWikiContext |
prepareContext(String action,
XWikiRequest request,
XWikiResponse response,
XWikiEngineContext engine_context) |
static String |
replacePlaceholders(String content,
XWikiContext context)
Insert back the replaced strings.
|
static void |
setComponentManager(org.xwiki.component.manager.ComponentManager componentManager) |
static String |
SQLFilter(String text) |
public static void parseTemplate(String template, XWikiContext context) throws XWikiException
Response
. This is the main entry point to the View part of the XWiki MVC architecture.template
- The name of the template to parse, without the .vm
prefix. The template will be searched
in the usual places: current XWikiSkins object, attachment of the current skin document, current skin
folder, baseskin folder, /templates/ folder.context
- the current contextXWikiException
- when the response cannot be written to the client (for example when the client canceled
the request, thus closing the socket)XWiki.parseTemplate(String, XWikiContext)
public static void parseTemplate(String template, boolean write, XWikiContext context) throws XWikiException
Response
.template
- The name of the template to parse, without the .vm
prefix. The template will be searched
in the usual places: current XWikiSkins object, attachment of the current skin document, current skin
folder, baseskin folder, /templates/ folder.write
- Whether the generated response should be written to the client or not. If false
, only the
needed headers are generated, suitable for implementing a HEAD response.context
- the current contextXWikiException
- when the response cannot be written to the client (for example when the client canceled
the request, thus closing the socket)XWiki.parseTemplate(String, XWikiContext)
public static String getRedirect(XWikiRequest request, String defaultRedirect)
xredirect
parameter in the query string. If this parameter is not set, or
is set to an empty value, return the default redirect specified as the second argument.request
- the current requestdefaultRedirect
- the default value to use if no xredirect
parameter is presentxredirect
parameter, or the specified default URLpublic static String getRedirect(String action, String queryString, XWikiContext context)
xredirect
parameter in the query string. If this parameter is not set, or
is set to an empty value, compose an URL back to the current document, using the specified action and query
string, and return it.action
- the XWiki action to use for composing the default redirect URL (view
, edit
, etc)queryString
- the query parameters to append to the fallback URLcontext
- the current contextxredirect
parameter, or computed using the current
document and the specified action and query stringpublic static String getRedirect(String action, String queryString, String... redirectParameters)
redirectParameters
(in order) is present in the query string, it is
returned as the redirect destination. If none of the parameters is set, compose an URL back to the current
document using the specified action and query string, and return it.action
- the XWiki action to use for composing the default redirect URL (view
, edit
, etc)queryString
- the query parameters to append to the fallback URLredirectParameters
- list of request parameters to look for as the redirect destination; each of the
parameters is tried in the order they are passed, and the first one set to a non-empty value is
returned, if anyredirectParameters
, or computed using the current
document and the specified action and query stringpublic static String getRedirect(String action, XWikiContext context)
xredirect
parameter in the query string. If this parameter is not set, or
is set to an empty value, compose an URL back to the current document, using the specified action, and return it.action
- the XWiki action to use for composing the default redirect URL (view
, edit
, etc)context
- the current contextxredirect
parameter, or computed using the current
document and the specified actionpublic static String getPage(XWikiRequest request, String defaultpage)
xpage
parameter in the query string. If this parameter is not set, or is set to an empty value, return
the provided default name.request
- the current requestdefaultpage
- the default value to use if no xpage
parameter is setxpage
parameter, or the specified default
templatepublic static String getFileName(List<org.apache.commons.fileupload.FileItem> filelist, String name)
filelist
- the list of uploaded files, computed by the FileUpload pluginname
- the name of the form fieldnull
otherwisepublic static byte[] getContent(List<org.apache.commons.fileupload.FileItem> filelist, String name) throws XWikiException
filelist
- the list of uploaded files, computed by the FileUpload pluginname
- the name of the form fieldnull
otherwiseXWikiException
- if the file cannot be read due to an underlying I/O exceptionpublic static XWikiContext prepareContext(String action, XWikiRequest request, XWikiResponse response, XWikiEngineContext engine_context) throws XWikiException
XWikiException
public static Map<String,String[]> parseParameters(String data, String encoding) throws UnsupportedEncodingException
=
or &
character that would otherwise be interpreted as a delimiter.
Code borrowed from Apache Tomcat 5.0
data
- input string containing request parametersencoding
- the encoding to use for transforming bytes into charactersIllegalArgumentException
- if the data is malformedUnsupportedEncodingException
public static Map<String,String[]> parseParameters(byte[] data, String encoding) throws UnsupportedEncodingException
=
or &
character that would otherwise be interpreted as a delimiter.
NOTE: byte array data is modified by this method. Caller beware.
Code borrowed from Apache Tomcat 5.0
data
- input byte array containing request parametersencoding
- Encoding to use for converting hexUnsupportedEncodingException
- if the data is malformed@Deprecated public static String formEncode(String value)
$services.xml.escape(content)
String
using numerical XML entities.value
- the text to escape, may be nullString
, null
if null input@Deprecated public static String encode(String text, XWikiContext context)
Util.encodeURI(String, XWikiContext)
since 1.3M2@Deprecated public static String decode(String text, XWikiContext context)
Util.decodeURI(String, XWikiContext)
since 1.3M2public static FileUploadPlugin handleMultipart(javax.servlet.http.HttpServletRequest request, XWikiContext context)
request
- the current request to processcontext
- the current contextFileUploadPlugin
used to parse the uploaded filespublic static void setComponentManager(org.xwiki.component.manager.ComponentManager componentManager)
componentManager
- the root component manager used by getComponent(Class)
and
getComponent(Class, String)
@Deprecated public static org.xwiki.component.manager.ComponentManager getRootComponentManager()
ComponentManager
, make sure you cannot do it any other way
possible since it add a strong dependency to a static to your code@Deprecated public static org.xwiki.component.manager.ComponentManager getComponentManager()
getContextComponentManager()
insteadgetComponent(Class)
and
getComponent(Class, String)
@Deprecated public static org.xwiki.component.manager.ComponentManager getContextComponentManager()
ComponentManager
, make sure you cannot do it any other way
possible since it add a strong dependency to a static to your codegetComponent(Class)
and
getComponent(Class, String)
@Deprecated public static <T> T getComponent(Class<T> role, String hint)
getComponent(Type, String)
insteadrole
- the class (aka role) that the component implementshint
- a value to differentiate different component implementations for the same roleRuntimeException
- if the component cannot be found/initialized, or if the component manager is not
initialized@Deprecated public static <T> T getComponent(Class<T> role)
getComponent(Type)
insteadrole
- the class (aka role) that the component implementsRuntimeException
- if the component cannot be found/initialized, or if the component manager is not
initialized@Deprecated public static <T> T getComponent(Type roleType, String roleHint)
roleType
- the class (aka role) that the component implementsroleHint
- a value to differentiate different component implementations for the same roleRuntimeException
- if the component cannot be found/initialized, or if the component manager is not
initialized@Deprecated public static <T> T getComponent(Type roleType)
roleType
- the class (aka role) that the component implementsRuntimeException
- if the component cannot be found/initialized, or if the component manager is not
initialized@Deprecated public static <T> List<T> getComponentList(Class<T> role)
getComponentManager()
insteadT
- the component typerole
- the role for which to return implementing componentsRuntimeException
- if some of the components cannot be found/initialized, or if the component manager is
not initializedpublic static XWikiContext getContext()
NOTE: Don't use this method to access the XWiki context in a component because
setComponentManager(ComponentManager)
is not called when running component unit tests. You have to take
the XWiki context yourself from the injected Execution when inside a component. This method should be used only
by non-component code.
null
if the execution context is not yet initializedpublic static boolean arePlaceholdersEnabled(XWikiContext context)
context
- The current context.true
if placeholders can be used, false
otherwise.public static void enablePlaceholders(XWikiContext context)
context
- The current context.public static void disablePlaceholders(XWikiContext context)
context
- The current context.public static String createPlaceholder(String value, XWikiContext context)
value
- The string to hide.context
- The current context.public static String replacePlaceholders(String content, XWikiContext context)
content
- The rendered content, with placeholders.context
- The current context.public static Boolean isAjaxRequest(XWikiContext context)
context
- the current request contextCopyright © 2004–2021 XWiki. All rights reserved.