in jspwiki-main/src/main/java/org/apache/wiki/plugin/WeblogPlugin.java [274:373]
private void addEntryHTML( final Context context, final DateFormat entryFormat, final boolean hasComments,
final StringBuilder buffer, final Page entry, final Map< String, String > params) {
final Engine engine = context.getEngine();
final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
buffer.append("<div class=\"weblogentry\">\n");
//
// Heading
//
buffer.append("<div class=\"weblogentryheading\">\n");
final Date entryDate = entry.getLastModified();
buffer.append( entryFormat != null ? entryFormat.format(entryDate) : entryDate );
buffer.append("</div>\n");
//
// Append the text of the latest version. Reset the context to that page.
//
final Context entryCtx = context.clone();
entryCtx.setPage( entry );
String html = engine.getManager( RenderingManager.class ).getHTML( entryCtx, engine.getManager( PageManager.class ).getPage( entry.getName() ) );
// Extract the first h1/h2/h3 as title, and replace with null
buffer.append("<div class=\"weblogentrytitle\">\n");
final Matcher matcher = HEADINGPATTERN.matcher( html );
if ( matcher.find() ) {
final String title = matcher.group(2);
html = matcher.replaceFirst("");
buffer.append( title );
} else {
buffer.append( entry.getName() );
}
buffer.append("</div>\n");
buffer.append("<div class=\"weblogentrybody\">\n");
final int preview = TextUtil.parseIntParameter(params.get(PARAM_PREVIEW), 0);
if (preview > 0) {
//
// We start with the first 'preview' number of characters from the text,
// and then add characters to it until we get to a linebreak.
// The idea is that cutting off at a linebreak is less likely
// to disturb the HTML and leave us with garbled output.
//
boolean hasBeenCutOff = false;
int cutoff = Math.min(preview, html.length());
while (cutoff < html.length()) {
if (html.charAt(cutoff) == '\r' || html.charAt(cutoff) == '\n') {
hasBeenCutOff = true;
break;
}
cutoff++;
}
buffer.append( html, 0, cutoff );
if (hasBeenCutOff) {
buffer.append( " <a href=\"" ).append( entryCtx.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), entry.getName() ) ).append( "\">" ).append( rb.getString( "weblogentryplugin.more" ) ).append( "</a>\n" );
}
} else {
buffer.append(html);
}
buffer.append("</div>\n");
//
// Append footer
//
buffer.append("<div class=\"weblogentryfooter\">\n");
String author = entry.getAuthor();
if( author != null ) {
if( engine.getManager( PageManager.class ).wikiPageExists(author) ) {
author = "<a href=\""+entryCtx.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), author )+"\">"+engine.getManager( RenderingManager.class ).beautifyTitle(author)+"</a>";
}
} else {
author = "AnonymousCoward";
}
buffer.append( MessageFormat.format( rb.getString( "weblogentryplugin.postedby" ), author ) );
buffer.append( "<a href=\"" ).append( entryCtx.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), entry.getName() ) ).append( "\">" ).append( rb.getString( "weblogentryplugin.permalink" ) ).append( "</a>" );
final String commentPageName = TextUtil.replaceString( entry.getName(), "blogentry", "comments" );
if( hasComments ) {
final int numComments = guessNumberOfComments( engine, commentPageName );
//
// We add the number of comments to the URL so that the user's browsers would realize that the page has changed.
//
buffer.append( " " );
final String addcomment = rb.getString("weblogentryplugin.addcomment");
buffer.append( "<a href=\"" ).append( entryCtx.getURL( ContextEnum.PAGE_COMMENT.getRequestContext(), commentPageName, "nc=" + numComments ) ).append( "\">" ).append( MessageFormat.format( addcomment, numComments ) ).append( "</a>" );
}
buffer.append("</div>\n");
// Done, close
buffer.append("</div>\n");
}