jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r759566 - /incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java
Date Sat, 28 Mar 2009 20:05:38 GMT
Author: jalkanen
Date: Sat Mar 28 20:05:38 2009
New Revision: 759566

URL: http://svn.apache.org/viewvc?rev=759566&view=rev
Log:
Removed unused code.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java?rev=759566&r1=759565&r2=759566&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java Sat
Mar 28 20:05:38 2009
@@ -20,21 +20,6 @@
  */
 package org.apache.wiki.providers;
 
-import java.io.*;
-import java.util.*;
-
-import org.apache.wiki.*;
-import org.apache.wiki.api.WikiPage;
-import org.apache.wiki.content.PageAlreadyExistsException;
-import org.apache.wiki.content.WikiName;
-import org.apache.wiki.log.Logger;
-import org.apache.wiki.log.LoggerFactory;
-import org.apache.wiki.search.QueryItem;
-import org.apache.wiki.search.SearchMatcher;
-import org.apache.wiki.search.SearchResult;
-import org.apache.wiki.search.SearchResultComparator;
-import org.apache.wiki.util.FileUtil;
-import org.apache.wiki.util.TextUtil;
 
 
 /**
@@ -50,15 +35,7 @@
  *
  */
 public abstract class AbstractFileProvider
-    implements WikiPageProvider
 {
-    private static final Logger   log = LoggerFactory.getLogger(AbstractFileProvider.class);
-    private String m_pageDirectory = "/tmp/";
-    
-    protected String m_encoding;
-    
-    protected WikiEngine m_engine;
-
     /**
      *  Name of the property that defines where page directories are.
      */
@@ -74,455 +51,4 @@
     /** The default encoding. */
     public static final String DEFAULT_ENCODING = "ISO-8859-1";
 
-    private boolean m_windowsHackNeeded = false;
-    
-    /**
-     *  {@inheritDoc}
-     *  @throws FileNotFoundException If the specified page directory does not exist.
-     *  @throws IOException In case the specified page directory is a file, not a directory.
-     */
-    public void initialize( WikiEngine engine, Properties properties )
-        throws NoRequiredPropertyException,
-               IOException, FileNotFoundException
-    {
-        log.debug("Initing FileSystemProvider");
-        m_pageDirectory = WikiEngine.getRequiredProperty( properties, PROP_PAGEDIR );
-
-        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() )
-            {
-                throw new IOException( "Page directory is not a directory: " + f.getAbsolutePath()
);
-            }
-            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") )
-        {
-            m_windowsHackNeeded = true;
-        }
-        
-        log.info( "Wikipages are read from '" + m_pageDirectory + "'" );
-    }
-
-
-    String getPageDirectory()
-    {
-        return m_pageDirectory;
-    }
-
-    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
-     *  and slashes are encoded with the percent notation.
-     *  
-     *  @param pagename The name to mangle
-     *  @return The mangled name.
-     */
-    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( "." ) )
-        {
-            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) )
-                {
-                    pagename = "$$$" + pagename;
-                }
-            }
-        }
-        
-        return pagename;
-    }
-
-    /**
-     *  This makes the reverse of mangleName.
-     *  
-     *  @param filename The filename to unmangle
-     *  @return The unmangled name.
-     */
-    protected String unmangleName( String filename )
-    {
-        // The exception should never happen.
-        try
-        {
-            if( m_windowsHackNeeded && filename.startsWith( "$$$") && filename.length()
> 3 )
-            {
-                filename = filename.substring(3);
-            }
-            
-            return TextUtil.urlDecode( filename, m_encoding );
-        }
-        catch( UnsupportedEncodingException e ) 
-        {
-            throw new InternalWikiException("Faulty encoding; should never happen");
-        }
-    }
-    
-    /**
-     *  Finds a Wiki page from the page repository.
-     *  
-     *  @param page The name of the page.
-     *  @return A File to the page.  May be null.
-     */
-    protected File findPage( String page )
-    {
-        return new File( m_pageDirectory, mangleName(page)+FILE_EXT );
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public boolean pageExists( String page )
-    {
-        File pagefile = findPage( page );
-
-        return pagefile.exists();        
-    }
-
-    /**
-     *  This implementation just returns the current version, as filesystem
-     *  does not provide versioning information for now.
-     *  
-     *  @param page {@inheritDoc}
-     *  @param version {@inheritDoc}
-     *  @throws {@inheritDoc}
-     */
-    public String getPageText( String page, int version )
-        throws ProviderException
-    {
-        return getPageText( page );
-    }
-
-    /**
-     *  Read the text directly from the correct file.
-     */
-    private String getPageText( String page )
-    {
-        String result  = null;
-        InputStream in = null;
-
-        File pagedata = findPage( page );
-
-        if( pagedata.exists() )
-        {
-            if( pagedata.canRead() )
-            {
-                try
-                {          
-                    in = new FileInputStream( pagedata );
-                    result = FileUtil.readContents( in, m_encoding );
-                }
-                catch( IOException e )
-                {
-                    log.error("Failed to read", e);
-                }
-                finally
-                {
-                    try
-                    {
-                        if( in  != null ) in.close();
-                    }
-                    catch( Exception e ) 
-                    {
-                        log.error("Closing failed",e);
-                    }
-                }
-            }
-            else
-            {
-                log.warn("Failed to read page '"+page+"' from '"+pagedata.getAbsolutePath()+"',
possibly a permissions problem");
-            }
-        }
-        else
-        {
-            // This is okay.
-            log.info("New page '"+page+"'");
-        }
-
-        return result;
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public void putPageText( WikiPage page, String text )        
-        throws ProviderException
-    {
-        File file = findPage( page.getName() );
-        PrintWriter out = null;
-
-        try
-        {
-            out = new PrintWriter(new OutputStreamWriter( new FileOutputStream( file ),
-                                                          m_encoding ));
-
-            out.print( text );
-        }
-        catch( IOException e )
-        {
-            log.error( "Saving failed" );
-        }
-        finally
-        {
-            if( out != null ) out.close();
-        }
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public Collection getAllPages()
-        throws ProviderException
-    {
-        log.debug("Getting all pages...");
-
-        ArrayList<WikiPage> set = new ArrayList<WikiPage>();
-
-        File wikipagedir = new File( m_pageDirectory );
-
-        File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
-        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");
-        }
-
-        for( int i = 0; i < wikipages.length; i++ )
-        {
-            String wikiname = wikipages[i].getName();
-            int cutpoint = wikiname.lastIndexOf( FILE_EXT );
-
-            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.");
-                continue;
-            }
-            
-            set.add( page );
-        }
-
-        return set;        
-    }
-
-    /**
-     *  Does not work.
-     *  
-     *  @param date {@inheritDoc}
-     *  @return {@inheritDoc}
-     */
-    public Collection getAllChangedSince( Date date )
-    {
-        return new ArrayList(); // FIXME
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public int getPageCount()
-    {
-        File wikipagedir = new File( m_pageDirectory );
-
-        File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
-        return wikipages.length;
-    }
-
-    /**
-     * Iterates through all WikiPages, matches them against the given query,
-     * and returns a Collection of SearchResult objects.
-     * 
-     * @param query {@inheritDoc}
-     * @return {@inheritDoc}
-     */
-    public Collection findPages( QueryItem[] query )
-    {
-        File wikipagedir = new File( m_pageDirectory );
-        TreeSet<SearchResult> res = new TreeSet<SearchResult>( new SearchResultComparator()
);
-        SearchMatcher matcher = new SearchMatcher( m_engine, query );
-
-        File[] wikipages = wikipagedir.listFiles( new WikiFileFilter() );
-
-        for( int i = 0; i < wikipages.length; i++ )
-        {
-            FileInputStream input = null;
-
-            // 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
-            {
-                input = new FileInputStream( wikipages[i] );
-                String pagetext = FileUtil.readContents( input, m_encoding );
-                SearchResult comparison = matcher.matchPageContent( wikiname, pagetext );
-                if( comparison != null )
-                {
-                    res.add( comparison );
-                }
-            }
-            catch( IOException e )
-            {
-                log.error( "Failed to read " + filename, e );
-            }
-            finally
-            {
-                try
-                {
-                    if( input != null ) input.close();
-                }
-                catch( IOException e ) {} // It's fine to fail silently.
-            }
-        }
-
-        return res;
-    }
-
-    /**
-     *  Always returns the latest version, since FileSystemProvider
-     *  does not support versioning.
-     *  
-     *  @param page {@inheritDoc}
-     *  @param version {@inheritDoc}
-     *  @return {@inheritDoc}
-     *  @throws {@inheritDoc}
-     */
-    public WikiPage getPageInfo( String page, int version )
-        throws ProviderException
-    {
-        File file = findPage( page );
-
-        if( !file.exists() )
-        {
-            return null;
-        }
-
-        WikiPage p;
-        try
-        {
-            p = m_engine.createPage( WikiName.valueOf( page ) );
-        }
-        catch( PageAlreadyExistsException e )
-        {
-            throw new ProviderException( e.getMessage() );
-        }
-        p.setLastModified( new Date(file.lastModified()) );
-
-        return p;
-    }
-
-    /**
-     *  The FileSystemProvider provides only one version.
-     *  
-     *  @param page {@inheritDoc}
-     *  @throws {@inheritDoc}
-     *  @return {@inheritDoc}
-     */
-    public List getVersionHistory( String page )
-        throws ProviderException
-    {
-        ArrayList<WikiPage> list = new ArrayList<WikiPage>();
-
-        list.add( getPageInfo( page, WikiPageProvider.LATEST_VERSION ) );
-
-        return list;
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public String getProviderInfo()
-    {
-        return "";
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public void deleteVersion( String pageName, int version )
-        throws ProviderException
-    {
-        if( version == WikiProvider.LATEST_VERSION )
-        {
-            File f = findPage( pageName );
-
-            f.delete();
-        }
-    }
-
-    /**
-     *  {@inheritDoc}
-     */
-    public void deletePage( String pageName )
-        throws ProviderException
-    {
-        File f = findPage( pageName );
-
-        f.delete();
-    }
-
-    /**
-     *  A simple filter which filters only those filenames which correspond to the
-     *  file extension used.
-     */
-    public static class WikiFileFilter
-        implements FilenameFilter
-    {
-        /**
-         *  {@inheritDoc}
-         */
-        public boolean accept( File dir, String name )
-        {
-            return name.endsWith( FILE_EXT );
-        }
-    }
 }



Mime
View raw message