Skip to content

Commit

Permalink
java 11 improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg authored and juanpablo-santos committed Jul 29, 2023
1 parent 5d78b49 commit 4cc284e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;


Expand Down Expand Up @@ -162,22 +163,14 @@ protected void initialize( final Properties props ) throws WikiException {

if( m_engine.getServletContext() != null ) {
LOG.debug( "Attempting to locate " + DEFAULT_XMLFILE + " from servlet context." );
if( xmlFile == null ) {
xmlStream = m_engine.getServletContext().getResourceAsStream( DEFAULT_XMLFILE );
} else {
xmlStream = m_engine.getServletContext().getResourceAsStream( xmlFile );
}
xmlStream = m_engine.getServletContext().getResourceAsStream(Objects.requireNonNullElse(xmlFile, DEFAULT_XMLFILE));
}

if( xmlStream == null ) {
// just a fallback element to the old behaviour prior to 2.5.8
LOG.debug( "Attempting to locate filters.xml from class path." );

if( xmlFile == null ) {
xmlStream = getClass().getResourceAsStream( "/filters.xml" );
} else {
xmlStream = getClass().getResourceAsStream( xmlFile );
}
xmlStream = getClass().getResourceAsStream(Objects.requireNonNullElse(xmlFile, "/filters.xml"));
}

if( (xmlStream == null) && (xmlFile != null) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ private static String translateLists(final String content, final String sourceSy
}
if ((inList == -1 && counter != 1) || (inList != -1 && inList + 1 < counter))
{
for (int c = 0; c < counter; c++)
{
result.append(actSourceSymbol);
}
result.append(actSourceSymbol.repeat(Math.max(0, counter)));
inList = -1;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;


Expand Down Expand Up @@ -109,11 +110,7 @@ public String execute( final Context context, final Map<String, String> params )
final Page page;
try {
final String pageName = engine.getFinalPageName( includedPage );
if( pageName != null ) {
page = engine.getManager( PageManager.class ).getPage( pageName );
} else {
page = engine.getManager( PageManager.class ).getPage( includedPage );
}
page = engine.getManager(PageManager.class).getPage(Objects.requireNonNullElse(pageName, includedPage));
} catch( final ProviderException e ) {
res.append( "<span class=\"error\">Page could not be found by the page provider.</span>" );
return res.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.io.StringReader;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.Objects;
import java.util.Properties;


Expand Down Expand Up @@ -233,11 +234,7 @@ boolean useCache( final Context context ) {
public String getHTML( final Context context, final WikiDocument doc ) throws IOException {
final Boolean wysiwygVariable = context.getVariable( Context.VAR_WYSIWYG_EDITOR_MODE );
final boolean wysiwygEditorMode;
if( wysiwygVariable != null ) {
wysiwygEditorMode = wysiwygVariable;
} else {
wysiwygEditorMode = false;
}
wysiwygEditorMode = Objects.requireNonNullElse(wysiwygVariable, false);
final WikiRenderer rend;
if( wysiwygEditorMode ) {
rend = getWysiwygRenderer( context, doc );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

Expand Down Expand Up @@ -309,11 +310,7 @@ public String generateBlogRSS( final Context wikiContext, final List< Page > cha
LOG.debug( "Generating RSS for blog, size={}", changed.size() );

final String ctitle = m_engine.getManager( VariableManager.class ).getVariable( wikiContext, PROP_CHANNEL_TITLE );
if( ctitle != null ) {
feed.setChannelTitle( ctitle );
} else {
feed.setChannelTitle( m_engine.getApplicationName() + ":" + wikiContext.getPage().getName() );
}
feed.setChannelTitle(Objects.requireNonNullElseGet(ctitle, () -> m_engine.getApplicationName() + ":" + wikiContext.getPage().getName()));

feed.setFeedURL( wikiContext.getViewURL( wikiContext.getPage().getName() ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ public Map< String, String > listTimeFormats( final PageContext pageContext ) {
} else {
Collections.sort( tfArr );

for (int i = 0; i < tfArr.size(); i++) {
tfArr.set(i, props.getProperty(tfArr.get(i)));
}
tfArr.replaceAll(props::getProperty);
}

final String prefTimeZone = Preferences.getPreference( context, "TimeZone" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ public class JSPWikiLinkRenderer implements NodeRenderer {
@Override
public Set< NodeRenderingHandler< ? > > getNodeRenderingHandlers() {
final HashSet< NodeRenderingHandler< ? > > set = new HashSet<>();
set.add( new NodeRenderingHandler<>( JSPWikiLink.class, new NodeRenderingHandler.CustomNodeRenderer< JSPWikiLink >() {
set.add( new NodeRenderingHandler<>( JSPWikiLink.class, new NodeRenderingHandler.CustomNodeRenderer<>() {

/**
* {@inheritDoc}
*/
@Override
public void render( final JSPWikiLink node, final NodeRendererContext context, final HtmlWriter html ) {
if( context.isDoNotRenderLinks() ) {
context.renderChildren( node );
public void render(final JSPWikiLink node, final NodeRendererContext context, final HtmlWriter html) {
if (context.isDoNotRenderLinks()) {
context.renderChildren(node);
} else {
// standard Link Rendering
final ResolvedLink resolvedLink = context.resolveLink( LinkType.LINK, node.getUrl().unescape(), null );
final ResolvedLink resolvedLink = context.resolveLink(LinkType.LINK, node.getUrl().unescape(), null);

html.attr( "href", resolvedLink.getUrl() );
if( node.getTitle().isNotNull() ) {
html.attr( "title", node.getTitle().unescape() );
html.attr("href", resolvedLink.getUrl());
if (node.getTitle().isNotNull()) {
html.attr("title", node.getTitle().unescape());
}
html.srcPos( node.getChars() ).withAttr( resolvedLink ).tag( "a" );
context.renderChildren( node );
html.tag( "/a" );
html.srcPos(node.getChars()).withAttr(resolvedLink).tag("a");
context.renderChildren(node);
html.tag("/a");
}
}
} ) );
Expand Down

0 comments on commit 4cc284e

Please sign in to comment.