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 Forte for Java, Community Edition. The Initial
 * Developer of the Original Code is Sun Microsystems, Inc. Portions
 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.modules.javacvs.passwd;

import java.util.*;
import org.netbeans.lib.cvsclient.connection.PServerConnection;

/** This class stores info about one cvs repository. It's read by {@link org.netbeans.modules.cvsclient.passwd.CVSPasswd }
 *
 * @author Milos Kleint
 * @version 1.0
 */
    public class PasswdEntry {
      String entry = null;
      String passwd = null;
      String type = null;
      String user = null;
      String server = null;
      String root = null;
      int port = PServerConnection.DEFAULT_PORT;
      String main = null;      

      public PasswdEntry() {
      }

      public boolean setEntry(String ent) {
        entry = ent;
        int spacePos = entry.indexOf(' ');
        if (spacePos < 0) {return false;} // corrupted line.
        main = entry.substring(0,spacePos);
        if (main.startsWith(":")) { main = main.substring(1);} //NOI18N
        passwd = entry.substring(spacePos + 1);
        StringTokenizer token = new StringTokenizer(main, ":",false);   //NOI18N      
        if (token.hasMoreTokens()) {
          type = token.nextToken();
        } else return false;
        if (token.hasMoreTokens()) {
          String userServer = token.nextToken();  
          int ind3 = userServer.indexOf('@');
          if (ind3 < 0) return false; // corrupted line
          user = userServer.substring(0, ind3);  //user name
          server = userServer.substring(ind3 + 1); // server name
        } else return false;
        if (token.hasMoreTokens()) {            
            final StringBuffer temp = new StringBuffer(""); //NOI18N
            while (token.hasMoreTokens()) {
                temp.append(token.nextToken());
                if (token.hasMoreTokens())
                    temp.append(':');
            }                
            root = temp.toString();            
            String numString = "";
            for (int index = 0; index < root.length(); index++) {
                char c = root.charAt(index);
                if (!Character.isDigit(c)) break;
                numString = numString + c;
            }
            if (numString.length() > 0) {
                try {
                    port = Integer.parseInt(numString);
                    root = root.substring(numString.length());
                } catch (NumberFormatException exc) {
                }
            }
        } else return false;
        return true;
     }

      public String getEntry(boolean withPasswd) {
        StringBuffer buff = new StringBuffer(":"); //NOI18N
        buff.append(type);
        buff.append(":"); //NOI18N
        buff.append(user);
        buff.append("@"); //NOI18N
        buff.append(server);
        buff.append(":"); //NOI18N
        if (port != PServerConnection.DEFAULT_PORT) {
            buff.append(port);
        }
        buff.append(root);
        if (withPasswd) {buff.append(" " + passwd);} //NOI18N
        return buff.toString();
      }
      
      public boolean matchToCurrent(String curr){
       String s = getEntry(false);
//       D("matchToCurrent:" + curr + " + " + s);
       if (s.equalsIgnoreCase(curr)) { return true; }
       return false;  
      }

      public String getType() {
        return type;
      }
/*      public void setType(String tp) {
        type = tp;
      }
*/      
      public String getRoot() {
        return root;
      } 

      public String getUser() {
        return user;
      } 
      
      public int getPort() {
          return port;
      }

      public String getPasswd() { // already scrambled
        return passwd;
      } 
/*      public void setRoot(String rootDir) {
        root = rootDir;
      } 

      public void setUser(String userName) {
        user= userName;
      } 

      public void setPasswd(String pass) {
        passwd = pass;
      } 
*/      
      
      public String toString() {
        return getEntry(true);
      }

      public String getServer() {
        return server;
      } 
/*
      public void setServer(String serv) {
        server = serv;
      } 
*/

/** Method used to compose the authentification string that is send to the server in the beginning of the communication.
 * For details see CVS Client/Server protocol specification.
 * @return the authentification string
 */
      public String getAuthString() {
        return (getRoot() + "\n" + getUser() + "\n" + getPasswd() + "\n"); //NOI18N
      }

      private void D(String debug) {
   //     System.out.println("PasswdEntry(): "+debug);
      }

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.