目前的最新版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 initialize
String 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" link
if (result.length() "/comments/"
entry.getWebsite().getUser().getUserName() +
"/" pageLink "/" URLEncoder.encode(entry.getAnchor(), "UTF-8")
"\"Read More