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.modules.javacvs.FsGlobalOptions;
import org.netbeans.lib.cvsclient.command.GlobalOptions;
import org.netbeans.lib.cvsclient.commandLine.GetOpt;

import java.util.*;
/**
 *
 * @author  Milos Kleint
 */
public class FsGlobalOptionsImpl extends FsGlobalOptions {

    private GlobalOptions globalOptions;
    
    private int usedGzipLevel = 6;
    
    /** Creates new FsGlobalOptionsImpl */
    public FsGlobalOptionsImpl(GlobalOptions underlyingOptions) {
        super();
        globalOptions = underlyingOptions;
    }
    
    public FsGlobalOptionsImpl() {
        super();
        globalOptions = new GlobalOptions();
    }
    
    public GlobalOptions getLibraryGlobalOptions() {
        GlobalOptions gl = new GlobalOptions();
        gl.setCVSRoot(getCVSRoot());
        gl.setCheckedOutFilesReadOnly(isCheckedOutFilesReadOnly());
        gl.setDoNoChanges(isDoNoChanges());
        gl.setNoHistoryLogging(isNoHistoryLogging());
        gl.setUseGzip(isUseGzip());
        return gl;
    }
    
    public String getCVSArguments() {
        return globalOptions.getCVSCommand();
    }
    
    public String getCvsrcEntry() {
        if (getCVSRoot() != null && !getCVSRoot().equals("")) {
            return "cvs " + globalOptions.getCVSCommand() + " -d " + getCVSRoot(); //NOI18N
        }
        return "cvs " + globalOptions.getCVSCommand(); //NOI18N
    }
    
    /**
     * Are checked out files read only
     * @return the answer
     */    
    public boolean isCheckedOutFilesReadOnly()
    {
        return globalOptions.isCheckedOutFilesReadOnly();
    }
    
    /**
     * Set whether checked out files are read only. False is the default.
     * @param readOnly true for readonly, false for read/write (default)
     */
    public void setCheckedOutFilesReadOnly(boolean readOnly)
    {
        globalOptions.setCheckedOutFilesReadOnly(readOnly);
    }
    
    /**
     * Get the CVS root
     * @return the CVS root value, e.g. :pserver:user@host@/usr/local/cvs
     */
    public String getCVSRoot()
    {
        return globalOptions.getCVSRoot();
    }
    
    /**
     * Set the CVS root
     * @return the value of CVS to use
     */
    public void setCVSRoot(String root)
    {
        globalOptions.setCVSRoot(root);
    }
    
    /**
     * Set whether to use Gzip for file transmission/reception
     * @param useGzip true if gzip should be used, false otherwise
     */
    public void setUseGzip(boolean useGzip)
    {
        globalOptions.setUseGzip(useGzip);
    }
    
    /** 
     * Get whether to use Gzip
     * @return true if Gzip should be used, false otherwise
     */
    public boolean isUseGzip()
    {
        return globalOptions.isUseGzip();
    }
    
    protected void setUsedGzipLevel(int level) {
        usedGzipLevel = level;
    }
    
    protected int getUsedGzipLevel() {
        return usedGzipLevel;
    }
    /** Getter for property doNoChanges.
     * @return Value of property doNoChanges.
     */
    public boolean isDoNoChanges() 
    {
        return globalOptions.isDoNoChanges();
    }
    
    /** Setter for property doNoChanges.
     * @param doNoChanges New value of property doNoChanges.
     */
    public void setDoNoChanges(boolean doNoChanges) 
    {
        globalOptions.setDoNoChanges(doNoChanges);
    }
    

        
    /** Getter for property noHistoryLogging.
     * @return Value of property noHistoryLogging.
     */
    public boolean isNoHistoryLogging() 
    {
        return globalOptions.isNoHistoryLogging();
    }
    
    /** Setter for property noHistoryLogging.
     * @param noHistoryLogging New value of property noHistoryLogging.
     */
    public void setNoHistoryLogging(boolean noHistoryLogging) 
    {
        globalOptions.setNoHistoryLogging(noHistoryLogging);
    }    

   /** Attempts to set it's properties by parsing the string parameter.
     * 
* If the switch is not identified, it's silently ignored. * To learn if all switches were set corrently, check the getCVSArguments() method. *
* * @param arguments Command's arguments as command-line switches. * */ public void parseCvsArguments(String arguments) { StringTokenizer tokens = new StringTokenizer(arguments, " \"", true); //NOI18N boolean withinString = false; LinkedList stringList = new LinkedList(); while (tokens.hasMoreTokens()) { String tok = tokens.nextToken(); if (tok.equals("\"")) { //NOI18N String param = ""; //NOI18N while (tokens.hasMoreTokens()) { String toke2 = tokens.nextToken(); if (toke2.equals("\"")) break; //NOI18N param = param + toke2; } stringList.add(param); } else { if (!tok.equals(" ")) { //NOI18N stringList.add(tok); } } } String[] args = new String[stringList.size()]; args = (String[])stringList.toArray(args); // 2. set the parameters to the command. globalOptions.resetCVSCommand(); final String getOptString = globalOptions.getOptString() + "z:"; //NOI18N // 'z' added because we need to save the usegzip property somehow.. GetOpt go = new GetOpt(args, getOptString); int ch = -1; go.optIndexSet(0); // maybe should be set to another number go.optIndexSet(0); boolean usagePrint = false; String arg; while ((ch = go.getopt()) != go.optEOF) { //workaround for saving usegzip property.. if (((char)ch) == 'z') { int level = 6; try { level = Integer.parseInt(go.optArgGet()); } catch (NumberFormatException exc) { level = 6; } setUsedGzipLevel(level); continue; } // System.out.println("option=" + (char)ch + "arg=" + go.optArgGet()); boolean ok = globalOptions.setCVSCommand((char)ch, go.optArgGet()); } } }
... 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.