1
// Copyright (c) 2004-2006 by Leif Frenzel - see http://leiffrenzel.de
2
package org.vcs.bazaar.eclipse.core.repository;
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;
14
/** <p>contains API to validate repository-related information.</p>
16
* @author Leif Frenzel
18
public class Validator {
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
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 );
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 );
38
public static IStatus validateRepository( final URI location )
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(),
48
BazaarText.Validator_URI_SCHEMA_NOT_RECOGNISED, null );