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/02/24 16:53:04 UTC
[jspwiki] 22/38: JSPWIKI-120: WikiProvider#initialize receives an
Engine instead of a WikiEngine
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 43bf1824740ccc21c9abe807914b1e321216e975
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Feb 21 17:25:22 2020 +0100
JSPWIKI-120: WikiProvider#initialize receives an Engine instead of a WikiEngine
---
.../main/java/org/apache/wiki/WikiProvider.java | 11 +-
.../apache/wiki/diff/ContextualDiffProvider.java | 19 +-
.../java/org/apache/wiki/diff/DiffProvider.java | 8 +-
.../org/apache/wiki/diff/ExternalDiffProvider.java | 10 +-
.../apache/wiki/diff/TraditionalDiffProvider.java | 18 +-
.../wiki/providers/AbstractFileProvider.java | 412 ++++++++----------
.../wiki/providers/BasicAttachmentProvider.java | 469 ++++++++-------------
.../wiki/providers/CachingAttachmentProvider.java | 80 ++--
.../org/apache/wiki/providers/CachingProvider.java | 135 +++---
.../apache/wiki/providers/FileSystemProvider.java | 179 +++-----
.../wiki/providers/VersioningFileProvider.java | 255 +++++------
.../wiki/providers/WikiAttachmentProvider.java | 107 ++---
.../apache/wiki/providers/WikiPageProvider.java | 61 +--
.../apache/wiki/search/BasicSearchProvider.java | 27 +-
.../apache/wiki/search/LuceneSearchProvider.java | 31 +-
.../java/org/apache/wiki/search/SearchMatcher.java | 12 +-
.../org/apache/wiki/providers/CounterProvider.java | 56 +--
.../apache/wiki/providers/VerySimpleProvider.java | 42 +-
.../wiki/search/tika/TikaSearchProvider.java | 17 +-
19 files changed, 772 insertions(+), 1177 deletions(-)
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
index 8e13402..c401dae 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
@@ -18,6 +18,7 @@
*/
package org.apache.wiki;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import java.io.IOException;
@@ -25,15 +26,13 @@ import java.util.Properties;
/**
- * A generic Wiki provider for all sorts of things that the Wiki can
- * store.
+ * A generic Wiki provider for all sorts of things that the Wiki can store.
*
* @since 2.0
*/
public interface WikiProvider {
- /**
- * Passing this to any method should get the latest version
- */
+
+ /** Passing this to any method should get the latest version */
int LATEST_VERSION = -1;
/**
@@ -44,7 +43,7 @@ public interface WikiProvider {
* @throws NoRequiredPropertyException If the provider needs a property which is not found in the property set
* @throws IOException If there is an IO problem
*/
- void initialize( WikiEngine engine, Properties properties ) throws NoRequiredPropertyException, IOException;
+ void initialize( Engine engine, Properties properties ) throws NoRequiredPropertyException, IOException;
/**
* Return a valid HTML string for information. May be anything.
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
index 27077c0..1fac181 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
@@ -21,7 +21,7 @@ package org.apache.wiki.diff;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.util.TextUtil;
import org.suigeneris.jrcs.diff.Diff;
@@ -101,18 +101,17 @@ public class ContextualDiffProvider implements DiffProvider {
*
* {@inheritDoc}
*/
- public String getProviderInfo()
+ @Override public String getProviderInfo()
{
return "ContextualDiffProvider";
}
/**
- * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.WikiEngine,
- * java.util.Properties)
+ * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.api.core.Engine, java.util.Properties)
*
* {@inheritDoc}
*/
- public void initialize( final WikiEngine engine, final Properties properties) throws NoRequiredPropertyException, IOException {
+ @Override public void initialize( final Engine engine, final Properties properties) throws NoRequiredPropertyException, IOException {
final String configuredLimit = properties.getProperty( PROP_UNCHANGED_CONTEXT_LIMIT, Integer.toString( LIMIT_MAX_VALUE ) );
int limit = LIMIT_MAX_VALUE;
try {
@@ -132,7 +131,7 @@ public class ContextualDiffProvider implements DiffProvider {
*
* {@inheritDoc}
*/
- public synchronized String makeDiffHtml( final WikiContext ctx, final String wikiOld, final String wikiNew ) {
+ @Override public synchronized String makeDiffHtml( final WikiContext ctx, final String wikiOld, final String wikiNew ) {
//
// Sequencing handles lineterminator to <br /> and every-other consequtive space to a
//
@@ -274,11 +273,11 @@ public class ContextualDiffProvider implements DiffProvider {
m_firstElem = orig.last() + 1;
}
- public void visit( final Revision rev ) {
+ @Override public void visit( final Revision rev ) {
// GNDN (Goes nowhere, does nothing)
}
- public void visit( final AddDelta delta ) {
+ @Override public void visit( final AddDelta delta ) {
updateState( delta );
// We have run Deletes up to now. Flush them out.
@@ -298,7 +297,7 @@ public class ContextualDiffProvider implements DiffProvider {
}
}
- public void visit( final ChangeDelta delta ) {
+ @Override public void visit( final ChangeDelta delta ) {
updateState( delta );
// We are in "neutral mode". A Change might be merged with an add or delete.
@@ -311,7 +310,7 @@ public class ContextualDiffProvider implements DiffProvider {
addNew( delta.getRevised() );
}
- public void visit( final DeleteDelta delta ) {
+ @Override public void visit( final DeleteDelta delta ) {
updateState( delta );
// We have run Adds up to now. Flush them out.
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
index 4a0aced..a6df9d0 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
@@ -19,8 +19,8 @@
package org.apache.wiki.diff;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import java.io.IOException;
@@ -49,20 +49,20 @@ public interface DiffProvider extends WikiProvider {
/**
* {@inheritDoc}
*/
- public String makeDiffHtml( final WikiContext ctx, final String oldWikiText, final String newWikiText ) {
+ @Override public String makeDiffHtml( final WikiContext ctx, final String oldWikiText, final String newWikiText ) {
return "You are using the NullDiffProvider, check your properties file.";
}
/**
* {@inheritDoc}
*/
- public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
+ @Override public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
}
/**
* {@inheritDoc}
*/
- public String getProviderInfo()
+ @Override public String getProviderInfo()
{
return "NullDiffProvider";
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
index fdf7cee..8b8cdc3 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
@@ -21,7 +21,7 @@ package org.apache.wiki.diff;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.util.FileUtil;
import org.apache.wiki.util.TextUtil;
@@ -75,16 +75,16 @@ public class ExternalDiffProvider implements DiffProvider {
* @see org.apache.wiki.WikiProvider#getProviderInfo()
* {@inheritDoc}
*/
- public String getProviderInfo()
+ @Override public String getProviderInfo()
{
return "ExternalDiffProvider";
}
/**
* {@inheritDoc}
- * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.WikiEngine, java.util.Properties)
+ * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.api.core.Engine, java.util.Properties)
*/
- public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
+ @Override public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
m_diffCommand = properties.getProperty( PROP_DIFFCOMMAND );
if( m_diffCommand == null || m_diffCommand.trim().equals( "" ) ) {
throw new NoRequiredPropertyException( "ExternalDiffProvider missing required property", PROP_DIFFCOMMAND );
@@ -98,7 +98,7 @@ public class ExternalDiffProvider implements DiffProvider {
* Makes the diff by calling "diff" program.
* {@inheritDoc}
*/
- public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
+ @Override public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
File f1 = null;
File f2 = null;
String diff = null;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
index 6bd60bf..474bd4d 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
@@ -21,7 +21,7 @@ package org.apache.wiki.diff;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.preferences.Preferences;
@@ -66,16 +66,16 @@ public class TraditionalDiffProvider implements DiffProvider {
* {@inheritDoc}
* @see org.apache.wiki.WikiProvider#getProviderInfo()
*/
- public String getProviderInfo()
+ @Override public String getProviderInfo()
{
return "TraditionalDiffProvider";
}
/**
* {@inheritDoc}
- * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.WikiEngine, java.util.Properties)
+ * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.api.core.Engine, java.util.Properties)
*/
- public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
+ @Override public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
}
/**
@@ -88,7 +88,7 @@ public class TraditionalDiffProvider implements DiffProvider {
*
* @return Full HTML diff.
*/
- public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
+ @Override public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
final String diffResult;
try {
@@ -129,24 +129,24 @@ public class TraditionalDiffProvider implements DiffProvider {
m_rb = Preferences.getBundle( ctx, InternationalizationManager.CORE_BUNDLE );
}
- public void visit( final Revision rev ) {
+ @Override public void visit( final Revision rev ) {
// GNDN (Goes nowhere, does nothing)
}
- public void visit( final AddDelta delta ) {
+ @Override public void visit( final AddDelta delta ) {
final Chunk changed = delta.getRevised();
print( changed, m_rb.getString( "diff.traditional.added" ) );
changed.toString( m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE );
}
- public void visit( final ChangeDelta delta ) {
+ @Override public void visit( final ChangeDelta delta ) {
final Chunk changed = delta.getOriginal();
print(changed, m_rb.getString( "diff.traditional.changed" ) );
changed.toString( m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE );
delta.getRevised().toString( m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE );
}
- public void visit( final DeleteDelta delta ) {
+ @Override public void visit( final DeleteDelta delta ) {
final Chunk changed = delta.getOriginal();
print( changed, m_rb.getString( "diff.traditional.removed" ) );
changed.toString( m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE );
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/AbstractFileProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/AbstractFileProvider.java
index 980fade..4ab94fc 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/AbstractFileProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/AbstractFileProvider.java
@@ -24,6 +24,7 @@ import org.apache.wiki.InternalWikiException;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.search.QueryItem;
@@ -56,24 +57,20 @@ import java.util.TreeSet;
/**
* Provides a simple directory based repository for Wiki pages.
* <P>
- * All files have ".txt" appended to make life easier for those
- * who insist on using Windows or other software which makes assumptions
+ * All files have ".txt" appended to make life easier for those who insist on using Windows or other software which makes assumptions
* on the files contents based on its name.
* <p>
* This class functions as a superclass to all file based providers.
*
* @since 2.1.21.
- *
*/
-public abstract class AbstractFileProvider
- implements WikiPageProvider
-{
- private static final Logger log = Logger.getLogger(AbstractFileProvider.class);
- private String m_pageDirectory = "/tmp/";
+public abstract class AbstractFileProvider implements WikiPageProvider {
+ private static final Logger log = Logger.getLogger(AbstractFileProvider.class);
+ private String m_pageDirectory = "/tmp/";
protected String m_encoding;
- protected WikiEngine m_engine;
+ protected Engine m_engine;
public static final String PROP_CUSTOMPROP_MAXLIMIT = "custom.pageproperty.max.allowed";
public static final String PROP_CUSTOMPROP_MAXKEYLENGTH = "custom.pageproperty.key.length";
@@ -87,14 +84,14 @@ public abstract class AbstractFileProvider
* This parameter limits the number of custom page properties allowed on a page
*/
public static int MAX_PROPLIMIT = DEFAULT_MAX_PROPLIMIT;
+
/**
- * This number limits the length of a custom page property key length
- * The default value here designed with future JDBC providers in mind.
+ * This number limits the length of a custom page property key length. The default value here designed with future JDBC providers in mind.
*/
public static int MAX_PROPKEYLENGTH = DEFAULT_MAX_PROPKEYLENGTH;
+
/**
- * This number limits the length of a custom page property value length
- * The default value here designed with future JDBC providers in mind.
+ * This number limits the length of a custom page property value length. The default value here designed with future JDBC providers in mind.
*/
public static int MAX_PROPVALUELENGTH = DEFAULT_MAX_PROPVALUELENGTH;
@@ -121,50 +118,37 @@ public abstract class AbstractFileProvider
* @throws IOException In case the specified page directory is a file, not a directory.
*/
@Override
- public void initialize( WikiEngine engine, Properties properties ) throws NoRequiredPropertyException, IOException, FileNotFoundException
- {
- log.debug("Initing FileSystemProvider");
- m_pageDirectory = TextUtil.getCanonicalFilePathProperty(properties, PROP_PAGEDIR,
- System.getProperty("user.home") + File.separator + "jspwiki-files");
-
- File f = new File(m_pageDirectory);
-
- if( !f.exists() )
- {
- if( !f.mkdirs() )
- {
- throw new IOException( "Failed to create page directory " + f.getAbsolutePath() + " , please check property "
- + PROP_PAGEDIR );
+ public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException, FileNotFoundException {
+ log.debug( "Initing FileSystemProvider" );
+ m_pageDirectory = TextUtil.getCanonicalFilePathProperty( properties, PROP_PAGEDIR,
+ System.getProperty( "user.home" ) + File.separator + "jspwiki-files" );
+
+ final File f = new File( m_pageDirectory );
+
+ if( !f.exists() ) {
+ if( !f.mkdirs() ) {
+ throw new IOException(
+ "Failed to create page directory " + f.getAbsolutePath() + " , please check property " + PROP_PAGEDIR );
}
- }
- else
- {
- if( !f.isDirectory() )
- {
+ } else {
+ if( !f.isDirectory() ) {
throw new IOException( "Page directory is not a directory: " + f.getAbsolutePath() );
}
- if( !f.canWrite() )
- {
+ if( !f.canWrite() ) {
throw new IOException( "Page directory is not writable: " + f.getAbsolutePath() );
}
}
m_engine = engine;
-
m_encoding = properties.getProperty( WikiEngine.PROP_ENCODING, DEFAULT_ENCODING );
-
- String os = System.getProperty( "os.name" ).toLowerCase();
-
- if( os.startsWith("windows") || os.equals("nt") )
- {
+ final String os = System.getProperty( "os.name" ).toLowerCase();
+ if( os.startsWith( "windows" ) || os.equals( "nt" ) ) {
m_windowsHackNeeded = true;
}
- if (properties != null) {
- MAX_PROPLIMIT = TextUtil.getIntegerProperty(properties,PROP_CUSTOMPROP_MAXLIMIT,DEFAULT_MAX_PROPLIMIT);
- MAX_PROPKEYLENGTH = TextUtil.getIntegerProperty(properties,PROP_CUSTOMPROP_MAXKEYLENGTH,DEFAULT_MAX_PROPKEYLENGTH);
- MAX_PROPVALUELENGTH = TextUtil.getIntegerProperty(properties,PROP_CUSTOMPROP_MAXVALUELENGTH,DEFAULT_MAX_PROPVALUELENGTH);
- }
+ MAX_PROPLIMIT = TextUtil.getIntegerProperty( properties, PROP_CUSTOMPROP_MAXLIMIT, DEFAULT_MAX_PROPLIMIT );
+ MAX_PROPKEYLENGTH = TextUtil.getIntegerProperty( properties, PROP_CUSTOMPROP_MAXKEYLENGTH, DEFAULT_MAX_PROPKEYLENGTH );
+ MAX_PROPVALUELENGTH = TextUtil.getIntegerProperty( properties, PROP_CUSTOMPROP_MAXVALUELENGTH, DEFAULT_MAX_PROPVALUELENGTH );
log.info( "Wikipages are read from '" + m_pageDirectory + "'" );
}
@@ -175,42 +159,31 @@ public abstract class AbstractFileProvider
return m_pageDirectory;
}
- private static final String[] WINDOWS_DEVICE_NAMES =
- {
+ private static final String[] WINDOWS_DEVICE_NAMES = {
"con", "prn", "nul", "aux", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9",
"com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9"
};
/**
- * This makes sure that the queried page name
- * is still readable by the file system. For example, all XML entities
+ * This makes sure that the queried page name is still readable by the file system. For example, all XML entities
* and slashes are encoded with the percent notation.
*
* @param pagename The name to mangle
* @return The mangled name.
*/
- protected String mangleName( String pagename )
- {
+ protected String mangleName( String pagename ) {
pagename = TextUtil.urlEncode( pagename, m_encoding );
-
pagename = TextUtil.replaceString( pagename, "/", "%2F" );
- //
- // Names which start with a dot must be escaped to prevent problems.
- // Since we use URL encoding, this is invisible in our unescaping.
- //
- if( pagename.startsWith( "." ) )
- {
+ // Names which start with a dot must be escaped to prevent problems. Since we use URL encoding, this is invisible in our unescaping.
+ if( pagename.startsWith( "." ) ) {
pagename = "%2E" + pagename.substring( 1 );
}
- if( m_windowsHackNeeded )
- {
- String pn = pagename.toLowerCase();
- for( int i = 0; i < WINDOWS_DEVICE_NAMES.length; i++ )
- {
- if( WINDOWS_DEVICE_NAMES[i].equals(pn) )
- {
+ if( m_windowsHackNeeded ) {
+ final String pn = pagename.toLowerCase();
+ for( int i = 0; i < WINDOWS_DEVICE_NAMES.length; i++ ) {
+ if( WINDOWS_DEVICE_NAMES[i].equals(pn) ) {
pagename = "$$$" + pagename;
}
}
@@ -225,12 +198,10 @@ public abstract class AbstractFileProvider
* @param filename The filename to unmangle
* @return The unmangled name.
*/
- protected String unmangleName( String filename )
- {
+ protected String unmangleName( String filename ) {
// The exception should never happen.
- if( m_windowsHackNeeded && filename.startsWith( "$$$") && filename.length() > 3 )
- {
- filename = filename.substring(3);
+ if( m_windowsHackNeeded && filename.startsWith( "$$$" ) && filename.length() > 3 ) {
+ filename = filename.substring( 3 );
}
return TextUtil.urlDecode( filename, m_encoding );
@@ -242,7 +213,7 @@ public abstract class AbstractFileProvider
* @param page The name of the page.
* @return A File to the page. May be null.
*/
- protected File findPage( String page )
+ protected File findPage( final String page )
{
return new File( m_pageDirectory, mangleName(page)+FILE_EXT );
}
@@ -251,63 +222,47 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public boolean pageExists( String page )
- {
- File pagefile = findPage( page );
-
- return pagefile.exists();
+ public boolean pageExists( final String page ) {
+ return findPage( page ).exists();
}
/**
* {@inheritDoc}
*/
@Override
- public boolean pageExists( String page, int version )
- {
- return pageExists (page);
+ public boolean pageExists( final String page, final int version ) {
+ return pageExists( page );
}
/**
- * This implementation just returns the current version, as filesystem
- * does not provide versioning information for now.
+ * This implementation just returns the current version, as filesystem does not provide versioning information for now.
*
- * @param page {@inheritDoc}
- * @param version {@inheritDoc}
- * @throws {@inheritDoc}
+ * {@inheritDoc}
*/
@Override
- public String getPageText( String page, int version )
- throws ProviderException
- {
+ public String getPageText( final String page, final int version ) throws ProviderException {
return getPageText( page );
}
/**
* Read the text directly from the correct file.
*/
- private String getPageText( String page )
- {
+ private String getPageText( final String page ) {
String result = null;
-
- File pagedata = findPage( page );
-
+ final File pagedata = findPage( page );
if( pagedata.exists() ) {
if( pagedata.canRead() ) {
- try( InputStream in = new FileInputStream( pagedata ) ) {
+ try( final InputStream in = new FileInputStream( pagedata ) ) {
result = FileUtil.readContents( in, m_encoding );
- } catch( IOException e ) {
- log.error("Failed to read", e);
+ } catch( final IOException e ) {
+ log.error( "Failed to read", e );
}
+ } else {
+ log.warn( "Failed to read page '" + page + "' from '" + pagedata.getAbsolutePath() + "', possibly a permissions problem" );
}
- else
- {
- log.warn("Failed to read page '"+page+"' from '"+pagedata.getAbsolutePath()+"', possibly a permissions problem");
- }
- }
- else
- {
+ } else {
// This is okay.
- log.info("New page '"+page+"'");
+ log.info( "New page '" + page + "'" );
}
return result;
@@ -317,12 +272,11 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public void putPageText( WikiPage page, String text ) throws ProviderException {
- File file = findPage( page.getName() );
-
- try( PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), m_encoding ) ) ) {
+ public void putPageText( final WikiPage page, final String text ) throws ProviderException {
+ final File file = findPage( page.getName() );
+ try( final PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), m_encoding ) ) ) {
out.print( text );
- } catch( IOException e ) {
+ } catch( final IOException e ) {
log.error( "Saving failed", e );
}
}
@@ -331,35 +285,26 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public Collection< WikiPage > getAllPages()
- throws ProviderException
- {
+ public Collection< WikiPage > getAllPages() throws ProviderException {
log.debug("Getting all pages...");
+ final ArrayList< WikiPage > set = new ArrayList<>();
+ final File wikipagedir = new File( m_pageDirectory );
+ final File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
- ArrayList<WikiPage> set = new ArrayList<>();
-
- File wikipagedir = new File( m_pageDirectory );
-
- File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
- if( wikipages == null )
- {
+ if( wikipages == null ) {
log.error("Wikipages directory '" + m_pageDirectory + "' does not exist! Please check " + PROP_PAGEDIR + " in jspwiki.properties.");
- throw new InternalWikiException("Page directory does not exist");
+ throw new InternalWikiException( "Page directory does not exist" );
}
- for( int i = 0; i < wikipages.length; i++ )
- {
- String wikiname = wikipages[i].getName();
- int cutpoint = wikiname.lastIndexOf( FILE_EXT );
+ for( final File wikipage : wikipages ) {
+ final String wikiname = wikipage.getName();
+ final int cutpoint = wikiname.lastIndexOf( FILE_EXT );
- WikiPage page = getPageInfo( unmangleName(wikiname.substring(0,cutpoint)),
- WikiPageProvider.LATEST_VERSION );
- if( page == null )
- {
+ final WikiPage page = getPageInfo( unmangleName( wikiname.substring( 0, cutpoint ) ), WikiPageProvider.LATEST_VERSION );
+ if( page == null ) {
// This should not really happen.
// FIXME: Should we throw an exception here?
- log.error("Page "+wikiname+" was found in directory listing, but could not be located individually.");
+ log.error( "Page " + wikiname + " was found in directory listing, but could not be located individually." );
continue;
}
@@ -376,7 +321,7 @@ public abstract class AbstractFileProvider
* @return {@inheritDoc}
*/
@Override
- public Collection< WikiPage > getAllChangedSince( Date date )
+ public Collection< WikiPage > getAllChangedSince( final Date date )
{
return new ArrayList<>(); // FIXME
}
@@ -385,49 +330,38 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public int getPageCount()
- {
- File wikipagedir = new File( m_pageDirectory );
-
- File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
- return wikipages.length;
+ public int getPageCount() {
+ final File wikipagedir = new File( m_pageDirectory );
+ final File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
+ return wikipages != null ? wikipages.length : 0;
}
/**
- * Iterates through all WikiPages, matches them against the given query,
- * and returns a Collection of SearchResult objects.
+ * Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.
*
- * @param query {@inheritDoc}
- * @return {@inheritDoc}
+ * {@inheritDoc}
*/
@Override
- public Collection< SearchResult > findPages( QueryItem[] query )
- {
- File wikipagedir = new File( m_pageDirectory );
- TreeSet<SearchResult> res = new TreeSet<>( new SearchResultComparator() );
- SearchMatcher matcher = new SearchMatcher( m_engine, query );
-
- File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
- for( int i = 0; i < wikipages.length; i++ )
- {
- // log.debug("Searching page "+wikipages[i].getPath() );
-
- String filename = wikipages[i].getName();
- int cutpoint = filename.lastIndexOf( FILE_EXT );
- String wikiname = filename.substring( 0, cutpoint );
-
- wikiname = unmangleName( wikiname );
-
- try( FileInputStream input = new FileInputStream( wikipages[i] ) ) {
- String pagetext = FileUtil.readContents( input, m_encoding );
- SearchResult comparison = matcher.matchPageContent( wikiname, pagetext );
- if( comparison != null ) {
- res.add( comparison );
+ public Collection< SearchResult > findPages( final QueryItem[] query ) {
+ final File wikipagedir = new File( m_pageDirectory );
+ final TreeSet< SearchResult > res = new TreeSet<>( new SearchResultComparator() );
+ final SearchMatcher matcher = new SearchMatcher( m_engine, query );
+ final File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
+
+ if( wikipages != null ) {
+ for( final File wikipage : wikipages ) {
+ final String filename = wikipage.getName();
+ final int cutpoint = filename.lastIndexOf( FILE_EXT );
+ final String wikiname = unmangleName( filename.substring( 0, cutpoint ) );
+ try( final FileInputStream input = new FileInputStream( wikipage ) ) {
+ final String pagetext = FileUtil.readContents( input, m_encoding );
+ final SearchResult comparison = matcher.matchPageContent( wikiname, pagetext );
+ if( comparison != null ) {
+ res.add( comparison );
+ }
+ } catch( final IOException e ) {
+ log.error( "Failed to read " + filename, e );
}
- } catch( IOException e ) {
- log.error( "Failed to read " + filename, e );
}
}
@@ -438,22 +372,17 @@ public abstract class AbstractFileProvider
* Always returns the latest version, since FileSystemProvider
* does not support versioning.
*
- * @param page {@inheritDoc}
- * @param version {@inheritDoc}
- * @return {@inheritDoc}
- * @throws {@inheritDoc}
+ * {@inheritDoc}
*/
@Override
- public WikiPage getPageInfo( String page, int version ) throws ProviderException {
- File file = findPage( page );
-
- if( !file.exists() )
- {
+ public WikiPage getPageInfo( final String page, final int version ) throws ProviderException {
+ final File file = findPage( page );
+ if( !file.exists() ) {
return null;
}
- WikiPage p = new WikiPage( m_engine, page );
- p.setLastModified( new Date(file.lastModified()) );
+ final WikiPage p = new WikiPage( m_engine, page );
+ p.setLastModified( new Date( file.lastModified() ) );
return p;
}
@@ -461,15 +390,11 @@ public abstract class AbstractFileProvider
/**
* The FileSystemProvider provides only one version.
*
- * @param page {@inheritDoc}
- * @throws {@inheritDoc}
- * @return {@inheritDoc}
+ * {@inheritDoc}
*/
@Override
- public List<WikiPage> getVersionHistory( String page ) throws ProviderException
- {
- ArrayList<WikiPage> list = new ArrayList<>();
-
+ public List< WikiPage > getVersionHistory( final String page ) throws ProviderException {
+ final ArrayList< WikiPage > list = new ArrayList<>();
list.add( getPageInfo( page, WikiPageProvider.LATEST_VERSION ) );
return list;
@@ -488,13 +413,9 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public void deleteVersion( String pageName, int version )
- throws ProviderException
- {
- if( version == WikiProvider.LATEST_VERSION )
- {
- File f = findPage( pageName );
-
+ public void deleteVersion( final String pageName, final int version ) throws ProviderException {
+ if( version == WikiProvider.LATEST_VERSION ) {
+ final File f = findPage( pageName );
f.delete();
}
}
@@ -503,11 +424,8 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public void deletePage( String pageName )
- throws ProviderException
- {
- File f = findPage( pageName );
-
+ public void deletePage( final String pageName ) throws ProviderException {
+ final File f = findPage( pageName );
f.delete();
}
@@ -516,13 +434,13 @@ public abstract class AbstractFileProvider
*
* @since 2.10.2
*/
- protected void setCustomProperties(WikiPage page, Properties properties) {
- Enumeration< ? > propertyNames = properties.propertyNames();
- while (propertyNames.hasMoreElements()) {
- String key = (String) propertyNames.nextElement();
- if (!key.equals(WikiPage.AUTHOR) && !key.equals(WikiPage.CHANGENOTE) && !key.equals(WikiPage.VIEWCOUNT)) {
- page.setAttribute(key, properties.get(key));
- }
+ protected void setCustomProperties( final WikiPage page, final Properties properties ) {
+ final Enumeration< ? > propertyNames = properties.propertyNames();
+ while( propertyNames.hasMoreElements() ) {
+ final String key = ( String )propertyNames.nextElement();
+ if( !key.equals( WikiPage.AUTHOR ) && !key.equals( WikiPage.CHANGENOTE ) && !key.equals( WikiPage.VIEWCOUNT ) ) {
+ page.setAttribute( key, properties.get( key ) );
+ }
}
}
@@ -532,10 +450,10 @@ public abstract class AbstractFileProvider
*
* @since 2.10.2
*/
- protected void getCustomProperties(WikiPage page, Properties defaultProperties) throws IOException {
- Properties customPageProperties = addCustomProperties(page,defaultProperties);
- validateCustomPageProperties(customPageProperties);
- defaultProperties.putAll(customPageProperties);
+ protected void getCustomProperties( final WikiPage page, final Properties defaultProperties ) throws IOException {
+ final Properties customPageProperties = addCustomProperties( page, defaultProperties );
+ validateCustomPageProperties( customPageProperties );
+ defaultProperties.putAll( customPageProperties );
}
/**
@@ -548,19 +466,19 @@ public abstract class AbstractFileProvider
* @param props the default properties of this page
* @return default implementation returns empty Properties.
*/
- protected Properties addCustomProperties(WikiPage page, Properties props) {
- Properties customProperties = new Properties();
- if (page != null) {
- Map<String,Object> atts = page.getAttributes();
- for (String key : atts.keySet()) {
- Object value = atts.get(key);
- if (key.startsWith("@") && value != null) {
- customProperties.put(key,value.toString());
- }
- }
+ protected Properties addCustomProperties( final WikiPage page, final Properties props ) {
+ final Properties customProperties = new Properties();
+ if( page != null ) {
+ final Map< String, Object > atts = page.getAttributes();
+ for( final String key : atts.keySet() ) {
+ final Object value = atts.get( key );
+ if( key.startsWith( "@" ) && value != null ) {
+ customProperties.put( key, value.toString() );
+ }
+ }
- }
- return customProperties;
+ }
+ return customProperties;
}
/**
@@ -570,34 +488,34 @@ public abstract class AbstractFileProvider
* @since 2.10.2
* @param customProperties the custom page properties being added
*/
- protected void validateCustomPageProperties(Properties customProperties) throws IOException {
+ protected void validateCustomPageProperties( final Properties customProperties ) throws IOException {
// Default validation rules
- if (customProperties != null && !customProperties.isEmpty()) {
- if (customProperties.size()>MAX_PROPLIMIT) {
- throw new IOException("Too many custom properties. You are adding "+customProperties.size()+", but max limit is "+MAX_PROPLIMIT);
- }
- Enumeration< ? > propertyNames = customProperties.propertyNames();
- while (propertyNames.hasMoreElements()) {
- String key = (String) propertyNames.nextElement();
- String value = (String)customProperties.get(key);
- if (key != null) {
- if (key.length()>MAX_PROPKEYLENGTH) {
- throw new IOException("Custom property key "+key+" is too long. Max allowed length is "+MAX_PROPKEYLENGTH);
- }
- if (!StringUtils.isAsciiPrintable(key)) {
- throw new IOException("Custom property key "+key+" is not simple ASCII!");
- }
- }
- if (value != null) {
- if (value.length()>MAX_PROPVALUELENGTH) {
- throw new IOException("Custom property key "+key+" has value that is too long. Value="+value+". Max allowed length is "+MAX_PROPVALUELENGTH);
- }
- if (!StringUtils.isAsciiPrintable(value)) {
- throw new IOException("Custom property key "+key+" has value that is not simple ASCII! Value="+value);
- }
- }
- }
- }
+ if( customProperties != null && !customProperties.isEmpty() ) {
+ if( customProperties.size() > MAX_PROPLIMIT ) {
+ throw new IOException( "Too many custom properties. You are adding " + customProperties.size() + ", but max limit is " + MAX_PROPLIMIT );
+ }
+ final Enumeration< ? > propertyNames = customProperties.propertyNames();
+ while( propertyNames.hasMoreElements() ) {
+ final String key = ( String )propertyNames.nextElement();
+ final String value = ( String )customProperties.get( key );
+ if( key != null ) {
+ if( key.length() > MAX_PROPKEYLENGTH ) {
+ throw new IOException( "Custom property key " + key + " is too long. Max allowed length is " + MAX_PROPKEYLENGTH );
+ }
+ if( !StringUtils.isAsciiPrintable( key ) ) {
+ throw new IOException( "Custom property key " + key + " is not simple ASCII!" );
+ }
+ }
+ if( value != null ) {
+ if( value.length() > MAX_PROPVALUELENGTH ) {
+ throw new IOException( "Custom property key " + key + " has value that is too long. Value=" + value + ". Max allowed length is " + MAX_PROPVALUELENGTH );
+ }
+ if( !StringUtils.isAsciiPrintable( value ) ) {
+ throw new IOException( "Custom property key " + key + " has value that is not simple ASCII! Value=" + value );
+ }
+ }
+ }
+ }
}
/**
@@ -609,7 +527,7 @@ public abstract class AbstractFileProvider
* {@inheritDoc}
*/
@Override
- public boolean accept( File dir, String name ) {
+ public boolean accept( final File dir, final String name ) {
return name.endsWith( FILE_EXT );
}
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
index 5f6d67c..7d9e8f1 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/BasicAttachmentProvider.java
@@ -19,9 +19,9 @@
package org.apache.wiki.providers;
import org.apache.log4j.Logger;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.attachment.Attachment;
@@ -40,9 +40,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
@@ -78,11 +76,10 @@ import java.util.regex.Pattern;
* <LI>1.author = author name for version 1 (etc)
* </UL>
*/
-public class BasicAttachmentProvider
- implements WikiAttachmentProvider
-{
- private WikiEngine m_engine;
- private String m_storageDir;
+public class BasicAttachmentProvider implements WikiAttachmentProvider {
+
+ private Engine m_engine;
+ private String m_storageDir;
/** The property name for where the attachments should be stored. Value is <tt>{@value}</tt>. */
public static final String PROP_STORAGEDIR = "jspwiki.basicAttachmentProvider.storageDir";
@@ -91,61 +88,54 @@ public class BasicAttachmentProvider
* Disable client cache for files with patterns
* since 2.5.96
*/
- private Pattern m_disableCache = null;
+ private Pattern m_disableCache = null;
/** The property name for specifying which attachments are not cached. Value is <tt>{@value}</tt>. */
public static final String PROP_DISABLECACHE = "jspwiki.basicAttachmentProvider.disableCache";
/** The name of the property file. */
- public static final String PROPERTY_FILE = "attachment.properties";
+ public static final String PROPERTY_FILE = "attachment.properties";
/** The default extension for the page attachment directory name. */
- public static final String DIR_EXTENSION = "-att";
+ public static final String DIR_EXTENSION = "-att";
/** The default extension for the attachment directory. */
public static final String ATTDIR_EXTENSION = "-dir";
- static final Logger log = Logger.getLogger( BasicAttachmentProvider.class );
+ private static final Logger log = Logger.getLogger( BasicAttachmentProvider.class );
/**
* {@inheritDoc}
*/
@Override
- public void initialize( WikiEngine engine, Properties properties )
- throws NoRequiredPropertyException,
- IOException
- {
+ public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
m_engine = engine;
- m_storageDir = TextUtil.getCanonicalFilePathProperty(properties, PROP_STORAGEDIR,
- System.getProperty("user.home") + File.separator + "jspwiki-files");
+ m_storageDir = TextUtil.getCanonicalFilePathProperty( properties, PROP_STORAGEDIR,
+ System.getProperty("user.home") + File.separator + "jspwiki-files");
- String patternString = engine.getWikiProperties().getProperty( PROP_DISABLECACHE );
- if ( patternString != null )
- {
+ final String patternString = engine.getWikiProperties().getProperty( PROP_DISABLECACHE );
+ if ( patternString != null ) {
m_disableCache = Pattern.compile(patternString);
}
- //
// Check if the directory exists - if it doesn't, create it.
- //
- File f = new File( m_storageDir );
-
- if( !f.exists() )
- {
+ final File f = new File( m_storageDir );
+ if( !f.exists() ) {
f.mkdirs();
}
- //
// Some sanity checks
- //
- if( !f.exists() )
- throw new IOException("Could not find or create attachment storage directory '"+m_storageDir+"'");
+ if( !f.exists() ) {
+ throw new IOException( "Could not find or create attachment storage directory '" + m_storageDir + "'" );
+ }
- if( !f.canWrite() )
- throw new IOException("Cannot write to the attachment storage directory '"+m_storageDir+"'");
-
- if( !f.isDirectory() )
- throw new IOException("Your attachment storage points to a file, not a directory: '"+m_storageDir+"'");
+ if( !f.canWrite() ) {
+ throw new IOException( "Cannot write to the attachment storage directory '" + m_storageDir + "'" );
+ }
+
+ if( !f.isDirectory() ) {
+ throw new IOException( "Your attachment storage points to a file, not a directory: '" + m_storageDir + "'" );
+ }
}
/**
@@ -153,29 +143,23 @@ public class BasicAttachmentProvider
*
* @param wikipage Page to which this attachment is attached.
*/
- private File findPageDir( String wikipage )
- throws ProviderException
- {
+ private File findPageDir( String wikipage ) throws ProviderException {
wikipage = mangleName( wikipage );
- File f = new File( m_storageDir, wikipage+DIR_EXTENSION );
+ final File f = new File( m_storageDir, wikipage + DIR_EXTENSION );
- if( f.exists() && !f.isDirectory() )
- {
- throw new ProviderException("Storage dir '"+f.getAbsolutePath()+"' is not a directory!");
+ if( f.exists() && !f.isDirectory() ) {
+ throw new ProviderException( "Storage dir '" + f.getAbsolutePath() + "' is not a directory!" );
}
return f;
}
- private static String mangleName( String wikiname )
- {
- String res = TextUtil.urlEncodeUTF8( wikiname );
-
- return res;
+ private static String mangleName( final String wikiname ) {
+ return TextUtil.urlEncodeUTF8( wikiname );
}
- private static String unmangleName( String filename )
+ private static String unmangleName( final String filename )
{
return TextUtil.urlDecodeUTF8( filename );
}
@@ -183,33 +167,18 @@ public class BasicAttachmentProvider
/**
* Finds the dir in which the attachment lives.
*/
- private File findAttachmentDir( Attachment att )
- throws ProviderException
- {
- File f = new File( findPageDir(att.getParentName()),
- mangleName(att.getFileName()+ATTDIR_EXTENSION) );
-
- //
- // Migration code for earlier versions of JSPWiki.
- // Originally, we used plain filename. Then we realized we need
- // to urlencode it. Then we realized that we have to use a
- // postfix to make sure illegal file names are never formed.
- //
- if( !f.exists() )
- {
- File oldf = new File( findPageDir( att.getParentName() ),
- mangleName( att.getFileName() ) );
- if( oldf.exists() )
- {
+ private File findAttachmentDir( final Attachment att ) throws ProviderException {
+ File f = new File( findPageDir( att.getParentName() ), mangleName( att.getFileName() + ATTDIR_EXTENSION ) );
+
+ // Migration code for earlier versions of JSPWiki. Originally, we used plain filename. Then we realized we need
+ // to urlencode it. Then we realized that we have to use a postfix to make sure illegal file names are never formed.
+ if( !f.exists() ) {
+ File oldf = new File( findPageDir( att.getParentName() ), mangleName( att.getFileName() ) );
+ if( oldf.exists() ) {
f = oldf;
- }
- else
- {
- oldf = new File( findPageDir( att.getParentName() ),
- att.getFileName() );
-
- if( oldf.exists() )
- {
+ } else {
+ oldf = new File( findPageDir( att.getParentName() ), att.getFileName() );
+ if( oldf.exists() ) {
f = oldf;
}
}
@@ -225,39 +194,31 @@ public class BasicAttachmentProvider
* @return Latest version number in the repository, or 0, if
* there is no page in the repository.
*/
- private int findLatestVersion( Attachment att )
- throws ProviderException
- {
- // File pageDir = findPageDir( att.getName() );
- File attDir = findAttachmentDir( att );
+ private int findLatestVersion( final Attachment att ) throws ProviderException {
+ final File attDir = findAttachmentDir( att );
// log.debug("Finding pages in "+attDir.getAbsolutePath());
- String[] pages = attDir.list( new AttachmentVersionFilter() );
+ final String[] pages = attDir.list( new AttachmentVersionFilter() );
- if( pages == null )
- {
+ if( pages == null ) {
return 0; // No such thing found.
}
int version = 0;
-
- for( int i = 0; i < pages.length; i++ )
- {
+ for( int i = 0; i < pages.length; i++ ) {
// log.debug("Checking: "+pages[i]);
- int cutpoint = pages[i].indexOf( '.' );
- String pageNum = ( cutpoint > 0 ) ? pages[i].substring( 0, cutpoint ) : pages[i] ;
+ final int cutpoint = pages[ i ].indexOf( '.' );
+ final String pageNum = ( cutpoint > 0 ) ? pages[ i ].substring( 0, cutpoint ) : pages[ i ];
- try
- {
- int res = Integer.parseInt( pageNum );
+ try {
+ final int res = Integer.parseInt( pageNum );
- if( res > version )
- {
- version = res;
- }
+ if( res > version ) {
+ version = res;
}
- catch( NumberFormatException e ) {} // It's okay to skip these.
- }
+ } catch( final NumberFormatException e ) {
+ } // It's okay to skip these.
+ }
return version;
}
@@ -270,13 +231,11 @@ public class BasicAttachmentProvider
* @param filename The file name to check
* @return The extension. If no extension is found, returns "bin".
*/
- protected static String getFileExtension( String filename )
- {
+ protected static String getFileExtension( final String filename ) {
String fileExt = "bin";
- int dot = filename.lastIndexOf('.');
- if( dot >= 0 && dot < filename.length()-1 )
- {
+ final int dot = filename.lastIndexOf('.');
+ if( dot >= 0 && dot < filename.length()-1 ) {
fileExt = mangleName( filename.substring( dot+1 ) );
}
@@ -290,7 +249,7 @@ public class BasicAttachmentProvider
private void putPageProperties( final Attachment att, final Properties properties ) throws IOException, ProviderException {
final File attDir = findAttachmentDir( att );
final File propertyFile = new File( attDir, PROPERTY_FILE );
- try( OutputStream out = new FileOutputStream( propertyFile ) ) {
+ try( final OutputStream out = new FileOutputStream( propertyFile ) ) {
properties.store( out, " JSPWiki page properties for " + att.getName() + ". DO NOT MODIFY!" );
}
}
@@ -314,45 +273,36 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void putAttachmentData( Attachment att, InputStream data ) throws ProviderException, IOException {
- File attDir = findAttachmentDir( att );
+ public void putAttachmentData( final Attachment att, final InputStream data ) throws ProviderException, IOException {
+ final File attDir = findAttachmentDir( att );
- if(!attDir.exists())
- {
+ if( !attDir.exists() ) {
attDir.mkdirs();
}
+ final int latestVersion = findLatestVersion( att );
+ final int versionNumber = latestVersion + 1;
- int latestVersion = findLatestVersion( att );
-
- // System.out.println("Latest version is "+latestVersion);
- int versionNumber = latestVersion+1;
-
- File newfile = new File( attDir, versionNumber + "." + getFileExtension( att.getFileName() ) );
+ final File newfile = new File( attDir, versionNumber + "." + getFileExtension( att.getFileName() ) );
try( final OutputStream out = new FileOutputStream( newfile ) ) {
- log.info("Uploading attachment "+att.getFileName()+" to page "+att.getParentName());
- log.info("Saving attachment contents to "+newfile.getAbsolutePath());
-
+ log.info( "Uploading attachment " + att.getFileName() + " to page " + att.getParentName() );
+ log.info( "Saving attachment contents to " + newfile.getAbsolutePath() );
FileUtil.copyContents( data, out );
- Properties props = getPageProperties( att );
+ final Properties props = getPageProperties( att );
String author = att.getAuthor();
-
- if( author == null )
- {
+ if( author == null ) {
author = "unknown"; // FIXME: Should be localized, but cannot due to missing WikiContext
}
+ props.setProperty( versionNumber + ".author", author );
- props.setProperty( versionNumber+".author", author );
-
- String changeNote = att.getAttribute(WikiPage.CHANGENOTE);
- if( changeNote != null )
- {
- props.setProperty( versionNumber+".changenote", changeNote );
+ final String changeNote = att.getAttribute( WikiPage.CHANGENOTE );
+ if( changeNote != null ) {
+ props.setProperty( versionNumber + ".changenote", changeNote );
}
putPageProperties( att, props );
- } catch( IOException e ) {
+ } catch( final IOException e ) {
log.error( "Could not save attachment data: ", e );
throw (IOException) e.fillInStackTrace();
}
@@ -366,31 +316,24 @@ public class BasicAttachmentProvider
return "";
}
- private File findFile( File dir, Attachment att )
- throws FileNotFoundException,
- ProviderException
- {
+ private File findFile( final File dir, final Attachment att ) throws FileNotFoundException, ProviderException {
int version = att.getVersion();
-
- if( version == WikiProvider.LATEST_VERSION )
- {
+ if( version == WikiProvider.LATEST_VERSION ) {
version = findLatestVersion( att );
}
- String ext = getFileExtension( att.getFileName() );
- File f = new File( dir, version+"."+ext );
+ final String ext = getFileExtension( att.getFileName() );
+ File f = new File( dir, version + "." + ext );
- if( !f.exists() )
- {
- if ("bin".equals(ext))
- {
- File fOld = new File( dir, version+"." );
- if (fOld.exists())
+ if( !f.exists() ) {
+ if( "bin".equals( ext ) ) {
+ final File fOld = new File( dir, version + "." );
+ if( fOld.exists() ) {
f = fOld;
+ }
}
- if( !f.exists() )
- {
- throw new FileNotFoundException("No such file: "+f.getAbsolutePath()+" exists.");
+ if( !f.exists() ) {
+ throw new FileNotFoundException( "No such file: " + f.getAbsolutePath() + " exists." );
}
}
@@ -401,22 +344,14 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public InputStream getAttachmentData( Attachment att )
- throws IOException,
- ProviderException
- {
- File attDir = findAttachmentDir( att );
-
- try
- {
- File f = findFile( attDir, att );
-
+ public InputStream getAttachmentData( final Attachment att ) throws IOException, ProviderException {
+ final File attDir = findAttachmentDir( att );
+ try {
+ final File f = findFile( attDir, att );
return new FileInputStream( f );
- }
- catch( FileNotFoundException e )
- {
- log.error("File not found: "+e.getMessage());
- throw new ProviderException("No such page was found.");
+ } catch( final FileNotFoundException e ) {
+ log.error( "File not found: " + e.getMessage() );
+ throw new ProviderException( "No such page was found." );
}
}
@@ -424,68 +359,36 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public List< Attachment > listAttachments( WikiPage page )
- throws ProviderException
- {
- List<Attachment> result = new ArrayList<>();
-
- File dir = findPageDir( page.getName() );
-
- if( dir != null )
- {
- String[] attachments = dir.list();
-
- if( attachments != null )
- {
- //
- // We now have a list of all potential attachments in
- // the directory.
- //
- for( int i = 0; i < attachments.length; i++ )
- {
- File f = new File( dir, attachments[i] );
-
- if( f.isDirectory() )
- {
+ public List< Attachment > listAttachments( final WikiPage page ) throws ProviderException {
+ final List< Attachment > result = new ArrayList<>();
+ final File dir = findPageDir( page.getName() );
+ if( dir != null ) {
+ final String[] attachments = dir.list();
+ if( attachments != null ) {
+ // We now have a list of all potential attachments in the directory.
+ for( int i = 0; i < attachments.length; i++ ) {
+ final File f = new File( dir, attachments[i] );
+ if( f.isDirectory() ) {
String attachmentName = unmangleName( attachments[i] );
- //
- // Is it a new-stylea attachment directory? If yes,
- // we'll just deduce the name. If not, however,
- // we'll check if there's a suitable property file
- // in the directory.
- //
- if( attachmentName.endsWith( ATTDIR_EXTENSION ) )
- {
- attachmentName = attachmentName.substring( 0, attachmentName.length()-ATTDIR_EXTENSION.length() );
- }
- else
- {
- File propFile = new File( f, PROPERTY_FILE );
-
- if( !propFile.exists() )
- {
- //
- // This is not obviously a JSPWiki attachment,
- // so let's just skip it.
- //
+ // Is it a new-stylea attachment directory? If yes, we'll just deduce the name. If not, however,
+ // we'll check if there's a suitable property file in the directory.
+ if( attachmentName.endsWith( ATTDIR_EXTENSION ) ) {
+ attachmentName = attachmentName.substring( 0, attachmentName.length() - ATTDIR_EXTENSION.length() );
+ } else {
+ final File propFile = new File( f, PROPERTY_FILE );
+ if( !propFile.exists() ) {
+ // This is not obviously a JSPWiki attachment, so let's just skip it.
continue;
}
}
- Attachment att = getAttachmentInfo( page, attachmentName,
- WikiProvider.LATEST_VERSION );
-
- //
- // Sanity check - shouldn't really be happening, unless
- // you mess with the repository directly.
- //
- if( att == null )
- {
+ final Attachment att = getAttachmentInfo( page, attachmentName, WikiProvider.LATEST_VERSION );
+ // Sanity check - shouldn't really be happening, unless you mess with the repository directly.
+ if( att == null ) {
throw new ProviderException("Attachment disappeared while reading information:"+
" if you did not touch the repository, there is a serious bug somewhere. "+
- "Attachment = "+attachments[i]+
- ", decoded = "+attachmentName );
+ "Attachment = " + attachments[ i ] + ", decoded = " + attachmentName );
}
result.add( att );
@@ -501,7 +404,7 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public Collection< Attachment > findAttachments( QueryItem[] query )
+ public Collection< Attachment > findAttachments( final QueryItem[] query )
{
return new ArrayList<>();
}
@@ -511,39 +414,28 @@ public class BasicAttachmentProvider
*/
// FIXME: Very unoptimized.
@Override
- public List<Attachment> listAllChanged( Date timestamp )
- throws ProviderException
- {
- File attDir = new File( m_storageDir );
-
- if( !attDir.exists() )
- {
- throw new ProviderException("Specified attachment directory "+m_storageDir+" does not exist!");
+ public List< Attachment > listAllChanged( final Date timestamp ) throws ProviderException {
+ final File attDir = new File( m_storageDir );
+ if( !attDir.exists() ) {
+ throw new ProviderException( "Specified attachment directory " + m_storageDir + " does not exist!" );
}
- ArrayList<Attachment> list = new ArrayList<>();
+ final ArrayList< Attachment > list = new ArrayList<>();
+ final String[] pagesWithAttachments = attDir.list( new AttachmentFilter() );
- String[] pagesWithAttachments = attDir.list( new AttachmentFilter() );
+ for( int i = 0; i < pagesWithAttachments.length; i++ ) {
+ String pageId = unmangleName( pagesWithAttachments[ i ] );
+ pageId = pageId.substring( 0, pageId.length() - DIR_EXTENSION.length() );
- for( int i = 0; i < pagesWithAttachments.length; i++ )
- {
- String pageId = unmangleName( pagesWithAttachments[i] );
- pageId = pageId.substring( 0, pageId.length()-DIR_EXTENSION.length() );
-
- Collection<Attachment> c = listAttachments( new WikiPage( m_engine, pageId ) );
-
- for( Iterator<Attachment> it = c.iterator(); it.hasNext(); )
- {
- Attachment att = it.next();
-
- if( att.getLastModified().after( timestamp ) )
- {
+ final Collection< Attachment > c = listAttachments( new WikiPage( m_engine, pageId ) );
+ for( final Attachment att : c ) {
+ if( att.getLastModified().after( timestamp ) ) {
list.add( att );
}
}
}
- Collections.sort( list, new PageTimeComparator() );
+ list.sort( new PageTimeComparator() );
return list;
}
@@ -569,7 +461,7 @@ public class BasicAttachmentProvider
// Should attachment be cachable by the client (browser)?
if (m_disableCache != null) {
- Matcher matcher = m_disableCache.matcher(name);
+ final Matcher matcher = m_disableCache.matcher(name);
if (matcher.matches()) {
att.setCacheable(false);
}
@@ -577,21 +469,21 @@ public class BasicAttachmentProvider
// System.out.println("Fetching info on version "+version);
try {
- Properties props = getPageProperties(att);
+ final Properties props = getPageProperties(att);
att.setAuthor( props.getProperty( version+".author" ) );
final String changeNote = props.getProperty( version+".changenote" );
if( changeNote != null ) {
att.setAttribute(WikiPage.CHANGENOTE, changeNote);
}
-
- File f = findFile( dir, att );
+
+ final File f = findFile( dir, att );
att.setSize( f.length() );
att.setLastModified( new Date(f.lastModified()) );
- } catch( FileNotFoundException e ) {
+ } catch( final FileNotFoundException e ) {
log.error( "Can't get attachment properties for " + att, e );
return null;
- } catch( IOException e ) {
+ } catch( final IOException e ) {
log.error("Can't read page properties", e );
throw new ProviderException("Cannot read page properties: "+e.getMessage());
}
@@ -604,28 +496,21 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public List<Attachment> getVersionHistory( Attachment att )
- {
- ArrayList<Attachment> list = new ArrayList<>();
+ public List< Attachment > getVersionHistory( final Attachment att ) {
+ final ArrayList< Attachment > list = new ArrayList<>();
- try
- {
- int latest = findLatestVersion( att );
+ try {
+ final int latest = findLatestVersion( att );
- for( int i = latest; i >= 1; i-- )
- {
- Attachment a = getAttachmentInfo( new WikiPage( m_engine, att.getParentName() ),
- att.getFileName(), i );
+ for( int i = latest; i >= 1; i-- ) {
+ final Attachment a = getAttachmentInfo( new WikiPage( m_engine, att.getParentName() ), att.getFileName(), i );
- if( a != null )
- {
+ if( a != null ) {
list.add( a );
}
}
- }
- catch( ProviderException e )
- {
- log.error("Getting version history failed for page: "+att,e);
+ } catch( final ProviderException e ) {
+ log.error( "Getting version history failed for page: " + att, e );
// FIXME: SHould this fail?
}
@@ -636,9 +521,7 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void deleteVersion( Attachment att )
- throws ProviderException
- {
+ public void deleteVersion( final Attachment att ) throws ProviderException {
// FIXME: Does nothing yet.
}
@@ -646,32 +529,26 @@ public class BasicAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void deleteAttachment( Attachment att )
- throws ProviderException
- {
- File dir = findAttachmentDir( att );
- String[] files = dir.list();
+ public void deleteAttachment( final Attachment att ) throws ProviderException {
+ final File dir = findAttachmentDir( att );
+ final String[] files = dir.list();
- for( int i = 0; i < files.length; i++ )
- {
- File file = new File( dir.getAbsolutePath() + "/" + files[i] );
+ for( int i = 0; i < files.length; i++ ) {
+ final File file = new File( dir.getAbsolutePath() + "/" + files[ i ] );
file.delete();
}
dir.delete();
}
-
/**
* Returns only those directories that contain attachments.
*/
- public static class AttachmentFilter
- implements FilenameFilter
- {
+ public static class AttachmentFilter implements FilenameFilter {
/**
* {@inheritDoc}
*/
@Override
- public boolean accept( File dir, String name )
+ public boolean accept( final File dir, final String name )
{
return name.endsWith( DIR_EXTENSION );
}
@@ -680,14 +557,12 @@ public class BasicAttachmentProvider
/**
* Accepts only files that are actual versions, no control files.
*/
- public static class AttachmentVersionFilter
- implements FilenameFilter
- {
+ public static class AttachmentVersionFilter implements FilenameFilter {
/**
* {@inheritDoc}
*/
@Override
- public boolean accept( File dir, String name )
+ public boolean accept( final File dir, final String name )
{
return !name.equals( PROPERTY_FILE );
}
@@ -696,27 +571,21 @@ public class BasicAttachmentProvider
/**
* {@inheritDoc}
*/
-
@Override
- public void moveAttachmentsForPage( String oldParent, String newParent )
- throws ProviderException
- {
- File srcDir = findPageDir( oldParent );
- File destDir = findPageDir( newParent );
-
- log.debug("Trying to move all attachments from "+srcDir+" to "+destDir);
-
- // If it exists, we're overwriting an old page (this has already been
- // confirmed at a higher level), so delete any existing attachments.
- if (destDir.exists())
- {
- log.error("Page rename failed because target dirctory "+destDir+" exists");
- }
- else
- {
- //destDir.getParentFile().mkdir();
- srcDir.renameTo(destDir);
+ public void moveAttachmentsForPage( final String oldParent, final String newParent ) throws ProviderException {
+ final File srcDir = findPageDir( oldParent );
+ final File destDir = findPageDir( newParent );
+
+ log.debug( "Trying to move all attachments from " + srcDir + " to " + destDir );
+
+ // If it exists, we're overwriting an old page (this has already been confirmed at a higher level), so delete any existing attachments.
+ if( destDir.exists() ) {
+ log.error( "Page rename failed because target dirctory " + destDir + " exists" );
+ } else {
+ // destDir.getParentFile().mkdir();
+ srcDir.renameTo( destDir );
}
}
+
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
index 930f8af..a7b6d3a 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
@@ -22,9 +22,9 @@ import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.attachment.Attachment;
@@ -54,9 +54,8 @@ import java.util.Properties;
*/
// EntryRefreshPolicy for that.
-public class CachingAttachmentProvider
- implements WikiAttachmentProvider
-{
+public class CachingAttachmentProvider implements WikiAttachmentProvider {
+
private static final Logger log = Logger.getLogger(CachingAttachmentProvider.class);
private WikiAttachmentProvider m_provider;
@@ -97,10 +96,10 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void initialize( WikiEngine engine, Properties properties ) throws NoRequiredPropertyException, IOException {
+ public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
log.info("Initing CachingAttachmentProvider");
- String attCollCacheName = engine.getApplicationName() + "." + ATTCOLLCACHE_NAME;
+ final String attCollCacheName = engine.getApplicationName() + "." + ATTCOLLCACHE_NAME;
if (m_cacheManager.cacheExists(attCollCacheName)) {
m_cache = m_cacheManager.getCache(attCollCacheName);
} else {
@@ -111,7 +110,7 @@ public class CachingAttachmentProvider
//
// cache for the individual Attachment objects, attachment name is key, the Attachment object is the cached object
//
- String attCacheName = engine.getApplicationName() + "." + ATTCACHE_NAME;
+ final String attCacheName = engine.getApplicationName() + "." + ATTCACHE_NAME;
if (m_cacheManager.cacheExists(attCacheName)) {
m_attCache = m_cacheManager.getCache(attCacheName);
} else {
@@ -130,24 +129,24 @@ public class CachingAttachmentProvider
try
{
- Class<?> providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
+ final Class<?> providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
m_provider = (WikiAttachmentProvider)providerclass.newInstance();
log.debug("Initializing real provider class "+m_provider);
m_provider.initialize( engine, properties );
}
- catch( ClassNotFoundException e )
+ catch( final ClassNotFoundException e )
{
log.error("Unable to locate provider class "+classname,e);
throw new IllegalArgumentException("no provider class", e);
}
- catch( InstantiationException e )
+ catch( final InstantiationException e )
{
log.error("Unable to create provider class "+classname,e);
throw new IllegalArgumentException("faulty provider class", e);
}
- catch( IllegalAccessException e )
+ catch( final IllegalAccessException e )
{
log.error("Illegal access to provider class "+classname,e);
throw new IllegalArgumentException("illegal provider class", e);
@@ -159,7 +158,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void putAttachmentData( Attachment att, InputStream data )
+ public void putAttachmentData( final Attachment att, final InputStream data )
throws ProviderException, IOException {
m_provider.putAttachmentData( att, data );
@@ -172,7 +171,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public InputStream getAttachmentData( Attachment att )
+ public InputStream getAttachmentData( final Attachment att )
throws ProviderException, IOException {
return m_provider.getAttachmentData( att );
}
@@ -181,13 +180,12 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public List< Attachment > listAttachments(WikiPage page) throws ProviderException {
+ public List< Attachment > listAttachments( final WikiPage page) throws ProviderException {
log.debug("Listing attachments for " + page);
- Element element = m_cache.get(page.getName());
+ final Element element = m_cache.get(page.getName());
if (element != null) {
- @SuppressWarnings("unchecked")
- List< Attachment > c = ( List< Attachment > )element.getObjectValue();
+ @SuppressWarnings("unchecked") final List< Attachment > c = ( List< Attachment > )element.getObjectValue();
log.debug("LIST from cache, " + page.getName() + ", size=" + c.size());
return cloneCollection(c);
}
@@ -197,9 +195,9 @@ public class CachingAttachmentProvider
return refresh(page);
}
- private <T> List<T> cloneCollection( Collection<T> c )
+ private <T> List<T> cloneCollection( final Collection<T> c )
{
- ArrayList<T> list = new ArrayList<>();
+ final ArrayList<T> list = new ArrayList<>();
list.addAll( c );
@@ -210,7 +208,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public Collection< Attachment > findAttachments( QueryItem[] query )
+ public Collection< Attachment > findAttachments( final QueryItem[] query )
{
return m_provider.findAttachments( query );
}
@@ -219,7 +217,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public List<Attachment> listAllChanged(Date timestamp) throws ProviderException {
+ public List<Attachment> listAllChanged( final Date timestamp) throws ProviderException {
List< Attachment > all = null;
//
// we do a one-time build up of the cache, after this the cache is updated for every attachment add/delete
@@ -229,19 +227,18 @@ public class CachingAttachmentProvider
// Put all pages in the cache :
synchronized (this) {
- for (Iterator< Attachment > i = all.iterator(); i.hasNext(); ) {
- Attachment att = i.next();
+ for ( final Iterator< Attachment > i = all.iterator(); i.hasNext(); ) {
+ final Attachment att = i.next();
m_attCache.put(new Element(att.getName(), att));
}
m_gotall = true;
}
} else {
- @SuppressWarnings("unchecked")
- List< String > keys = m_attCache.getKeysWithExpiryCheck();
+ @SuppressWarnings("unchecked") final List< String > keys = m_attCache.getKeysWithExpiryCheck();
all = new ArrayList<>();
- for (String key : keys) {
- Element element = m_attCache.get(key);
- Attachment cachedAttachment = ( Attachment )element.getObjectValue();
+ for ( final String key : keys) {
+ final Element element = m_attCache.get(key);
+ final Attachment cachedAttachment = ( Attachment )element.getObjectValue();
if (cachedAttachment != null) {
all.add(cachedAttachment);
}
@@ -257,8 +254,8 @@ public class CachingAttachmentProvider
*
* @return null, if no such attachment was in this collection.
*/
- private Attachment findAttachmentFromCollection( Collection< Attachment > c, String name ) {
- for( Attachment att : new ArrayList< >( c ) ) {
+ private Attachment findAttachmentFromCollection( final Collection< Attachment > c, final String name ) {
+ for( final Attachment att : new ArrayList< >( c ) ) {
if( name.equals( att.getFileName() ) ) {
return att;
}
@@ -272,9 +269,9 @@ public class CachingAttachmentProvider
*
* @return The newly fetched object from the provider.
*/
- private List<Attachment> refresh( WikiPage page ) throws ProviderException
+ private List<Attachment> refresh( final WikiPage page ) throws ProviderException
{
- List<Attachment> c = m_provider.listAttachments( page );
+ final List<Attachment> c = m_provider.listAttachments( page );
m_cache.put(new Element(page.getName(), c));
return c;
@@ -285,7 +282,7 @@ public class CachingAttachmentProvider
*/
@SuppressWarnings("unchecked")
@Override
- public Attachment getAttachmentInfo(WikiPage page, String name, int version) throws ProviderException {
+ public Attachment getAttachmentInfo( final WikiPage page, final String name, final int version) throws ProviderException {
if (log.isDebugEnabled()) {
log.debug("Getting attachments for " + page + ", name=" + name + ", version=" + version);
}
@@ -299,7 +296,7 @@ public class CachingAttachmentProvider
}
Collection<Attachment> c = null;
- Element element = m_cache.get(page.getName());
+ final Element element = m_cache.get(page.getName());
if (element == null) {
log.debug(page.getName() + " wasn't in the cache");
@@ -320,7 +317,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public List<Attachment> getVersionHistory( Attachment att )
+ public List<Attachment> getVersionHistory( final Attachment att )
{
return m_provider.getVersionHistory( att );
}
@@ -329,7 +326,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void deleteVersion( Attachment att ) throws ProviderException
+ public void deleteVersion( final Attachment att ) throws ProviderException
{
// This isn't strictly speaking correct, but it does not really matter
m_cache.remove(att.getParentName());
@@ -340,7 +337,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void deleteAttachment( Attachment att ) throws ProviderException
+ public void deleteAttachment( final Attachment att ) throws ProviderException
{
m_cache.remove(att.getParentName());
m_attCache.remove(att.getName());
@@ -375,7 +372,7 @@ public class CachingAttachmentProvider
* {@inheritDoc}
*/
@Override
- public void moveAttachmentsForPage( String oldParent, String newParent ) throws ProviderException
+ public void moveAttachmentsForPage( final String oldParent, final String newParent ) throws ProviderException
{
m_provider.moveAttachmentsForPage(oldParent, newParent);
m_cache.remove(newParent);
@@ -385,11 +382,10 @@ public class CachingAttachmentProvider
// This is a kludge to make sure that the pages are removed
// from the other cache as well.
//
- String checkName = oldParent + "/";
+ final String checkName = oldParent + "/";
- @SuppressWarnings("unchecked")
- List< String > names = m_cache.getKeysWithExpiryCheck();
- for( String name : names )
+ @SuppressWarnings("unchecked") final List< String > names = m_cache.getKeysWithExpiryCheck();
+ for( final String name : names )
{
if( name.startsWith( checkName ) )
{
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
index 234d74b..d4088db 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
@@ -23,8 +23,8 @@ import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.pages.PageManager;
@@ -72,7 +72,7 @@ public class CachingProvider implements WikiPageProvider {
private WikiPageProvider m_provider;
// FIXME: Find another way to the search engine to use instead of from WikiEngine?
- private WikiEngine m_engine;
+ private Engine m_engine;
private Cache m_cache;
/** Name of the regular page cache. */
@@ -106,7 +106,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
+ public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
log.debug("Initing CachingProvider");
// engine is used for getting the search engine
@@ -121,7 +121,7 @@ public class CachingProvider implements WikiPageProvider {
m_cacheManager.addCache(m_cache);
}
- String textCacheName = engine.getApplicationName() + "." + TEXTCACHE_NAME;
+ final String textCacheName = engine.getApplicationName() + "." + TEXTCACHE_NAME;
if (m_cacheManager.cacheExists(textCacheName)) {
m_textCache= m_cacheManager.getCache(textCacheName);
} else {
@@ -130,7 +130,7 @@ public class CachingProvider implements WikiPageProvider {
m_cacheManager.addCache(m_textCache);
}
- String historyCacheName = engine.getApplicationName() + "." + HISTORYCACHE_NAME;
+ final String historyCacheName = engine.getApplicationName() + "." + HISTORYCACHE_NAME;
if (m_cacheManager.cacheExists(historyCacheName)) {
m_historyCache= m_cacheManager.getCache(historyCacheName);
} else {
@@ -152,40 +152,33 @@ public class CachingProvider implements WikiPageProvider {
throw new NoRequiredPropertyException( e.getMessage(), PageManager.PROP_PAGEPROVIDER );
}
- try
- {
- Class< ? > providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname);
+ try {
+ final Class< ? > providerclass = ClassUtil.findClass( "org.apache.wiki.providers", classname );
- m_provider = (WikiPageProvider)providerclass.newInstance();
+ m_provider = ( WikiPageProvider )providerclass.newInstance();
- log.debug("Initializing real provider class "+m_provider);
+ log.debug( "Initializing real provider class " + m_provider );
m_provider.initialize( engine, properties );
- }
- catch( ClassNotFoundException e )
- {
- log.error("Unable to locate provider class "+classname,e);
- throw new IllegalArgumentException("no provider class", e);
- }
- catch( InstantiationException e )
- {
- log.error("Unable to create provider class "+classname,e);
- throw new IllegalArgumentException("faulty provider class", e);
- }
- catch( IllegalAccessException e )
- {
- log.error("Illegal access to provider class "+classname,e);
- throw new IllegalArgumentException("illegal provider class", e);
+ } catch( final ClassNotFoundException e ) {
+ log.error( "Unable to locate provider class " + classname, e );
+ throw new IllegalArgumentException( "no provider class", e );
+ } catch( final InstantiationException e ) {
+ log.error( "Unable to create provider class " + classname, e );
+ throw new IllegalArgumentException( "faulty provider class", e );
+ } catch( final IllegalAccessException e ) {
+ log.error( "Illegal access to provider class " + classname, e );
+ throw new IllegalArgumentException( "illegal provider class", e );
}
}
- private WikiPage getPageInfoFromCache(String name) throws ProviderException {
+ private WikiPage getPageInfoFromCache( final String name) throws ProviderException {
// Sanity check; seems to occur sometimes
if (name == null) return null;
- Element cacheElement = m_cache.get(name);
+ final Element cacheElement = m_cache.get(name);
if (cacheElement == null) {
- WikiPage refreshed = m_provider.getPageInfo(name, WikiPageProvider.LATEST_VERSION);
+ final WikiPage refreshed = m_provider.getPageInfo(name, WikiPageProvider.LATEST_VERSION);
if (refreshed != null) {
m_cache.put(new Element(name, refreshed));
return refreshed;
@@ -202,7 +195,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public boolean pageExists( String pageName, int version )
+ public boolean pageExists( final String pageName, final int version )
{
if( pageName == null ) return false;
@@ -212,7 +205,7 @@ public class CachingProvider implements WikiPageProvider {
{
p = getPageInfoFromCache( pageName );
}
- catch( ProviderException e )
+ catch( final ProviderException e )
{
log.info("Provider failed while trying to check if page exists: "+pageName);
return false;
@@ -220,7 +213,7 @@ public class CachingProvider implements WikiPageProvider {
if( p != null )
{
- int latestVersion = p.getVersion();
+ final int latestVersion = p.getVersion();
if( version == latestVersion || version == LATEST_VERSION )
{
@@ -234,7 +227,7 @@ public class CachingProvider implements WikiPageProvider {
{
return getPageInfo( pageName, version ) != null;
}
- catch( ProviderException e )
+ catch( final ProviderException e )
{}
return false;
@@ -244,7 +237,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public boolean pageExists( String pageName )
+ public boolean pageExists( final String pageName )
{
if( pageName == null ) return false;
@@ -254,7 +247,7 @@ public class CachingProvider implements WikiPageProvider {
{
p = getPageInfoFromCache( pageName );
}
- catch( ProviderException e )
+ catch( final ProviderException e )
{
log.info("Provider failed while trying to check if page exists: "+pageName);
return false;
@@ -295,7 +288,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public String getPageText( String pageName, int version )
+ public String getPageText( final String pageName, final int version )
throws ProviderException
{
String result = null;
@@ -308,7 +301,7 @@ public class CachingProvider implements WikiPageProvider {
}
else
{
- WikiPage p = getPageInfoFromCache( pageName );
+ final WikiPage p = getPageInfoFromCache( pageName );
//
// Or is this the latest version fetched by version number?
@@ -327,12 +320,12 @@ public class CachingProvider implements WikiPageProvider {
}
- private String getTextFromCache(String pageName) throws ProviderException {
+ private String getTextFromCache( final String pageName) throws ProviderException {
String text = null;
if (pageName == null) return null;
- Element cacheElement = m_textCache.get(pageName);
+ final Element cacheElement = m_textCache.get(pageName);
if (cacheElement != null) {
m_cacheHits++;
@@ -352,7 +345,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public void putPageText(WikiPage page, String text) throws ProviderException {
+ public void putPageText( final WikiPage page, final String text) throws ProviderException {
synchronized (this) {
m_provider.putPageText(page, text);
@@ -373,7 +366,7 @@ public class CachingProvider implements WikiPageProvider {
*/
@Override
public Collection< WikiPage > getAllPages() throws ProviderException {
- Collection< WikiPage > all;
+ final Collection< WikiPage > all;
if (m_gotall == false) {
all = m_provider.getAllPages();
@@ -381,8 +374,8 @@ public class CachingProvider implements WikiPageProvider {
// Make sure that all pages are in the cache.
synchronized (this) {
- for (Iterator< WikiPage > i = all.iterator(); i.hasNext(); ) {
- WikiPage p = i.next();
+ for ( final Iterator< WikiPage > i = all.iterator(); i.hasNext(); ) {
+ final WikiPage p = i.next();
m_cache.put(new Element(p.getName(), p));
}
@@ -390,12 +383,11 @@ public class CachingProvider implements WikiPageProvider {
m_gotall = true;
}
} else {
- @SuppressWarnings("unchecked")
- List< String > keys = m_cache.getKeysWithExpiryCheck();
+ @SuppressWarnings("unchecked") final List< String > keys = m_cache.getKeysWithExpiryCheck();
all = new TreeSet<>();
- for (String key : keys) {
- Element element = m_cache.get(key);
- WikiPage cachedPage = ( WikiPage )element.getObjectValue();
+ for ( final String key : keys) {
+ final Element element = m_cache.get(key);
+ final WikiPage cachedPage = ( WikiPage )element.getObjectValue();
if (cachedPage != null) {
all.add(cachedPage);
}
@@ -416,7 +408,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public Collection< WikiPage > getAllChangedSince( Date date )
+ public Collection< WikiPage > getAllChangedSince( final Date date )
{
return m_provider.getAllChangedSince( date );
}
@@ -435,7 +427,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public Collection< SearchResult > findPages( QueryItem[] query )
+ public Collection< SearchResult > findPages( final QueryItem[] query )
{
//
// If the provider is a fast searcher, then
@@ -451,24 +443,19 @@ public class CachingProvider implements WikiPageProvider {
// necessary variables.
//
- private void refreshMetadata( WikiPage page )
- {
- if( page != null && !page.hasMetadata() )
- {
- RenderingManager mgr = m_engine.getRenderingManager();
+ private void refreshMetadata( final WikiPage page ) {
+ if( page != null && !page.hasMetadata() ) {
+ final RenderingManager mgr = m_engine.getManager( RenderingManager.class );
- try
- {
- String data = m_provider.getPageText(page.getName(), page.getVersion());
+ try {
+ final String data = m_provider.getPageText( page.getName(), page.getVersion() );
- WikiContext ctx = new WikiContext( m_engine, page );
- MarkupParser parser = mgr.getParser( ctx, data );
+ final WikiContext ctx = new WikiContext( m_engine, page );
+ final MarkupParser parser = mgr.getParser( ctx, data );
parser.parse();
- }
- catch( Exception ex )
- {
- log.debug("Failed to retrieve variables for wikipage "+page);
+ } catch( final Exception ex ) {
+ log.debug( "Failed to retrieve variables for wikipage " + page );
}
}
}
@@ -477,18 +464,18 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public WikiPage getPageInfo( String pageName, int version ) throws ProviderException
+ public WikiPage getPageInfo( final String pageName, final int version ) throws ProviderException
{
WikiPage page = null;
- WikiPage cached = getPageInfoFromCache( pageName );
+ final WikiPage cached = getPageInfoFromCache( pageName );
- int latestcached = (cached != null) ? cached.getVersion() : Integer.MIN_VALUE;
+ final int latestcached = (cached != null) ? cached.getVersion() : Integer.MIN_VALUE;
if( version == WikiPageProvider.LATEST_VERSION || version == latestcached )
{
if( cached == null )
{
- WikiPage data = m_provider.getPageInfo( pageName, version );
+ final WikiPage data = m_provider.getPageInfo( pageName, version );
if( data != null )
{
@@ -518,11 +505,11 @@ public class CachingProvider implements WikiPageProvider {
*/
@SuppressWarnings("unchecked")
@Override
- public List< WikiPage > getVersionHistory(String pageName) throws ProviderException {
+ public List< WikiPage > getVersionHistory( final String pageName) throws ProviderException {
List< WikiPage > history = null;
if (pageName == null) return null;
- Element element = m_historyCache.get(pageName);
+ final Element element = m_historyCache.get(pageName);
if (element != null) {
m_historyCacheHits++;
@@ -555,7 +542,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public void deleteVersion( String pageName, int version )
+ public void deleteVersion( final String pageName, final int version )
throws ProviderException
{
//
@@ -564,9 +551,9 @@ public class CachingProvider implements WikiPageProvider {
//
synchronized( this )
{
- WikiPage cached = getPageInfoFromCache( pageName );
+ final WikiPage cached = getPageInfoFromCache( pageName );
- int latestcached = (cached != null) ? cached.getVersion() : Integer.MIN_VALUE;
+ final int latestcached = (cached != null) ? cached.getVersion() : Integer.MIN_VALUE;
//
// If we have this version cached, remove from cache.
@@ -587,7 +574,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public void deletePage( String pageName )
+ public void deletePage( final String pageName )
throws ProviderException
{
//
@@ -606,7 +593,7 @@ public class CachingProvider implements WikiPageProvider {
* {@inheritDoc}
*/
@Override
- public void movePage(String from, String to) throws ProviderException {
+ public void movePage( final String from, final String to) throws ProviderException {
m_provider.movePage(from, to);
synchronized (this) {
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/FileSystemProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/FileSystemProvider.java
index c8c7e3b..802beab 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/FileSystemProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/FileSystemProvider.java
@@ -38,28 +38,22 @@ import java.util.Properties;
* on the files contents based on its name.
*
*/
-public class FileSystemProvider
- extends AbstractFileProvider
-{
- private static final Logger log = Logger.getLogger(FileSystemProvider.class);
- /**
- * All metadata is stored in a file with this extension.
- */
+public class FileSystemProvider extends AbstractFileProvider {
+
+ private static final Logger log = Logger.getLogger( FileSystemProvider.class );
+
+ /** All metadata is stored in a file with this extension. */
public static final String PROP_EXT = ".properties";
/**
* {@inheritDoc}
*/
- public void putPageText( WikiPage page, String text )
- throws ProviderException
- {
- try
- {
+ @Override
+ public void putPageText( final WikiPage page, final String text ) throws ProviderException {
+ try {
super.putPageText( page, text );
putPageProperties( page );
- }
- catch( IOException e )
- {
+ } catch( final IOException e ) {
log.error( "Saving failed" );
}
}
@@ -67,112 +61,72 @@ public class FileSystemProvider
/**
* Stores basic metadata to a file.
*/
- private void putPageProperties( WikiPage page )
- throws IOException
- {
- Properties props = new Properties();
- OutputStream out = null;
-
- try
- {
- String author = page.getAuthor();
- String changenote = page.getAttribute( WikiPage.CHANGENOTE );
- String viewcount = page.getAttribute( WikiPage.VIEWCOUNT );
-
- if( author != null )
- {
- props.setProperty( WikiPage.AUTHOR, author );
- }
-
- if( changenote != null )
- {
- props.setProperty( WikiPage.CHANGENOTE, changenote );
- }
+ private void putPageProperties( final WikiPage page ) throws IOException {
+ final Properties props = new Properties();
+ final String author = page.getAuthor();
+ final String changenote = page.getAttribute( WikiPage.CHANGENOTE );
+ final String viewcount = page.getAttribute( WikiPage.VIEWCOUNT );
+
+ if( author != null ) {
+ props.setProperty( WikiPage.AUTHOR, author );
+ }
- if( viewcount != null )
- {
- props.setProperty( WikiPage.VIEWCOUNT, viewcount );
- }
-
- // Get additional custom properties from page and add to props
- getCustomProperties(page, props);
-
-
- File file = new File( getPageDirectory(),
- mangleName(page.getName())+PROP_EXT );
-
- out = new FileOutputStream( file );
+ if( changenote != null ) {
+ props.setProperty( WikiPage.CHANGENOTE, changenote );
+ }
- props.store( out, "JSPWiki page properties for page "+page.getName() );
+ if( viewcount != null ) {
+ props.setProperty( WikiPage.VIEWCOUNT, viewcount );
}
- finally
- {
- if( out != null ) out.close();
+
+ // Get additional custom properties from page and add to props
+ getCustomProperties(page, props);
+
+ final File file = new File( getPageDirectory(), mangleName( page.getName() ) + PROP_EXT );
+ try( final OutputStream out = new FileOutputStream( file ) ) {
+ props.store( out, "JSPWiki page properties for page "+page.getName() );
}
}
/**
* Gets basic metadata from file.
*/
- private void getPageProperties( WikiPage page )
- throws IOException
- {
- Properties props = new Properties();
- InputStream in = null;
-
- try
- {
- File file = new File( getPageDirectory(),
- mangleName(page.getName())+PROP_EXT );
-
- if( file.exists() )
- {
- in = new FileInputStream( file );
-
- props.load(in);
-
+ private void getPageProperties( final WikiPage page ) throws IOException {
+ final File file = new File( getPageDirectory(), mangleName( page.getName() ) + PROP_EXT );
+ if( file.exists() ) {
+ try( final InputStream in = new FileInputStream( file ) ) {
+ final Properties props = new Properties();
+ props.load( in );
page.setAuthor( props.getProperty( WikiPage.AUTHOR ) );
-
- String changenote = props.getProperty( WikiPage.CHANGENOTE );
- if( changenote != null )
- {
+
+ final String changenote = props.getProperty( WikiPage.CHANGENOTE );
+ if( changenote != null ) {
page.setAttribute( WikiPage.CHANGENOTE, changenote );
}
-
- String viewcount = props.getProperty( WikiPage.VIEWCOUNT );
- if( viewcount != null )
- {
+
+ final String viewcount = props.getProperty( WikiPage.VIEWCOUNT );
+ if( viewcount != null ) {
page.setAttribute( WikiPage.VIEWCOUNT, viewcount );
}
-
+
// Set the props values to the page attributes
- setCustomProperties(page, props);
- }
- }
- finally
- {
- if( in != null ) in.close();
+ setCustomProperties( page, props );
+ }
}
}
/**
* {@inheritDoc}
*/
- public WikiPage getPageInfo( String page, int version )
- throws ProviderException
- {
- WikiPage p = super.getPageInfo( page, version );
-
- if( p != null )
- {
- try
- {
+ @Override
+ public WikiPage getPageInfo( final String page, final int version ) throws ProviderException {
+ final WikiPage p = super.getPageInfo( page, version );
+ if( p != null ) {
+ try {
getPageProperties( p );
- }
- catch( IOException e )
- {
- log.error("Unable to read page properties", e );
- throw new ProviderException("Unable to read page properties, check logs.");
+ } catch( final IOException e ) {
+ log.error( "Unable to read page properties", e );
+ throw new ProviderException( "Unable to read page properties, check logs." );
}
}
@@ -182,26 +136,23 @@ public class FileSystemProvider
/**
* {@inheritDoc}
*/
- public void deletePage(String pageName) throws ProviderException
- {
- super.deletePage(pageName);
-
- File file = new File( getPageDirectory(),
- mangleName(pageName)+PROP_EXT );
-
- if( file.exists() ) file.delete();
+ @Override
+ public void deletePage( final String pageName) throws ProviderException {
+ super.deletePage( pageName );
+ final File file = new File( getPageDirectory(), mangleName(pageName)+PROP_EXT );
+ if( file.exists() ) {
+ file.delete();
+ }
}
/**
* {@inheritDoc}
*/
- public void movePage( String from,
- String to )
- throws ProviderException
- {
- File fromPage = findPage( from );
- File toPage = findPage( to );
-
+ @Override
+ public void movePage( final String from, final String to ) throws ProviderException {
+ final File fromPage = findPage( from );
+ final File toPage = findPage( to );
fromPage.renameTo( toPage );
}
+
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/VersioningFileProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/VersioningFileProvider.java
index 27dd7cb..5faea43 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/VersioningFileProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/VersioningFileProvider.java
@@ -20,9 +20,9 @@ package org.apache.wiki.providers;
import org.apache.log4j.Logger;
import org.apache.wiki.InternalWikiException;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.util.FileUtil;
@@ -38,7 +38,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
@@ -84,56 +83,41 @@ public class VersioningFileProvider extends AbstractFileProvider {
* {@inheritDoc}
*/
@Override
- public void initialize( WikiEngine engine, Properties properties )
- throws NoRequiredPropertyException,
- IOException
- {
+ public void initialize( final Engine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
super.initialize( engine, properties );
// some additional sanity checks :
- File oldpages = new File(getPageDirectory(), PAGEDIR);
- if (!oldpages.exists())
- {
- if (!oldpages.mkdirs())
- {
- throw new IOException("Failed to create page version directory " + oldpages.getAbsolutePath());
+ final File oldpages = new File( getPageDirectory(), PAGEDIR );
+ if( !oldpages.exists() ) {
+ if( !oldpages.mkdirs() ) {
+ throw new IOException( "Failed to create page version directory " + oldpages.getAbsolutePath() );
}
- }
- else
- {
- if (!oldpages.isDirectory())
- {
- throw new IOException("Page version directory is not a directory: " + oldpages.getAbsolutePath());
+ } else {
+ if( !oldpages.isDirectory() ) {
+ throw new IOException( "Page version directory is not a directory: " + oldpages.getAbsolutePath() );
}
- if (!oldpages.canWrite())
- {
- throw new IOException("Page version directory is not writable: " + oldpages.getAbsolutePath());
+ if( !oldpages.canWrite() ) {
+ throw new IOException( "Page version directory is not writable: " + oldpages.getAbsolutePath() );
}
}
- log.info("Using directory " + oldpages.getAbsolutePath() + " for storing old versions of pages");
+ log.info( "Using directory " + oldpages.getAbsolutePath() + " for storing old versions of pages" );
}
/**
* Returns the directory where the old versions of the pages
* are being kept.
*/
- private File findOldPageDir( String page )
- {
- if( page == null )
- {
- throw new InternalWikiException("Page may NOT be null in the provider!");
+ private File findOldPageDir( final String page ) {
+ if( page == null ) {
+ throw new InternalWikiException( "Page may NOT be null in the provider!" );
}
-
- File oldpages = new File( getPageDirectory(), PAGEDIR );
-
- return new File( oldpages, mangleName(page) );
+ final File oldpages = new File( getPageDirectory(), PAGEDIR );
+ return new File( oldpages, mangleName( page ) );
}
/**
- * Goes through the repository and decides which version is
- * the newest one in that directory.
+ * Goes through the repository and decides which version is the newest one in that directory.
*
- * @return Latest version number in the repository, or -1, if
- * there is no page in the repository.
+ * @return Latest version number in the repository, or -1, if there is no page in the repository.
*/
// FIXME: This is relatively slow.
@@ -174,42 +158,32 @@ public class VersioningFileProvider extends AbstractFileProvider {
return version;
}
*/
- private int findLatestVersion( String page )
- {
+ private int findLatestVersion( final String page ) {
int version = -1;
- try
- {
- Properties props = getPageProperties( page );
-
- for( Iterator<Object> i = props.keySet().iterator(); i.hasNext(); )
- {
- String key = (String)i.next();
+ try {
+ final Properties props = getPageProperties( page );
- if( key.endsWith(".author") )
- {
- int cutpoint = key.indexOf('.');
- if( cutpoint > 0 )
- {
- String pageNum = key.substring(0,cutpoint);
+ for( final Object o : props.keySet() ) {
+ final String key = ( String )o;
+ if( key.endsWith( ".author" ) ) {
+ final int cutpoint = key.indexOf( '.' );
+ if( cutpoint > 0 ) {
+ final String pageNum = key.substring( 0, cutpoint );
- try
- {
- int res = Integer.parseInt( pageNum );
+ try {
+ final int res = Integer.parseInt( pageNum );
- if( res > version )
- {
+ if( res > version ) {
version = res;
}
- }
- catch( NumberFormatException e ) {} // It's okay to skip these.
+ } catch( final NumberFormatException e ) {
+ } // It's okay to skip these.
}
}
}
- }
- catch( IOException e )
- {
- log.error("Unable to figure out latest version - dying...",e);
+ } catch( final IOException e ) {
+ log.error( "Unable to figure out latest version - dying...", e );
}
return version;
@@ -237,8 +211,8 @@ public class VersioningFileProvider extends AbstractFileProvider {
return cp.m_props;
}
- try( InputStream in = new BufferedInputStream(new FileInputStream( propertyFile ) ) ) {
- Properties props = new Properties();
+ try( final InputStream in = new BufferedInputStream(new FileInputStream( propertyFile ) ) ) {
+ final Properties props = new Properties();
props.load( in );
cp = new CachedProperties( page, props, lastModified );
m_cachedProperties = cp; // Atomic
@@ -272,7 +246,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
*
* @throws NoSuchVersionException if there is no such version.
*/
- private int realVersion( String page, int requestedVersion ) throws NoSuchVersionException {
+ private int realVersion( final String page, final int requestedVersion ) throws NoSuchVersionException {
//
// Quickly check for the most common case.
//
@@ -281,7 +255,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
return -1;
}
- int latest = findLatestVersion(page);
+ final int latest = findLatestVersion(page);
if( requestedVersion == latest ||
(requestedVersion == 1 && latest == -1 ) )
@@ -300,10 +274,10 @@ public class VersioningFileProvider extends AbstractFileProvider {
* {@inheritDoc}
*/
@Override
- public synchronized String getPageText( String page, int version )
+ public synchronized String getPageText( final String page, int version )
throws ProviderException
{
- File dir = findOldPageDir( page );
+ final File dir = findOldPageDir( page );
version = realVersion( page, version );
if( version == -1 )
@@ -313,7 +287,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
return super.getPageText( page, WikiPageProvider.LATEST_VERSION );
}
- File pageFile = new File( dir, ""+version+FILE_EXT );
+ final File pageFile = new File( dir, ""+version+FILE_EXT );
if( !pageFile.exists() )
throw new NoSuchVersionException("Version "+version+"does not exist.");
@@ -329,7 +303,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
if( pagedata.canRead() ) {
try( final InputStream in = new FileInputStream( pagedata ) ) {
result = FileUtil.readContents( in, m_encoding );
- } catch( IOException e ) {
+ } catch( final IOException e ) {
log.error("Failed to read", e);
throw new ProviderException("I/O error: "+e.getMessage());
}
@@ -388,8 +362,8 @@ public class VersioningFileProvider extends AbstractFileProvider {
if( oldFile != null && oldFile.exists() ) {
final File pageFile = new File( pageDir, versionNumber + FILE_EXT );
- try( InputStream in = new BufferedInputStream( new FileInputStream( oldFile ) );
- OutputStream out = new BufferedOutputStream( new FileOutputStream( pageFile ) ) ) {
+ try( final InputStream in = new BufferedInputStream( new FileInputStream( oldFile ) );
+ final OutputStream out = new BufferedOutputStream( new FileOutputStream( pageFile ) ) ) {
FileUtil.copyContents( in, out );
//
@@ -413,18 +387,16 @@ public class VersioningFileProvider extends AbstractFileProvider {
// Finally, write page version data.
//
// FIXME: No rollback available.
- Properties props = getPageProperties( page.getName() );
+ final Properties props = getPageProperties( page.getName() );
String authorFirst = null;
// if the following file exists, we are NOT migrating from FileSystemProvider
- File pagePropFile = new File(getPageDirectory() + File.separator + PAGEDIR + File.separator + mangleName(page.getName()) + File.separator + "page" + FileSystemProvider.PROP_EXT);
+ final File pagePropFile = new File(getPageDirectory() + File.separator + PAGEDIR + File.separator + mangleName(page.getName()) + File.separator + "page" + FileSystemProvider.PROP_EXT);
if( firstUpdate && ! pagePropFile.exists() ) {
- // we might not yet have a versioned author because the
- // old page was last maintained by FileSystemProvider
- Properties props2 = getHeritagePageProperties( page.getName() );
+ // we might not yet have a versioned author because the old page was last maintained by FileSystemProvider
+ final Properties props2 = getHeritagePageProperties( page.getName() );
- // remember the simulated original author (or something)
- // in the new properties
+ // remember the simulated original author (or something) in the new properties
authorFirst = props2.getProperty( "1.author", "unknown" );
props.setProperty( "1.author", authorFirst );
}
@@ -437,7 +409,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
page.setAuthor(newAuthor);
props.setProperty( versionNumber + ".author", newAuthor );
- String changeNote = page.getAttribute(WikiPage.CHANGENOTE);
+ final String changeNote = page.getAttribute(WikiPage.CHANGENOTE);
if( changeNote != null ) {
props.setProperty( versionNumber + ".changenote", changeNote );
}
@@ -455,92 +427,74 @@ public class VersioningFileProvider extends AbstractFileProvider {
* {@inheritDoc}
*/
@Override
- public WikiPage getPageInfo( String page, int version )
- throws ProviderException
- {
- int latest = findLatestVersion(page);
- int realVersion;
+ public WikiPage getPageInfo( final String page, final int version ) throws ProviderException {
+ final int latest = findLatestVersion( page );
+ final int realVersion;
WikiPage p = null;
- if( version == WikiPageProvider.LATEST_VERSION ||
- version == latest ||
- (version == 1 && latest == -1) )
- {
+ if( version == WikiPageProvider.LATEST_VERSION || version == latest || (version == 1 && latest == -1) ) {
//
- // Yes, we need to talk to the top level directory
- // to get this version.
+ // Yes, we need to talk to the top level directory to get this version.
//
- // I am listening to Press Play On Tape's guitar version of
- // the good old C64 "Wizardry" -tune at this moment.
+ // I am listening to Press Play On Tape's guitar version of the good old C64 "Wizardry" -tune at this moment.
// Oh, the memories...
//
realVersion = (latest >= 0) ? latest : 1;
p = super.getPageInfo( page, WikiPageProvider.LATEST_VERSION );
- if( p != null )
- {
+ if( p != null ) {
p.setVersion( realVersion );
}
- }
- else
- {
+ } else {
//
// The file is not the most recent, so we'll need to
// find it from the deep trenches of the "OLD" directory
// structure.
//
realVersion = version;
- File dir = findOldPageDir( page );
+ final File dir = findOldPageDir( page );
- if( !dir.exists() || !dir.isDirectory() )
- {
+ if( !dir.exists() || !dir.isDirectory() ) {
return null;
}
- File file = new File( dir, version+FILE_EXT );
+ final File file = new File( dir, version + FILE_EXT );
- if( file.exists() )
- {
+ if( file.exists() ) {
p = new WikiPage( m_engine, page );
- p.setLastModified( new Date(file.lastModified()) );
+ p.setLastModified( new Date( file.lastModified() ) );
p.setVersion( version );
}
}
//
- // Get author and other metadata information
- // (Modification date has already been set.)
+ // Get author and other metadata information (Modification date has already been set.)
//
- if( p != null )
- {
- try
- {
- Properties props = getPageProperties( page );
- String author = props.getProperty( realVersion+".author" );
- if ( author == null )
- {
+ if( p != null ) {
+ try {
+ final Properties props = getPageProperties( page );
+ String author = props.getProperty( realVersion + ".author" );
+ if( author == null ) {
// we might not have a versioned author because the
// old page was last maintained by FileSystemProvider
- Properties props2 = getHeritagePageProperties( page );
+ final Properties props2 = getHeritagePageProperties( page );
author = props2.getProperty( WikiPage.AUTHOR );
}
- if ( author != null )
- {
+ if( author != null ) {
p.setAuthor( author );
}
- String changenote = props.getProperty( realVersion+".changenote" );
- if( changenote != null ) p.setAttribute( WikiPage.CHANGENOTE, changenote );
+ final String changenote = props.getProperty( realVersion + ".changenote" );
+ if( changenote != null )
+ p.setAttribute( WikiPage.CHANGENOTE, changenote );
// Set the props values to the page attributes
- setCustomProperties(p, props);
- }
- catch( IOException e )
- {
- log.error( "Cannot get author for page"+page+": ", e );
+ setCustomProperties( p, props );
+ } catch( final IOException e ) {
+ log.error( "Cannot get author for page" + page + ": ", e );
}
}
@@ -551,23 +505,17 @@ public class VersioningFileProvider extends AbstractFileProvider {
* {@inheritDoc}
*/
@Override
- public boolean pageExists( String pageName, int version )
- {
+ public boolean pageExists( final String pageName, final int version ) {
if (version == WikiPageProvider.LATEST_VERSION || version == findLatestVersion( pageName ) ) {
return pageExists(pageName);
}
- File dir = findOldPageDir( pageName );
-
- if( !dir.exists() || !dir.isDirectory() )
- {
+ final File dir = findOldPageDir( pageName );
+ if( !dir.exists() || !dir.isDirectory() ) {
return false;
}
- File file = new File( dir, version+FILE_EXT );
-
- return file.exists();
-
+ return new File( dir, version + FILE_EXT ).exists();
}
/**
@@ -575,18 +523,16 @@ public class VersioningFileProvider extends AbstractFileProvider {
*/
// FIXME: Does not get user information.
@Override
- public List< WikiPage > getVersionHistory( String page ) throws ProviderException {
- ArrayList<WikiPage> list = new ArrayList<>();
- int latest = findLatestVersion( page );
+ public List< WikiPage > getVersionHistory( final String page ) throws ProviderException {
+ final ArrayList< WikiPage > list = new ArrayList<>();
+ final int latest = findLatestVersion( page );
// list.add( getPageInfo(page,WikiPageProvider.LATEST_VERSION) );
- for( int i = latest; i > 0; i-- )
- {
- WikiPage info = getPageInfo( page, i );
+ for( int i = latest; i > 0; i-- ) {
+ final WikiPage info = getPageInfo( page, i );
- if( info != null )
- {
+ if( info != null ) {
list.add( info );
}
}
@@ -642,26 +588,19 @@ public class VersioningFileProvider extends AbstractFileProvider {
*/
// FIXME: Should log errors.
@Override
- public void deletePage( String page )
- throws ProviderException
- {
+ public void deletePage( final String page ) throws ProviderException {
super.deletePage( page );
+ final File dir = findOldPageDir( page );
+ if( dir.exists() && dir.isDirectory() ) {
+ final File[] files = dir.listFiles( new WikiFileFilter() );
- File dir = findOldPageDir( page );
-
- if( dir.exists() && dir.isDirectory() )
- {
- File[] files = dir.listFiles( new WikiFileFilter() );
-
- for( int i = 0; i < files.length; i++ )
- {
- files[i].delete();
+ for( int i = 0; i < files.length; i++ ) {
+ files[ i ].delete();
}
- File propfile = new File( dir, PROPERTYFILE );
+ final File propfile = new File( dir, PROPERTYFILE );
- if( propfile.exists() )
- {
+ if( propfile.exists() ) {
propfile.delete();
}
@@ -742,7 +681,7 @@ public class VersioningFileProvider extends AbstractFileProvider {
final Collection< WikiPage > pages = super.getAllPages();
final Collection< WikiPage > returnedPages = new ArrayList<>();
for( final WikiPage page : pages ) {
- WikiPage info = getPageInfo( page.getName(), WikiProvider.LATEST_VERSION );
+ final WikiPage info = getPageInfo( page.getName(), WikiProvider.LATEST_VERSION );
returnedPages.add( info );
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiAttachmentProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiAttachmentProvider.java
index 2af6f9f..a02b00a 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiAttachmentProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiAttachmentProvider.java
@@ -18,33 +18,28 @@
*/
package org.apache.wiki.providers;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.exceptions.ProviderException;
+import org.apache.wiki.attachment.Attachment;
+import org.apache.wiki.search.QueryItem;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Date;
import java.util.List;
-import org.apache.wiki.WikiPage;
-import org.apache.wiki.WikiProvider;
-import org.apache.wiki.api.exceptions.ProviderException;
-import org.apache.wiki.attachment.Attachment;
-import org.apache.wiki.search.QueryItem;
/**
- * Defines an attachment provider - a class which is capable of saving
- * binary data as attachments.
+ * Defines an attachment provider - a class which is capable of saving binary data as attachments.
* <P>
- * The difference between this class and WikiPageProvider is that there
- * PageProviders handle Unicode text, whereas we handle binary data.
- * While there are quite a lot of similarities in how we handle
- * things, many providers can really use just one. In addition,
- * since binary files can be really large, we rely on
- * Input/OutputStreams.
- *
+ * The difference between this class and WikiPageProvider is that there PageProviders handle Unicode text, whereas we handle binary data.
+ * While there are quite a lot of similarities in how we handle things, many providers can really use just one. In addition,
+ * since binary files can be really large, we rely on Input/OutputStreams.
*/
-public interface WikiAttachmentProvider
- extends WikiProvider
-{
+public interface WikiAttachmentProvider extends WikiProvider {
+
/**
* Put new attachment data.
*
@@ -53,23 +48,17 @@ public interface WikiAttachmentProvider
* @throws IOException If writing fails
* @throws ProviderException If there are other errors.
*/
- void putAttachmentData( Attachment att, InputStream data )
- throws ProviderException,
- IOException;
+ void putAttachmentData( Attachment att, InputStream data ) throws ProviderException, IOException;
/**
* Get attachment data.
*
* @param att The attachment
- * @return An InputStream which you contains the raw data of the object. It's your
- * responsibility to close it.
+ * @return An InputStream which you contains the raw data of the object. It's your responsibility to close it.
* @throws ProviderException If the attachment cannot be found
* @throws IOException If the attachment cannot be opened
*/
-
- InputStream getAttachmentData( Attachment att )
- throws ProviderException,
- IOException;
+ InputStream getAttachmentData( Attachment att ) throws ProviderException, IOException;
/**
* Lists all attachments attached to a page.
@@ -78,25 +67,22 @@ public interface WikiAttachmentProvider
* @return A collection of Attachment objects. May be empty, but never null.
* @throws ProviderException If something goes wrong when listing the attachments.
*/
- List< Attachment > listAttachments( WikiPage page )
- throws ProviderException;
+ List< Attachment > listAttachments( WikiPage page ) throws ProviderException;
/**
* Finds attachments based on the query.
+ *
* @param query An array of QueryItem objects to search for
* @return A Collection of Attachment objects. May be empty, but never null.
*/
Collection< Attachment > findAttachments( QueryItem[] query );
/**
- * Lists changed attachments since given date. Can also be used to fetch
- * a list of all pages.
+ * Lists changed attachments since given date. Can also be used to fetch a list of all pages.
* <P>
- * This is different from WikiPageProvider, where you basically get a list
- * of all pages, then sort them locally. However, since some providers
- * can be more efficient in locating recently changed files (like any database)
- * than our non-optimized Java
- * code, it makes more sense to fetch the whole list this way.
+ * This is different from WikiPageProvider, where you basically get a list of all pages, then sort them locally. However, since some
+ * providers can be more efficient in locating recently changed files (like any database) than our non-optimized Java code, it makes
+ * more sense to fetch the whole list this way.
* <P>
* To get all files, call this with Date(0L);
*
@@ -104,8 +90,7 @@ public interface WikiAttachmentProvider
* @return A List of Attachment objects, in most-recently-changed first order.
* @throws ProviderException If something goes wrong.
*/
- List<Attachment> listAllChanged( Date timestamp )
- throws ProviderException;
+ List< Attachment > listAllChanged( Date timestamp ) throws ProviderException;
/**
* Returns info about an attachment.
@@ -116,64 +101,46 @@ public interface WikiAttachmentProvider
* @return An attachment object
* @throws ProviderException If the attachment cannot be found or some other error occurs.
*/
- Attachment getAttachmentInfo( WikiPage page, String name, int version )
- throws ProviderException;
+ Attachment getAttachmentInfo( WikiPage page, String name, int version ) throws ProviderException;
/**
- * Returns version history. Each element should be
- * an Attachment.
+ * Returns version history. Each element should be an Attachment.
*
* @param att The attachment for which to find the version history for.
* @return A List of Attachment objects.
*/
- List<Attachment> getVersionHistory( Attachment att );
+ List< Attachment > getVersionHistory( Attachment att );
/**
- * Removes a specific version from the repository. The implementations
- * should really do no more security checks, since that is the domain
- * of the AttachmentManager. Just delete it as efficiently as you can.
+ * Removes a specific version from the repository. The implementations should really do no more security checks, since that is the
+ * domain of the AttachmentManager. Just delete it as efficiently as you can.
*
* @since 2.0.19.
- *
- * @param att Attachment to be removed. The version field is checked, and thus
- * only that version is removed.
- *
+ * @param att Attachment to be removed. The version field is checked, and thus only that version is removed.
* @throws ProviderException If the attachment cannot be removed for some reason.
*/
-
- void deleteVersion( Attachment att )
- throws ProviderException;
+ void deleteVersion( Attachment att ) throws ProviderException;
/**
- * Removes an entire page from the repository. The implementations
- * should really do no more security checks, since that is the domain
- * of the AttachmentManager. Just delete it as efficiently as you can. You should also
- * delete any auxiliary files and directories that belong to this attachment,
- * IF they were created
- * by this provider.
+ * Removes an entire page from the repository. The implementations should really do no more security checks, since that is the domain
+ * of the AttachmentManager. Just delete it as efficiently as you can. You should also delete any auxiliary files and directories
+ * that belong to this attachment, IF they were created by this provider.
*
* @since 2.0.17.
- *
* @param att Attachment to delete.
- *
* @throws ProviderException If the page could not be removed for some reason.
*/
- void deleteAttachment( Attachment att )
- throws ProviderException;
+ void deleteAttachment( Attachment att ) throws ProviderException;
/**
- * Move all the attachments for a given page so that they are attached to a
- * new page.
+ * Move all the attachments for a given page so that they are attached to a new page.
*
* @param oldParent Name of the page we are to move the attachments from.
* @param newParent Name of the page we are to move the attachments to.
- *
- * @throws ProviderException If the attachments could not be moved for some
- * reason.
+ * @throws ProviderException If the attachments could not be moved for some reason.
*/
- void moveAttachmentsForPage( String oldParent,
- String newParent )
- throws ProviderException;
+ void moveAttachmentsForPage( String oldParent, String newParent ) throws ProviderException;
+
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiPageProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiPageProvider.java
index a0540fa..5fde3c9 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiPageProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/WikiPageProvider.java
@@ -18,36 +18,31 @@
*/
package org.apache.wiki.providers;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.search.QueryItem;
import org.apache.wiki.search.SearchResult;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
/**
* Each Wiki page provider should implement this interface.
* <P>
- * You can build whatever page providers based on this, just
- * leave the unused methods do something useful.
+ * You can build whatever page providers based on this, just leave the unused methods do something useful.
* <P>
- * WikiPageProvider uses Strings and ints to refer to pages. This may
- * be a bit odd, since WikiAttachmentProviders all use Attachment
- * instead of name/version. We will perhaps modify these in the
- * future. In the mean time, name/version is quite sufficient.
+ * WikiPageProvider uses Strings and ints to refer to pages. This may be a bit odd, since WikiAttachmentProviders all use Attachment
+ * instead of name/version. We will perhaps modify these in the future. In the mean time, name/version is quite sufficient.
* <P>
- * FIXME: In reality we should have an AbstractWikiPageProvider,
- * which would provide intelligent backups for subclasses.
+ * FIXME: In reality we should have an AbstractWikiPageProvider, which would provide intelligent backups for subclasses.
*/
public interface WikiPageProvider extends WikiProvider {
/**
- * Attempts to save the page text for page "page". Note that the
- * provider creates a new version regardless of what the version
+ * Attempts to save the page text for page "page". Note that the provider creates a new version regardless of what the version
* parameter of the WikiPage is.
*
* @param page The WikiPage to save
@@ -71,12 +66,10 @@ public interface WikiPageProvider extends WikiProvider {
* @param version The version to check
* @return True, if page exists; false otherwise.
*/
-
- boolean pageExists(String page, int version);
+ boolean pageExists( String page, int version );
/**
- * Finds pages based on the query. Only applicable to providers
- * which implement the FastSearch interface. Otherwise JSPWiki
+ * Finds pages based on the query. Only applicable to providers which implement the FastSearch interface. Otherwise JSPWiki
* will use its internal cache.
* <p>
* This method should really be a part of the FastSearch IF.
@@ -97,8 +90,7 @@ public interface WikiPageProvider extends WikiProvider {
WikiPage getPageInfo( String page, int version ) throws ProviderException;
/**
- * Returns all pages. Each element in the returned
- * Collection should be a WikiPage.
+ * Returns all pages. Each element in the returned Collection should be a WikiPage.
*
* @return A collection of WikiPages
* @throws ProviderException If something goes wrong.
@@ -124,8 +116,7 @@ public interface WikiPageProvider extends WikiProvider {
int getPageCount() throws ProviderException;
/**
- * Returns version history. Each element should be
- * a WikiPage.
+ * Returns version history. Each element should be a WikiPage.
*
* @param page The name of the page to get the history from.
* @return A collection of WikiPages.
@@ -138,43 +129,32 @@ public interface WikiPageProvider extends WikiProvider {
*
* @param page Name of the page to fetch.
* @param version Version of the page to fetch.
- *
* @return The content of the page, or null, if the page does not exist.
* @throws ProviderException If something goes wrong.
*/
String getPageText( String page, int version ) throws ProviderException;
/**
- * Removes a specific version from the repository. The implementations
- * should really do no more security checks, since that is the domain
- * of the PageManager. Just delete it as efficiently as you can.
+ * Removes a specific version from the repository. The implementations should really do no more security checks, since that is the
+ * domain of the PageManager. Just delete it as efficiently as you can.
*
* @since 2.0.17.
- *
* @param pageName Name of the page to be removed.
* @param version Version of the page to be removed. May be LATEST_VERSION.
- *
* @throws ProviderException If the page cannot be removed for some reason.
*/
void deleteVersion( String pageName, int version ) throws ProviderException;
/**
- * Removes an entire page from the repository. The implementations
- * should really do no more security checks, since that is the domain
- * of the PageManager. Just delete it as efficiently as you can. You should also
- * delete any auxiliary files that belong to this page, IF they were created
- * by this provider.
+ * Removes an entire page from the repository. The implementations should really do no more security checks, since that is the domain
+ * of the PageManager. Just delete it as efficiently as you can. You should also delete any auxiliary files that belong to this page,
+ * IF they were created by this provider.
*
- * <P>The reason why this is named differently from
- * deleteVersion() (logically, this method should be an
- * overloaded version) is that I want to be absolutely sure I
- * don't accidentally use the wrong method. With overloading
- * something like that happens sometimes...
+ * <P>The reason why this is named differently from deleteVersion() (logically, this method should be an overloaded version) is that
+ * I want to be absolutely sure I don't accidentally use the wrong method. With overloading something like that happens sometimes...
*
* @since 2.0.17.
- *
* @param pageName Name of the page to be removed completely.
- *
* @throws ProviderException If the page could not be removed for some reason.
*/
void deletePage( String pageName ) throws ProviderException;
@@ -184,7 +164,6 @@ public interface WikiPageProvider extends WikiProvider {
*
* @param from Name of the page to move.
* @param to New name of the page.
- *
* @throws ProviderException If the page could not be moved for some reason.
*/
void movePage(String from, String to) throws ProviderException;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java
index 12e2887..981294f 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java
@@ -20,13 +20,15 @@ package org.apache.wiki.search;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.attachment.Attachment;
+import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.auth.AuthorizationManager;
import org.apache.wiki.auth.permissions.PagePermission;
+import org.apache.wiki.pages.PageManager;
import org.apache.wiki.providers.WikiPageProvider;
import java.io.IOException;
@@ -45,25 +47,24 @@ import java.util.TreeSet;
public class BasicSearchProvider implements SearchProvider {
private static final Logger log = Logger.getLogger( BasicSearchProvider.class );
-
- private WikiEngine m_engine;
+ private Engine m_engine;
/**
* {@inheritDoc}
*/
- public void initialize( final WikiEngine engine, final Properties props ) throws NoRequiredPropertyException, IOException {
+ @Override public void initialize( final Engine engine, final Properties props ) throws NoRequiredPropertyException, IOException {
m_engine = engine;
}
/**
* {@inheritDoc}
*/
- public void pageRemoved( final WikiPage page ) {}
+ @Override public void pageRemoved( final WikiPage page ) {}
/**
* {@inheritDoc}
*/
- public void reindexPage( final WikiPage page ) {}
+ @Override public void reindexPage( final WikiPage page ) {}
/**
* Parses a query into something that we can use.
@@ -111,10 +112,10 @@ public class BasicSearchProvider implements SearchProvider {
}
private String attachmentNames( final WikiPage page ) {
- if( m_engine.getAttachmentManager().hasAttachments( page ) ) {
+ if( m_engine.getManager( AttachmentManager.class ).hasAttachments( page ) ) {
final List< Attachment > attachments;
try {
- attachments = m_engine.getAttachmentManager().listAttachments( page );
+ attachments = m_engine.getManager( AttachmentManager.class ).listAttachments( page );
} catch( final ProviderException e ) {
log.error( "Unable to get attachments for page", e );
return "";
@@ -139,13 +140,13 @@ public class BasicSearchProvider implements SearchProvider {
final SearchMatcher matcher = new SearchMatcher( m_engine, query );
final Collection< WikiPage > allPages;
try {
- allPages = m_engine.getPageManager().getAllPages();
+ allPages = m_engine.getManager( PageManager.class ).getAllPages();
} catch( final ProviderException pe ) {
log.error( "Unable to retrieve page list", pe );
return null;
}
- final AuthorizationManager mgr = m_engine.getAuthorizationManager();
+ final AuthorizationManager mgr = m_engine.getManager( AuthorizationManager.class );
for( final WikiPage page : allPages ) {
try {
@@ -154,7 +155,7 @@ public class BasicSearchProvider implements SearchProvider {
if( wikiContext == null || mgr.checkPermission( wikiContext.getWikiSession(), pp ) ) {
final String pageName = page.getName();
final String pageContent =
- m_engine.getPageManager().getPageText( pageName, WikiPageProvider.LATEST_VERSION ) + attachmentNames( page );
+ m_engine.getManager( PageManager.class ).getPageText( pageName, WikiPageProvider.LATEST_VERSION ) + attachmentNames( page );
final SearchResult comparison = matcher.matchPageContent( pageName, pageContent );
if( comparison != null ) {
res.add( comparison );
@@ -174,14 +175,14 @@ public class BasicSearchProvider implements SearchProvider {
/**
* {@inheritDoc}
*/
- public Collection< SearchResult > findPages( final String query, final WikiContext wikiContext ) {
+ @Override public Collection< SearchResult > findPages( final String query, final WikiContext wikiContext ) {
return findPages( parseQuery( query ), wikiContext );
}
/**
* {@inheritDoc}
*/
- public String getProviderInfo() {
+ @Override public String getProviderInfo() {
return "BasicSearchProvider";
}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
index c6ab12a..30fbed8 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
@@ -50,15 +50,16 @@ import org.apache.wiki.InternalWikiException;
import org.apache.wiki.WatchDog;
import org.apache.wiki.WikiBackgroundThread;
import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
import org.apache.wiki.WikiProvider;
+import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
import org.apache.wiki.attachment.Attachment;
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.auth.AuthorizationManager;
import org.apache.wiki.auth.permissions.PagePermission;
+import org.apache.wiki.pages.PageManager;
import org.apache.wiki.providers.WikiPageProvider;
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.FileUtil;
@@ -90,7 +91,7 @@ public class LuceneSearchProvider implements SearchProvider {
protected static final Logger log = Logger.getLogger(LuceneSearchProvider.class);
- private WikiEngine m_engine;
+ private Engine m_engine;
private Executor searchExecutor;
// Lucene properties.
@@ -131,7 +132,7 @@ public class LuceneSearchProvider implements SearchProvider {
* {@inheritDoc}
*/
@Override
- public void initialize( final WikiEngine engine, final Properties props ) throws NoRequiredPropertyException, IOException {
+ public void initialize( final Engine engine, final Properties props ) throws NoRequiredPropertyException, IOException {
m_engine = engine;
searchExecutor = Executors.newCachedThreadPool();
@@ -176,7 +177,7 @@ public class LuceneSearchProvider implements SearchProvider {
*
* @return Current WikiEngine
*/
- protected WikiEngine getEngine()
+ protected Engine getEngine()
{
return m_engine;
}
@@ -204,17 +205,17 @@ public class LuceneSearchProvider implements SearchProvider {
final Directory luceneDir = new SimpleFSDirectory( dir.toPath() );
try( final IndexWriter writer = getIndexWriter( luceneDir ) ) {
- final Collection< WikiPage > allPages = m_engine.getPageManager().getAllPages();
+ final Collection< WikiPage > allPages = m_engine.getManager( PageManager.class ).getAllPages();
for( final WikiPage page : allPages ) {
try {
- final String text = m_engine.getPageManager().getPageText( page.getName(), WikiProvider.LATEST_VERSION );
+ final String text = m_engine.getManager( PageManager.class ).getPageText( page.getName(), WikiProvider.LATEST_VERSION );
luceneIndexPage( page, text, writer );
} catch( final IOException e ) {
log.warn( "Unable to index page " + page.getName() + ", continuing to next ", e );
}
}
- final Collection< Attachment > allAttachments = m_engine.getAttachmentManager().getAllAttachments();
+ final Collection< Attachment > allAttachments = m_engine.getManager( AttachmentManager.class ).getAllAttachments();
for( final Attachment att : allAttachments ) {
try {
final String text = getAttachmentContent( att.getName(), WikiProvider.LATEST_VERSION );
@@ -252,7 +253,7 @@ public class LuceneSearchProvider implements SearchProvider {
* @return the content of the Attachment as a String.
*/
protected String getAttachmentContent( final String attachmentName, final int version ) {
- final AttachmentManager mgr = m_engine.getAttachmentManager();
+ final AttachmentManager mgr = m_engine.getManager( AttachmentManager.class );
try {
final Attachment att = mgr.getAttachmentInfo( attachmentName, version );
//FIXME: Find out why sometimes att is null
@@ -272,7 +273,7 @@ public class LuceneSearchProvider implements SearchProvider {
* This should be replaced /moved to Attachment search providers or some other 'pluggable' way to search attachments
*/
protected String getAttachmentContent( final Attachment att ) {
- final AttachmentManager mgr = m_engine.getAttachmentManager();
+ final AttachmentManager mgr = m_engine.getManager( AttachmentManager.class );
//FIXME: Add attachment plugin structure
final String filename = att.getFileName();
@@ -378,7 +379,7 @@ public class LuceneSearchProvider implements SearchProvider {
// Now add the names of the attachments of this page
try {
- final List< Attachment > attachments = m_engine.getAttachmentManager().listAttachments( page );
+ final List< Attachment > attachments = m_engine.getManager( AttachmentManager.class ).listAttachments( page );
String attachmentNames = "";
for( final Attachment att : attachments ) {
@@ -434,9 +435,9 @@ public class LuceneSearchProvider implements SearchProvider {
// TODO: Think if this was better done in the thread itself?
if( page instanceof Attachment ) {
- text = getAttachmentContent( (Attachment) page );
+ text = getAttachmentContent( ( Attachment )page );
} else {
- text = m_engine.getPageManager().getPureText( page );
+ text = m_engine.getManager( PageManager.class ).getPureText( page );
}
if( text != null ) {
@@ -490,14 +491,14 @@ public class LuceneSearchProvider implements SearchProvider {
}
final ScoreDoc[] hits = searcher.search(luceneQuery, MAX_SEARCH_HITS).scoreDocs;
- final AuthorizationManager mgr = m_engine.getAuthorizationManager();
+ final AuthorizationManager mgr = m_engine.getManager( AuthorizationManager.class );
list = new ArrayList<>(hits.length);
for( final ScoreDoc hit : hits ) {
final int docID = hit.doc;
final Document doc = searcher.doc( docID );
final String pageName = doc.get( LUCENE_ID );
- final WikiPage page = m_engine.getPageManager().getPage( pageName, WikiPageProvider.LATEST_VERSION );
+ final WikiPage page = m_engine.getManager( PageManager.class ).getPage( pageName, WikiPageProvider.LATEST_VERSION );
if( page != null ) {
final PagePermission pp = new PagePermission( page, PagePermission.VIEW_ACTION );
@@ -555,7 +556,7 @@ public class LuceneSearchProvider implements SearchProvider {
private WatchDog m_watchdog;
- private LuceneUpdater( final WikiEngine engine, final LuceneSearchProvider provider, final int initialDelay, final int indexDelay ) {
+ private LuceneUpdater( final Engine engine, final LuceneSearchProvider provider, final int initialDelay, final int indexDelay ) {
super( engine, indexDelay );
m_provider = provider;
m_initialDelay = initialDelay;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java
index c741ac7..1c2a4a4 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java
@@ -18,8 +18,8 @@
*/
package org.apache.wiki.search;
-import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.core.Engine;
import java.io.BufferedReader;
import java.io.IOException;
@@ -36,7 +36,7 @@ import java.io.StringReader;
public class SearchMatcher {
private QueryItem[] m_queries;
- private WikiEngine m_engine;
+ private Engine m_engine;
/**
* Creates a new SearchMatcher.
@@ -44,7 +44,7 @@ public class SearchMatcher {
* @param engine The WikiEngine
* @param queries A list of queries
*/
- public SearchMatcher( final WikiEngine engine, final QueryItem[] queries ) {
+ public SearchMatcher( final Engine engine, final QueryItem[] queries ) {
m_engine = engine;
m_queries = queries != null ? queries.clone() : null;
}
@@ -134,7 +134,7 @@ public class SearchMatcher {
* Returns Wikipage for this result.
* @return WikiPage
*/
- public WikiPage getPage() {
+ @Override public WikiPage getPage() {
return m_page;
}
@@ -143,7 +143,7 @@ public class SearchMatcher {
*
* @return Score from 0+
*/
- public int getScore() {
+ @Override public int getScore() {
return m_score;
}
@@ -152,7 +152,7 @@ public class SearchMatcher {
*
* @return an empty array
*/
- public String[] getContexts() {
+ @Override public String[] getContexts() {
// Unimplemented
return new String[0];
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/providers/CounterProvider.java b/jspwiki-main/src/test/java/org/apache/wiki/providers/CounterProvider.java
index 1003e56..4a29105 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/providers/CounterProvider.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/providers/CounterProvider.java
@@ -18,6 +18,12 @@
*/
package org.apache.wiki.providers;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.exceptions.ProviderException;
+import org.apache.wiki.search.QueryItem;
+import org.apache.wiki.search.SearchResult;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -25,35 +31,24 @@ import java.util.List;
import java.util.Properties;
import java.util.Vector;
-import org.apache.log4j.Logger;
-import org.apache.wiki.WikiEngine;
-import org.apache.wiki.WikiPage;
-import org.apache.wiki.api.exceptions.ProviderException;
-import org.apache.wiki.search.QueryItem;
-import org.apache.wiki.search.SearchResult;
-
/**
* A provider who counts the hits to different parts.
*/
-public class CounterProvider
- implements WikiPageProvider
-{
+public class CounterProvider implements WikiPageProvider {
+
public int m_getPageCalls = 0;
public int m_pageExistsCalls = 0;
public int m_getPageTextCalls = 0;
public int m_getAllPagesCalls = 0;
public int m_initCalls = 0;
- static Logger log = Logger.getLogger( CounterProvider.class );
-
WikiPage[] m_pages = new WikiPage[0];
String m_defaultText = "[Foo], [Bar], [Blat], [Blah]";
@Override
- public void initialize( WikiEngine engine, Properties props )
- {
+ public void initialize( final Engine engine, final Properties props ) {
m_pages = new WikiPage[]
{ new WikiPage(engine, "Foo"),
new WikiPage(engine, "Bar"),
@@ -77,13 +72,13 @@ public class CounterProvider
}
@Override
- public void putPageText( WikiPage page, String text )
+ public void putPageText( final WikiPage page, final String text )
throws ProviderException
{
}
@Override
- public boolean pageExists( String page )
+ public boolean pageExists( final String page )
{
m_pageExistsCalls++;
@@ -91,18 +86,18 @@ public class CounterProvider
}
@Override
- public boolean pageExists( String page, int version )
+ public boolean pageExists( final String page, final int version )
{
return pageExists (page);
}
@Override
- public Collection< SearchResult > findPages( QueryItem[] query )
+ public Collection< SearchResult > findPages( final QueryItem[] query )
{
return null;
}
- private WikiPage findPage( String page )
+ private WikiPage findPage( final String page )
{
for( int i = 0; i < m_pages.length; i++ )
{
@@ -114,14 +109,11 @@ public class CounterProvider
}
@Override
- public WikiPage getPageInfo( String page, int version )
+ public WikiPage getPageInfo( final String page, final int version )
{
m_getPageCalls++;
- //System.out.println("GETPAGEINFO="+page);
- //TestEngine.trace();
-
- WikiPage p = findPage(page);
+ final WikiPage p = findPage(page);
return p;
}
@@ -131,7 +123,7 @@ public class CounterProvider
{
m_getAllPagesCalls++;
- List<WikiPage> l = new ArrayList<>();
+ final List<WikiPage> l = new ArrayList<>();
for( int i = 0; i < m_pages.length; i++ )
{
@@ -142,7 +134,7 @@ public class CounterProvider
}
@Override
- public Collection< WikiPage > getAllChangedSince( Date date )
+ public Collection< WikiPage > getAllChangedSince( final Date date )
{
return new ArrayList<>();
}
@@ -154,25 +146,25 @@ public class CounterProvider
}
@Override
- public List< WikiPage > getVersionHistory( String page )
+ public List< WikiPage > getVersionHistory( final String page )
{
return new Vector<>();
}
@Override
- public String getPageText( String page, int version )
+ public String getPageText( final String page, final int version )
{
m_getPageTextCalls++;
return m_defaultText;
}
@Override
- public void deleteVersion( String page, int version )
+ public void deleteVersion( final String page, final int version )
{
}
@Override
- public void deletePage( String page )
+ public void deletePage( final String page )
{
}
@@ -180,10 +172,8 @@ public class CounterProvider
* @see org.apache.wiki.providers.WikiPageProvider#movePage(java.lang.String, java.lang.String)
*/
@Override
- public void movePage( String from, String to ) throws ProviderException
+ public void movePage( final String from, final String to ) throws ProviderException
{
- // TODO Auto-generated method stub
-
}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/providers/VerySimpleProvider.java b/jspwiki-main/src/test/java/org/apache/wiki/providers/VerySimpleProvider.java
index a3067d0..f7fa810 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/providers/VerySimpleProvider.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/providers/VerySimpleProvider.java
@@ -18,6 +18,12 @@
*/
package org.apache.wiki.providers;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.exceptions.ProviderException;
+import org.apache.wiki.search.QueryItem;
+import org.apache.wiki.search.SearchResult;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -25,12 +31,6 @@ import java.util.List;
import java.util.Properties;
import java.util.Vector;
-import org.apache.wiki.WikiEngine;
-import org.apache.wiki.WikiPage;
-import org.apache.wiki.api.exceptions.ProviderException;
-import org.apache.wiki.search.QueryItem;
-import org.apache.wiki.search.SearchResult;
-
/**
* This is a simple provider that is used by some of the tests. It has some
* specific behaviours, like it always contains a single page.
@@ -53,10 +53,10 @@ public class VerySimpleProvider implements WikiPageProvider
*/
public static final String AUTHOR = "default-author";
- private WikiEngine m_engine;
+ private Engine m_engine;
@Override
- public void initialize( WikiEngine engine, Properties props )
+ public void initialize( final Engine engine, final Properties props )
{
m_engine = engine;
}
@@ -68,7 +68,7 @@ public class VerySimpleProvider implements WikiPageProvider
}
@Override
- public void putPageText( WikiPage page, String text )
+ public void putPageText( final WikiPage page, final String text )
throws ProviderException
{
}
@@ -77,7 +77,7 @@ public class VerySimpleProvider implements WikiPageProvider
* Always returns true.
*/
@Override
- public boolean pageExists( String page )
+ public boolean pageExists( final String page )
{
return true;
}
@@ -86,7 +86,7 @@ public class VerySimpleProvider implements WikiPageProvider
* Always returns true.
*/
@Override
- public boolean pageExists( String page, int version )
+ public boolean pageExists( final String page, final int version )
{
return true;
}
@@ -95,7 +95,7 @@ public class VerySimpleProvider implements WikiPageProvider
* Always returns null.
*/
@Override
- public Collection< SearchResult > findPages( QueryItem[] query )
+ public Collection< SearchResult > findPages( final QueryItem[] query )
{
return null;
}
@@ -104,12 +104,12 @@ public class VerySimpleProvider implements WikiPageProvider
* Returns always a valid WikiPage.
*/
@Override
- public WikiPage getPageInfo( String page, int version )
+ public WikiPage getPageInfo( final String page, final int version )
{
m_latestReq = page;
m_latestVers = version;
- WikiPage p = new WikiPage( m_engine, page );
+ final WikiPage p = new WikiPage( m_engine, page );
p.setVersion( 5 );
p.setAuthor( AUTHOR );
p.setLastModified( new Date(0L) );
@@ -122,7 +122,7 @@ public class VerySimpleProvider implements WikiPageProvider
@Override
public Collection< WikiPage > getAllPages()
{
- List< WikiPage > l = new ArrayList<>();
+ final List< WikiPage > l = new ArrayList<>();
l.add( getPageInfo( PAGENAME, 5 ) );
return l;
}
@@ -131,7 +131,7 @@ public class VerySimpleProvider implements WikiPageProvider
* Returns the same as getAllPages().
*/
@Override
- public Collection< WikiPage > getAllChangedSince( Date date )
+ public Collection< WikiPage > getAllChangedSince( final Date date )
{
return getAllPages();
}
@@ -149,7 +149,7 @@ public class VerySimpleProvider implements WikiPageProvider
* Always returns an empty list.
*/
@Override
- public List< WikiPage > getVersionHistory( String page )
+ public List< WikiPage > getVersionHistory( final String page )
{
return new Vector<>();
}
@@ -159,7 +159,7 @@ public class VerySimpleProvider implements WikiPageProvider
* then returns an empty string.
*/
@Override
- public String getPageText( String page, int version )
+ public String getPageText( final String page, final int version )
{
m_latestReq = page;
m_latestVers = version;
@@ -168,12 +168,12 @@ public class VerySimpleProvider implements WikiPageProvider
}
@Override
- public void deleteVersion( String page, int version )
+ public void deleteVersion( final String page, final int version )
{
}
@Override
- public void deletePage( String page )
+ public void deletePage( final String page )
{
}
@@ -181,7 +181,7 @@ public class VerySimpleProvider implements WikiPageProvider
* @see org.apache.wiki.providers.WikiPageProvider#movePage(java.lang.String, java.lang.String)
*/
@Override
- public void movePage( String from, String to ) throws ProviderException
+ public void movePage( final String from, final String to ) throws ProviderException
{
// TODO Auto-generated method stub
diff --git a/jspwiki-tika-searchprovider/src/main/java/org/apache/wiki/search/tika/TikaSearchProvider.java b/jspwiki-tika-searchprovider/src/main/java/org/apache/wiki/search/tika/TikaSearchProvider.java
index 2d9a95e..4f778d0 100644
--- a/jspwiki-tika-searchprovider/src/main/java/org/apache/wiki/search/tika/TikaSearchProvider.java
+++ b/jspwiki-tika-searchprovider/src/main/java/org/apache/wiki/search/tika/TikaSearchProvider.java
@@ -54,8 +54,8 @@ import java.util.Set;
public class TikaSearchProvider extends LuceneSearchProvider {
private static final Logger LOG = Logger.getLogger( TikaSearchProvider.class );
- AutoDetectParser parser;
- Set< String > textualMetadataFields;
+ final AutoDetectParser parser;
+ final Set< String > textualMetadataFields;
public TikaSearchProvider() {
parser = new AutoDetectParser();
@@ -91,8 +91,7 @@ public class TikaSearchProvider extends LuceneSearchProvider {
*/
@Override
protected String getAttachmentContent( final Attachment att ) {
- // LOG.debug("indexing "+att.getFileName());
- final AttachmentManager mgr = getEngine().getAttachmentManager();
+ final AttachmentManager mgr = getEngine().getManager( AttachmentManager.class );
final StringBuilder out = new StringBuilder();
try( final InputStream attStream = mgr.getAttachmentStream( att ) ) {
@@ -106,14 +105,14 @@ public class TikaSearchProvider extends LuceneSearchProvider {
out.append( handler.toString() );
final String[] names = metadata.names();
- for( int j = 0; j < names.length; j++ ) {
- if( textualMetadataFields.contains( names[ j ] ) ) {
- out.append( " " ).append( metadata.get( names[ j ] ) );
+ for( final String name : names ) {
+ if( textualMetadataFields.contains( name ) ) {
+ out.append( " " ).append( metadata.get( name ) );
}
}
- } catch( TikaException | SAXException e ) {
+ } catch( final TikaException | SAXException e ) {
LOG.error( "Attachment cannot be parsed", e );
- } catch( ProviderException | IOException e ) {
+ } catch( final ProviderException | IOException e ) {
LOG.error( "Attachment cannot be loaded", e );
}