JCVSProjectDef.java :  » Source-Control » jcvsweb » com » ice » jcvsweb » bean » Java Open Source

Java Open Source » Source Control » jcvsweb 
jcvsweb » com » ice » jcvsweb » bean » JCVSProjectDef.java

package com.ice.jcvsweb.bean;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;

import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.ice.cvsc.CVSRequest;
import com.ice.jcvsweb.helper.XMLHelper;


/**
 * 
 * @author Tim Endres, <a href="mailto:time@jcvs.org">time@jcvs.org</a>
 * @see com.ice.cvsc
 */

public
class    JCVSProjectDef
  {
  /**
   * A local CVS working directory being presented by jCVS.
   */
  public static final String    PTSTR_JCVS = "jcvs";
  /**
   * A simple link to another jCVS servlet.
   */
  public static final String    PTSTR_LINK = "link";

  /**
   * An undefined project.
   */
  public static final int      PT_UNDEF = 0;
  /**
   * A local CVS working directory being presented by jCVS.
   */
  public static final int      PT_JCVS = 1;
  /**
   * A simple link to another jCVS servlet.
   */
  public static final int      PT_LINK = 2;

  /**
   * This is the type of project definition. Currently, there are
   * "local servlet" (PT_JCVS), and "link to servlet" (PT_LINK) types.
   */
  private int        type = PT_UNDEF;

  /**
   * The key used to identify this project internally and in the URL.
   */
  private String      key = null;

  /**
   * The username of the owner of this project.
   */
  private String      owner = null;

  /**
   * The display name of this project.
   */
  private String      name = null;

  /**
   * A short title for this project.
   */
  private String      title = null;

  /**
   * The long and detailed description of this project definition.
   */
  private String      desc = null;

  /**
   * The CVS hostname.
   */
  private String      host = null;

  /**
   * The CVS port.
   */
  private int        cvsPort = 2401;

  /**
   * The CVS connection method (pserver, rsh, ssh).
   */
  private int        cvsMethod = CVSRequest.METHOD_INETD;

  /**
   * The root directory used for the CVS repository.
   */
  private String      cvsRoot = null;

  /**
   * The CVS login username.
   */
  private String      login = null;

  /**
   * The CVS login password.
   */
  private String      pass = null;

  /**
   * The local directory for jCVS working directories.
   */
  private String      localDir = null;

  /**
   * The temporary directory for jCVS to use during CVS operations.
   */
  private String      tempDir = null;

  /**
   * This url links to the Home Page.
   */
  private String      homeUrl = null;

  /**
   * This url links to the jCVS Servlet.
   */
  private String      jcvsUrl = null;

  /**
   * This project that this definition describes.
   */
  private JCVSProject    project = null;


  /**
   * This url links to the jCVS Servlet.
   */
  private HashMap      views = null;

  /**
   * This url links to the jCVS Servlet.
   */
  private boolean      viewingRestricted = false;

  /**
   * Sets the CVSRequest trace flags on view checkouts.
   */
  private boolean      dbgChkOut = false;


  public
  JCVSProjectDef()
    {
    this.views = new HashMap();
    }


  public boolean
  isLink()
    {
    return (type == PT_LINK);
    }

  public int
  getType()
    {
    return this.type;
    }

  public void
  setType( int type )
    {
    this.type = type;
    }

  public JCVSProject
  getProject()
    {
    return this.project;
    }

  public void
  setProject( JCVSProject project )
    {
    this.project = project;
    }

  public String
  getKey()
    {
    return this.key;
    }

  public void
  setKey( String key )
    {
    this.key = key;
    }

  public String
  getOwner()
    {
    return this.owner;
    }

  public void
  setOwner( String owner )
    {
    this.owner = owner;
    }

  public String
  getName()
    {
    return this.name;
    }

  public void
  setName( String name )
    {
    this.name = name;
    }

  public String
  getTitle()
    {
    return this.title;
    }

  public void
  setTitle( String title )
    {
    this.title = title;
    }

  public String
  getDescription()
    {
    return this.desc;
    }

  public void
  setDescription( String desc )
    {
    this.desc = desc;
    }

  public String
  getHomePage()
    {
    return this.homeUrl;
    }

  public void
  setHomePage( String homeUrl )
    {
    this.homeUrl = homeUrl;
    }

  public String
  getJcvsLink()
    {
    return this.jcvsUrl;
    }

  public void
  setJcvsLink( String jcvsUrl )
    {
    this.jcvsUrl = jcvsUrl;
    }

  public String
  getCvsHost()
    {
    return this.host;
    }

  public void
  setCvsHost( String host )
    {
    this.host = host;
    }

  public int
  getCvsPort()
    {
    return this.cvsPort;
    }

  public void
  setCvsPort( int cvsPort )
    {
    this.cvsPort = cvsPort;
    }

  public int
  getCvsMethod()
    {
    return this.cvsMethod;
    }

  public void
  setCvsMethod( int cvsMethod )
    {
    this.cvsMethod = cvsMethod;
    }

  public String
  getCvsMethodName()
    {
    return (
      this.cvsMethod == CVSRequest.METHOD_INETD
        ? "pserver"
        : ( this.cvsMethod == CVSRequest.METHOD_SSH
          ? "ssh"
          : "rsh"
          )
        );
  //  return CVSRequest.getConnMethodName( this.cvsMethod );
    }

  public void
  setCvsMethodName( String methodName )
    {
    if ( "ssh".equals( methodName ) )
      this.cvsMethod = CVSRequest.METHOD_SSH;
    else if ( "rsh".equals( methodName ) )
      this.cvsMethod = CVSRequest.METHOD_RSH;
    else
      this.cvsMethod = CVSRequest.METHOD_INETD;
    }

  public String
  getCvsRoot()
    {
    return this.cvsRoot;
    }

  public void
  setCvsRoot( String cvsRoot )
    {
    this.cvsRoot = cvsRoot;
    }

  public String
  getCvsLogin()
    {
    return this.login;
    }

  public void
  setCvsLogin( String login )
    {
    this.login = login;
    }

  public String
  getCvsPassword()
    {
    return this.pass;
    }

  public void
  setCvsPassword( String pass )
    {
    this.pass = pass;
    }

  public String
  getLocalDirectory()
    {
    return this.localDir;
    }

  public void
  setLocalDirectory( String localDir )
    {
    this.localDir = localDir;
    }

  public String
  getTempDirectory()
    {
    return this.tempDir;
    }

  public void
  setTempDirectory( String tempDir )
    {
    this.tempDir = tempDir;
    }

  public boolean
  getViewingRestricted()
    {
    return this.viewingRestricted;
    }

  public void
  setViewingRestricted( boolean viewingRestricted )
    {
    this.viewingRestricted = viewingRestricted;
    }

  public boolean
  getDebugCheckout()
    {
    return this.dbgChkOut;
    }

  public void
  setDebugCheckout( boolean dbgChkOut )
    {
    this.dbgChkOut = dbgChkOut;
    }

  public void
  addView( JCVSProjectView view )
    {
    this.views.put( view.getKey(), view );
    }

  public JCVSProjectView
  getView( String cvsTag )
    {
    return (JCVSProjectView) this.views.get( cvsTag );
    }

  public Iterator
  getTagsIterator()
    {
    return this.views.keySet().iterator();
    }

  public Iterator
  getViewIterator()
    {
    return this.views.values().iterator();
    }

  public String
  toString()
    {
    StringBuffer sBuf = new StringBuffer( 128 );

    sBuf.append( "[ " );
    sBuf.append( "key=" ).append( this.key ).append( ", " );
    sBuf.append( "type=" ).append( this.type ).append( ", " );
    sBuf.append( "owner=" ).append( this.owner ).append( ", " );
    sBuf.append( "name=" ).append( this.name ).append( ", " );
    sBuf.append( "viewRest=" ).append( this.viewingRestricted ).append( ", " );
    sBuf.append( "host=" ).append( this.host ).append( ", " );
    sBuf.append( "cvsRoot=" ).append( this.cvsRoot ).append( ", " );
    sBuf.append( "login=" ).append( this.login ).append( ", " );
    sBuf.append( "pass=" ).append( this.pass ).append( ", " );
    sBuf.append( "tempDir=" ).append( this.tempDir ).append( ", " );
    sBuf.append( "localDir=" ).append( this.localDir ).append( ", " );
    sBuf.append( "title=" ).append( this.title ).append( ", " );
    sBuf.append( "homeUrl=" ).append( this.homeUrl ).append( ", " );
    sBuf.append( "jcvsUrl=" ).append( this.jcvsUrl ).append( ", " );
    sBuf.append( " ]" );

    return sBuf.toString();
    }

  public void
  loadConfiguration( Node defNode )
    throws SAXException
    {
    NodeList children = defNode.getChildNodes();
    for ( int ni = 0 ; ni < children.getLength() ; ++ni )
      {
      Node child = children.item( ni );
      if ( child != null && child.getNodeType() == Node.ELEMENT_NODE )
        {
        String name = child.getNodeName();
        String value = XMLHelper.getElementValue( (Element) child );

        if ( "type".equals( name ) )
          {
          if ( "link".equals( value ) )
            this.setType( PT_LINK );
          else if ( "jcvs".equals( value ) )
            this.setType( PT_JCVS );
          }
        else if ( "host".equals( name ) )
          {
          this.setCvsHost( value );
          }
        else if ( "owner".equals( name ) )
          {
          this.setOwner( value );
          }
        else if ( "port".equals( name ) )
          {
          int port = 2401;
          try { port = Integer.parseInt( value ); }
            catch ( Exception ex ) { port = 2401; }
          this.setCvsPort( port );
          }
        else if ( "method".equals( name ) )
          {
          int method = CVSRequest.METHOD_INETD;

          if ( "ssh".equals( value ) )
            method = CVSRequest.METHOD_SSH;
          else if ( "rsh".equals( value ) )
            method = CVSRequest.METHOD_RSH;

          this.setCvsMethod( method );
          }
        else if ( "login".equals( name ) )
          {
          this.setCvsLogin( value );
          }
        else if ( "pass".equals( name ) )
          {
          this.setCvsPassword( value );
          }
        else if ( "cvsroot".equals( name ) )
          {
          this.setCvsRoot( value );
          }
        else if ( "name".equals( name ) )
          {
          this.setName( value );
          }
        else if ( "title".equals( name ) )
          {
          this.setTitle( value );
          }
        else if ( "tempdir".equals( name ) )
          {
          this.setTempDirectory( value );
          }
        else if ( "localdir".equals( name ) )
          {
          this.setLocalDirectory( value );
          }
        else if ( "desc".equals( name ) )
          {
          this.setDescription( value );
          }
        else if ( "homepage".equals( name ) )
          {
          this.setHomePage( value );
          }
        else if ( "jcvsurl".equals( name ) )
          {
          this.setJcvsLink( value );
          }
        else if ( "restricted".equals( name ) )
          {
          this.setViewingRestricted( value.equals( "true" ) );
          }
        else if ( "debug-chkout".equals( name ) )
          {
          this.setDebugCheckout( value.equals( "true" ) );
          }
        }
      else
        {
        if ( child.getNodeType() != Node.TEXT_NODE )
          System.err.println( "SKIP node type"
            + " [" + child.getNodeType() + "] '"
            + XMLHelper.getNodeTypeName( child.getNodeType() )
            + "' name = '" + child.getNodeName() + "'" );
        }
      }

  // UNDONE HIGH
  //  if ( ! this.validate() )
  //    {
  // Validate the localdir, cvsroot, etc...
  //    }
    }

  public void
  saveConfiguration( PrintWriter pW, String prefix )
    {
    pW.print  ( prefix );
    pW.println( "<jcvs-def>" );
    pW.println( "" );

    pW.print  ( prefix );
    pW.print  ( "  <key>" );
    pW.print  ( this.key );
    pW.println( "</key>" );

    pW.print  ( prefix );
    pW.print  ( "  <type>" );
    pW.print  (
          ( this.type == PT_JCVS
            ? PTSTR_JCVS
            : PTSTR_LINK ) );
    pW.println( "</type>" );

    pW.print  ( prefix );
    pW.print  ( "  <owner>" );
    pW.print  ( this.owner );
    pW.println( "</owner>" );

    pW.print  ( prefix );
    pW.print  ( "  <name>" );
    pW.print  ( this.name );
    pW.println( "</name>" );

    pW.print  ( prefix );
    pW.print  ( "  <restricted>" );
    pW.print  ( this.viewingRestricted ? "true" : "false" );
    pW.println( "</restricted>" );

    pW.print  ( prefix );
    pW.print  ( "  <debug-chkout>" );
    pW.print  ( this.dbgChkOut ? "true" : "false" );
    pW.println( "</debug-chkout>" );

    pW.print  ( prefix );
    pW.print  ( "  <title>" );
    pW.print  ( this.title );
    pW.println( "</title>" );

    pW.print  ( prefix );
    pW.print  ( "  <homepage>" );
    pW.print  ( this.homeUrl );
    pW.println( "</homepage>" );

    pW.print  ( prefix );
    pW.print  ( "  <jcvsurl>" );
    pW.print  ( this.jcvsUrl );
    pW.println( "</jcvsurl>" );

    pW.print  ( prefix );
    pW.print  ( "  <title>" );
    pW.print  ( this.title );
    pW.println( "</title>" );

    pW.print  ( prefix );
    pW.print  ( "  <host>" );
    pW.print  ( this.host );
    pW.println( "</host>" );

    pW.print  ( prefix );
    pW.print  ( "  <method>" );
    pW.print  ( this.getCvsMethodName() );
    pW.println( "</method>" );

    pW.print  ( prefix );
    pW.print  ( "  <port>" );
    pW.print  ( this.cvsPort );
    pW.println( "</port>" );

    pW.print  ( prefix );
    pW.print  ( "  <login>" );
    pW.print  ( this.login );
    pW.println( "</login>" );

    pW.print  ( prefix );
    pW.print  ( "  <pass>" );
    pW.print  ( this.pass );
    pW.println( "</pass>" );

    pW.print  ( prefix );
    pW.print  ( "  <cvsroot>" );
    pW.print  ( this.cvsRoot );
    pW.println( "</cvsroot>" );

    pW.print  ( prefix );
    pW.print  ( "  <localdir>" );
    pW.print  ( this.localDir );
    pW.println( "</localdir>" );

    pW.print  ( prefix );
    pW.print  ( "  <tempdir>" );
    pW.print  ( this.tempDir );
    pW.println( "</tempdir>" );

    pW.print  ( prefix );
    pW.print  ( "  <desc>" );
    pW.print  ( this.desc );
    pW.println( "</desc>" );

    pW.println( "" );
    pW.print  ( prefix );
    pW.println( "</jcvs-def>" );
    }

  }
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.