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

📄 rollercontext.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            mContext.log("ERROR reading dictionary file");        }        finally        {            if (is != null)            {                try                {                    is.close();                }                catch (Exception e)                {                    e.printStackTrace();                }            }        }    }    //-----------------------------------------------------------------------    /**     * Returns the full url for the website of the specified username.     */    public String getContextUrl(HttpServletRequest request, String username)    {        String url = this.getContextUrl(request);        if (username != null)        {            url = url + "/page/" + username;        }        return url;    }    //-----------------------------------------------------------------------    /** Get absolute URL of Roller context */    public String getContextUrl(HttpServletRequest request)    {        String url = request.getContextPath();        if (url.endsWith("/"))        {            url = url.substring(0, url.length() - 1);        }        return url;    }    //-----------------------------------------------------------------------    /** Get absolute URL of Roller context */    public String getAbsoluteContextUrl(HttpServletRequest request)    {        String url = RollerRuntimeConfig.getProperty("site.absoluteurl");                if (url == null || url.trim().length() == 0)        {            try            {                URL absURL = RequestUtils.absoluteURL(request, "/");                url = absURL.toString();            }            catch (MalformedURLException e)            {                url = "/";                mLogger.error("ERROR: forming absolute URL", e);            }        }        if (url.endsWith("/"))        {            url = url.substring(0, url.length() - 1);        }        mContext.setAttribute("org.roller.absoluteContextURL", url);        return url;    }    //-----------------------------------------------------------------------    /**     * For use by MetaWeblog API.     * @return Context URL or null if not initialized yet.     */    public String getAbsoluteContextUrl()    {        return (String) mContext.getAttribute("org.roller.absoluteContextURL");    }    //-----------------------------------------------------------------------    public String createEntryPermalink(        WeblogEntryData entry,        HttpServletRequest request,        boolean absolute)    {        String link = null;        try        {            String baseUrl = null;            if (absolute)            {                baseUrl = getAbsoluteContextUrl(request);            }            else            {                baseUrl = getContextUrl(request);            }            String dayString = DateUtil.format8chars(entry.getPubTime());            UserData ud = entry.getWebsite().getUser();            link =                Utilities.escapeHTML(                    baseUrl                        + "/page/"                        + ud.getUserName()                        + "?entry="                        + entry.getAnchor());        }        catch (Exception e)        {            mLogger.error("Unexpected exception", e);        }        return link;    }    //-----------------------------------------------------------------------    /**     * Return the real filepath to the theme.     *     * @param theme     * @return String     */    public String getThemePath(String theme)    {        String themespath = RollerRuntimeConfig.getProperty("users.themes.path");        // Figure path to new user theme        return mContext.getRealPath(            "/" + themespath + "/" + theme);    }    //-----------------------------------------------------------------------    /**     * Get the list of Theme names.  This consists     * of the directories under the /themes directory.     *     * @return String[]     */    public String[] getThemeNames()    {        String themespath = RollerRuntimeConfig.getProperty("users.themes.path");                String themesPath =            mContext.getRealPath("/" + themespath);        File themeDir = new File(themesPath);        return themeDir.list(new FilenameFilter()        {            public boolean accept(File dir, String name)            {                File file =                    new File(dir.getAbsolutePath() + File.separator + name);                return file.isDirectory();            }        });    }    //-----------------------------------------------------------------------    /**     * Returns the mContext.     * @return ServletContext     */    public static ServletContext getServletContext()    {        return mContext;    }    //-----------------------------------------------------------------------    /**     * Reads the Theme files from harddisk (if necessary) and places them into a     * ThemeCache.  If the requested Theme's pages are already in the cache,     * return them instead.     *     * @param themeName     * @return HashMap     * @throws FileNotFoundException     * @throws IOException     */    public HashMap readThemeMacros(String themeName)        throws FileNotFoundException, IOException    {        if (mLogger.isDebugEnabled())        {            mLogger.debug("themeName=" + themeName);        }        // Load all Velocity templates from root directory of the theme        String pageName = null;        String themeDir = this.getThemePath(themeName);        String[] children = getThemeFilenames(themeDir);        HashMap pages = new HashMap();        ThemeCache themeCache = ThemeCache.getInstance();        for (int i = 0; i < children.length; i++)        {            pageName = children[i].substring(0, children[i].length() - 3);            if (themeCache.getFromCache(themeName, pageName) != null)            {                pages.put(                    pageName,                    themeCache.getFromCache(themeName, pageName));            }            else            {                BufferedReader rdr = null;                try                {                    rdr = new BufferedReader(                        new FileReader(                            themeDir + File.separator + children[i]));                    String line = null;                    StringBuffer sb = new StringBuffer();                    while (null != (line = rdr.readLine()))                    {                        sb.append(line);                        sb.append("\n");                    }                        pages.put(pageName, sb.toString());                    themeCache.putIntoCache(themeName, pageName, sb.toString());                }                finally                 {                    if (rdr != null) rdr.close();                }            }        }        return pages;    }    //-----------------------------------------------------------------------    public static String[] getThemeFilenames(String themeDir)    {        ThemeCache themeCache = ThemeCache.getInstance();        if (themeCache.getFileList(themeDir) != null)        {            return themeCache.getFileList(themeDir);        }        File dir = new File(themeDir);        FilenameFilter filter = new FilenameFilter()        {            public boolean accept(File dir, String name)            {                return name.endsWith(".vm");            }        };        String[] children = dir.list(filter);        themeCache.setFileList(themeDir, children);        return children;    }    //-----------------------------------------------------------------------    /** Roller version */    public String getRollerVersion()    {        return mVersion;    }    //-----------------------------------------------------------------------    /** Roller build time */    public String getRollerBuildTime()    {        return mBuildTime;    }    //-----------------------------------------------------------------------    /** Get username that built Roller */    public String getRollerBuildUser()    {        return mBuildUser;    }    //-----------------------------------------------------------------------    public static CommentAuthenticator getCommentAuthenticator()     {        if (mCommentAuthenticator == null)         {            String name = RollerConfig.getProperty("comment.authenticator.classname");            try             {                Class clazz = Class.forName(name);                mCommentAuthenticator=(CommentAuthenticator)clazz.newInstance();            }            catch (Exception e)            {                mLogger.error(e);                mCommentAuthenticator = new DefaultCommentAuthenticator();            }        }                return mCommentAuthenticator;    }}

⌨️ 快捷键说明

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