alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javacvs.commands;

import org.netbeans.lib.cvsclient.*;
import org.netbeans.lib.cvsclient.connection.*;
import org.netbeans.lib.cvsclient.file.*;
import org.netbeans.lib.cvsclient.response.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.util.IgnoreFileFilter;

import org.netbeans.modules.javacvs.passwd.*;
import org.netbeans.modules.javacvs.commands.*;
import java.io.*;
import org.openide.util.NbBundle;
//import org.openide.util.SharedClassObject;
import java.text.MessageFormat;


/** Class implementing the ClientProvider interface that provides context needed for the commands to run.
 *
 * @author mkleint
 */
public class StandardClientProvider implements ClientProvider, Serializable {

    private GlobalOptions globalOptions;
    private String cvsRoot;
    private String localPath;
    private boolean offLine;
    private IgnoreFileFilter fileFilter;
    private static final int STANDARD_PORT = 2401;
    
    private int cvsPort = STANDARD_PORT;
    
    private static final String CVS_DIR = "CVS"; //NOI18N
    private static final String ROOT_FILE = "Root"; //NOI18N
    private static final String CVS_ROOTFILE = File.separator  + CVS_DIR + File.separator + ROOT_FILE;

    
    private File homeDirectory;
    
    /** Creates new StandardClientProvider instance.
     */
    public StandardClientProvider(File homeDir, String root) {
        this(homeDir);
        globalOptions = new GlobalOptions();
        globalOptions.setCVSRoot(root);
        setCvsRootString(root);
    }
    
    public StandardClientProvider(File homeDir) {
        // making sure cache exists..
        homeDirectory = homeDir;
    }
    
    protected File getHome() {
        return homeDirectory;
    }
    

    protected String readRoot(File dirFile) {
        if (dirFile.exists()) {
            BufferedReader buff = null;
            String line = null;
            try {
                buff = new BufferedReader(new InputStreamReader(
                                             new FileInputStream(dirFile.getAbsolutePath())));
                line = buff.readLine();
            } catch (IOException exc) { //doesn't matter - nothing will be filled in
                line = null;
            }
            finally {
                if (buff != null) {
                    try {
                        buff.close();
                    } catch (IOException eIO) {}
                }
            }
            return line;
        }
        else {
            return null;
        }
    }
    
    public void setCvsPort(int port) {
        cvsPort = port;
    }
    
    public int getCvsPort() {
        return cvsPort;
    }
    
    private PServerConnection setupConnection(PasswdEntry entry) throws AuthenticationException {
       PServerConnection conn = new PServerConnection();
       conn.setUserName(entry.getUser());
       conn.setHostName(entry.getServer());
       conn.setRepository(entry.getRoot());
       conn.setPort(entry.getPort());
       conn.setEncodedPassword(entry.getPasswd());
       conn.open();
       return conn;
    }
    
    public void setLocalPath(String path) {
        localPath = path;
    }
    
    public String getLocalPath() {
        return localPath;
    }
    
    public Client createClient(String root) throws ClientCreationException {
            Client myClient = new Client(null, new StandardAdminHandler());    
            myClient.setLocalPath(localPath);
            myClient.setIgnoreFileFilter(getIgnoreFilter());
            return myClient;
    }
    
    public void openConnection(Client client, String root) throws AuthenticationException {
            CVSPasswd pass = new CVSPasswd(homeDirectory.getAbsolutePath(), ".cvspass"); //NOI18N
            pass.loadPassFile();
            PasswdEntry entry = pass.find(root);
            if (entry == null) {
                ClientCreationException exc = new ClientCreationException("", //NOI18N
                   NbBundle.getMessage(StandardClientProvider.class, "StandardClientProvider.notInPassFile")); //NOI18N
                throw exc;
            }   //TODO - not found in .cvspass file - ignore or show error??
            client.setConnection(setupConnection(entry));
    }

    public JavaCvsCommandFactory getCommandFactory() {
        return JavaCvsCommandFactory.getInstance();
    }
    
    
    public GlobalOptions getGlobalOptions() {
        return globalOptions;
    }
    
    public void setGlobalOptions(GlobalOptions opt) {
        globalOptions = opt;
    }
    
    
    public String getCvsRootString() {
        return cvsRoot;
    }
    
    public void setCvsRootString(String root) {
        cvsRoot = root;
    }
    
    public IgnoreFileFilter getIgnoreFilter() {
        return fileFilter;
    }    
    public void  setIgnoreFilter(IgnoreFileFilter fileFilter) {
        this.fileFilter = fileFilter;
    }    
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.