Repository: incubator-juneau Updated Branches: refs/heads/master d767cb658 -> 9c746e647
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9c746e64/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java index 5e030de..e635521 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java @@ -15,8 +15,8 @@ package org.apache.juneau.rest; import static java.util.Collections.*; import static java.util.logging.Level.*; import static javax.servlet.http.HttpServletResponse.*; +import static org.apache.juneau.html.HtmlDocSerializerContext.*; import static org.apache.juneau.internal.IOUtils.*; -import static org.apache.juneau.internal.StringUtils.*; import java.io.*; import java.lang.reflect.*; @@ -37,7 +37,6 @@ import org.apache.juneau.http.*; import org.apache.juneau.ini.*; import org.apache.juneau.internal.*; import org.apache.juneau.parser.*; -import org.apache.juneau.parser.ParseException; import org.apache.juneau.rest.widget.*; import org.apache.juneau.serializer.*; import org.apache.juneau.svl.*; @@ -74,7 +73,7 @@ public final class RestRequest extends HttpServletRequestWrapper { private final RestContext context; - private final String method, stylesheet; + private final String method; private RequestBody body; private Method javaMethod; private ObjectMap properties; @@ -95,7 +94,6 @@ public final class RestRequest extends HttpServletRequestWrapper { private ConfigFile cf; private Swagger swagger, fileSwagger; private Map<String,Widget> widgets; - private HtmlDocContext hdc; /** * Constructor. @@ -126,11 +124,6 @@ public final class RestRequest extends HttpServletRequestWrapper { method = _method; - String _stylesheet = getQuery().getString("stylesheet"); - if (_stylesheet != null) - req.getSession().setAttribute("stylesheet", _stylesheet); - stylesheet = (String)req.getSession().getAttribute("stylesheet"); - headers = new RequestHeaders(); for (Enumeration<String> e = getHeaderNames(); e.hasMoreElements();) { String name = e.nextElement(); @@ -168,7 +161,7 @@ public final class RestRequest extends HttpServletRequestWrapper { final void init(Method javaMethod, ObjectMap properties, Map<String,String> defHeader, Map<String,String> defQuery, Map<String,String> defFormData, String defaultCharset, SerializerGroup mSerializers, ParserGroup mParsers, UrlEncodingParser mUrlEncodingParser, - BeanContext beanContext, EncoderGroup encoders, Map<String,Widget> widgets, HtmlDocContext hdc) { + BeanContext beanContext, EncoderGroup encoders, Map<String,Widget> widgets) { this.javaMethod = javaMethod; this.properties = properties; this.urlEncodingParser = mUrlEncodingParser; @@ -196,7 +189,13 @@ public final class RestRequest extends HttpServletRequestWrapper { this.defaultCharset = defaultCharset; this.defFormData = defFormData; this.widgets = widgets; - this.hdc = hdc; + + String stylesheet = getQuery().getString("stylesheet"); + if (stylesheet != null) + getSession().setAttribute("stylesheet", stylesheet.replace(' ', '$')); // Prevent SVL insertion. + stylesheet = (String)getSession().getAttribute("stylesheet"); + if (stylesheet != null) + properties.put(HTMLDOC_stylesheet, new String[]{stylesheet}); if (debug) { String msg = "" @@ -316,91 +315,6 @@ public final class RestRequest extends HttpServletRequestWrapper { } else if (c == 'H') { if ("Header".equals(category)) return getHeader(name); - if ("HtmlDocSerializer".equals(category) && cm != null) { - char c2 = StringUtils.charAt(name, 0); - if (c2 == 'a') { - if ("aside".equals(name)) - return resolveVars(hdc.aside); - } else if (c2 == 'f') { - if ("footer".equals(name)) - return resolveVars(hdc.footer); - } else if (c2 == 'h') { - if ("header".equals(name)) - return resolveVars(hdc.header); - if ("head.list".equals(name)) - return resolveVars(hdc.head); - } else if (c2 == 'n') { - if ("nav".equals(name)) - return resolveVars(hdc.nav); - if ("navlinks.list".equals(name)) { - if (hdc.navlinks == null || hdc.navlinks.length == 0) - return null; - try { - List<String> la = new ArrayList<String>(); - for (String l : hdc.navlinks) { - // Temporary backwards compatibility with JSON object format. - if (l.startsWith("{")) { - ObjectMap m = new ObjectMap(l); - for (Map.Entry<String,Object> e : m.entrySet()) - la.add(resolveVars(e.getKey()) + ":" + resolveVars(StringUtils.toString(e.getValue()))); - } else { - la.add(resolveVars(l)); - } - } - return la; - } catch (ParseException e) { - throw new RuntimeException(e); - } - } - if ("noResultsMessage".equals(name)) - return resolveVars(hdc.noResultsMessage); - if ("nowrap".equals(name)) - return hdc.nowrap; - } else if (c2 == 's') { - if ("script.list".equals(name)) { - Set<String> l = new LinkedHashSet<String>(); - if (hdc.script != null) - l.add(resolveVars(hdc.script)); - for (Widget w : getWidgets().values()) { - String script; - try { - script = w.getScript(this); - } catch (Exception e) { - script = e.getLocalizedMessage(); - } - if (script != null) - l.add(resolveVars(script)); - } - return l; - } - if ("style.list".equals(name)) { - Set<String> l = new LinkedHashSet<String>(); - if (hdc.style != null) - l.add(resolveVars(hdc.style)); - for (Widget w : getWidgets().values()) { - String style; - try { - style = w.getStyle(this); - } catch (Exception e) { - style = e.getLocalizedMessage(); - } - if (style != null) - l.add(resolveVars(style)); - } - return l; - } - if ("stylesheet".equals(name)) { - String s = getStylesheet(); - // Exclude absolute URIs to stylesheets for security reasons. - if (s == null || isAbsoluteUri(s)) - s = hdc.stylesheet; - return s == null ? null : resolveVars(s); - } - } else if (c2 == 't') { - if ("template".equals(name)) - return hdc.template; - } - } } else if (c == 'P') { if ("Path".equals(category)) return getPath(name); @@ -456,14 +370,6 @@ public final class RestRequest extends HttpServletRequestWrapper { //-------------------------------------------------------------------------------- /** - * Servlet calls this method to initialize the properties. - */ - RestRequest setProperties(ObjectMap properties) { - this.properties = properties; - return this; - } - - /** * Retrieve the properties active for this request. * * <p> @@ -898,15 +804,6 @@ public final class RestRequest extends HttpServletRequestWrapper { //-------------------------------------------------------------------------------- /** - * Returns the value of the <jk>"stylesheet"</js> parameter. - * - * @return The value of the <jk>"stylesheet"</js> parameter, or <jk>null</jk> if it wasn't specified. - */ - protected String getStylesheet() { - return stylesheet; - } - - /** * Returns the serializers associated with this request. * * @return The serializers associated with this request. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9c746e64/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java index fe8622d..4d9e8cc 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/HtmlDoc.java @@ -107,8 +107,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#header(Object)} and {@link HtmlDocBuilder#header(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#header(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -156,8 +155,7 @@ public @interface HtmlDoc { * <li> * This field can also use URIs of any support type in {@link UriResolver}. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#navlinks(Object[])} and {@link HtmlDocBuilder#navlinks(Object[])} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#navlinks(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -206,8 +204,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#nav(Object)} and {@link HtmlDocBuilder#nav(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#nav(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -249,8 +246,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#aside(Object)} and {@link HtmlDocBuilder#aside(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#aside(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -292,8 +288,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#footer(Object)} and {@link HtmlDocBuilder#footer(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#footer(Object[])} methods. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -333,8 +328,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#style(Object)} and {@link HtmlDocBuilder#style(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#style(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -374,8 +368,7 @@ public @interface HtmlDoc { * defined by {@link UriResolver}. * <br>See {@link RestContext#getVarResolver()} for the list of supported variables. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#stylesheet(Object)}/{@link HtmlDocBuilder#stylesheet(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#stylesheet(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -383,7 +376,7 @@ public @interface HtmlDoc { * parent class. * </ul> */ - String stylesheet() default ""; + String[] stylesheet() default {}; /** * Sets the HTML script section contents. @@ -412,8 +405,7 @@ public @interface HtmlDoc { * <li> * Multiple values are combined with newlines into a single string. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#script(Object)} and {@link HtmlDocBuilder#script(Object)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#script(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -456,8 +448,7 @@ public @interface HtmlDoc { * <li> * The head content from the parent can be included by adding the literal <js>"INHERIT"</js> as a value. * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#head(Object[])} and {@link HtmlDocBuilder#head(Object[])} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#head(Object[])} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> @@ -490,8 +481,7 @@ public @interface HtmlDoc { * <h6 class='topic'>Other Notes</h6> * <ul class='spaced-list'> * <li> - * The programmatic equivalent to this annotation are the - * {@link HtmlDocConfig#template(Class)} and {@link HtmlDocBuilder#template(Class)} methods. + * The programmatic equivalent to this annotation is the {@link HtmlDocBuilder#template(Class)} method. * <li> * On methods, this value is inherited from the <ja>@HtmlDoc</ja> annotation on the servlet/resource class. * <li> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9c746e64/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/UrlVar.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/UrlVar.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/UrlVar.java index 7e0b3af..be54af0 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/UrlVar.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/UrlVar.java @@ -31,7 +31,6 @@ import org.apache.juneau.svl.*; * See {@link UriResolver} for the kinds of URIs that can be resolved. * <ul> * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets()} - * <li>{@link HtmlDocConfig#widget(Class)} * </ul> * * <p> http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9c746e64/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java ---------------------------------------------------------------------- diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java index 0d5c241..2bdd87c 100644 --- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java +++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/vars/WidgetVar.java @@ -30,7 +30,6 @@ import org.apache.juneau.svl.*; * They're registered via the following mechanisms: * <ul> * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets()} - * <li>{@link HtmlDocConfig#widget(Class)} * </ul> * * @see org.apache.juneau.svl @@ -57,9 +56,26 @@ public class WidgetVar extends SimpleVar { @Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req); + boolean isScript = false, isStyle = false; + + if (key.endsWith(".script")) { + key = key.substring(0, key.length() - 7); + isScript = true; + } + + if (key.endsWith(".style")) { + key = key.substring(0, key.length() - 6); + isStyle = true; + } + Widget w = req.getWidgets().get(key); if (w == null) return "unknown-widget-"+key; + + if (isScript) + return w.getScript(req); + if (isStyle) + return w.getStyle(req); return w.getHtml(req); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/9c746e64/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/widget/Widget.java ---------------------------------------------------------------------- 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 7e6eb97..37e6e06 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 @@ -26,7 +26,7 @@ import org.apache.juneau.utils.*; * Widgets are associated with resources through the following * <ul> * <li>{@link HtmlDoc#widgets() @HtmlDoc.widgets} - * <li>{@link HtmlDocConfig#widget(Class)} + * <li>{@link RestConfig#addWidget(Class)} * </ul> * * <p>