public abstract class Widget extends Object
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)
Resolves the HTML content for this widget.
|
String |
getName()
The widget key.
|
String |
getScript(RestRequest req)
Resolves any Javascript that should be added to the
|
String |
getStyle(RestRequest req)
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,
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,
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,
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.
public String getHtml(RestRequest req) throws Exception
A returned value of
req
- The HTTP request object.Exception
public String getScript(RestRequest req) throws Exception
A returned value of
req
- The HTTP request object.Exception
public String getStyle(RestRequest req) throws Exception
A returned value of
req
- The HTTP request object.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
protected String getClasspathResourceAsString(String name, Locale locale) throws IOException
getClasspathResourceAsString(String)
except also looks for localized-versions of the file.
If the locale
is specified, then we look for resources whose name matches that locale.
For example, if looking for the resource
name
- Name of the desired resource.locale
- The locale. Can be IOException
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
protected String loadScriptWithVars(RestRequest req, String name) throws IOException
loadScript(String)
but replaces request-time SVL variables.
req
- The current HTTP request.name
- Name of the desired resource.IOException
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
protected String loadStyleWithVars(RestRequest req, String name) throws IOException
loadStyle(String)
but replaces request-time SVL variables.
req
- The current HTTP request.name
- Name of the desired resource.IOException
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
protected String loadHtmlWithVars(RestRequest req, String name) throws IOException
loadHtml(String)
but replaces request-time SVL variables.
req
- The current HTTP request.name
- Name of the desired resource.IOException
Copyright © 2018 Apache. All rights reserved.