Update of
/cvsroot/roller/roller/contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7247/contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore
Modified Files:
ReadMorePlugin.java
Log Message:
Tweaked PagePlugins, and added "help text"/description to UI.
Index: ReadMorePlugin.java
===================================================================
RCS file:
/cvsroot/roller/roller/contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore/ReadMorePlugin.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ReadMorePlugin.java 8 Jul 2004 06:48:58 -0000 1.1
--- ReadMorePlugin.java 14 Jul 2004 01:30:54 -0000 1.2
***************
*** 1,107 ****
! /*
! * Created on Nov 2, 2003
! *
! */
! package org.roller.presentation.velocity.plugins.readmore;
!
! 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.UserManager;
! import org.roller.pojos.WeblogEntryData;
! import org.roller.presentation.RollerRequest;
! import org.roller.presentation.velocity.PagePlugin;
! import org.roller.util.Utilities;
!
! /**
! * @author lance
! *
! */
! public class ReadMorePlugin implements PagePlugin
! {
! public String name = "Read More Summary";
!
! private static Log mLogger =
! LogFactory.getFactory().getInstance(ReadMorePlugin.class);
!
! String ctxPath = "";
! UserManager uMgr = null;
!
! 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)
! {
! if (rreq != null)
! {
! ctxPath = rreq.getRequest().getContextPath();
! try
! {
! uMgr = rreq.getRoller().getUserManager();
! }
! catch (RollerException e)
! {
! mLogger.error("Unable to reach UserManager", e);
! }
! }
! }
!
! /*
! * 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();
!
! String result = Utilities.truncateNicely(entry.getText(), 240, 260,
"... ");
!
! // if the result is shorter, we need to add "Read More" link
! if (result.length() < entry.getText().length())
! {
! String pageLink = "Weblog";
! if (uMgr != null)
! {
! try
! {
! pageLink = uMgr.retrievePage(
! entry.getWebsite().getDefaultPageId()
! ).getLink();
! }
! catch (Exception e)
! {
! // nothing much I can do, go with
default "Weblog" value
! // could be RollerException or NullPointerException
! }
! }
!
! if (result.endsWith("</p>")) result += "<p>";
!
! String link = "<a href=\"" + ctxPath + "/comments/" +
! entry.getWebsite().getUser().getUserName() +
! "/" + pageLink + "/" + entry.getAnchor() +
! "\">Read More</a></p>";
!
! result += link;
! }
! return result;
! }
!
! }
--- 1 ----
! /*
* 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;
/**
* @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,
"... ");
// if the result is shorter, we need to add "Read More" link
if (result.length() < entry.getText().length())
{
String link = "<div class=\"readMore\"><a href=\"" +
ctxPath + "/comments/" +
entry.getWebsite().getUser().getUserName() +
"/" + pageLink + "/" + entry.getAnchor() +
"\">Read More</a></div>";
result += link;
}
return result;
}
public String getName() { return name; }
public String getDescription() { return
StringEscapeUtils.escapeJavaScript(description); }
}
\ No newline at end of file
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
|