You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/01/09 23:44:49 UTC

[jspwiki] branch master updated (c9bc3c7 -> 33f5b20)

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git.


    from c9bc3c7  2.11.0-M7-git-04
     new 7d31bed  apply intellij suggested format + fixes
     new c95693f  move ATTR_CONTEXT constant from WikiTagBase to WikiContext
     new 33f5b20  generate jacoco xml report instead of binary file

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Jenkinsfile                                        |   2 +-
 .../src/main/java/org/apache/wiki/WikiContext.java | 369 ++++++++-------------
 .../org/apache/wiki/auth/AuthorizationManager.java |  38 +--
 .../apache/wiki/tags/AttachmentsIteratorTag.java   |   6 +-
 .../org/apache/wiki/tags/HistoryIteratorTag.java   |   6 +-
 .../java/org/apache/wiki/tags/IteratorTag.java     |  19 +-
 .../apache/wiki/tags/SearchResultIteratorTag.java  |  39 +--
 .../java/org/apache/wiki/tags/TranslateTag.java    |  43 +--
 .../java/org/apache/wiki/tags/WikiBodyTag.java     |  29 +-
 .../java/org/apache/wiki/tags/WikiTagBase.java     |   4 +-
 .../java/org/apache/wiki/ui/WikiJSPFilter.java     |  11 +-
 .../java/org/apache/wiki/ui/WikiServletFilter.java | 102 ++----
 12 files changed, 252 insertions(+), 416 deletions(-)


[jspwiki] 01/03: apply intellij suggested format + fixes

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 7d31beddff2cc365b6877dbfce0bb6b08dccdb4b
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Jan 10 00:16:36 2020 +0100

    apply intellij suggested format + fixes
---
 .../src/main/java/org/apache/wiki/WikiContext.java | 366 ++++++++-------------
 1 file changed, 140 insertions(+), 226 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
index bea0ea4..f4a97d5 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
@@ -42,31 +42,21 @@ import java.util.HashMap;
 import java.util.PropertyPermission;
 
 /**
- *  <p>Provides state information throughout the processing of a page.  A
- *  WikiContext is born when the JSP pages that are the main entry
- *  points, are invoked.  The JSPWiki engine creates the new
- *  WikiContext, which basically holds information about the page, the
- *  handling engine, and in which context (view, edit, etc) the
- *  call was done.</p>
- *  <p>A WikiContext also provides request-specific variables, which can
- *  be used to communicate between plugins on the same page, or
- *  between different instances of the same plugin.  A WikiContext
- *  variable is valid until the processing of the page has ended.  For
+ *  <p>Provides state information throughout the processing of a page.  A WikiContext is born when the JSP pages that are the main entry
+ *  points, are invoked.  The JSPWiki engine creates the new WikiContext, which basically holds information about the page, the
+ *  handling engine, and in which context (view, edit, etc) the call was done.</p>
+ *  <p>A WikiContext also provides request-specific variables, which can be used to communicate between plugins on the same page, or
+ *  between different instances of the same plugin.  A WikiContext variable is valid until the processing of the page has ended.  For
  *  an example, please see the Counter plugin.</p>
- *  <p>When a WikiContext is created, it automatically associates a
- *  {@link WikiSession} object with the user's HttpSession. The
- *  WikiSession contains information about the user's authentication
- *  status, and is consulted by {@link #getCurrentUser()}.
- *  object</p>
- *  <p>Do not cache the page object that you get from the WikiContext; always
- *  use getPage()!</p>
+ *  <p>When a WikiContext is created, it automatically associates a {@link WikiSession} object with the user's HttpSession. The
+ *  WikiSession contains information about the user's authentication status, and is consulted by {@link #getCurrentUser()} object.</p>
+ *  <p>Do not cache the page object that you get from the WikiContext; always use getPage()!</p>
  *
  *  @see org.apache.wiki.plugin.Counter
- *
  */
 public class WikiContext implements Cloneable, Command {
 
-    private    Command m_command = null;
+    private    Command m_command;
 
     private    WikiPage   m_page;
     private    WikiPage   m_realPage;
@@ -76,9 +66,9 @@ public class WikiContext implements Cloneable, Command {
     private    HashMap<String,Object> m_variableMap = new HashMap<>();
 
     /** Stores the HttpServletRequest.  May be null, if the request did not come from a servlet. */
-    protected  HttpServletRequest m_request = null;
+    protected HttpServletRequest m_request;
 
-    private    WikiSession m_session = null;
+    private WikiSession m_session;
 
     /** User is administering JSPWiki (Install, SecurityConfig). */
     public static final String INSTALL = WikiCommand.INSTALL.getRequestContext();
@@ -167,14 +157,12 @@ public class WikiContext implements Cloneable, Command {
     private static final Permission DUMMY_PERMISSION = new PropertyPermission( "os.name", "read" );
 
     /**
-     *  Create a new WikiContext for the given WikiPage. Delegates to
-     * {@link #WikiContext(WikiEngine, HttpServletRequest, WikiPage)}.
+     *  Create a new WikiContext for the given WikiPage. Delegates to {@link #WikiContext(WikiEngine, HttpServletRequest, WikiPage)}.
+     *
      *  @param engine The WikiEngine that is handling the request.
-     *  @param page   The WikiPage.  If you want to create a
-     *  WikiContext for an older version of a page, you must use this
-     *  constructor.
+     *  @param page The WikiPage. If you want to create a WikiContext for an older version of a page, you must use this constructor.
      */
-    public WikiContext( WikiEngine engine, WikiPage page )
+    public WikiContext( final WikiEngine engine, final WikiPage page )
     {
         this( engine, null, findCommand( engine, null, page ) );
     }
@@ -236,19 +224,15 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     * Creates a new WikiContext for the given WikiEngine, WikiPage and
-     * HttpServletRequest. This method simply looks up the appropriate Command
-     * using {@link #findCommand(WikiEngine, HttpServletRequest, WikiPage)} and
-     * delegates to
+     * Creates a new WikiContext for the given WikiEngine, WikiPage and HttpServletRequest. This method simply looks up the appropriate
+     * Command using {@link #findCommand(WikiEngine, HttpServletRequest, WikiPage)} and delegates to
      * {@link #WikiContext(WikiEngine, HttpServletRequest, Command)}.
+     *
      * @param engine The WikiEngine that is handling the request
-     * @param request The HttpServletRequest that should be associated with this
-     *            context. This parameter may be <code>null</code>.
-     * @param page The WikiPage. If you want to create a WikiContext for an
-     *            older version of a page, you must supply this parameter
+     * @param request The HttpServletRequest that should be associated with this context. This parameter may be <code>null</code>.
+     * @param page The WikiPage. If you want to create a WikiContext for an older version of a page, you must supply this parameter
      */
-    public WikiContext(WikiEngine engine, HttpServletRequest request, WikiPage page)
-    {
+    public WikiContext( final WikiEngine engine, final HttpServletRequest request, final WikiPage page ) {
         this( engine, request, findCommand( engine, request, page ) );
     }
 
@@ -273,44 +257,35 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  Sets a reference to the real page whose content is currently being
-     *  rendered.
+     *  Sets a reference to the real page whose content is currently being rendered.
      *  <p>
-     *  Sometimes you may want to render the page using some other page's context.
-     *  In those cases, it is highly recommended that you set the setRealPage()
-     *  to point at the real page you are rendering.  Please see InsertPageTag
-     *  for an example.
+     *  Sometimes you may want to render the page using some other page's context. In those cases, it is highly recommended that you set
+     *  the setRealPage() to point at the real page you are rendering.  Please see InsertPageTag for an example.
      *  <p>
-     *  Also, if your plugin e.g. does some variable setting, be aware that if it
-     *  is embedded in the LeftMenu or some other page added with InsertPageTag,
-     *  you should consider what you want to do - do you wish to really reference
-     *  the "master" page or the included page.
+     *  Also, if your plugin e.g. does some variable setting, be aware that if it is embedded in the LeftMenu or some other page added
+     *  with InsertPageTag, you should consider what you want to do - do you wish to really reference the "master" page or the included
+     *  page.
      *
      *  @param page  The real page which is being rendered.
      *  @return The previous real page
      *  @since 2.3.14
      *  @see org.apache.wiki.tags.InsertPageTag
      */
-    public WikiPage setRealPage( WikiPage page )
-    {
-        WikiPage old = m_realPage;
+    public WikiPage setRealPage( final WikiPage page ) {
+        final WikiPage old = m_realPage;
         m_realPage = page;
         updateCommand( m_command.getRequestContext() );
         return old;
     }
 
     /**
-     *  Gets a reference to the real page whose content is currently being rendered.
-     *  If your plugin e.g. does some variable setting, be aware that if it
-     *  is embedded in the LeftMenu or some other page added with InsertPageTag,
-     *  you should consider what you want to do - do you wish to really reference
-     *  the "master" page or the included page.
+     *  Gets a reference to the real page whose content is currently being rendered. If your plugin e.g. does some variable setting, be
+     *  aware that if it is embedded in the LeftMenu or some other page added with InsertPageTag, you should consider what you want to
+     *  do - do you wish to really reference the "master" page or the included page.
      *  <p>
-     *  For example, in the default template, there is a page called "LeftMenu".
-     *  Whenever you access a page, e.g. "Main", the master page will be Main, and
-     *  that's what the getPage() will return - regardless of whether your plugin
-     *  resides on the LeftMenu or on the Main page.  However, getRealPage()
-     *  will return "LeftMenu".
+     *  For example, in the default template, there is a page called "LeftMenu". Whenever you access a page, e.g. "Main", the master
+     *  page will be Main, and that's what the getPage() will return - regardless of whether your plugin resides on the LeftMenu or on
+     *  the Main page.  However, getRealPage() will return "LeftMenu".
      *
      *  @return A reference to the real page.
      *  @see org.apache.wiki.tags.InsertPageTag
@@ -322,29 +297,19 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  Figure out to which page we are really going to.  Considers
-     *  special page names from the jspwiki.properties, and possible aliases.
-     *  This method forwards requests to
-     *  {@link org.apache.wiki.ui.CommandResolver#getSpecialPageReference(String)}.
+     *  Figure out to which page we are really going to.  Considers special page names from the jspwiki.properties, and possible aliases.
+     *  This method forwards requests to {@link org.apache.wiki.ui.CommandResolver#getSpecialPageReference(String)}.
      *  @return A complete URL to the new page to redirect to
      *  @since 2.2
      */
-
-    public String getRedirectURL()
-    {
-        String pagename = m_page.getName();
+    public String getRedirectURL() {
+        final String pagename = m_page.getName();
         String redirURL = m_engine.getCommandResolver().getSpecialPageReference( pagename );
-
-        if( redirURL == null )
-        {
-            String alias = m_page.getAttribute( WikiPage.ALIAS );
-
-            if( alias != null )
-            {
+        if( redirURL == null ) {
+            final String alias = m_page.getAttribute( WikiPage.ALIAS );
+            if( alias != null ) {
                 redirURL = getViewURL( alias );
-            }
-            else
-            {
+            } else {
                 redirURL = m_page.getAttribute( WikiPage.REDIRECT );
             }
         }
@@ -378,14 +343,14 @@ public class WikiContext implements Cloneable, Command {
      *  @param page The wikipage
      *  @since 2.1.37.
      */
-    public void setPage( WikiPage page )
-    {
+    public void setPage( final WikiPage page ) {
         m_page = page;
         updateCommand( m_command.getRequestContext() );
     }
 
     /**
      *  Returns the request context.
+     *
      *  @return The name of the request context (e.g. VIEW).
      */
     @Override
@@ -395,12 +360,11 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  Sets the request context.  See above for the different
-     *  request contexts (VIEW, EDIT, etc.)
+     *  Sets the request context.  See above for the different request contexts (VIEW, EDIT, etc.)
      *
      *  @param arg The request context (one of the predefined contexts.)
      */
-    public void setRequestContext( String arg )
+    public void setRequestContext( final String arg )
     {
         updateCommand( arg );
     }
@@ -431,36 +395,33 @@ public class WikiContext implements Cloneable, Command {
      *  @param key The variable name.
      *  @return The variable contents.
      */
-    public Object getVariable( String key )
+    public Object getVariable( final String key )
     {
         return m_variableMap.get( key );
     }
 
     /**
-     *  Sets a variable.  The variable is valid while the WikiContext is valid,
-     *  i.e. while page processing continues.  The variable data is discarded
-     *  once the page processing is finished.
+     *  Sets a variable.  The variable is valid while the WikiContext is valid, i.e. while page processing continues.  The variable data
+     *  is discarded once the page processing is finished.
      *
      *  @param key The variable name.
      *  @param data The variable value.
      */
-    public void setVariable( String key, Object data )
-    {
+    public void setVariable( final String key, final Object data ) {
         m_variableMap.put( key, data );
         updateCommand( m_command.getRequestContext() );
     }
 
     /**
-     * This is just a simple helper method which will first check the context
-     * if there is already an override in place, and if there is not,
+     * This is just a simple helper method which will first check the context if there is already an override in place, and if there is not,
      * it will then check the given properties.
      *
-     * @param key      What key are we searching for?
+     * @param key What key are we searching for?
      * @param defValue Default value for the boolean
-     * @return  {@code true} or {@code false}.
+     * @return {@code true} or {@code false}.
      */
     public boolean getBooleanWikiProperty( final String key, final boolean defValue ) {
-        Object bool = getVariable( key );
+        final Object bool = getVariable( key );
         if( bool != null ) {
             return TextUtil.isPositive( (String) bool );
         }
@@ -469,22 +430,17 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  This method will safely return any HTTP parameters that
-     *  might have been defined.  You should use this method instead
-     *  of peeking directly into the result of getHttpRequest(), since
-     *  this method is smart enough to do all of the right things,
+     *  This method will safely return any HTTP parameters that might have been defined.  You should use this method instead
+     *  of peeking directly into the result of getHttpRequest(), since this method is smart enough to do all of the right things,
      *  figure out UTF-8 encoded parameters, etc.
      *
      *  @since 2.0.13.
      *  @param paramName Parameter name to look for.
      *  @return HTTP parameter, or null, if no such parameter existed.
      */
-    public String getHttpParameter( String paramName )
-    {
+    public String getHttpParameter( final String paramName ) {
         String result = null;
-
-        if( m_request != null )
-        {
+        if( m_request != null ) {
             result = m_request.getParameter( paramName );
         }
 
@@ -492,10 +448,8 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  If the request did originate from a HTTP request,
-     *  then the HTTP request can be fetched here.  However, it the request
-     *  did NOT originate from a HTTP request, then this method will
-     *  return null, and YOU SHOULD CHECK FOR IT!
+     *  If the request did originate from a HTTP request, then the HTTP request can be fetched here.  However, it the request
+     *  did NOT originate from a HTTP request, then this method will return null, and YOU SHOULD CHECK FOR IT!
      *
      *  @return Null, if no HTTP request was done.
      *  @since 2.0.13.
@@ -511,29 +465,25 @@ public class WikiContext implements Cloneable, Command {
      *  @param dir The template name
      *  @since 2.1.15.
      */
-    public void setTemplate( String dir )
+    public void setTemplate( final String dir )
     {
         m_template = dir;
     }
 
     /**
-     * Returns the target of this wiki context: a page, group name or JSP. If
-     * the associated Command is a PageCommand, this method returns the page's
-     * name. Otherwise, this method delegates to the associated Command's
-     * {@link org.apache.wiki.ui.Command#getName()} method. Calling classes
-     * can rely on the results of this method for looking up canonically-correct
-     * page or group names. Because it does not automatically assume that the
-     * wiki context is a PageCommand, calling this method is inherently safer
-     * than calling <code>getPage().getName()</code>.
+     * Returns the target of this wiki context: a page, group name or JSP. If the associated Command is a PageCommand, this method
+     * returns the page's name. Otherwise, this method delegates to the associated Command's {@link org.apache.wiki.ui.Command#getName()}
+     * method. Calling classes can rely on the results of this method for looking up canonically-correct page or group names. Because it
+     * does not automatically assume that the wiki context is a PageCommand, calling this method is inherently safer than calling
+     * {@code getPage().getName()}.
+     *
      * @return the name of the target of this wiki context
      * @see org.apache.wiki.ui.PageCommand#getName()
      * @see org.apache.wiki.ui.GroupCommand#getName()
      */
     @Override
-	public String getName()
-    {
-        if ( m_command instanceof PageCommand )
-        {
+	public String getName() {
+        if ( m_command instanceof PageCommand ) {
             return m_page != null ? m_page.getName() : "<no page>";
         }
         return m_command.getName();
@@ -541,6 +491,7 @@ public class WikiContext implements Cloneable, Command {
 
     /**
      *  Gets the template that is to be used throughout this request.
+     *
      *  @since 2.1.15.
      *  @return template name
      */
@@ -550,18 +501,14 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  Convenience method that gets the current user. Delegates the
-     *  lookup to the WikiSession associated with this WikiContect.
-     *  May return null, in case the current
-     *  user has not yet been determined; or this is an internal system.
-     *  If the WikiSession has not been set, <em>always</em> returns null.
+     *  Convenience method that gets the current user. Delegates the lookup to the WikiSession associated with this WikiContect.
+     *  May return null, in case the current user has not yet been determined; or this is an internal system. If the WikiSession has not
+     *  been set, <em>always</em> returns null.
      *
      *  @return The current user; or maybe null in case of internal calls.
      */
-    public Principal getCurrentUser()
-    {
-        if (m_session == null)
-        {
+    public Principal getCurrentUser() {
+        if (m_session == null) {
             // This shouldn't happen, really...
             return WikiPrincipal.GUEST;
         }
@@ -574,7 +521,7 @@ public class WikiContext implements Cloneable, Command {
      *  @param page The page to which to link.
      *  @return An URL to the page.  This honours the current absolute/relative setting.
      */
-    public String getViewURL( String page )
+    public String getViewURL( final String page )
     {
         return getURL( VIEW, page, null );
     }
@@ -591,13 +538,12 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  Returns an URL from a page. It this WikiContext instance was constructed
-     *  with an actual HttpServletRequest, we will attempt to construct the
-     *  URL using HttpUtil, which preserves the HTTPS portion if it was used.
+     *  Returns an URL from a page. It this WikiContext instance was constructed with an actual HttpServletRequest, we will attempt to
+     *  construct the URL using HttpUtil, which preserves the HTTPS portion if it was used.
      *
      *  @param context The request context (e.g. WikiContext.UPLOAD)
-     *  @param page    The page to which to link
-     *  @param params  A list of parameters, separated with "&amp;"
+     *  @param page The page to which to link
+     *  @param params A list of parameters, separated with "&amp;"
      *
      *  @return An URL to the given context and page.
      */
@@ -610,6 +556,7 @@ public class WikiContext implements Cloneable, Command {
 
     /**
      * Returns the Command associated with this WikiContext.
+     *
      * @return the command
      */
     public Command getCommand()
@@ -628,7 +575,7 @@ public class WikiContext implements Cloneable, Command {
         try {
             // super.clone() must always be called to make sure that inherited objects
             // get the right type
-            WikiContext copy = (WikiContext)super.clone();
+            final WikiContext copy = (WikiContext)super.clone();
 
             copy.m_engine = m_engine;
             copy.m_command = m_command;
@@ -640,26 +587,24 @@ public class WikiContext implements Cloneable, Command {
             copy.m_page        = m_page;
             copy.m_realPage    = m_realPage;
             return copy;
-        } catch( CloneNotSupportedException e ){} // Never happens
+        } catch( final CloneNotSupportedException e ){} // Never happens
 
         return null;
     }
 
     /**
-     *  Creates a deep clone of the WikiContext.  This is useful when you want
-     *  to be sure that you don't accidentally mess with page attributes, etc.
+     *  Creates a deep clone of the WikiContext.  This is useful when you want to be sure that you don't accidentally mess with page
+     *  attributes, etc.
      *
      *  @since  2.8.0
      *  @return A deep clone of the WikiContext.
      */
     @SuppressWarnings("unchecked")
-    public WikiContext deepClone()
-    {
-        try
-        {
+    public WikiContext deepClone() {
+        try {
             // super.clone() must always be called to make sure that inherited objects
             // get the right type
-            WikiContext copy = (WikiContext)super.clone();
+            final WikiContext copy = (WikiContext)super.clone();
 
             //  No need to deep clone these
             copy.m_engine  = m_engine;
@@ -673,16 +618,14 @@ public class WikiContext implements Cloneable, Command {
             copy.m_realPage    = (WikiPage)m_realPage.clone();
             return copy;
         }
-        catch( CloneNotSupportedException e ){} // Never happens
+        catch( final CloneNotSupportedException e ){} // Never happens
 
         return null;
     }
 
     /**
-     *  Returns the WikiSession associated with the context.
-     *  This method is guaranteed to always return a valid WikiSession.
-     *  If this context was constructed without an associated
-     *  HttpServletRequest, it will return {@link WikiSession#guestSession(WikiEngine)}.
+     *  Returns the WikiSession associated with the context. This method is guaranteed to always return a valid WikiSession.
+     *  If this context was constructed without an associated HttpServletRequest, it will return {@link WikiSession#guestSession(WikiEngine)}.
      *
      *  @return The WikiSession associate with this context.
      */
@@ -692,49 +635,37 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     *  This method can be used to find the WikiContext programmatically
-     *  from a JSP PageContext. We check the request context.
-     *  The wiki context, if it exists,
-     *  is looked up using the key
-     *  {@link org.apache.wiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     *  This method can be used to find the WikiContext programmatically from a JSP PageContext. We check the request context.
+     *  The wiki context, if it exists, is looked up using the key {@link org.apache.wiki.tags.WikiTagBase#ATTR_CONTEXT}.
      *
      *  @since 2.4
      *  @param pageContext the JSP page context
      *  @return Current WikiContext, or null, of no context exists.
      */
-    public static WikiContext findContext( PageContext pageContext )
-    {
-        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
-        WikiContext context = (WikiContext)request.getAttribute( WikiTagBase.ATTR_CONTEXT );
-        return context;
+    public static WikiContext findContext( final PageContext pageContext ) {
+        final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
+        return (WikiContext)request.getAttribute( WikiTagBase.ATTR_CONTEXT );
     }
 
     /**
-     * Returns the permission required to successfully execute this context.
-     * For example, the a wiki context of VIEW for a certain page means that
-     * the PagePermission "view" is required for the page. In some cases, no
-     * particular permission is required, in which case a dummy permission will
-     * be returned ({@link java.util.PropertyPermission}<code> "os.name",
-     * "read"</code>). This method is guaranteed to always return a valid,
-     * non-null permission.
+     * Returns the permission required to successfully execute this context. For example, the a wiki context of VIEW for a certain page
+     * means that the PagePermission "view" is required for the page. In some cases, no particular permission is required, in which case
+     * a dummy permission will be returned ({@link java.util.PropertyPermission}<code> "os.name", "read"</code>). This method is guaranteed
+     * to always return a valid, non-null permission.
+     *
      * @return the permission
      * @since 2.4
      */
     @Override
-	public Permission requiredPermission()
-    {
+	public Permission requiredPermission() {
         // This is a filthy rotten hack -- absolutely putrid
-        if ( WikiCommand.INSTALL.equals( m_command ) )
-        {
+        if ( WikiCommand.INSTALL.equals( m_command ) ) {
             // See if admin users exists
-            try
-            {
-                UserManager userMgr = m_engine.getUserManager();
-                UserDatabase userDb = userMgr.getUserDatabase();
+            try {
+                final UserManager userMgr = m_engine.getUserManager();
+                final UserDatabase userDb = userMgr.getUserDatabase();
                 userDb.findByLoginName( Installer.ADMIN_ID );
-            }
-            catch ( NoSuchPrincipalException e )
-            {
+            } catch ( final NoSuchPrincipalException e ) {
                 return DUMMY_PERMISSION;
             }
             return new AllPermission( m_engine.getApplicationName() );
@@ -742,8 +673,7 @@ public class WikiContext implements Cloneable, Command {
 
         // TODO: we should really break the contract so that this
         // method returns null, but until then we will use this hack
-        if ( m_command.requiredPermission() == null )
-        {
+        if( m_command.requiredPermission() == null ) {
             return DUMMY_PERMISSION;
         }
 
@@ -751,116 +681,100 @@ public class WikiContext implements Cloneable, Command {
     }
 
     /**
-     * Associates a target with the current Command and returns
-     * the new targeted Command. If the Command associated with this
+     * Associates a target with the current Command and returns the new targeted Command. If the Command associated with this
      * WikiContext is already "targeted", it is returned instead.
+     *
      * @see org.apache.wiki.ui.Command#targetedCommand(java.lang.Object)
      *
      * {@inheritDoc}
      */
     @Override
-	public Command targetedCommand( Object target )
-    {
-        if ( m_command.getTarget() == null )
-        {
+	public Command targetedCommand( final Object target ) {
+        if ( m_command.getTarget() == null ) {
             return m_command.targetedCommand( target );
         }
         return m_command;
     }
 
     /**
-     *  Returns true, if the current user has administrative permissions (i.e. the omnipotent
-     *  AllPermission).
+     *  Returns true, if the current user has administrative permissions (i.e. the omnipotent AllPermission).
      *
      *  @since 2.4.46
      *  @return true, if the user has all permissions.
      */
     public boolean hasAdminPermissions() {
-        return m_engine.getAuthorizationManager().checkPermission( getWikiSession(), new AllPermission(m_engine.getApplicationName()) );
+        return m_engine.getAuthorizationManager().checkPermission( getWikiSession(), new AllPermission( m_engine.getApplicationName() ) );
     }
 
     /**
      * Figures out which template a new WikiContext should be using.
      * @param request the HTTP request
      */
-    protected void setDefaultTemplate( HttpServletRequest request )
-    {
-        String defaultTemplate = m_engine.getTemplateDir();
+    protected void setDefaultTemplate( final HttpServletRequest request ) {
+        final String defaultTemplate = m_engine.getTemplateDir();
 
         //  Figure out which template we should be using for this page.
         String template = null;
-        if ( request != null )
-        {
+        if ( request != null ) {
             template = request.getParameter( "skin" );
 
-            if( template != null ) template = template.replaceAll("\\p{Punct}", "");
+            if( template != null ) {
+                template = template.replaceAll("\\p{Punct}", "");
+            }
         }
 
         // If request doesn't supply the value, extract from wiki page
-        if( template == null )
-        {
-            WikiPage page = getPage();
-            if ( page != null )
-            {
+        if( template == null ) {
+            final WikiPage page = getPage();
+            if ( page != null ) {
                 template = page.getAttribute( WikiEngine.PROP_TEMPLATEDIR );
             }
 
         }
 
         // If something over-wrote the default, set the new value.
-        if ( template != null )
-        {
+        if ( template != null ) {
             setTemplate( template );
-        }
-        else
-        {
+        } else {
             setTemplate( defaultTemplate );
         }
     }
 
     /**
-     * Looks up and returns a PageCommand based on a supplied WikiPage and HTTP
-     * request. First, the appropriate Command is obtained by examining the HTTP
-     * request; the default is {@link PageCommand#VIEW}. If the Command is a
-     * PageCommand (and it should be, in most cases), a targeted Command is
-     * created using the (non-<code>null</code>) WikiPage as target.
+     * Looks up and returns a PageCommand based on a supplied WikiPage and HTTP request. First, the appropriate Command is obtained by
+     * examining the HTTP request; the default is {@link PageCommand#VIEW}. If the Command is a PageCommand (and it should be, in most
+     * cases), a targeted Command is created using the (non-<code>null</code>) WikiPage as target.
+     *
      * @param engine the wiki engine
      * @param request the HTTP request
      * @param page the wiki page
      * @return the correct command
      */
-    protected static Command findCommand( WikiEngine engine, HttpServletRequest request, WikiPage page )
-    {
-        String defaultContext = PageCommand.VIEW.getRequestContext();
+    protected static Command findCommand( final WikiEngine engine, final HttpServletRequest request, final WikiPage page ) {
+        final String defaultContext = PageCommand.VIEW.getRequestContext();
         Command command = engine.getCommandResolver().findCommand( request, defaultContext );
-        if ( command instanceof PageCommand && page != null )
-        {
+        if ( command instanceof PageCommand && page != null ) {
             command = command.targetedCommand( page );
         }
         return command;
     }
 
     /**
-     * Protected method that updates the internally cached Command.
-     * Will always be called when the page name, request context, or variable
+     * Protected method that updates the internally cached Command. Will always be called when the page name, request context, or variable
      * changes.
+     *
      * @param requestContext the desired request context
      * @since 2.4
      */
-    protected void updateCommand( String requestContext )
-    {
-        if ( requestContext == null )
-        {
+    protected void updateCommand( final String requestContext ) {
+        if ( requestContext == null ) {
             m_command = PageCommand.NONE;
-        }
-        else
-        {
-            CommandResolver resolver = m_engine.getCommandResolver();
+        } else {
+            final CommandResolver resolver = m_engine.getCommandResolver();
             m_command = resolver.findCommand( m_request, requestContext );
         }
 
-        if ( m_command instanceof PageCommand && m_page != null )
-        {
+        if ( m_command instanceof PageCommand && m_page != null ) {
             m_command = m_command.targetedCommand( m_page );
         }
     }


[jspwiki] 02/03: move ATTR_CONTEXT constant from WikiTagBase to WikiContext

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit c95693f092fa329e40e9e9ccd734bc71bcff4fc0
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Jan 10 00:30:06 2020 +0100

    move ATTR_CONTEXT constant from WikiTagBase to WikiContext
---
 .../src/main/java/org/apache/wiki/WikiContext.java |   7 +-
 .../org/apache/wiki/auth/AuthorizationManager.java |  38 +++-----
 .../apache/wiki/tags/AttachmentsIteratorTag.java   |   6 +-
 .../org/apache/wiki/tags/HistoryIteratorTag.java   |   6 +-
 .../java/org/apache/wiki/tags/IteratorTag.java     |  19 ++--
 .../apache/wiki/tags/SearchResultIteratorTag.java  |  39 +++-----
 .../java/org/apache/wiki/tags/TranslateTag.java    |  43 +++------
 .../java/org/apache/wiki/tags/WikiBodyTag.java     |  29 ++----
 .../java/org/apache/wiki/tags/WikiTagBase.java     |   4 +-
 .../java/org/apache/wiki/ui/WikiJSPFilter.java     |  11 ++-
 .../java/org/apache/wiki/ui/WikiServletFilter.java | 102 +++++++--------------
 11 files changed, 113 insertions(+), 191 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
index f4a97d5..4f4f42c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
@@ -24,7 +24,6 @@ import org.apache.wiki.auth.UserManager;
 import org.apache.wiki.auth.WikiPrincipal;
 import org.apache.wiki.auth.permissions.AllPermission;
 import org.apache.wiki.auth.user.UserDatabase;
-import org.apache.wiki.tags.WikiTagBase;
 import org.apache.wiki.ui.Command;
 import org.apache.wiki.ui.CommandResolver;
 import org.apache.wiki.ui.GroupCommand;
@@ -70,6 +69,8 @@ public class WikiContext implements Cloneable, Command {
 
     private WikiSession m_session;
 
+    public static final String ATTR_CONTEXT = "jspwiki.context";
+
     /** User is administering JSPWiki (Install, SecurityConfig). */
     public static final String INSTALL = WikiCommand.INSTALL.getRequestContext();
 
@@ -636,7 +637,7 @@ public class WikiContext implements Cloneable, Command {
 
     /**
      *  This method can be used to find the WikiContext programmatically from a JSP PageContext. We check the request context.
-     *  The wiki context, if it exists, is looked up using the key {@link org.apache.wiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     *  The wiki context, if it exists, is looked up using the key {@link #ATTR_CONTEXT}.
      *
      *  @since 2.4
      *  @param pageContext the JSP page context
@@ -644,7 +645,7 @@ public class WikiContext implements Cloneable, Command {
      */
     public static WikiContext findContext( final PageContext pageContext ) {
         final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
-        return (WikiContext)request.getAttribute( WikiTagBase.ATTR_CONTEXT );
+        return (WikiContext)request.getAttribute( ATTR_CONTEXT );
     }
 
     /**
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/AuthorizationManager.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/AuthorizationManager.java
index e1acca7..040046d 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/auth/AuthorizationManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/AuthorizationManager.java
@@ -39,7 +39,6 @@ import org.apache.wiki.event.WikiEventManager;
 import org.apache.wiki.event.WikiSecurityEvent;
 import org.apache.wiki.i18n.InternationalizationManager;
 import org.apache.wiki.preferences.Preferences;
-import org.apache.wiki.tags.WikiTagBase;
 import org.apache.wiki.util.ClassUtil;
 import org.freshcookies.security.policy.LocalPolicy;
 
@@ -383,7 +382,7 @@ public class AuthorizationManager {
      * If the user is allowed, this method returns <code>true</code>;
      * <code>false</code> otherwise. If access is allowed,
      * the wiki context will be added to the request as an attribute
-     * with the key name {@link org.apache.wiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     * with the key name {@link org.apache.wiki.WikiContext#ATTR_CONTEXT}.
      * Note that this method will automatically redirect the user to
      * a login or error page, as appropriate, if access fails. This is
      * NOT guaranteed to be default behavior in the future.
@@ -404,7 +403,7 @@ public class AuthorizationManager {
      * and delegating the access check to {@link #checkPermission(WikiSession, Permission)}.
      * If the user is allowed, this method returns <code>true</code>;
      * <code>false</code> otherwise. Also, the wiki context will be added to the request as attribute
-     * with the key name {@link org.apache.wiki.tags.WikiTagBase#ATTR_CONTEXT}.
+     * with the key name {@link org.apache.wiki.WikiContext#ATTR_CONTEXT}.
      *
      * @param context wiki context to check if it is accesible
      * @param response The servlet response object
@@ -412,33 +411,26 @@ public class AuthorizationManager {
      * @return the result of the access check
      * @throws IOException If something goes wrong
      */
-    public boolean hasAccess( WikiContext context, HttpServletResponse response, boolean redirect ) throws IOException
-    {
-        boolean allowed = checkPermission( context.getWikiSession(), context.requiredPermission() );
-        ResourceBundle rb = Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE );
+    public boolean hasAccess( final WikiContext context, final HttpServletResponse response, final boolean redirect ) throws IOException {
+        final boolean allowed = checkPermission( context.getWikiSession(), context.requiredPermission() );
+        final ResourceBundle rb = Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE );
 
         // Stash the wiki context
-        if ( context.getHttpRequest() != null && context.getHttpRequest().getAttribute( WikiTagBase.ATTR_CONTEXT ) == null )
-        {
-            context.getHttpRequest().setAttribute( WikiTagBase.ATTR_CONTEXT, context );
+        if ( context.getHttpRequest() != null && context.getHttpRequest().getAttribute( WikiContext.ATTR_CONTEXT ) == null ) {
+            context.getHttpRequest().setAttribute( WikiContext.ATTR_CONTEXT, context );
         }
 
         // If access not allowed, redirect
-        if( !allowed && redirect )
-        {
-            Principal currentUser  = context.getWikiSession().getUserPrincipal();
-            String pageurl = context.getPage().getName();
-            if( context.getWikiSession().isAuthenticated() )
-            {
+        if( !allowed && redirect ) {
+            final Principal currentUser  = context.getWikiSession().getUserPrincipal();
+            final String pageurl = context.getPage().getName();
+            if( context.getWikiSession().isAuthenticated() ) {
                 log.info("User "+currentUser.getName()+" has no access - forbidden (permission=" + context.requiredPermission() + ")" );
-                context.getWikiSession().addMessage(
-                               MessageFormat.format( rb.getString("security.error.noaccess.logged"), context.getName()) );
-            }
-            else
-            {
+                context.getWikiSession().addMessage( MessageFormat.format( rb.getString( "security.error.noaccess.logged" ),
+                                                     context.getName()) );
+            } else {
                 log.info("User "+currentUser.getName()+" has no access - redirecting (permission=" + context.requiredPermission() + ")");
-                context.getWikiSession().addMessage(
-                               MessageFormat.format( rb.getString("security.error.noaccess"), context.getName()) );
+                context.getWikiSession().addMessage( MessageFormat.format( rb.getString("security.error.noaccess"), context.getName() ) );
             }
             response.sendRedirect( m_engine.getURL(WikiContext.LOGIN, pageurl, null, false ) );
         }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java
index 232e4ca..41f1c67 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/AttachmentsIteratorTag.java
@@ -53,7 +53,7 @@ public class AttachmentsIteratorTag extends IteratorTag {
      */
     @Override
     public final int doStartTag()  {
-        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
         final WikiEngine engine = m_wikiContext.getEngine();
         final AttachmentManager mgr = engine.getAttachmentManager();
         final WikiPage page;
@@ -81,7 +81,7 @@ public class AttachmentsIteratorTag extends IteratorTag {
                     final Attachment  att = (Attachment) m_iterator.next();
                     final WikiContext context = (WikiContext)m_wikiContext.clone();
                     context.setPage( att );
-                    pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
+                    pageContext.setAttribute( WikiContext.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
                     pageContext.setAttribute( getId(), att );
                 } else {
                     return SKIP_BODY;
@@ -119,7 +119,7 @@ public class AttachmentsIteratorTag extends IteratorTag {
             final Attachment att = ( Attachment )m_iterator.next();
             final WikiContext context = ( WikiContext )m_wikiContext.clone();
             context.setPage( att );
-            pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT,  context, PageContext.REQUEST_SCOPE );
+            pageContext.setAttribute( WikiContext.ATTR_CONTEXT,  context, PageContext.REQUEST_SCOPE );
             pageContext.setAttribute( getId(), att );
 
             return EVAL_BODY_BUFFERED;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java
index 5134cfa..6686c54 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/HistoryIteratorTag.java
@@ -47,7 +47,7 @@ public class HistoryIteratorTag extends IteratorTag  {
 
     @Override
     public final int doStartTag() {
-        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
         final WikiEngine engine = m_wikiContext.getEngine();
         final WikiPage page = m_wikiContext.getPage();
 
@@ -65,7 +65,7 @@ public class HistoryIteratorTag extends IteratorTag  {
                 if( m_iterator.hasNext() ) {
                     final WikiContext context = ( WikiContext )m_wikiContext.clone();
                     context.setPage( ( WikiPage )m_iterator.next() );
-                    pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
+                    pageContext.setAttribute( WikiContext.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
                     pageContext.setAttribute( getId(), context.getPage() );
                 } else {
                     return SKIP_BODY;
@@ -97,7 +97,7 @@ public class HistoryIteratorTag extends IteratorTag  {
         if( m_iterator != null && m_iterator.hasNext() ) {
             final WikiContext context = ( WikiContext )m_wikiContext.clone();
             context.setPage( ( WikiPage )m_iterator.next() );
-            pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
+            pageContext.setAttribute( WikiContext.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
             pageContext.setAttribute( getId(), context.getPage() );
             return EVAL_BODY_BUFFERED;
         }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/IteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/IteratorTag.java
index e04470d..78a1a46 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/IteratorTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/IteratorTag.java
@@ -18,19 +18,18 @@
  */
 package org.apache.wiki.tags;
 
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
+import org.apache.log4j.Logger;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.WikiPage;
 
 import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.BodyTagSupport;
 import javax.servlet.jsp.tagext.TryCatchFinally;
-
-import org.apache.log4j.Logger;
-import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiPage;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
 
 
 /**
@@ -130,7 +129,7 @@ public abstract class IteratorTag extends BodyTagSupport implements TryCatchFina
         //
         //  Push it to the iterator stack, and set the id.
         //
-        pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
+        pageContext.setAttribute( WikiContext.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
         pageContext.setAttribute( getId(), o );
     }
 
@@ -141,7 +140,7 @@ public abstract class IteratorTag extends BodyTagSupport implements TryCatchFina
     public int doEndTag()
     {
         // Return back to the original.
-        pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, m_wikiContext, PageContext.REQUEST_SCOPE );
+        pageContext.setAttribute( WikiContext.ATTR_CONTEXT, m_wikiContext, PageContext.REQUEST_SCOPE );
 
         return EVAL_PAGE;
     }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/SearchResultIteratorTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/SearchResultIteratorTag.java
index 0eb68eb..f3f8ed2 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/SearchResultIteratorTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/SearchResultIteratorTag.java
@@ -18,13 +18,6 @@
  */
 package org.apache.wiki.tags;
 
-import java.io.IOException;
-import java.util.Collection;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.PageContext;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -32,6 +25,12 @@ import org.apache.wiki.search.SearchResult;
 import org.apache.wiki.ui.Command;
 import org.apache.wiki.ui.PageCommand;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import java.io.IOException;
+import java.util.Collection;
+
 /**
  *  Iterates through Search result results.
  *
@@ -89,7 +88,7 @@ public class SearchResultIteratorTag
         }
 
         m_count = 0;
-        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+        m_wikiContext = (WikiContext) pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
 
         return nextResult();
     }
@@ -107,9 +106,7 @@ public class SearchResultIteratorTag
             WikiContext context = new WikiContext( engine, request, command );
             
             // Stash it in the page context
-            pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT,
-                                      context,
-                                      PageContext.REQUEST_SCOPE );
+            pageContext.setAttribute( WikiContext.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE );
             pageContext.setAttribute( getId(), r );
 
             return EVAL_BODY_BUFFERED;
@@ -118,18 +115,13 @@ public class SearchResultIteratorTag
         return SKIP_BODY;
     }
 
-    public int doAfterBody()
-    {
-        if( bodyContent != null )
-        {
-            try
-            {
-                JspWriter out = getPreviousOut();
+    public int doAfterBody() {
+        if( bodyContent != null ) {
+            try {
+                final JspWriter out = getPreviousOut();
                 out.print(bodyContent.getString());
                 bodyContent.clearBody();
-            }
-            catch( IOException e )
-            {
+            } catch( final IOException e ) {
                 log.error("Unable to get inner tag text", e);
                 // FIXME: throw something?
             }
@@ -138,10 +130,9 @@ public class SearchResultIteratorTag
         return nextResult();
     }
 
-    public int doEndTag()
-    {
+    public int doEndTag() {
         m_iterator = null;
-
         return super.doEndTag();
     }
+
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/TranslateTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/TranslateTag.java
index d838d1b..f6cbd0c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/TranslateTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/TranslateTag.java
@@ -18,15 +18,14 @@
  */
 package org.apache.wiki.tags;
 
+import org.apache.log4j.Logger;
+import org.apache.wiki.WikiContext;
+
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.BodyContent;
 import javax.servlet.jsp.tagext.BodyTagSupport;
 
-import org.apache.wiki.WikiContext;
-
-import org.apache.log4j.Logger;
-
 /**
  *  Converts the body text into HTML content.
  *
@@ -37,45 +36,31 @@ public class TranslateTag
 {
     private static final long serialVersionUID = 0L;
     
-    static    Logger    log = Logger.getLogger( TranslateTag.class );
+    private static final Logger log = Logger.getLogger( TranslateTag.class );
 
-    public final int doAfterBody()
-        throws JspException
-    {
-        try
-        {
-            WikiContext context = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT,
-                                                                          PageContext.REQUEST_SCOPE );
+    public final int doAfterBody() throws JspException {
+        try {
+            WikiContext context = (WikiContext) pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
 
-            //
-            //  Because the TranslateTag should not affect any of the real page attributes
-            //  we have to make a clone here.
-            //
-            
+            //  Because the TranslateTag should not affect any of the real page attributes we have to make a clone here.
             context = context.deepClone();
             
-            //
             //  Get the page data.
-            //
-            BodyContent bc = getBodyContent();
+            final BodyContent bc = getBodyContent();
             String wikiText = bc.getString();
             bc.clearBody();
 
-            if( wikiText != null )
-            {
+            if( wikiText != null ) {
                 wikiText = wikiText.trim();
-            
-                String result = context.getEngine().textToHTML( context, wikiText );
-
+                final String result = context.getEngine().textToHTML( context, wikiText );
                 getPreviousOut().write( result );
             }
-        }
-        catch( Exception e )
-        {
+        } catch( final Exception e ) {
             log.error( "Tag failed", e );
-            throw new JspException( "Tag failed, check logs: "+e.getMessage() );
+            throw new JspException( "Tag failed, check logs: " + e.getMessage() );
         }
 
         return SKIP_BODY;
     }
+
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiBodyTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiBodyTag.java
index a73a794..fe86320 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiBodyTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiBodyTag.java
@@ -18,16 +18,14 @@
  */
 package org.apache.wiki.tags;
 
-import java.io.IOException;
+import org.apache.log4j.Logger;
+import org.apache.wiki.WikiContext;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.BodyTagSupport;
 import javax.servlet.jsp.tagext.TryCatchFinally;
-
-import org.apache.log4j.Logger;
-
-import org.apache.wiki.WikiContext;
+import java.io.IOException;
 
 
 /**
@@ -40,22 +38,15 @@ public abstract class WikiBodyTag extends BodyTagSupport implements TryCatchFina
 	protected WikiContext m_wikiContext;
     private static final Logger log = Logger.getLogger( WikiBodyTag.class );
 
-    public int doStartTag() throws JspException
-    {
-        try
-        {
-            m_wikiContext = (WikiContext) pageContext.getAttribute( WikiTagBase.ATTR_CONTEXT,
-                                                                    PageContext.REQUEST_SCOPE );
-
-            if( m_wikiContext == null )
-            {
+    public int doStartTag() throws JspException {
+        try {
+            m_wikiContext = (WikiContext) pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+            if( m_wikiContext == null ) {
                 throw new JspException("WikiContext may not be NULL - serious internal problem!");
             }
 
             return doWikiStartTag();
-        }
-        catch( Exception e )
-        {
+        } catch( final Exception e ) {
             log.error( "Tag failed", e );
             throw new JspException( "Tag failed, check logs: "+e.getMessage() );
         }
@@ -70,8 +61,7 @@ public abstract class WikiBodyTag extends BodyTagSupport implements TryCatchFina
      */
     public abstract int doWikiStartTag() throws JspException, IOException;
 
-    public void doCatch(Throwable arg0) throws Throwable
-    {
+    public void doCatch(Throwable arg0) throws Throwable {
     }
 
     public void doFinally()
@@ -79,5 +69,4 @@ public abstract class WikiBodyTag extends BodyTagSupport implements TryCatchFina
         m_wikiContext = null;
     }  
     
-    
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java
index 8d2b0be..123b2af 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/WikiTagBase.java
@@ -40,8 +40,6 @@ public abstract class WikiTagBase extends TagSupport implements TryCatchFinally
     private static final long serialVersionUID = -1409836349293777141L;
     private static final Logger log = Logger.getLogger( WikiTagBase.class );
 
-    public static final String ATTR_CONTEXT = "jspwiki.context";
-
     protected WikiContext m_wikiContext;
 
     /**
@@ -64,7 +62,7 @@ public abstract class WikiTagBase extends TagSupport implements TryCatchFinally
     
     public int doStartTag() throws JspException {
         try {
-            m_wikiContext = ( WikiContext )pageContext.getAttribute( ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+            m_wikiContext = ( WikiContext )pageContext.getAttribute( WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
             if( m_wikiContext == null ) {
                 throw new JspException("WikiContext may not be NULL - serious internal problem!");
             }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java
index 41d55c9..7dee58c 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiJSPFilter.java
@@ -19,6 +19,7 @@
 package org.apache.wiki.ui;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
 import org.apache.wiki.WatchDog;
 import org.apache.wiki.WikiContext;
@@ -75,8 +76,9 @@ import java.nio.charset.Charset;
  * @see TemplateManager
  * @see org.apache.wiki.tags.RequestResourceTag
  */
-public class WikiJSPFilter extends WikiServletFilter
-{
+public class WikiJSPFilter extends WikiServletFilter {
+
+    private static final Logger log = Logger.getLogger( WikiJSPFilter.class );
     private String m_wiki_encoding;
     private boolean useEncoding;
 
@@ -249,9 +251,8 @@ public class WikiJSPFilter extends WikiServletFilter
      *  Simple response wrapper that just allows us to gobble through the entire
      *  response before it's output.
      */
-    private static class JSPWikiServletResponseWrapper
-        extends HttpServletResponseWrapper
-    {
+    private static class JSPWikiServletResponseWrapper extends HttpServletResponseWrapper {
+
         ByteArrayOutputStream m_output;
         private ByteArrayServletOutputStream m_servletOut;
         private PrintWriter m_writer;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java
index 45a95e1..4d8e08f 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java
@@ -25,7 +25,6 @@ import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.auth.SessionMonitor;
 import org.apache.wiki.auth.WikiSecurityException;
-import org.apache.wiki.tags.WikiTagBase;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -40,23 +39,17 @@ import java.io.IOException;
 import java.io.PrintWriter;
 
 /**
- * Filter that verifies that the {@link org.apache.wiki.WikiEngine} is running, and
- * sets the authentication status for the user's WikiSession. Each HTTP request
- * processed by this filter is wrapped by a {@link WikiRequestWrapper}. The wrapper's
- * primary responsibility is to return the correct <code>userPrincipal</code> and
- * <code>remoteUser</code> for authenticated JSPWiki users (whether 
- * authenticated by container or by JSPWiki's custom system).
- * The wrapper's other responsibility is to incorporate JSPWiki built-in roles
- * into the role-checking algorithm for {@link  HttpServletRequest#isUserInRole(String)}.
- * Just before the request is wrapped, the method {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)} executes;
- * this method contains all of the logic needed to grab any user login credentials set 
- * by the container or by cookies.
- *  
- *
+ * Filter that verifies that the {@link org.apache.wiki.WikiEngine} is running, and sets the authentication status for the user's
+ * WikiSession. Each HTTP request processed by this filter is wrapped by a {@link WikiRequestWrapper}. The wrapper's primary responsibility
+ * is to return the correct <code>userPrincipal</code> and <code>remoteUser</code> for authenticated JSPWiki users (whether authenticated
+ * by container or by JSPWiki's custom system). The wrapper's other responsibility is to incorporate JSPWiki built-in roles
+ * into the role-checking algorithm for {@link  HttpServletRequest#isUserInRole(String)}. Just before the request is wrapped, the method
+ * {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)} executes; this method contains all of the logic needed to
+ * grab any user login credentials set by the container or by cookies.
  */
-public class WikiServletFilter implements Filter
-{
-    protected static final Logger log = Logger.getLogger( WikiServletFilter.class );
+public class WikiServletFilter implements Filter {
+
+    private static final Logger log = Logger.getLogger( WikiServletFilter.class );
     protected WikiEngine m_engine = null;
 
     /**
@@ -73,13 +66,11 @@ public class WikiServletFilter implements Filter
      * @param config The FilterConfig.
      * @throws ServletException If a WikiEngine cannot be started.
      */
-    public void init( FilterConfig config ) throws ServletException
-    {
-        ServletContext context = config.getServletContext();
+    public void init( final FilterConfig config ) throws ServletException {
+        final ServletContext context = config.getServletContext();
 
         // TODO REMOVEME when resolving JSPWIKI-129
-        if( System.getSecurityManager() != null )
-        {
+        if( System.getSecurityManager() != null ) {
             context.log( "== JSPWIKI WARNING ==   : This container is running with a security manager. JSPWiki does not yet really support that right now. See issue JSPWIKI-129 for details and information on how to proceed." );
         }
 
@@ -89,13 +80,11 @@ public class WikiServletFilter implements Filter
     /**
      * Destroys the WikiServletFilter.
      */
-    public void destroy()
-    {
+    public void destroy() {
     }
 
     /**
-    * Checks that the WikiEngine is running ok, wraps the current
-    * HTTP request, and sets the correct authentication state for the users's
+    * Checks that the WikiEngine is running ok, wraps the current HTTP request, and sets the correct authentication state for the users's
     * WikiSession. First, the method {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)}
     * executes, which sets the authentication state. Then, the request is wrapped with a
     * {@link WikiRequestWrapper}.
@@ -105,19 +94,14 @@ public class WikiServletFilter implements Filter
     * @throws ServletException if {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)} fails for any reason
     * @throws IOException If writing to the servlet response fails. 
     */
-    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException, ServletException
-    {
-        //
+    public void doFilter( final ServletRequest request, final ServletResponse response, final FilterChain chain ) throws IOException, ServletException {
         //  Sanity check; it might be true in some conditions, but we need to know where.
-        //
-        if( chain == null )
-        {
+        if( chain == null ) {
             throw new ServletException("FilterChain is null, even if it should not be.  Please report this to the jspwiki development team.");
         }
         
-        if( m_engine == null )
-        {
-            PrintWriter out = response.getWriter();
+        if( m_engine == null ) {
+            final PrintWriter out = response.getWriter();
             out.print("<!DOCTYPE html><html lang=\"en\"><head><title>Fatal problem with JSPWiki</title></head>");
             out.print("<body>");
             out.print("<h1>JSPWiki has not been started</h1>");
@@ -138,33 +122,24 @@ public class WikiServletFilter implements Filter
         // Set the character encoding
         httpRequest.setCharacterEncoding( m_engine.getContentEncoding().displayName() );
         
-        if ( !isWrapped( request ) )
-        {
+        if ( !isWrapped( request ) ) {
             // Prepare the WikiSession
-            try
-            {
+            try {
                 m_engine.getAuthenticationManager().login( httpRequest );
-                WikiSession wikiSession = SessionMonitor.getInstance( m_engine ).find( httpRequest.getSession() );
+                final WikiSession wikiSession = SessionMonitor.getInstance( m_engine ).find( httpRequest.getSession() );
                 httpRequest = new WikiRequestWrapper( m_engine, httpRequest );
-                if ( log.isDebugEnabled() )
-                {
+                if ( log.isDebugEnabled() ) {
                     log.debug( "Executed security filters for user=" + wikiSession.getLoginPrincipal().getName() + ", path=" + httpRequest.getRequestURI() );
                 }
-            }
-            catch ( WikiSecurityException e )
-            {
+            } catch( final WikiSecurityException e ) {
                 throw new ServletException( e );
             }
         }
 
-        try
-        {
+        try {
             NDC.push( m_engine.getApplicationName()+":"+httpRequest.getRequestURL() );
-            
             chain.doFilter( httpRequest, response );
-        }
-        finally
-        {
+        } finally {
             NDC.pop();
             NDC.remove();
         }
@@ -172,19 +147,14 @@ public class WikiServletFilter implements Filter
     }
 
     /**
-     *  Figures out the wiki context from the request.  This method does not create the
-     *  context if it does not exist.
+     *  Figures out the wiki context from the request.  This method does not create the context if it does not exist.
      *  
      *  @param request The request to examine
      *  @return A valid WikiContext value (or null, if the context could not be located).
      */
-    protected WikiContext getWikiContext( ServletRequest  request )
-    {
-        HttpServletRequest httpRequest = (HttpServletRequest) request;
-    
-        WikiContext ctx = (WikiContext) httpRequest.getAttribute( WikiTagBase.ATTR_CONTEXT );
-        
-        return ctx;
+    protected WikiContext getWikiContext( final ServletRequest request ) {
+        final HttpServletRequest httpRequest = (HttpServletRequest) request;
+        return (WikiContext) httpRequest.getAttribute( WikiContext.ATTR_CONTEXT );
     }
 
     /** 
@@ -194,15 +164,11 @@ public class WikiServletFilter implements Filter
      * @return <code>true</code> if the request has previously been wrapped;
      * <code>false</code> otherwise
      */
-    private boolean isWrapped( ServletRequest request )
-    {
-        while ( !(request instanceof WikiRequestWrapper )
-            && request != null
-            && request instanceof HttpServletRequestWrapper )
-        {
-            request = ((HttpServletRequestWrapper) request).getRequest();
+    private boolean isWrapped( ServletRequest request ) {
+        while( !(request instanceof WikiRequestWrapper ) && request != null && request instanceof HttpServletRequestWrapper ) {
+            request = ( ( HttpServletRequestWrapper ) request ).getRequest();
         }
-        return request instanceof WikiRequestWrapper ? true : false;
+        return request instanceof WikiRequestWrapper;
     }
 
 }


[jspwiki] 03/03: generate jacoco xml report instead of binary file

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 33f5b20c82e02cb9854dc9af7528eb101dc097f9
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Jan 10 00:42:38 2020 +0100

    generate jacoco xml report instead of binary file
    
    as the latter isn't supported by sonar(cloud) anymore. cfr: https://jira.sonarsource.com/browse/MMF-1651
    This should bring back coverage on sonarcloud.io instance
---
 Jenkinsfile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 3563795..71e3202 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -39,7 +39,7 @@ try {
                     withCredentials( [ string( credentialsId: 'sonarcloud-jspwiki', variable: 'SONAR_TOKEN' ) ] ) {
                         def sonarOptions = "-Dsonar.projectKey=jspwiki-builder -Dsonar.organization=apache -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN"
                         echo 'Will use SonarQube instance at https://sonarcloud.io'
-                        sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Pattach-additional-artifacts sonar:sonar -up $sonarOptions"
+                        sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent org.jacoco:jacoco-maven-plugin:report install -Pattach-additional-artifacts sonar:sonar -up $sonarOptions"
                     }
                     pom = readMavenPom file: 'pom.xml'
                     writeFile file: 'target/classes/apidocs.txt', text: 'file created in order to allow aggregated javadoc generation, target/classes is needed for all modules'