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 2017/12/16 19:03:43 UTC
[jspwiki] 02/04: code format plus a couple of really minor refactors
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 b37be85088152097402a87bbc05a6dbc1ae22a51
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Dec 16 19:55:12 2017 +0100
code format plus a couple of really minor refactors
---
.../src/main/java/org/apache/wiki/PageManager.java | 2 +-
.../main/java/org/apache/wiki/WikiProvider.java | 10 ++--
.../src/main/java/org/apache/wiki/WikiServlet.java | 64 ++++++++++++----------
.../apache/wiki/attachment/AttachmentManager.java | 19 +++----
.../wiki/providers/CachingAttachmentProvider.java | 39 ++++++-------
.../wiki/stress/StressTestVersioningProvider.java | 42 +++++++-------
6 files changed, 87 insertions(+), 89 deletions(-)
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/PageManager.java b/jspwiki-war/src/main/java/org/apache/wiki/PageManager.java
index 08cdd6d..0482bc0 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/PageManager.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/PageManager.java
@@ -693,7 +693,7 @@ public class PageManager extends ModuleManager implements WikiEventListener {
* {@inheritDoc}
*/
@Override
- public Collection modules() {
+ public Collection< WikiModuleInfo > modules() {
return null;
}
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/WikiProvider.java b/jspwiki-war/src/main/java/org/apache/wiki/WikiProvider.java
index 5b5a9e9..ae3460c 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/WikiProvider.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/WikiProvider.java
@@ -14,7 +14,7 @@
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
- under the License.
+ under the License.
*/
package org.apache.wiki;
@@ -23,6 +23,7 @@ import java.io.IOException;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
+
/**
* A generic Wiki provider for all sorts of things that the Wiki can
* store.
@@ -38,7 +39,7 @@ public interface WikiProvider
/**
* Initializes the page provider.
- *
+ *
* @param engine WikiEngine to own this provider
* @param properties A set of properties used to initialize this provider
* @throws NoRequiredPropertyException If the provider needs a property which is not found in the property set
@@ -49,13 +50,12 @@ public interface WikiProvider
IOException;
/**
- * Return a valid HTML string for information. May
- * be anything.
+ * Return a valid HTML string for information. May be anything.
* @since 1.6.4
* @return A string describing the provider.
*/
-
String getProviderInfo();
+
}
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java b/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java
index 79fc432..b8a405b 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/WikiServlet.java
@@ -14,19 +14,25 @@
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
- under the License.
+ under the License.
*/
package org.apache.wiki;
-import javax.servlet.*;
-import javax.servlet.http.*;
-import java.io.*;
+import java.io.IOException;
-import net.sf.ehcache.CacheManager;
-import org.apache.log4j.Logger;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.log4j.Logger;
import org.apache.wiki.url.DefaultURLConstructor;
+import net.sf.ehcache.CacheManager;
+
+
/**
* This provides a master servlet for dealing with short urls. It mostly does
* redirects to the proper JSP pages. It also intercepts the servlet
@@ -35,20 +41,19 @@ import org.apache.wiki.url.DefaultURLConstructor;
* @since 2.2
*/
public class WikiServlet extends HttpServlet {
+
private static final long serialVersionUID = 3258410651167633973L;
private WikiEngine m_engine;
- static final Logger log = Logger.getLogger(WikiServlet.class.getName());
+ static final Logger log = Logger.getLogger( WikiServlet.class.getName() );
/**
* {@inheritDoc}
*/
- public void init(ServletConfig config)
- throws ServletException {
- super.init(config);
-
- m_engine = WikiEngine.getInstance(config);
-
- log.info("WikiServlet initialized.");
+ @Override
+ public void init( ServletConfig config ) throws ServletException {
+ super.init( config );
+ m_engine = WikiEngine.getInstance( config );
+ log.info( "WikiServlet initialized." );
}
/**
@@ -60,8 +65,9 @@ public class WikiServlet extends HttpServlet {
*
* @see javax.servlet.GenericServlet#destroy()
*/
+ @Override
public void destroy() {
- log.info("WikiServlet shutdown.");
+ log.info( "WikiServlet shutdown." );
CacheManager.getInstance().shutdown();
m_engine.shutdown();
super.destroy();
@@ -70,30 +76,28 @@ public class WikiServlet extends HttpServlet {
/**
* {@inheritDoc}
*/
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
- doGet(req, res);
+ @Override
+ public void doPost( HttpServletRequest req, HttpServletResponse res ) throws IOException, ServletException {
+ doGet( req, res );
}
/**
* {@inheritDoc}
*/
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws IOException, ServletException {
- String pageName = DefaultURLConstructor.parsePageFromURL(req,
- m_engine.getContentEncoding());
+ @Override
+ public void doGet( HttpServletRequest req, HttpServletResponse res ) throws IOException, ServletException {
+ String pageName = DefaultURLConstructor.parsePageFromURL( req, m_engine.getContentEncoding() );
- log.info("Request for page: " + pageName);
-
- if (pageName == null) {
+ log.info( "Request for page: " + pageName );
+ if( pageName == null ) {
pageName = m_engine.getFrontPage(); // FIXME: Add special pages as well
}
- String jspPage = m_engine.getURLConstructor().getForwardPage(req);
-
- RequestDispatcher dispatcher = req.getRequestDispatcher("/" + jspPage + "?page="
- + m_engine.encodeName(pageName) + "&" + req.getQueryString());
+ String jspPage = m_engine.getURLConstructor().getForwardPage( req );
+ RequestDispatcher dispatcher = req.getRequestDispatcher( "/" + jspPage + "?page=" +
+ m_engine.encodeName( pageName ) + "&" + req.getQueryString() );
- dispatcher.forward(req, res);
+ dispatcher.forward( req, res );
}
+
}
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java b/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
index 7cc7b60..2c7719a 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/attachment/AttachmentManager.java
@@ -47,13 +47,12 @@ import org.apache.wiki.parser.MarkupParser;
import org.apache.wiki.providers.WikiAttachmentProvider;
import org.apache.wiki.util.ClassUtil;
+
/**
- * Provides facilities for handling attachments. All attachment
- * handling goes through this class.
+ * Provides facilities for handling attachments. All attachment handling goes through this class.
* <p>
- * The AttachmentManager provides a facade towards the current WikiAttachmentProvider
- * that is in use. It is created by the WikiEngine as a singleton object, and
- * can be requested through the WikiEngine.
+ * The AttachmentManager provides a facade towards the current WikiAttachmentProvider that is in use.
+ * It is created by the WikiEngine as a singleton object, and can be requested through the WikiEngine.
*
* @since 1.9.28
*/
@@ -341,12 +340,9 @@ public class AttachmentManager
// System.out.println("Seeking info on "+currentPage+"::"+attachmentname);
//
- // Finally, figure out whether this is a real attachment or a generated
- // attachment.
+ // Finally, figure out whether this is a real attachment or a generated attachment.
//
- Attachment att;
-
- att = getDynamicAttachment( currentPage.getName()+"/"+attachmentname );
+ Attachment att = getDynamicAttachment( currentPage.getName()+"/"+attachmentname );
if( att == null )
{
@@ -548,8 +544,7 @@ public class AttachmentManager
m_provider.putAttachmentData( att, in );
- m_engine.getReferenceManager().updateReferences( att.getName(),
- new Vector() );
+ m_engine.getReferenceManager().updateReferences( att.getName(), new Vector< String >() );
WikiPage parent = new WikiPage( m_engine, att.getParentName() );
m_engine.updateReferences( parent );
diff --git a/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java b/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
index 80207ec..4949b04 100644
--- a/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
+++ b/jspwiki-war/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
@@ -1,4 +1,4 @@
-/*
+/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@@ -14,7 +14,7 @@
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
- under the License.
+ under the License.
*/
package org.apache.wiki.providers;
@@ -39,7 +39,7 @@ import org.apache.wiki.util.TextUtil;
/**
* Provides a caching attachment provider. This class rests on top of a
* real provider class and provides a cache to speed things up. Only the
- * Attachment objects are cached; the actual attachment contents are
+ * Attachment objects are cached; the actual attachment contents are
* fetched always from the provider.
*
* @since 2.1.64.
@@ -82,7 +82,7 @@ public class CachingAttachmentProvider
/** Property that supplies the directory used to store attachments. */
public static final String PROP_STORAGEDIR = "jspwiki.basicAttachmentProvider.storageDir";
-
+
private boolean m_gotall = false;
/**
@@ -116,9 +116,9 @@ public class CachingAttachmentProvider
// Find and initialize real provider.
//
String classname = TextUtil.getRequiredProperty( properties, AttachmentManager.PROP_PROVIDER );
-
+
try
- {
+ {
Class<?> providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
m_provider = (WikiAttachmentProvider)providerclass.newInstance();
@@ -186,12 +186,12 @@ public class CachingAttachmentProvider
private <T> Collection<T> cloneCollection( Collection<T> c )
{
ArrayList<T> list = new ArrayList<T>();
-
+
list.addAll( c );
-
+
return list;
}
-
+
/**
* {@inheritDoc}
*/
@@ -240,14 +240,9 @@ public class CachingAttachmentProvider
*
* @return null, if no such attachment was in this collection.
*/
- private Attachment findAttachmentFromCollection( Collection c, String name )
- {
- for( Iterator i = c.iterator(); i.hasNext(); )
- {
- Attachment att = (Attachment) i.next();
-
- if( name.equals( att.getFileName() ) )
- {
+ private Attachment findAttachmentFromCollection( Collection< Attachment > c, String name ) {
+ for( Attachment att : c ) {
+ if( name.equals( att.getFileName() ) ) {
return att;
}
}
@@ -343,14 +338,14 @@ public class CachingAttachmentProvider
/**
* Returns the WikiAttachmentProvider that this caching provider delegates to.
- *
+ *
* @return The real provider underneath this one.
*/
public WikiAttachmentProvider getRealProvider()
{
return m_provider;
}
-
+
/**
* {@inheritDoc}
*/
@@ -359,14 +354,14 @@ public class CachingAttachmentProvider
m_provider.moveAttachmentsForPage(oldParent, newParent);
m_cache.remove(newParent);
m_cache.remove(oldParent);
-
+
//
// This is a kludge to make sure that the pages are removed
// from the other cache as well.
//
String checkName = oldParent + "/";
-
- Collection<String> names = m_cache.getKeysWithExpiryCheck();
+
+ Collection< String > names = m_cache.getKeysWithExpiryCheck();
for( String name : names )
{
if( name.startsWith( checkName ) )
diff --git a/jspwiki-war/src/test/java/org/apache/wiki/stress/StressTestVersioningProvider.java b/jspwiki-war/src/test/java/org/apache/wiki/stress/StressTestVersioningProvider.java
index 40dfd6e..74e0c28 100644
--- a/jspwiki-war/src/test/java/org/apache/wiki/stress/StressTestVersioningProvider.java
+++ b/jspwiki-war/src/test/java/org/apache/wiki/stress/StressTestVersioningProvider.java
@@ -1,4 +1,4 @@
-/*
+/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@@ -14,16 +14,22 @@
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
- under the License.
+ under the License.
*/
package org.apache.wiki.stress;
-import junit.framework.*;
-import java.io.*;
-import java.util.*;
+import java.io.File;
+import java.util.Collection;
+import java.util.Properties;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.providers.FileSystemProvider;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import org.apache.wiki.*;
-import org.apache.wiki.providers.*;
public class StressTestVersioningProvider extends TestCase
{
@@ -78,7 +84,7 @@ public class StressTestVersioningProvider extends TestCase
WikiPage pageinfo = engine.getPage( NAME1 );
assertEquals( "wrong version", maxver, pageinfo.getVersion() );
-
+
// +2 comes from \r\n.
assertEquals( "wrong text", maxver+2, engine.getText(NAME1).length() );
}
@@ -103,20 +109,18 @@ public class StressTestVersioningProvider extends TestCase
System.out.println("Saved "+mark.toString(maxpages)+" pages/second");
mark.reset();
-
+
mark.start();
- Collection pages = engine.getPageManager().getAllPages();
+ Collection< WikiPage > pages = engine.getPageManager().getAllPages();
mark.stop();
-
+
System.out.println("Got a list of all pages in "+mark);
-
+
mark.reset();
mark.start();
-
- for( Iterator i = pages.iterator(); i.hasNext(); )
- {
- String foo = engine.getPureText( (WikiPage)i.next() );
-
+
+ for( WikiPage page : pages ) {
+ String foo = engine.getPureText( page );
assertNotNull( foo );
}
mark.stop();
@@ -129,12 +133,12 @@ public class StressTestVersioningProvider extends TestCase
{
runMassiveFileTest(100);
}
-
+
public void testMillionFiles2() throws Exception
{
runMassiveFileTest(1000);
}
-
+
public void testMillionFiles3() throws Exception
{
runMassiveFileTest(10000);
--
To stop receiving notification emails like this one, please contact
"commits@jspwiki.apache.org" <co...@jspwiki.apache.org>.