下面列出了javax.servlet.jsp.JspWriter#println ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void render(ProfileElement element, PageContext context, RendererFilter filter)
throws IOException {
JspWriter out = context.getOut();
//out.print(element.getName());
//out.print(":");
out.print("<select name=\"");
out.print(element.getAbsoluteName());
out.println("\">");
out.print("<option value=\"true\"");
if(element.getValue().equals(Boolean.TRUE)) {
out.print(" SELECTED ");
}
out.println(">true</option>");
out.print("<option value=\"false\"");
if(element.getValue().equals(Boolean.FALSE)) {
out.print(" SELECTED ");
}
out.println(">false</false>");
out.print("</select><br/>");
}
private void renderExport(JspWriter out) throws IOException {
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
StringBuilder page =
new StringBuilder((String) request.getAttribute("requestedUri"));
page.append("?" + RequestContext.LIST_DISPLAY_EXPORT + "=1");
if (request.getQueryString() != null) {
page.append("&" + request.getQueryString());
}
IconTag i = new IconTag("item-download-csv");
out.println("<div class=\"spacewalk-csv-download\"><a class=\"btn btn-link\"" +
" href=\"" + page + "\">" + i.render() +
LocalizationService.getInstance().getMessage("listdisplay.csv") +
"</a></div>");
}
private static void customize ( final JspWriter out, final CleanupConfiguration cfg ) throws IOException
{
final String json = HtmlEscapers.htmlEscaper ().escape ( new GsonBuilder ().create ().toJson ( cfg ) );
out.print ( "<div class=\"container-fluid\">" );
out.print ( "<div class=\"row\"><div class=\"col-md-12\">" );
out.print ( "<form action=\"edit\" method=\"get\">" );
out.print ( "<input type=\"hidden\" name=\"configuration\" value=\"" + json + "\"/>" );
out.print ( "<button class=\"btn btn-primary\" type=\"submit\">Edit</button>" );
out.println ( "</form></div></div></div>" );
}
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
for( int i = 0; i < keys.size(); i++ ) {
String key = keys.get( i );
Object value = values.get( i );
out.println( "<li>" + key + " = " + value + "</li>" );
}
}
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
out.println(fckEditor);
} catch (IOException e) {
throw new JspException(
"Tag response could not be written to the user!", e);
}
return EVAL_PAGE;
}
protected void renderPanelHeading(JspWriter out) throws IOException {
StringWriter headFilterContent = new StringWriter();
StringWriter titleContent = new StringWriter();
StringWriter headAddons = new StringWriter();
renderTitle(titleContent);
if (getPageList().hasFilter()) {
headFilterContent.append("<div class=\"spacewalk-list-filter\">");
renderFilterBox(headFilterContent);
headFilterContent.append("</div>");
}
renderHeadExtraAddons(headAddons);
int headContentLength = headFilterContent.getBuffer().length() +
titleContent.getBuffer().length() +
headAddons.getBuffer().length();
if (headContentLength > 0) {
out.println("<div class=\"panel-heading\">");
out.println(titleContent.toString());
out.println("<div class=\"spacewalk-list-head-addons\">");
out.println(headFilterContent.toString());
out.println("<div class=\"spacewalk-list-head-addons-extra\">");
out.println(headAddons.toString());
out.println("</div>");
out.println("</div>");
out.println("</div>");
}
}
@Override
public int doStartTag() throws JspException {
JspWriter writer = pageContext.getOut();
try {
WCTTreeSet entries = list.getCopy();
entries.add(currentValue);
if(onChangeFunction != null && !onChangeFunction.isEmpty())
{
writer.println("<select id=\"" + paramName + "\" name=\"" + paramName + "\" onchange=\""+onChangeFunction+"\">");
}
else
{
writer.println("<select id=\"" + paramName + "\" name=\"" + paramName + "\">");
}
for (String entry : entries) {
if (entry.equals(currentValue)) {
writer.println("<option value=\"" + entry +"\" selected>" + entry +"</option>");
}
else {
writer.println("<option value=\"" + entry +"\">" + entry +"</option>");
}
}
writer.println("</select>");
}
catch (IOException e) {
throw new JspException(e.getMessage(), e);
}
return TagSupport.SKIP_BODY;
}
private void renderEmptyString(JspWriter out) throws IOException {
if (formatMessage) {
out.println("<div class=\"list-empty-message\">" +
LocalizationService.getInstance().getMessage(noDataText) +
"</div>");
}
else {
out.println(noDataText);
}
}
/** {@inheritDoc} */
public int doAfterBody() throws JspException {
JspWriter out = null;
try {
out = pageContext.getOut();
if (pageContext.getAttribute("current") == null) {
out.println("</tr>");
out.println("</thead>");
out.println("<tbody>");
}
else {
out.println("</tr>");
}
if (getIterator().hasNext()) {
setColumnCount(0);
Object next = getIterator().next();
out.println(getTrElement(next, currRow++));
pageContext.setAttribute("current", next);
return EVAL_BODY_AGAIN;
}
}
catch (IOException e) {
throw new JspException("Error while writing to JSP: " +
e.getMessage());
}
return SKIP_BODY;
}
/**
* {@inheritDoc}
*/
public int doEndTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
// Get the selected systems if there is a user
RhnSet rs = null;
if (user != null) {
rs = RhnSetDecl.SYSTEMS.lookup(user);
}
// The number of systems selected for SSM
int size = 0;
if (rs != null) {
size = rs.size();
}
StringBuilder result = new StringBuilder();
result.append("<span id=\"spacewalk-set-system_list-counter\" ")
.append("class=\"badge\">")
.append(Integer.toString(size))
.append("</span>")
.append(LocalizationService.getInstance()
.getMessage(size == 1 ?
"header.jsp.singleSystemSelected" :
"header.jsp.systemsSelected"));
out.println(result);
return EVAL_PAGE;
}
catch (IOException ioe) {
throw new JspException("IO error writing to JSP file:", ioe);
}
}
private void renderEmptyString(JspWriter out) throws IOException {
if (formatMessage) {
out.println("<div class=\"list-empty-message\">" +
LocalizationService.getInstance().getMessage(noDataText) +
"</div>");
}
else {
out.println(noDataText);
}
}
private void renderActionButtons(JspWriter out) throws IOException {
if (getPageList().size() == 0 || getButton() == null) {
return;
}
if (!hasButtonAttrs()) {
return;
}
out.println("<div class=\"col-sm-12 text-right\">");
if (getButton2() != null && AclManager.hasAcl(getButton2Acl(),
(HttpServletRequest) pageContext.getRequest(), getMixins())) {
out.println("<button class=\"btn btn-default\"" +
" type=\"submit\" name=\"dispatch\" value=\"" +
LocalizationService.getInstance().getMessage(getButton2()) +
"\">" +
LocalizationService.getInstance().getMessage(getButton2()) +
"</button>");
}
if (getButton() != null && AclManager.hasAcl(getButtonAcl(),
(HttpServletRequest) pageContext.getRequest(), getMixins())) {
out.println("<button class=\"btn btn-primary\"" +
" type=\"submit\" name=\"dispatch\" value=\"" +
LocalizationService.getInstance().getMessage(getButton()) +
"\">" +
LocalizationService.getInstance().getMessage(getButton()) +
"</button>");
}
out.println("</div>");
}
public void render(ProfileElement element, PageContext context, RendererFilter filter) throws IOException {
JspWriter out = context.getOut();
//out.print(element.getName());
//out.print(":");
if (((SimpleProfileElement) element).isTransient()) {
out.println(element.getValue()+"<br/>\n");
} else {
out.print("<select name=\"");
out.print(element.getAbsoluteName());
out.println("\">");
// Get the options.
SimpleProfileElement simpleElement = (SimpleProfileElement) element;
Object[] legalValues = simpleElement.getLegalValues();
//Have legal values. Build combobox.
for(int i=0 ; i < legalValues.length ; i++){
out.print("<option value=\""+legalValues[i]+"\"");
if(element.getValue().equals(legalValues[i])){
out.print(" selected");
}
out.println(">"+legalValues[i]+"</option>\n");
}
out.println("</select><br/>\n");
}
}
@Override
public int doStartTag() throws JspException {
String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL);
serverURL = serverURL == null ? null : serverURL.trim();
if (serverURL != null) {
try {
HttpSession session = ((HttpServletRequest) this.pageContext.getRequest()).getSession();
String pageDirection = (String) session.getAttribute(LocaleFilter.DIRECTION); // RTL or LTR (default)
boolean rtl = CssTag.RTL_DIR.equalsIgnoreCase(pageDirection);
List<String> themeList = CSSThemeUtil.getAllUserThemes();
String customStylesheetLink = null;
for (String theme : themeList) {
if (theme != null) {
theme = appendStyle(theme, rtl);
customStylesheetLink = generateLink(theme, serverURL);
}
if (customStylesheetLink != null) {
JspWriter writer = pageContext.getOut();
writer.println(customStylesheetLink);
}
}
} catch (IOException e) {
CssTag.log.error("CssTag unable to write out CSS details due to IOException.", e);
// don't throw a JSPException as we want the system to still function.
}
} else {
CssTag.log.warn(
"CSSTag unable to write out CSS entries as the server url is missing from the configuration file.");
}
return Tag.SKIP_BODY;
}
protected void renderPanelHeading(JspWriter out) throws IOException {
StringWriter headFilterContent = new StringWriter();
StringWriter titleContent = new StringWriter();
StringWriter headAddons = new StringWriter();
renderTitle(titleContent);
if (getPageList().hasFilter()) {
headFilterContent.append("<div class=\"spacewalk-list-filter\">");
renderFilterBox(headFilterContent);
headFilterContent.append("</div>");
}
renderHeadExtraAddons(headAddons);
int headContentLength = headFilterContent.getBuffer().length() +
titleContent.getBuffer().length() +
headAddons.getBuffer().length();
if (headContentLength > 0) {
out.println("<div class=\"panel-heading\">");
out.println(titleContent.toString());
out.println("<div class=\"spacewalk-list-head-addons\">");
out.println(headFilterContent.toString());
out.println("<div class=\"spacewalk-list-head-addons-extra\">");
out.println(headAddons.toString());
out.println("</div>");
out.println("</div>");
out.println("</div>");
}
}
/**
* Displays the opening of the TD tag and prepares it for
* displaying the body contents.
* @param out JspWriter to write to.
* @param parent Containing JspTag.
* @throws IOException if an error occurs writing to the JspWriter.
*/
protected void renderData(JspWriter out, UnpagedListDisplayTag parent)
throws IOException {
String nodeIdString = parent.getNodeIdString();
// Deal with structural markup before we get to this <td>
if (parent.getColumnCount() == 0 && parent.getCurrRow() == 0) {
out.println("</thead><tbody>");
}
setupAttribute(td, "width", getWidth());
setupAttribute(td, "colspan", getColspan());
if (getNowrap() != null && getNowrap().equals("true")) {
setupAttribute(td, "nowrap", "nowrap");
}
// Only one column
if (parent.getNumberOfColumns() == 1) {
setupAttribute(td, "class", "first-column last-column");
}
// Are we the first column?
else if (parent.getColumnCount() == 0) {
setupAttribute(td, "class", "first-column");
}
// Are we the last column?
else if (parent.getColumnCount() == parent.getNumberOfColumns() - 1) {
setupAttribute(td, "class", "last-column");
}
// Are we a middle column?
else {
setupAttribute(td, "class", getCssClass());
}
parent.incrColumnCount();
if (parent.getType().equals("treeview") && parent.isChild(nodeIdString)) {
setupAttribute(td, "style", getStyle() + "display: none;");
}
else {
setupAttribute(td, "style", getStyle());
}
out.print(td.renderOpenTag());
if (parent.getType().equals("treeview") &&
parent.isParent(nodeIdString) &&
parent.getColumnCount() == 1) {
out.print("<a onclick=\"toggleRowVisibility('" +
parent.createIdString(nodeIdString) +
"');\" " + "style=\"cursor: pointer;\">" +
"<img name=\"" +
parent.createIdString(nodeIdString) +
"-image\" src=\"/img/list-expand.gif\" alt=\"" +
LocalizationService.getInstance().
getMessage("channels.parentchannel.alt") +
"\"/></a>");
parent.setCurrRow(parent.getCurrRow() + 1);
}
if (showUrl()) {
setupAttribute(href, "href", getUrl());
out.print(href.renderOpenTag());
}
}
/** {@inheritDoc} */
public int doEndTag() throws JspException {
JspWriter out = null;
try {
if (getPageList().isEmpty()) {
return EVAL_PAGE;
}
if (isExport()) {
ExportWriter eh = createExportWriter();
String[] columns = StringUtils.split(this.getExportColumns(),
',');
eh.setColumns(Arrays.asList(columns));
ServletExportHandler seh = new ServletExportHandler(eh);
pageContext.getOut().clear();
pageContext.getOut().clearBuffer();
pageContext.getResponse().reset();
seh.writeExporterToOutput(
(HttpServletResponse) pageContext.getResponse(),
getPageList());
return SKIP_PAGE;
}
// Get the JSPWriter that the body used, then pop the
// bodyContent, so that we can get the real JspWriter with getOut.
BodyContent body = getBodyContent();
pageContext.popBody();
out = pageContext.getOut();
if (body != null) {
String bodyString = body.getString();
out.println(bodyString);
}
// Rely on content to have emitted a tbody tag somewhere
out.println("</tbody>");
out.println("</table>\n");
out.println("</div>\n");
out.println("</div>\n");
setNumberOfColumns(0);
setColumnCount(0);
setCurrRow(0);
}
catch (IOException e) {
throw new JspException("IO error" + e.getMessage());
}
finally {
pageContext.setAttribute("current", null);
}
return EVAL_PAGE;
}
public int doEndTag() throws JspException {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
try{
WechatMPUtil util = WechatMPUtil.getInstance(key);
if(null != util){
String url = "";
if("auto".equals(server)){
server = HttpUtil.parseHost(request.getServerName());
}
if(null != server){
if(server.contains("127.0.0.1") || server.contains("localhost")){
server = null;
}
}
if(BasicUtil.isEmpty(server)){
server = util.getConfig().WEB_SERVER;
}
if(BasicUtil.isEmpty(server)){
server = HttpUtil.parseHost(request.getServerName());
}
url = HttpUtil.mergePath(server , BasicUtil.evl(request.getAttribute("javax.servlet.forward.request_uri"),"")+"");
if(null != util.getConfig().WEB_SERVER && util.getConfig().WEB_SERVER.startsWith("https")){
url = url.replace("http:","https:");
}
String param = request.getQueryString();
if(BasicUtil.isNotEmpty(param)){
url += "?" + param;
}
if(ConfigTable.isDebug() && log.isWarnEnabled()){
log.warn("[config init][url:{}]",url);
}
Map<String,Object> map = util.jsapiSign(url);
String config = "<script language=\"javascript\">\n";
if(debug){
String alert = "请注意url,经过代理的应用有可能造成域名不符(如localhost,127.0.0.1等),请在anyline-wechat-mp.xml中配置WEB_SERVER=http://www.xx.com\\n,并在微信后台设置服务器IP白名单";
alert += "SIGN SRC: appId=" + util.getConfig().APP_ID + ",noncestr="+map.get("noncestr")
+",jsapi_ticket="+map.get("jsapi_ticket")+",url="+url+",timestamp="+map.get("timestamp");
config += "alert(\""+alert+"\");\n";
}
config += "";
config += "wx.config({\n";
config += "debug:"+debug+",\n";
config += "appId:'"+util.getConfig().APP_ID+"',\n";
config += "timestamp:"+map.get("timestamp")+",\n";
config += "nonceStr:'"+map.get("noncestr") + "',\n";
config += "signature:'"+map.get("sign")+"',\n";
config += "jsApiList:[";
String apiList[] = apis.split(",");
int size = apiList.length;
for(int i=0; i<size; i++){
String api = apiList[i];
api = api.replace("'", "").replace("\"", "");
if(i>0){
config += ",";
}
config += "'" + api + "'";
}
config += "]\n";
config += "});\n";
config += "</script>";
JspWriter out = pageContext.getOut();
out.println(config);
}
} catch (Exception e) {
e.printStackTrace();
if(ConfigTable.isDebug() && log.isWarnEnabled()){
e.printStackTrace();
}
} finally {
release();
}
return EVAL_PAGE;
}
/** {@inheritDoc} */
public int doStartTag() throws JspException {
rowCnt = 0;
JspWriter out = null;
try {
out = pageContext.getOut();
setupPageList();
// Now that we have setup the proper tag state we
// need to return if this is an export render.
if (isExport()) {
return SKIP_PAGE;
}
String sortedColumn = getSortedColumn();
if (sortedColumn != null) {
doSort(sortedColumn);
}
out.print("<div class=\"spacewalk-list\">");
out.print("<div class=\"panel panel-default\">");
renderPanelHeading(out);
/* If the type is list, we must set the width explicitly. Otherwise,
* it shouldn't matter
*/
if (getType().equals("list")) {
out.print("<table class=\"table\"");
}
else if (getType().equals("treeview")) {
out.print("<table class=\"table\" id=\"channel-list\"");
}
else {
out.print("<table class=\"" + getType() + "\"");
}
/*if (isTransparent()) {
out.print(" style=\"border-bottom: 1px solid #ffffff;\" ");
}*/
out.println(">");
out.println("<thead>");
out.println("<tr>");
if (getIterator() != null && getIterator().hasNext()) {
// Push a new BodyContent writer onto the stack so that
// we can buffer the body data.
bodyContent = pageContext.pushBody();
return EVAL_BODY_INCLUDE;
}
return SKIP_BODY;
}
catch (IOException ioe) {
throw new JspException("IO error writing to JSP file:", ioe);
}
}
@Override
public int doEndTag() {
JspWriter writer = this.pageContext.getOut();
try {
OfficialCard card = OfficialDataStore.getInstance().getCardByName(this.getCardName());
String contextPath = this.pageContext.getServletContext().getContextPath();
String cardPageUrl = contextPath + "/Wiki/Cards/" + card.getCardId() + ".shtml";
String frameUrlFormat = contextPath + "/resources/img/frame/Square_%s_Frame.png";
String invisibleFrameUrl = contextPath + "/resources/img/frame/Invisible_Square_Frame.png";
String starUrl = contextPath + "/resources/img/frame/Star_" + card.getColor() + "_Bar.png";
String logoUrl = card.getLogoUrl();
/*
<div class="card-logo-container">
<div class="card-logo">
<a href="<c:url value="/Wiki" />/Cards/${card.cardName}.shtml"><cf:cardLogo cardName="${card.cardName}" /></a>
</div>
<div class="card-name">
${card.cardName}
</div>
</div>
*/
writer.println(String.format(
"<div class='card-logo-container%s'>",
this.isResponsive() ? " responsive" : ""));
writer.println(String.format(
"<div class='card-frame'><img src='%s' style='width: 100%%' /></div>",
this.frameVisible ? String.format(frameUrlFormat, card.getRaceName()) : invisibleFrameUrl));
writer.println(String.format(
"<div class='card-logo'>" +
"<a href='%s' target='_self'>" +
"<img src='%s' alt='%s' title='%s' style='width: 100%%' />" +
"</a>" +
"</div>",
cardPageUrl,
logoUrl, this.getCardName(), this.getCardName()));
if (this.cardNameVisible) {
writer.println(String.format(
"<div class='card-name'>%s</div>", this.getCardName()));
}
if (this.starBarVisible) {
writer.println(String.format(
"<div class='card-star'><img src='%s' style='width: 100%%' /></div>", starUrl));
}
writer.println(
"</div>");
} catch (IOException e) {
logger.error(e);
}
return Tag.SKIP_BODY;
}