修改ReadMorePlugin.java,使其支持中文标题(roller webblog)

针对Roller webblog的ReadMorePlugin.java,原版不支持中文标题。通过在render方法中将entry.getAnchor()修改为URLEncoder.encode(entry.getAnchor(), “UTF-8”),解决了这一问题。修改后的代码可以正确处理中文链接,确保了对中文标题的支持。" 52504693,5004735,多阶编码本模型在前景检测中的应用,"['计算机视觉', '图像处理', '机器学习', '背景模型', '实时处理']
摘要由CSDN通过智能技术生成
目前的最新版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() < entry.getText().length())
{
String link = "
 
 ";

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); }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值