-
Notifications
You must be signed in to change notification settings - Fork 37
/
PluggableMarkupTag.java
49 lines (39 loc) · 1.41 KB
/
PluggableMarkupTag.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.sdl.webapp.common.impl.taglib.dxa;
import com.sdl.webapp.common.markup.PluggableMarkupRegistry;
import com.sdl.webapp.common.markup.html.HtmlNode;
import lombok.Setter;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
@Setter
public class PluggableMarkupTag extends TagSupport {
private PluggableMarkupRegistry registry;
private String label;
/**
* {@inheritDoc}
*/
@Override
public int doStartTag() throws JspException {
try {
for (HtmlNode markup : this.getPluggableMarkupRegistry().getPluggableMarkup(this.label)) {
pageContext.getOut().write(markup.toHtml());
}
} catch (IOException e) {
throw new JspException("Error while generating pluggable markup for label=" + this.label, e);
}
return SKIP_BODY;
}
/**
* <p>getPluggableMarkupRegistry.</p>
*
* @return a {@link PluggableMarkupRegistry} object.
*/
protected PluggableMarkupRegistry getPluggableMarkupRegistry() {
if (this.registry == null) {
this.registry = WebApplicationContextUtils.getRequiredWebApplicationContext(pageContext.getServletContext())
.getBean(PluggableMarkupRegistry.class);
}
return this.registry;
}
}