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 c38bbac156f6748b400adcbd4c0830b3010bd8fd Author: juanpablo <[email protected]> AuthorDate: Wed Mar 11 18:58:24 2020 +0100 JSPWIKI-303: WikiContext and WikiPage implement Context and Page respectively --- .../src/main/java/org/apache/wiki/WikiContext.java | 32 ++++++++++++++++++---- .../src/main/java/org/apache/wiki/WikiPage.java | 24 ++++++++++++++-- 2 files changed, 48 insertions(+), 8 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 5830adc..adf5799 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java @@ -19,7 +19,9 @@ package org.apache.wiki; import org.apache.log4j.Logger; +import org.apache.wiki.api.core.Context; import org.apache.wiki.api.core.Engine; +import org.apache.wiki.api.core.Page; import org.apache.wiki.api.core.Session; import org.apache.wiki.auth.AuthorizationManager; import org.apache.wiki.auth.NoSuchPrincipalException; @@ -57,7 +59,7 @@ import java.util.PropertyPermission; * * @see org.apache.wiki.plugin.Counter */ -public class WikiContext implements Cloneable, Command { +public class WikiContext implements Context, Command { private Command m_command; private WikiPage m_page; @@ -303,9 +305,10 @@ public class WikiContext implements Cloneable, Command { * @since 2.3.14 * @see org.apache.wiki.tags.InsertPageTag */ - public WikiPage setRealPage( final WikiPage page ) { + @Override + public WikiPage setRealPage( final Page page ) { final WikiPage old = m_realPage; - m_realPage = page; + m_realPage = ( WikiPage )page; updateCommand( m_command.getRequestContext() ); return old; } @@ -323,6 +326,7 @@ public class WikiContext implements Cloneable, Command { * @see org.apache.wiki.tags.InsertPageTag * @see org.apache.wiki.parser.JSPWikiMarkupParser */ + @Override public WikiPage getRealPage() { return m_realPage; @@ -334,6 +338,7 @@ public class WikiContext implements Cloneable, Command { * @return A complete URL to the new page to redirect to * @since 2.2 */ + @Override public String getRedirectURL() { final String pagename = m_page.getName(); String redirURL = m_engine.getManager( CommandResolver.class ).getSpecialPageReference( pagename ); @@ -354,6 +359,7 @@ public class WikiContext implements Cloneable, Command { * * @return The engine owning this context. */ + @Override public WikiEngine getEngine() { return ( WikiEngine )m_engine; } @@ -363,6 +369,7 @@ public class WikiContext implements Cloneable, Command { * * @return the page which was fetched. */ + @Override public WikiPage getPage() { return m_page; @@ -374,8 +381,9 @@ public class WikiContext implements Cloneable, Command { * @param page The wikipage * @since 2.1.37. */ - public void setPage( final WikiPage page ) { - m_page = page; + @Override + public void setPage( final Page page ) { + m_page = (WikiPage)page; updateCommand( m_command.getRequestContext() ); } @@ -395,6 +403,7 @@ public class WikiContext implements Cloneable, Command { * * @param arg The request context (one of the predefined contexts.) */ + @Override public void setRequestContext( final String arg ) { updateCommand( arg ); @@ -426,6 +435,7 @@ public class WikiContext implements Cloneable, Command { * @param key The variable name. * @return The variable contents. */ + @Override public Object getVariable( final String key ) { return m_variableMap.get( key ); @@ -438,6 +448,7 @@ public class WikiContext implements Cloneable, Command { * @param key The variable name. * @param data The variable value. */ + @Override public void setVariable( final String key, final Object data ) { m_variableMap.put( key, data ); updateCommand( m_command.getRequestContext() ); @@ -451,6 +462,7 @@ public class WikiContext implements Cloneable, Command { * @param defValue Default value for the boolean * @return {@code true} or {@code false}. */ + @Override public boolean getBooleanWikiProperty( final String key, final boolean defValue ) { final Object bool = getVariable( key ); if( bool != null ) { @@ -469,6 +481,7 @@ public class WikiContext implements Cloneable, Command { * @param paramName Parameter name to look for. * @return HTTP parameter, or null, if no such parameter existed. */ + @Override public String getHttpParameter( final String paramName ) { String result = null; if( m_request != null ) { @@ -485,6 +498,7 @@ public class WikiContext implements Cloneable, Command { * @return Null, if no HTTP request was done. * @since 2.0.13. */ + @Override public HttpServletRequest getHttpRequest() { return m_request; @@ -496,6 +510,7 @@ public class WikiContext implements Cloneable, Command { * @param dir The template name * @since 2.1.15. */ + @Override public void setTemplate( final String dir ) { m_template = dir; @@ -526,6 +541,7 @@ public class WikiContext implements Cloneable, Command { * @since 2.1.15. * @return template name */ + @Override public String getTemplate() { return m_template; @@ -538,6 +554,7 @@ public class WikiContext implements Cloneable, Command { * * @return The current user; or maybe null in case of internal calls. */ + @Override public Principal getCurrentUser() { if (m_session == null) { // This shouldn't happen, really... @@ -552,6 +569,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. */ + @Override public String getViewURL( final String page ) { return getURL( VIEW, page, null ); } @@ -563,6 +581,7 @@ public class WikiContext implements Cloneable, Command { * @param page The page to which to link * @return An URL to the page, honours the absolute/relative setting in jspwiki.properties */ + @Override public String getURL( final String context, final String page ) { return getURL( context, page, null ); } @@ -577,6 +596,7 @@ public class WikiContext implements Cloneable, Command { * * @return An URL to the given context and page. */ + @Override public String getURL( final String context, final String page, final String params ) { // FIXME: is rather slow return m_engine.getURL( context, page, params ); @@ -657,6 +677,7 @@ public class WikiContext implements Cloneable, Command { * * @return The Session associated with this context. */ + @Override public WikiSession getWikiSession() { return ( WikiSession )m_session; } @@ -729,6 +750,7 @@ public class WikiContext implements Cloneable, Command { * @since 2.4.46 * @return true, if the user has all permissions. */ + @Override public boolean hasAdminPermissions() { return m_engine.getManager( AuthorizationManager.class ).checkPermission( getWikiSession(), new AllPermission( m_engine.getApplicationName() ) ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiPage.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiPage.java index 9dbc46b..6c8c973 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiPage.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiPage.java @@ -19,6 +19,7 @@ package org.apache.wiki; import org.apache.wiki.api.core.Engine; +import org.apache.wiki.api.core.Page; import org.apache.wiki.auth.acl.Acl; import org.apache.wiki.auth.acl.AclEntry; import org.apache.wiki.auth.acl.AclImpl; @@ -38,7 +39,7 @@ import java.util.Map; // author, date, etc. should also be part of the metadata. We also // need to figure out the metadata lifecycle. -public class WikiPage implements Cloneable, Comparable< WikiPage > { +public class WikiPage implements Page, Comparable< WikiPage > { private String m_name; private Engine m_engine; @@ -88,6 +89,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return The page name. */ + @Override public String getName() { return m_name; @@ -103,6 +105,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @param key The key using which the attribute is fetched * @return The attribute. If the attribute has not been set, returns null. */ + @Override @SuppressWarnings( "unchecked" ) public < T > T getAttribute( final String key ) { @@ -116,6 +119,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @param key The key for the attribute used to fetch the attribute later on. * @param attribute The attribute value */ + @Override public void setAttribute( final String key, final Object attribute ) { m_attributes.put( key, attribute ); @@ -128,7 +132,8 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @return The attribute Map. Please note that this is a direct * reference, not a copy. */ - public Map< String, Object > getAttributes() + @Override + public Map< String, Object > getAttributes() { return m_attributes; } @@ -140,6 +145,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @return If the attribute existed, returns the object. * @since 2.1.111 */ + @Override @SuppressWarnings( "unchecked" ) public < T > T removeAttribute( final String key ) { @@ -151,6 +157,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return The last modification date */ + @Override public Date getLastModified() { return m_lastModified; @@ -162,6 +169,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @param date The date */ + @Override public void setLastModified( final Date date ) { m_lastModified = date; @@ -173,6 +181,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @param version The version number */ + @Override public void setVersion( final int version ) { m_version = version; @@ -183,6 +192,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return the version number of this page. */ + @Override public int getVersion() { return m_version; @@ -194,6 +204,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @return the size of the page. * @since 2.1.109 */ + @Override public long getSize() { return m_fileSize; @@ -205,6 +216,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @param size The size of the page. * @since 2.1.109 */ + @Override public void setSize( final long size ) { m_fileSize = size; @@ -238,6 +250,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @param author The author name. */ + @Override public void setAuthor( final String author ) { m_author = author; @@ -248,6 +261,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return Author name, or possibly null. */ + @Override public String getAuthor() { return m_author; @@ -258,6 +272,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return The name of the wiki. */ + @Override public String getWiki() { return m_wiki; @@ -266,6 +281,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { /** * This method will remove all metadata from the page. */ + @Override public void invalidateMetadata() { m_hasMetadata = false; setAcl( null ); @@ -280,6 +296,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * * @return true, if the page has metadata. */ + @Override public boolean hasMetadata() { return m_hasMetadata; @@ -288,6 +305,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { /** * Sets the metadata flag to true. Never call. */ + @Override public void setHasMetadata() { m_hasMetadata = true; @@ -311,7 +329,7 @@ public class WikiPage implements Cloneable, Comparable< WikiPage > { * @return A deep clone of the WikiPage */ @Override - public Object clone() { + public WikiPage clone() { final WikiPage p = new WikiPage( m_engine, m_name ); p.m_wiki = m_wiki;
