Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,9 @@ public Collection< SearchResult > findPages( final String query, final int flags

String[] fragments = new String[ 0 ];
if( text != null && highlighter != null ) {
final TokenStream tokenStream = getLuceneAnalyzer().tokenStream( LUCENE_PAGE_CONTENTS, new StringReader( text ) );
fragments = highlighter.getBestFragments( tokenStream, text, MAX_FRAGMENTS );
try (TokenStream tokenStream = getLuceneAnalyzer().tokenStream(LUCENE_PAGE_CONTENTS, new StringReader(text))) {
fragments = highlighter.getBestFragments(tokenStream, text, MAX_FRAGMENTS);
}
}

final SearchResult result = new SearchResultImpl( page, score, fragments );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public final int doStartTag() {
public final int doAfterBody() {
if( bodyContent != null ) {
try {
final JspWriter out = getPreviousOut();
JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
bodyContent.clearBody();
} catch( final IOException e ) {
Expand Down
81 changes: 41 additions & 40 deletions jspwiki-main/src/main/java/org/apache/wiki/tags/DiffLinkTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,53 @@ public final int doWikiStartTag() throws IOException {
}
}

final JspWriter out = pageContext.getOut();
try (JspWriter out = pageContext.getOut()) {

int r1;
int r2;
int r1;
int r2;

// In case the page does not exist, we fail silently.
if( !engine.getManager( PageManager.class ).wikiPageExists( pageName ) ) {
return SKIP_BODY;
}

if( VER_LATEST.equals( getVersion() ) ) {
final Page latest = engine.getManager( PageManager.class ).getPage( pageName, WikiProvider.LATEST_VERSION );
if( latest == null ) {
// This may occur if matchEnglishPlurals is on, and we access the wrong page name
// In case the page does not exist, we fail silently.
if (!engine.getManager(PageManager.class).wikiPageExists(pageName)) {
return SKIP_BODY;
}
r1 = latest.getVersion();
} else if( VER_PREVIOUS.equals( getVersion() ) ) {
r1 = m_wikiContext.getPage().getVersion() - 1;
r1 = Math.max( r1, 1 );
} else if( VER_CURRENT.equals( getVersion() ) ) {
r1 = m_wikiContext.getPage().getVersion();
} else {
r1 = Integer.parseInt( getVersion() );
}

if( VER_LATEST.equals( getNewVersion() ) ) {
final Page latest = engine.getManager( PageManager.class ).getPage( pageName, WikiProvider.LATEST_VERSION );
r2 = latest.getVersion();
} else if( VER_PREVIOUS.equals( getNewVersion() ) ) {
r2 = m_wikiContext.getPage().getVersion() - 1;
r2 = Math.max( r2, 1 );
} else if( VER_CURRENT.equals( getNewVersion() ) ) {
r2 = m_wikiContext.getPage().getVersion();
} else {
r2 = Integer.parseInt( getNewVersion() );
}
if (VER_LATEST.equals(getVersion())) {
final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
if (latest == null) {
// This may occur if matchEnglishPlurals is on, and we access the wrong page name
return SKIP_BODY;
}
r1 = latest.getVersion();
} else if (VER_PREVIOUS.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion() - 1;
r1 = Math.max(r1, 1);
} else if (VER_CURRENT.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion();
} else {
r1 = Integer.parseInt(getVersion());
}

final String url = m_wikiContext.getURL( ContextEnum.PAGE_DIFF.getRequestContext(), pageName, "r1="+r1+"&amp;r2="+r2 );
switch( m_format ) {
case ANCHOR:
out.print("<a href=\""+url+"\">");
break;
case URL:
out.print( url );
break;
if (VER_LATEST.equals(getNewVersion())) {
final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
r2 = latest.getVersion();
} else if (VER_PREVIOUS.equals(getNewVersion())) {
r2 = m_wikiContext.getPage().getVersion() - 1;
r2 = Math.max(r2, 1);
} else if (VER_CURRENT.equals(getNewVersion())) {
r2 = m_wikiContext.getPage().getVersion();
} else {
r2 = Integer.parseInt(getNewVersion());
}

final String url = m_wikiContext.getURL(ContextEnum.PAGE_DIFF.getRequestContext(), pageName, "r1=" + r1 + "&amp;r2=" + r2);
switch (m_format) {
case ANCHOR:
out.print("<a href=\"" + url + "\">");
break;
case URL:
out.print(url);
break;
}
}

return EVAL_BODY_INCLUDE;
Expand Down
19 changes: 10 additions & 9 deletions jspwiki-main/src/main/java/org/apache/wiki/tags/EditLinkTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ public final int doWikiStartTag() throws IOException {
//
// Finally, print out the correct link, according to what user commanded.
//
final JspWriter out = pageContext.getOut();
switch( m_format ) {
case ANCHOR:
out.print( "<a href=\"" + m_wikiContext.getURL( ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString ) +
"\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">" );
break;
case URL:
out.print( m_wikiContext.getURL( ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString ) );
break;
try (JspWriter out = pageContext.getOut()) {
switch (m_format) {
case ANCHOR:
out.print("<a href=\"" + m_wikiContext.getURL(ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString) +
"\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
break;
case URL:
out.print(m_wikiContext.getURL(ContextEnum.PAGE_EDIT.getRequestContext(), pageName, versionString));
break;
}
}

return EVAL_BODY_INCLUDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public final int doStartTag() {
public final int doAfterBody() {
if( bodyContent != null ) {
try {
final JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
try (JspWriter out = getPreviousOut()) {
out.print(bodyContent.getString());
}
bodyContent.clearBody();
} catch( final IOException e ) {
LOG.error("Unable to get inner tag text", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ public final int doWikiStartTag() throws IOException {
LOG.debug("Request diff between version "+verold+" and "+vernew);

if( ctx.getPage() != null ) {
final JspWriter out = pageContext.getOut();
final String diff = engine.getManager( DifferenceManager.class ).getDiff( ctx, vernew, verold);
try (JspWriter out = pageContext.getOut()) {
final String diff = engine.getManager(DifferenceManager.class).getDiff(ctx, vernew, verold);

if( diff.isEmpty() ) {
return EVAL_BODY_INCLUDE;
}
if (diff.isEmpty()) {
return EVAL_BODY_INCLUDE;
}

out.write( diff );
out.write(diff);
}
}

return SKIP_BODY;
Expand Down
20 changes: 13 additions & 7 deletions jspwiki-main/src/main/java/org/apache/wiki/tags/InsertPageTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ public final int doWikiStartTag() throws IOException, ProviderException {

LOG.debug("Inserting page "+insertedPage);

final JspWriter out = pageContext.getOut();
final Page oldPage = m_wikiContext.setRealPage( insertedPage );

switch( m_mode ) {
case HTML: out.print( engine.getManager( RenderingManager.class ).getHTML( m_wikiContext, insertedPage ) ); break;
case PLAIN: out.print( engine.getManager( PageManager.class ).getText( insertedPage ) ); break;
final Page oldPage;
try (JspWriter out = pageContext.getOut()) {
oldPage = m_wikiContext.setRealPage(insertedPage);

switch (m_mode) {
case HTML:
out.print(engine.getManager(RenderingManager.class).getHTML(m_wikiContext, insertedPage));
break;
case PLAIN:
out.print(engine.getManager(PageManager.class).getText(insertedPage));
break;
}
}

m_wikiContext.setRealPage( oldPage );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ public int doEndTag() {
public int doAfterBody() {
if( bodyContent != null ) {
try {
final JspWriter out = getPreviousOut();
out.print( bodyContent.getString() );
try (JspWriter out = getPreviousOut()) {
out.print(bodyContent.getString());
}
bodyContent.clearBody();
} catch( final IOException e ) {
LOG.error( "Unable to get inner tag text", e );
Expand Down
59 changes: 30 additions & 29 deletions jspwiki-main/src/main/java/org/apache/wiki/tags/LinkTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,41 +335,42 @@ public int doWikiStartTag() throws Exception {
public int doEndTag() {
try {
final Engine engine = m_wikiContext.getEngine();
final JspWriter out = pageContext.getOut();
final String url = figureOutURL();
try (JspWriter out = pageContext.getOut()) {
final String url = figureOutURL();

final StringBuilder sb = new StringBuilder( 20 );
final StringBuilder sb = new StringBuilder(20);

sb.append( (m_cssClass != null) ? "class=\""+m_cssClass+"\" " : "" );
sb.append( (m_style != null) ? "style=\""+m_style+"\" " : "" );
sb.append( (m_target != null ) ? "target=\""+m_target+"\" " : "" );
sb.append( (m_title != null ) ? "title=\""+m_title+"\" " : "" );
sb.append( (m_rel != null ) ? "rel=\""+m_rel+"\" " : "" );
sb.append( (m_accesskey != null) ? "accesskey=\""+m_accesskey+"\" " : "" );
sb.append( (m_tabindex != null) ? "tabindex=\""+m_tabindex+"\" " : "" );
sb.append((m_cssClass != null) ? "class=\"" + m_cssClass + "\" " : "");
sb.append((m_style != null) ? "style=\"" + m_style + "\" " : "");
sb.append((m_target != null) ? "target=\"" + m_target + "\" " : "");
sb.append((m_title != null) ? "title=\"" + m_title + "\" " : "");
sb.append((m_rel != null) ? "rel=\"" + m_rel + "\" " : "");
sb.append((m_accesskey != null) ? "accesskey=\"" + m_accesskey + "\" " : "");
sb.append((m_tabindex != null) ? "tabindex=\"" + m_tabindex + "\" " : "");

if( engine.getManager( PageManager.class ).getPage( m_pageName ) instanceof Attachment ) {
sb.append( engine.getManager( AttachmentManager.class ).forceDownload( m_pageName ) ? "download " : "" );
}
if (engine.getManager(PageManager.class).getPage(m_pageName) instanceof Attachment) {
sb.append(engine.getManager(AttachmentManager.class).forceDownload(m_pageName) ? "download " : "");
}

switch( m_format ) {
case URL:
out.print( url );
break;
default:
case ANCHOR:
out.print("<a "+ sb +" href=\""+url+"\">");
break;
}
switch (m_format) {
case URL:
out.print(url);
break;
default:
case ANCHOR:
out.print("<a " + sb + " href=\"" + url + "\">");
break;
}

// Add any explicit body content. This is not the intended use of LinkTag, but happens to be the way it has worked previously.
if( m_bodyContent != null ) {
final String linktext = m_bodyContent.getString().trim();
out.write( linktext );
}
// Add any explicit body content. This is not the intended use of LinkTag, but happens to be the way it has worked previously.
if (m_bodyContent != null) {
final String linktext = m_bodyContent.getString().trim();
out.write(linktext);
}

// Finish off by closing opened anchor
if( m_format == ANCHOR ) out.print("</a>");
// Finish off by closing opened anchor
if (m_format == ANCHOR) out.print("</a>");
}
} catch( final Exception e ) {
// Yes, we want to catch all exceptions here, including RuntimeExceptions
LOG.error( "Tag failed", e );
Expand Down
63 changes: 32 additions & 31 deletions jspwiki-main/src/main/java/org/apache/wiki/tags/LinkToTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,42 +88,43 @@ public int doWikiStartTag() throws IOException {
}
}

final JspWriter out = pageContext.getOut();
final String url;
final String linkclass;
String forceDownload = "";
try (JspWriter out = pageContext.getOut()) {
final String url;
final String linkclass;
String forceDownload = "";

if( isattachment ) {
url = m_wikiContext.getURL( ContextEnum.PAGE_ATTACH.getRequestContext(), pageName, ( getVersion() != null ) ? "version=" + getVersion() : null );
linkclass = "attachment";
if (isattachment) {
url = m_wikiContext.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), pageName, (getVersion() != null) ? "version=" + getVersion() : null);
linkclass = "attachment";

if( m_wikiContext.getEngine().getManager( AttachmentManager.class ).forceDownload( pageName ) ) {
forceDownload = "download ";
}
if (m_wikiContext.getEngine().getManager(AttachmentManager.class).forceDownload(pageName)) {
forceDownload = "download ";
}

} else {
final StringBuilder params = new StringBuilder();
if( getVersion() != null ) {
params.append( "version=" ).append( getVersion() );
}
if( getTemplate() != null ) {
params.append( params.length() > 0 ? "&amp;" : "" ).append( "skin=" ).append( getTemplate() );
} else {
final StringBuilder params = new StringBuilder();
if (getVersion() != null) {
params.append("version=").append(getVersion());
}
if (getTemplate() != null) {
params.append(params.length() > 0 ? "&amp;" : "").append("skin=").append(getTemplate());
}

url = m_wikiContext.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), pageName, params.toString());
linkclass = "wikipage";
}

url = m_wikiContext.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), pageName, params.toString() );
linkclass = "wikipage";
}

switch( m_format ) {
case ANCHOR:
out.print( "<a class=\"" + linkclass +
"\" href=\"" + url +
"\" accesskey=\"" + m_accesskey +
"\" title=\"" + m_title + "\" " + forceDownload + ">" );
break;
case URL:
out.print( url );
break;
switch (m_format) {
case ANCHOR:
out.print("<a class=\"" + linkclass +
"\" href=\"" + url +
"\" accesskey=\"" + m_accesskey +
"\" title=\"" + m_title + "\" " + forceDownload + ">");
break;
case URL:
out.print(url);
break;
}
}

return EVAL_BODY_INCLUDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ public void setAccesskey( final String access )
}

if( engine.getManager( PageManager.class ).wikiPageExists(pageName) ) {
final JspWriter out = pageContext.getOut();
final String url = m_wikiContext.getURL( ContextEnum.PAGE_INFO.getRequestContext(), pageName );
try (JspWriter out = pageContext.getOut()) {
final String url = m_wikiContext.getURL(ContextEnum.PAGE_INFO.getRequestContext(), pageName);

switch( m_format ) {
case ANCHOR: out.print("<a class=\"pageinfo\" href=\""+url+"\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">"); break;
case URL: out.print( url ); break;
switch (m_format) {
case ANCHOR:
out.print("<a class=\"pageinfo\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
break;
case URL:
out.print(url);
break;
}
}
return EVAL_BODY_INCLUDE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public int doAfterBody()
{
try
{
final BodyContent bc = getBodyContent();

getPreviousOut().write( executePlugin( m_plugin, m_args, (bc != null) ? bc.getString() : null) );
try (BodyContent bc = getBodyContent()) {

getPreviousOut().write(executePlugin(m_plugin, m_args, (bc != null) ? bc.getString() : null));
}
}
catch( final Exception e )
{
Expand Down
Loading