~piastucki/bzr-eclipse/history-view-enhancements

« back to all changes in this revision

Viewing changes to org.vcs.bazaar.eclipse.core/src/org/vcs/bazaar/eclipse/core/repository/Validator.java

  • Committer: Guillermo Gonzalez
  • Date: 2007-03-14 12:15:50 UTC
  • Revision ID: guillo.gonzo@gmail.com-20070314121550-tltk3b6f3zblf0dh
Initial commit with the new code layout.
Now starts the real work

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2004-2006 by Leif Frenzel - see http://leiffrenzel.de
 
2
package org.vcs.bazaar.eclipse.core.repository;
 
3
 
 
4
import java.io.File;
 
5
import java.net.URI;
 
6
 
 
7
import org.eclipse.core.runtime.IStatus;
 
8
import org.eclipse.core.runtime.Status;
 
9
import org.vcs.bazaar.eclipse.BazaarEclipsePlugin;
 
10
import org.vcs.bazaar.eclipse.core.utils.DefaultStatus;
 
11
import org.vcs.bazaar.eclipse.core.utils.ResourceUtil;
 
12
import org.vcs.bazaar.eclipse.internal.BazaarText;
 
13
 
 
14
/** <p>contains API to validate repository-related information.</p>
 
15
  * 
 
16
  * @author Leif Frenzel
 
17
  */
 
18
public class Validator {
 
19
 
 
20
  /** <p>validates whether the specified path is the path to a darcs 
 
21
    * repository folder, or one of it's subfolders, on the local 
 
22
    * filesystem.</p> */
 
23
  public static IStatus validateLocalRepository( final URI path ) {
 
24
    DefaultStatus result = new DefaultStatus();
 
25
    if( path == null || path.getScheme() == "file" || path.getPath().length() == 0 ) { //$NON-NLS-1$
 
26
      result.setError( BazaarText.Validator_noFile );
 
27
    } else {
 
28
      File file = new File( path );
 
29
      if( !file.exists() || !file.isDirectory() ) {
 
30
        result.setError( BazaarText.Validator_nonExistent + path );
 
31
      } else if( !ResourceUtil.validateRepositoryFolder( file ) ) {
 
32
        result.setError( BazaarText.Validator_noRepo + path );
 
33
      }
 
34
    }
 
35
    return result;
 
36
  }
 
37
  
 
38
  public static IStatus validateRepository( final URI location ) 
 
39
  {
 
40
    IStatus status;
 
41
    if("file".equals(location.getScheme())) { //$NON-NLS-1$
 
42
      status = validateLocalRepository(location);
 
43
    } else if("http".equals(location.getScheme())) { //$NON-NLS-1$
 
44
      status = new DefaultStatus();
 
45
    } else { // no known validator for this schema?
 
46
      status = new Status( IStatus.ERROR, BazaarEclipsePlugin.getPluginId(),
 
47
          IStatus.ERROR,
 
48
          BazaarText.Validator_URI_SCHEMA_NOT_RECOGNISED, null );
 
49
    }
 
50
    return status;
 
51
  }
 
52
}