⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 variablemanager.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            //            if( (context.getVariable( varName )) != null )            {                return context.getVariable( varName ).toString();            }            //            //  Well, I guess it wasn't a final straw.  We also allow             //  variables from the session and the request (in this order).            //            HttpServletRequest req = context.getHttpRequest();            if( req != null && req.getSession() != null )            {                HttpSession session = req.getSession();                try                {                    String s;                                        if( (s = (String)session.getAttribute( varName )) != null )                        return s;                    if( (s = context.getHttpParameter( varName )) != null )                        return s;                }                catch( ClassCastException e ) {}            }            //            // And the final straw: see if the current page has named metadata.            //                        WikiPage pg = context.getPage();            if( pg != null )            {                Object metadata = pg.getAttribute( varName );                if( metadata != null )                    return metadata.toString();            }                        //            // And the final straw part 2: see if the "real" current page has            // named metadata. This allows a parent page to control a inserted            // page through defining variables            //            WikiPage rpg = context.getRealPage();            if( rpg != null )            {                Object metadata = rpg.getAttribute( varName );                if( metadata != null )                    return metadata.toString();            }                        //            // Next-to-final straw: attempt to fetch using property name            // We don't allow fetching any other properties than those starting            // with "jspwiki.".  I know my own code, but I can't vouch for bugs            // in other people's code... :-)            //                        if( varName.startsWith("jspwiki.") )            {                Properties props = context.getEngine().getWikiProperties();                String s = props.getProperty( varName );                if( s != null )                {                    return s;                }            }                        //            //  Final defaults for some known quantities.            //            if( varName.equals( VAR_ERROR ) || varName.equals( VAR_MSG ) )                return "";              throw new NoSuchVariableException( "No variable "+varName+" defined." );        }        catch( Exception e )        {            log.info("Interesting exception: cannot fetch variable value",e);        }        return "";    }    /**     *  This class provides the implementation for the different system variables.     *  It is called via Reflection - any access to a variable called $xxx is mapped     *  to getXxx() on this class.     *  <p>     *  This is a lot neater than using a huge if-else if branching structure     *  that we used to have before.     *  <p>     *  Note that since we are case insensitive for variables, and VariableManager     *  calls var.toLowerCase(), the getters for the variables do not have     *  capitalization anywhere.  This may look a bit odd, but then again, this     *  is not meant to be a public class.     *       *  @since 2.7.0     *     */    private static class SystemVariables    {        private WikiContext m_context;        public SystemVariables(WikiContext context)        {            m_context=context;        }        public String getPagename()        {            return m_context.getPage().getName();        }        public String getApplicationname()        {            return m_context.getEngine().getApplicationName();        }        public String getJspwikiversion()        {            return Release.getVersionString();        }        public String getEncoding()        {            return m_context.getEngine().getContentEncoding();        }        public String getTotalpages()        {            return Integer.toString(m_context.getEngine().getPageCount());        }        public String getPageprovider()        {            return m_context.getEngine().getCurrentProvider();        }        public String getPageproviderdescription()        {            return m_context.getEngine().getCurrentProviderInfo();        }        public String getAttachmentprovider()        {            WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();            return (p != null) ? p.getClass().getName() : "-";        }        public String getAttachmentproviderdescription()        {            WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();            return (p != null) ? p.getProviderInfo() : "-";        }        public String getInterwikilinks()        {            StringBuffer res = new StringBuffer();            for( Iterator i = m_context.getEngine().getAllInterWikiLinks().iterator(); i.hasNext(); )            {                if( res.length() > 0 ) res.append(", ");                String link = (String) i.next();                res.append( link );                res.append( " --> " );                res.append( m_context.getEngine().getInterWikiURL(link) );                }            return res.toString();        }        public String getInlinedimages()        {            StringBuffer res = new StringBuffer();            for( Iterator i = m_context.getEngine().getAllInlinedImagePatterns().iterator(); i.hasNext(); )            {                if( res.length() > 0 ) res.append(", ");                String ptrn = (String) i.next();                res.append(ptrn);            }            return res.toString();        }        @SuppressWarnings("deprecation")        public String getPluginpath()        {            String s = m_context.getEngine().getPluginSearchPath();            return (s == null) ? "-" : s;        }        public String getBaseurl()        {            return m_context.getEngine().getBaseURL();        }        public String getUptime()        {            Date now = new Date();            long secondsRunning = (now.getTime() - m_context.getEngine().getStartTime().getTime()) / 1000L;            long seconds = secondsRunning % 60;            long minutes = (secondsRunning /= 60) % 60;            long hours = (secondsRunning /= 60) % 24;            long days = secondsRunning /= 24;            return days + "d, " + hours + "h " + minutes + "m " + seconds + "s";        }        public String getLoginstatus()        {            WikiSession session = m_context.getWikiSession();            return m_context.getBundle(InternationalizationManager.CORE_BUNDLE).getString( "varmgr." + session.getStatus());        }        public String getUsername()        {            Principal wup = m_context.getCurrentUser();                        ResourceBundle rb = m_context.getBundle( InternationalizationManager.CORE_BUNDLE );            return wup != null ? wup.getName() : rb.getString( "varmgr.not.logged.in" );        }        public String getRequestcontext()        {            return m_context.getRequestContext();        }        public String getPagefilters()        {            List filters = m_context.getEngine().getFilterManager().getFilterList();            StringBuffer sb = new StringBuffer();            for (Iterator i = filters.iterator(); i.hasNext();)            {                PageFilter pf = (PageFilter) i.next();                String f = pf.getClass().getName();                if( pf instanceof InternalModule )                    continue;                if( sb.length() > 0 )                    sb.append(", ");                sb.append(f);            }            return sb.toString();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -