You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2018/07/13 13:40:44 UTC
[juneau] branch master updated: Add var-resolver helper methods to
Widget class.
This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new cbaa73e Add var-resolver helper methods to Widget class.
cbaa73e is described below
commit cbaa73ed0b75807bc58c0d487a529832fcfab4ac
Author: JamesBognar <ja...@apache.org>
AuthorDate: Fri Jul 13 09:40:29 2018 -0400
Add var-resolver helper methods to Widget class.
---
juneau-doc/src/main/javadoc/overview.html | 8 ++++
.../java/org/apache/juneau/rest/widget/Widget.java | 54 ++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/juneau-doc/src/main/javadoc/overview.html b/juneau-doc/src/main/javadoc/overview.html
index f048e17..e608d4d 100644
--- a/juneau-doc/src/main/javadoc/overview.html
+++ b/juneau-doc/src/main/javadoc/overview.html
@@ -21820,6 +21820,14 @@
<li class='jm'>{@link org.apache.juneau.rest.widget.MenuItemWidget#getBeforeShowScript(RestRequest) getBeforeShowScript(RestRequest)}
<li class='jm'>{@link org.apache.juneau.rest.widget.MenuItemWidget#getAfterShowScript(RestRequest) getAfterShowScript(RestRequest)}
</ul>
+ <li>
+ New methods added to {@link org.apache.juneau.rest.widget.Widget} to allow retrieving classpath resources with embedded SVL variables:
+ <li class='jc'>{@link org.apache.juneau.rest.widget.Widget}
+ <ul>
+ <li class='jm'>{@link org.apache.juneau.rest.widget.Widget#loadHtmlWithVars(RestRequest,String) loadHtmlWithVars(RestRequest,String)}
+ <li class='jm'>{@link org.apache.juneau.rest.widget.Widget#loadScriptWithVars(RestRequest,String) loadScriptWithVars(RestRequest,String)}
+ <li class='jm'>{@link org.apache.juneau.rest.widget.Widget#loadStyleWithVars(RestRequest,String) loadStyleWithVars(RestRequest,String)}
+ </ul>
</ul>
<h5 class='topic w800'>juneau-rest-microservice</h5>
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
index 45d848f..b065160 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java
@@ -251,6 +251,24 @@ public abstract class Widget {
}
/**
+ * Same as {@link #loadScript(String)} but replaces request-time SVL variables.
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='jm'>{@link org.apache.juneau.rest.RestContext#getVarResolver()}
+ * <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.SvlVariables">Overview > juneau-rest-server > SVL Variables</a>
+ * </ul>
+ *
+ * @param req The current HTTP request.
+ * @param name Name of the desired resource.
+ * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found.
+ * @throws IOException
+ */
+ protected String loadScriptWithVars(RestRequest req, String name) throws IOException {
+ return req.getVarResolverSession().resolve(loadScript(name));
+ }
+
+ /**
* Convenience method for calling {@link #getClasspathResourceAsString(String)} except also strips CSS comments from
* the file.
*
@@ -269,6 +287,24 @@ public abstract class Widget {
}
/**
+ * Same as {@link #loadStyle(String)} but replaces request-time SVL variables.
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='jm'>{@link org.apache.juneau.rest.RestContext#getVarResolver()}
+ * <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.SvlVariables">Overview > juneau-rest-server > SVL Variables</a>
+ * </ul>
+ *
+ * @param req The current HTTP request.
+ * @param name Name of the desired resource.
+ * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found.
+ * @throws IOException
+ */
+ protected String loadStyleWithVars(RestRequest req, String name) throws IOException {
+ return req.getVarResolverSession().resolve(loadStyle(name));
+ }
+
+ /**
* Convenience method for calling {@link #getClasspathResourceAsString(String)} except also strips HTML comments from the
* file.
*
@@ -285,4 +321,22 @@ public abstract class Widget {
s = s.replaceAll("(?s)<!--(.*?)-->\\s*", "");
return s;
}
+
+ /**
+ * Same as {@link #loadHtml(String)} but replaces request-time SVL variables.
+ *
+ * <h5 class='section'>See Also:</h5>
+ * <ul>
+ * <li class='jm'>{@link org.apache.juneau.rest.RestContext#getVarResolver()}
+ * <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.SvlVariables">Overview > juneau-rest-server > SVL Variables</a>
+ * </ul>
+ *
+ * @param req The current HTTP request.
+ * @param name Name of the desired resource.
+ * @return The resource converted to a string, or <jk>null</jk> if the resource could not be found.
+ * @throws IOException
+ */
+ protected String loadHtmlWithVars(RestRequest req, String name) throws IOException {
+ return req.getVarResolverSession().resolve(loadHtml(name));
+ }
}