📄 macros.java
字号:
} //------------------------------------------------------------------------ /** * Show most recent 15 weblog enties using specified day template. * @param dayTemplate Name of day template. * @return HTML for weblog entries. */ public String showWeblogEntries( String dayTemplate ) { return showWeblogEntries(dayTemplate,15); } //------------------------------------------------------------------------ /** * Show weblog enties using specified day template. * @param dayTemplate Name of day template. * @param maxEntries Maximum number of entries to display. * @return HTML for weblog entries. */ public String showWeblogEntries( String dayTemplate, int maxEntries ) { String ret = null; try { // protection from recursion if ( mEntriesDayTLS.get() == null ) { mEntriesDayTLS.set( new Integer(0) ); } else { Integer countObj = (Integer)mEntriesDayTLS.get(); int count = countObj.intValue(); if ( count++ > MAX_RECURSION_DEPTH ) { return "ERROR: recursion level too deep"; } mEntriesDayTLS.set( new Integer(count) ); } ViewWeblogEntriesTag entriesTag = new ViewWeblogEntriesTag(); entriesTag.setPageContext(mPageContext); entriesTag.setMaxEntries(maxEntries); entriesTag.setDayTemplate( dayTemplate ); ret = entriesTag.emit(); } finally { mEntriesDayTLS.set( null ); } return ret; } //------------------------------------------------------------------------ /** * Display weblog calendar. * @return HTML for calendar. */ public String showWeblogCalendar() { return showWeblogCalendar(false); } //------------------------------------------------------------------------ /** * Display big weblog calendar, well suited for an archive page. * @return HTML for calendar. */ public String showBigWeblogCalendar() { return showWeblogCalendar(true); } //------------------------------------------------------------------------ /** * Weblog calendar display implementation. * @param big Show big archive style calendar. * @return HTML for calendar. */ public String showWeblogCalendar( boolean big ) { return mPageHelper.showWeblogCalendar(big, null); } //------------------------------------------------------------------------ /** * Show a list of links to each of your weblog categores. * @return HTML for category chooser. */ public String showWeblogCategoryChooser() { WeblogCategoryChooserTag catTag = new WeblogCategoryChooserTag(); catTag.setPageContext(mPageContext); return catTag.emit(); } //------------------------------------------------------------------------ /** * Show a list of links to each of your RSS feeds. * @return HTML for RSS feed links. */ public String showRSSLinks() { String links = "ERROR: creating RSS links"; try { RollerRequest rreq = getRollerRequest(); RollerContext rctx = RollerContext.getRollerContext( rreq.getServletContext()); UserData ud = rreq.getUser(); String baseUrl = rctx.getContextUrl( (HttpServletRequest)mPageContext.getRequest()); StringBuffer sb = new StringBuffer(); sb.append("<a href=\""); sb.append( baseUrl ); sb.append("/rss/"); sb.append( ud.getUserName() ); sb.append("\">All</a> "); sb.append("[<a href=\""); sb.append( baseUrl ); sb.append("/rss/"); sb.append( ud.getUserName() ); sb.append("?excerpts=true\">"); sb.append("excerpts</a>]"); sb.append("<br />"); List cats = rreq.getRoller().getWeblogManager() .getWeblogCategories(rreq.getWebsite(), false); for (Iterator wbcItr = cats.iterator(); wbcItr.hasNext();) { WeblogCategoryData category = (WeblogCategoryData) wbcItr.next(); String catName = category.getName(); sb.append("<a href=\""); sb.append( baseUrl ); sb.append("/rss/"); sb.append( ud.getUserName() ); sb.append("?catname="); sb.append( catName ); sb.append("\">"); sb.append( catName ); sb.append("</a> "); sb.append("[<a href=\""); sb.append( baseUrl ); sb.append("/rss/"); sb.append( ud.getUserName() ); sb.append("?catname="); sb.append( catName ); sb.append("&excerpts=true\">"); sb.append("excerpts</a>]"); sb.append("<br />"); } links = sb.toString(); } catch (Exception e) { mLogger.error("Unexpected exception",e); } return links; } //------------------------------------------------------------------------ /** * Show RSS auto-discovery element. * @return HTML for RSS auto-discovery element. */ public String showRSSAutodiscoveryLink() { String links = "ERROR: error generating RSS autodiscovery link"; try { RollerRequest rreq = RollerRequest.getRollerRequest( (HttpServletRequest)mPageContext.getRequest()); RollerContext rctx = RollerContext.getRollerContext( rreq.getServletContext()); StringBuffer sb = new StringBuffer(); sb.append("<link rel=\"alternate\" type=\"application/rss+xml\" "); sb.append("title=\"RSS\" href=\""); sb.append( rctx.getContextUrl( (HttpServletRequest)mPageContext.getRequest()) ); sb.append( "/rss/" ); sb.append( getUser().getUserName() ); sb.append( "\">" ); links = sb.toString(); } catch (Throwable e) { mLogger.error("Showing RSS link",e); } return links; } //------------------------------------------------------------------------ /** * Show RSS badge with link to your main RSS feed. * @return HTML for RSS badge with link to your main RSS feed. */ public String showRSSBadge() { RssBadgeTag rssTag = new RssBadgeTag(); rssTag.setPageContext(mPageContext); return rssTag.emit(); } //------------------------------------------------------------------------ /** * Expand macros in specified page and include the results in this page. * @param Name of page to include. * @return HTML for included page. */ public String includePage( String pageName ) { String ret = null; try { // protection from recursion if ( mIncludePageTLS.get() == null ) { mIncludePageTLS.set( new Integer(0) ); } else { Integer countObj = (Integer)mIncludePageTLS.get(); int count = countObj.intValue(); if ( count++ > MAX_RECURSION_DEPTH ) { return "ERROR: recursion level too deep"; } mIncludePageTLS.set( new Integer(count) ); } // Get included page template RollerRequest rreq = RollerRequest.getRollerRequest( (HttpServletRequest)mPageContext.getRequest()); UserManager userMgr = rreq.getRoller().getUserManager(); PageData pd = userMgr.getPageByName( rreq.getWebsite(), pageName ); Template vtemplate = null; if (pd != null) { vtemplate = RuntimeSingleton.getTemplate( pd.getId() ); } else { // maybe its in preview mode and doesn't exist yet? vtemplate = RuntimeSingleton.getTemplate( pageName ); } if (vtemplate == null) { ret = pageName + " : No Page or Template found."; } else { // Run it through Velocity StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); VelocityContext vcontext = new VelocityContext(); ContextLoader.setupContext(vcontext,rreq, (HttpServletResponse)mPageContext.getResponse()); vtemplate.merge( vcontext, pw ); ret = sw.toString(); } } catch (Exception e) { ret = "ERROR: including page " + pageName; } finally { mIncludePageTLS.set( null ); } return ret; } //------------------------------------------------------------------------ /** * Shows HTML for an image in user's resource directory. * @param fileName File name in resource directory * @param linkUrl URL that image links to, null or empty if none * @param alt Description of image and of link * @param border For IMG tag's border attribute * @param halign For IMG tag's halign attribute * @param valign For IMG tag's valign attribute * @return String HTML for displaying image */ public String showResourceImage( String fileName, String linkUrl, String alt, int border, String halign, String valign ) { HttpServletRequest request = (HttpServletRequest) mPageContext.getRequest(); String username = getRollerRequest().getUser().getUserName(); ServletContext app = mPageContext.getServletContext(); StringBuffer sb = new StringBuffer(); String uploadPath = null; try { uploadPath = RollerFactory.getRoller().getFileManager().getUploadUrl(); } catch(Exception e) {} if ( uploadPath != null && uploadPath.trim().length() > 0 ) { sb.append( uploadPath ); sb.append( "/"); sb.append( username ); sb.append( "/"); sb.append( fileName); } else { sb.append( request.getContextPath() ); sb.append( RollerContext.USER_RESOURCES ); sb.append( "/"); sb.append( username ); sb.append( "/"); sb.append( fileName); } return showImage( sb.toString(),linkUrl,alt,border,halign,valign ); } //------------------------------------------------------------------------ /** * Shows HTML for an image in user's resource directory. * @param imageUrl URL to image * @param linkUrl URL that image links to, null or empty if none * @param alt Description of image and of link * @param border For IMG tag's border attribute * @param halign For IMG tag's halign attribute * @param valign For IMG tag's valign attribute * @return String HTML for displaying image */ public String showImage( String imageUrl, String linkUrl, String alt, int border, String halign, String valign ) { StringBuffer sb = new StringBuffer(); if ( linkUrl!=null && linkUrl.trim().length()>0 ) { sb.append( "<a href=\""); sb.append( linkUrl ); sb.append( "\" >"); } sb.append("<img src=\""); sb.append( imageUrl ); sb.append( "\" alt=\""); sb.append( alt); sb.append( "\" border=\""); sb.append( border); sb.append( "\" halign=\""); sb.append( halign); sb.append( "\" valign=\""); sb.append( valign); sb.append( "\" />"); if ( linkUrl!=null && linkUrl.trim().length()>0 ) { sb.append( "</a>"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -