📄 macros.java
字号:
return sb.toString(); } //------------------------------------------------------------------------ /** * Gets path to images directory on your Roller server. * @return Path to images directory on your Roller server. */ public String showImagePath() { HttpServletRequest request = (HttpServletRequest) mPageContext.getRequest(); StringBuffer sb = new StringBuffer(); sb.append( request.getContextPath() ); sb.append( "/images" ); return sb.toString(); } //------------------------------------------------------------------------ /** * Gets path to your /resources directory, where you may have uploaded * files. * @return Resource path. */ public String showResourcePath() { 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 ); } else { sb.append( request.getContextPath() ); sb.append( RollerContext.USER_RESOURCES ); } sb.append( "/" ); sb.append( username ); return sb.toString(); } //------------------------------------------------------------------------ /** * This is a convenience method to calculate the path to a theme. It * basically adds a contextPath and the themes directory. * @param Name of theme. * @return Theme path. */ public String showThemePath( String theme ) { String themesdir = RollerRuntimeConfig.getProperty("users.themes.path"); HttpServletRequest request = (HttpServletRequest)mPageContext.getRequest(); StringBuffer sb = new StringBuffer(); sb.append( request.getContextPath()); sb.append(themesdir); sb.append( "/" ); sb.append( theme ); return sb.toString(); } //------------------------------------------------------------------------ /** * This is a convenience method to calculate the path to a theme image. * @param theme Name of theme. * @param imageName Name of image. * @return Path to image in theme. */ public String showThemeImagePath( String theme, String imageName ) { StringBuffer sb = new StringBuffer(); sb.append( showThemePath(theme)); sb.append( "/images/"); sb.append( imageName); return sb.toString(); } //------------------------------------------------------------------------ /** * Display a theme image. * @param theme Name of theme. * @param imageName Name of image. * @return HTML for image. */ public String showThemeImage( String theme, String imageName ) { StringBuffer sb = new StringBuffer(); sb.append( "<img alt=\""+imageName+"\" src=\""); sb.append( showThemeImagePath(theme, imageName)); sb.append( "\"/>"); return sb.toString(); } //------------------------------------------------------------------------ /** * Return the path to a theme's styles directory. * @param theme Name of theme. * @param stylesheet Name of stylesheet. * @return Theme style path. */ public String showThemeStylePath( String theme, String stylesheet ) { StringBuffer sb = new StringBuffer(); sb.append( showThemePath(theme)); sb.append( "/styles/"); sb.append( stylesheet); return sb.toString(); } //------------------------------------------------------------------------ /** * Return HTML for referencing a theme. * @param theme Name of theme * @param stylesheet Name of stylesheet in theme. * @param useImport Use import statement rather than link element. * @return HTML for importing theme. */ public String showThemeStyle( String theme, String stylesheet, boolean useImport ) { StringBuffer sb = new StringBuffer(); if (useImport) { sb.append( "<style type=\"text/css\">"); sb.append( "@import url("); sb.append( showThemeStylePath(theme, stylesheet)); sb.append( ");"); sb.append( "</style>"); } else { sb.append( "<link rel=\"stylesheet\" type=\"text/css\" href=\""); sb.append( showThemeStylePath(theme, stylesheet)); sb.append( "\" />"); } return sb.toString(); } //------------------------------------------------------------------------ /** * Convenience macro to import a stylesheet using the import statement. * @param theme Theme name. * @param stylesheet Name of stylesheet within theme. * @return HTML for importing theme. */ public String showThemeStyleImport( String theme, String stylesheet ) { return showThemeStyle(theme, stylesheet, true); } //------------------------------------------------------------------------ /** * Return the path to a theme's scripts directory. * @param theme Name of theme. * @param scriptFile Name of script in theme. * @return Path to theme. */ public String showThemeScriptPath( String theme, String scriptFile ) { StringBuffer sb = new StringBuffer(); sb.append( showThemePath(theme)); sb.append( "/scripts/"); sb.append( scriptFile); return sb.toString(); } //------------------------------------------------------------------------ /** * Return the full HTML to use a scriptFile, for example: * <pre> * <script type="text/javascript" src="/themes/default/scripts/sample.js"> * </script>. * </pre> * @param theme Name of theme. * @param scriptFile Name of script in theme. * @return Path to theme. */ public String showThemeScript( String theme, String scriptFile) { StringBuffer sb = new StringBuffer(); sb.append( "<script type=\"text/javascript\" src=\""); sb.append( showThemeScriptPath(theme, scriptFile)); sb.append( "\"></script>"); // a /> doesn't work in IE return sb.toString(); } //------------------------------------------------------------------------ /** * Return the title of the current Roller page being processed. * @return Title of the current Roller page being processed. */ public String showPageName() { PageData pd = null; RollerRequest rreq = getRollerRequest(); try { pd = rreq.getPage(); } catch (Exception e) { return "ERROR finding page in request: " + e.toString(); } return pd.getName(); } //------------------------------------------------------------------------ /** * Return the description of the current Roller page being processed. * @return Description of the current Roller page being processed. */ public String showPageDescription() { PageData pd = null; RollerRequest rreq = getRollerRequest(); try { pd = rreq.getPage(); } catch (Exception e) { return "ERROR finding page in request: " + e.toString(); } return pd.getDescription(); } //------------------------------------------------------------------------ /** * Return the updateTime of the current Roller page being processed. * @return UpdateTime of the current Roller page being processed. */ public String showPageUpdateTime() { PageData pd = null; RollerRequest rreq = getRollerRequest(); try { pd = rreq.getPage(); } catch (Exception e) { return "ERROR finding page in request: " + e.toString(); } if (pd.getUpdateTime() == null) return ""; return pd.getUpdateTime().toString(); } //------------------------------------------------------------------------ /** * Show list of links to today's biggest referers. Shows up to up * referers and limits each to 20 characters width. * @return HTML to display referers. */ public String showReferers() { return showReferers(15,20); } //------------------------------------------------------------------------ /** * Show list of links to today's biggest referers. Shows up to up * specified number referers and limits each to 20 characters width. * @param max Maximum number of referers to display. * @return HTML to display referers. */ public String showReferers( int max ) { return showReferers(max,20); } //------------------------------------------------------------------------ /** * Show list of links to today's biggest referers. Shows up to up * specified number referers and limits each to specified characters width. * @param max Maximum number of referers to display. * @param maxWidth Maximum width in characters of each referer. * @return HTML to display referers. */ public String showReferers( int max, int maxWidth ) { try { RollerRequest rreq = getRollerRequest(); RefererManager refmgr = rreq.getRoller().getRefererManager(); StringBuffer sb = new StringBuffer(); sb.append("Today's Page Hits:"); sb.append( refmgr.getDayHits(rreq.getWebsite()) ); sb.append("<br/>"); sb.append("Total Page Hits:"); sb.append( refmgr.getTotalHits(rreq.getWebsite()) ); sb.append("<br/>"); List refs = refmgr.getTodaysReferers(rreq.getWebsite()); sb.append(""); sb.append("<ul class=\"rReferersList\">"); int count = refs.size()>max ? max : refs.size(); for (int i = 0; i < count; i++) { RefererData data = (RefererData)refs.get(i); sb.append("<li class=\"rReferersListItem\">"); sb.append( data.getDisplayUrl( maxWidth, true ) ); sb.append("</li>"); } sb.append("</ul>"); return sb.toString(); } catch (Exception e) { mLogger.error("Displaying referers list",e); return "ERROR: displaying referers list"; } } //------------------------------------------------------------------------ /** * Remove occurences of HTML from a string. Does this by stripping out * any text that exists between the characters "<" and ">". * @param s String that may contain some HTML. * @return String with no HTML. */ public static String removeHTML(String s) { if ( s==null ) return ""; else return Utilities.removeHTML(s); } /** * Escape all characters that need to be escaped for HTML. * @param s String that may contain some special HTML characters. * @return String with special HTML characters escaped. */ public static String escapeHTML( String s ) { if ( s==null ) return ""; else return Utilities.escapeHTML(s); } /** Run both removeHTML and escapeHTML on a string. * @param s String to be run through removeHTML and escapeHTML. * @return String with HTML removed and HTML special characters escaped. */ public static String removeAndEscapeHTML( String s ) { if ( s==null ) return ""; else return Utilities.escapeHTML( removeHTML(s) ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -