public abstract class Widget extends Object implements HtmlWidget
Widgets must provide one of the following public constructors:
public Widget();
public Widget(PropertyStore);
Widgets can be defined as inner classes of REST resource classes.
Constructor and Description |
---|
Widget() |
Modifier and Type | Method and Description |
---|---|
protected String |
getClasspathResourceAsString(String name)
Retrieves the specified classpath resource and returns the contents as a string.
|
protected String |
getClasspathResourceAsString(String name,
Locale locale)
Same as
getClasspathResourceAsString(String) except also looks for localized-versions of the file. |
String |
getHtml(RestRequest req)
Deprecated.
|
String |
getHtml(RestRequest req,
RestResponse res)
Resolves the HTML content for this widget.
|
String |
getHtml(VarResolverSession session)
Resolves the HTML content for this widget.
|
String |
getName()
The widget key.
|
String |
getScript(RestRequest req)
Deprecated.
|
String |
getScript(RestRequest req,
RestResponse res)
Resolves any Javascript that should be added to the
|
String |
getScript(VarResolverSession session)
Resolves any Javascript that should be added to the
|
String |
getStyle(RestRequest req)
Deprecated.
|
String |
getStyle(RestRequest req,
RestResponse res)
Resolves any CSS styles that should be added to the
|
String |
getStyle(VarResolverSession session)
Resolves any CSS styles that should be added to the
|
protected String |
loadHtml(String name)
Convenience method for calling
getClasspathResourceAsString(String) except also strips HTML comments from the
file. |
protected String |
loadHtmlWithVars(RestRequest req,
RestResponse res,
String name)
Same as
loadHtml(String) but replaces request-time SVL variables. |
protected String |
loadScript(String name)
Convenience method for calling
getClasspathResourceAsString(String) except also strips Javascript comments from
the file. |
protected String |
loadScriptWithVars(RestRequest req,
RestResponse res,
String name)
Same as
loadScript(String) but replaces request-time SVL variables. |
protected String |
loadStyle(String name)
Convenience method for calling
getClasspathResourceAsString(String) except also strips CSS comments from
the file. |
protected String |
loadStyleWithVars(RestRequest req,
RestResponse res,
String name)
Same as
loadStyle(String) but replaces request-time SVL variables. |
public Widget()
public String getName()
(i.e. The variable name inside the
The returned value must not be
If not overridden, the default value is the class simple name.
getName
in interface HtmlWidget
public String getHtml(VarResolverSession session) throws Exception
HtmlWidget
A returned value of
getHtml
in interface HtmlWidget
session
- The current serializer session.Exception
- Error occurred.public String getScript(VarResolverSession session) throws Exception
HtmlWidget
A returned value of
getScript
in interface HtmlWidget
session
- The current serializer session.Exception
- Error occurred.public String getStyle(VarResolverSession session) throws Exception
HtmlWidget
A returned value of
getStyle
in interface HtmlWidget
session
- The current serializer session.Exception
- Error occurred.public String getHtml(RestRequest req, RestResponse res) throws Exception
A returned value of
req
- The HTTP request object.res
- The current HTTP response.Exception
- Error occurred.@Deprecated public String getHtml(RestRequest req) throws Exception
getHtml(RestRequest, RestResponse)
.Exception
public String getScript(RestRequest req, RestResponse res) throws Exception
A returned value of
req
- The HTTP request object.res
- The current HTTP response.Exception
- Error occurred.@Deprecated public String getScript(RestRequest req) throws Exception
getScript(RestRequest, RestResponse)
.Exception
public String getStyle(RestRequest req, RestResponse res) throws Exception
A returned value of
req
- The HTTP request object.res
- The current HTTP response.Exception
- Error occurred.@Deprecated public String getStyle(RestRequest req) throws Exception
getStyle(RestRequest, RestResponse)
.Exception
protected String getClasspathResourceAsString(String name) throws IOException
Same as Class.getResourceAsStream(String)
except if it doesn't find the resource on this class, searches
up the parent hierarchy chain.
If the resource cannot be found in the classpath, then an attempt is made to look relative to the JVM working directory.
Path traversals outside the working directory are not allowed for security reasons.
name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String getClasspathResourceAsString(String name, Locale locale) throws IOException
getClasspathResourceAsString(String)
except also looks for localized-versions of the file.
If the
For example, if looking for the resource
name
- Name of the desired resource.locale
- The locale. Can be IOException
- Thrown by underlying stream.protected String loadScript(String name) throws IOException
getClasspathResourceAsString(String)
except also strips Javascript comments from
the file.
Comments are assumed to be Java-style block comments:
name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String loadScriptWithVars(RestRequest req, RestResponse res, String name) throws IOException
loadScript(String)
but replaces request-time SVL variables.
req
- The current HTTP request.res
- The current HTTP response.name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String loadStyle(String name) throws IOException
getClasspathResourceAsString(String)
except also strips CSS comments from
the file.
Comments are assumed to be Java-style block comments:
name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String loadStyleWithVars(RestRequest req, RestResponse res, String name) throws IOException
loadStyle(String)
but replaces request-time SVL variables.
req
- The current HTTP request.res
- The current HTTP response.name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String loadHtml(String name) throws IOException
getClasspathResourceAsString(String)
except also strips HTML comments from the
file.
Comment are assumed to be
name
- Name of the desired resource.IOException
- Thrown by underlying stream.protected String loadHtmlWithVars(RestRequest req, RestResponse res, String name) throws IOException
loadHtml(String)
but replaces request-time SVL variables.
req
- The current HTTP request.res
- The current HTTP response.name
- Name of the desired resource.IOException
- Thrown by underlying stream.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.