目前的最新版roller的readmore插件,并不支持中文标题,需要对ReadMorePlugin.java文件进行如下修改 ReadMorePlugin.java文件中的105行(render方法中),原: entry.getAnchor() 修改为: URLEncoder.encode(entry.getAnchor(), “UTF-8”) 既可 修改后的源码如下:
/** Created on Nov 2, 2003**/package org.roller.PResentation.velocity.plugins.readmore;import org.apache.commons.lang.StringEscapeUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.velocity.context.Context;import org.roller.RollerException;import org.roller.model.RollerFactory;import org.roller.model.UserManager;import org.roller.pojos.WeblogEntryData;import org.roller.pojos.WebsiteData;import org.roller.presentation.RollerRequest;import org.roller.presentation.velocity.PagePlugin;import org.roller.util.Utilities;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;/*** @author lance**/public class ReadMorePlugin implements PagePlugin{protected String name = "Read More Summary";protected String description = "Stops entry after 250 characters and creates " +"a link to the full entry.";private static Log mLogger =LogFactory.getFactory().getInstance(ReadMorePlugin.class);String ctXPath = "";public ReadMorePlugin(){mLogger.debug("ReadMorePlugin instantiated.");}public String toString() { return name; }/* (non-Javadoc)* @see org.roller.presentation.velocity.PagePlugin#init(org.roller.presentation.RollerRequest, org.apache.velocity.context.Context)*/public void init(RollerRequest rreq, Context ctx) throws RollerException{if (rreq == null) throw new RollerException("RollerRequest is null.");ctxPath = rreq.getRequest().getContextPath();}/*** @param mgr* @param data* @return*/private String getPageLink(UserManager mgr, WebsiteData website) throws RollerException{return mgr.retrievePage(website.getDefaultPageId()).getLink();}/** This method cannot do it's intended job (since it cannot* read the current Entry) so it is to do no work!** (non-Javadoc)* @see org.roller.presentation.velocity.PagePlugin#render(java.lang.String)*/public String render(String str){return str;}public String render(WeblogEntryData entry, boolean skipFlag){if (skipFlag)return entry.getText();// in case it didn't initializeString pageLink = "Weblog";try{pageLink = getPageLink(RollerFactory.getRoller().getUserManager(), entry.getWebsite());}catch (RollerException e){mLogger.warn("Unable to get pageLink", e);}String result = Utilities.truncateNicely(entry.getText(), 240, 260, "... ");try{// if the result is shorter, we need to add "Read More" linkif (result.length() < entry.getText().length()){String link = ""/comments/" entry.getWebsite().getUser().getUserName() +"/" pageLink "/" URLEncoder.encode(entry.getAnchor(), "UTF-8") "/">Read More";result += link;}}catch (UnsupportedEncodingException e){// go with the "no encoding" version}return result;}public String getName() { return name; }public String getDescription() { return StringEscapeUtils.escapeJavascript(description); }}
新闻热点
疑难解答