package com.ice.jcvsweb.bean;
import java.io.File;
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.jcvsweb.helper.XMLHelper;
/**
*
* @author Tim Endres, <a href="mailto:time@jcvs.org">time@jcvs.org</a>
* @see com.ice.cvsc
*/
public
class JCVSUserPerm
implements Comparable
{
/**
* The unique ID of the user.
*/
private String userName = null;
/**
* The key of the project these permissions apply to.
*/
private String projectKey = null;
/**
* The permission flags.
*/
private boolean viewPerm = false;
private boolean adminPerm = false;
public
JCVSUserPerm()
{
}
public int
compareTo( Object o )
{
if ( o instanceof JCVSUserPerm )
{
String oUserName = ((JCVSUserPerm)o).getUserName();
return ( this.userName == null )
? ( oUserName == null ? 0 : -1 )
: this.userName.compareTo( oUserName );
}
return 0;
}
public String
getUserName()
{
return this.userName;
}
public void
setUserName( String userName )
{
this.userName = userName;
}
public String
getProjectKey()
{
return this.projectKey;
}
public void
setProjectKey( String projectKey )
{
this.projectKey = projectKey;
}
public boolean
getViewPerm()
{
return this.viewPerm;
}
public void
setViewPerm( boolean viewPerm )
{
this.viewPerm = viewPerm;
}
public boolean
getAdminPerm()
{
return this.adminPerm;
}
public void
setAdminPerm( boolean adminPerm )
{
this.adminPerm = adminPerm;
}
public String
toString()
{
StringBuffer sBuf = new StringBuffer( 128 );
sBuf.append( "[ " );
sBuf.append( "userName=" ).append( this.userName ).append( ", " );
sBuf.append( "projectKey=" ).append( this.projectKey ).append( ", " );
sBuf.append( "view=" ).append( this.viewPerm ).append( ", " );
sBuf.append( "admin=" ).append( this.adminPerm );
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 );
String permVal = value.toLowerCase();
boolean permTrue = permVal.equals( "true" );
System.err.println( "LOAD PERM: '" + name + "' = '" + value + "'" );
if ( "user".equals( name ) )
{
this.setUserName( value );
}
else if ( "project".equals( name ) )
{
this.setProjectKey( value );
}
else if ( "view".equals( name ) )
{
this.setViewPerm( permTrue );
}
else if ( "admin".equals( name ) )
{
this.setAdminPerm( permTrue );
}
}
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() )
// {
// }
}
public void
saveConfiguration( PrintWriter pW, String prefix )
{
pW.print ( prefix );
pW.println( "<jcvs-user-perm>" );
pW.println( "" );
pW.print ( prefix );
pW.print ( " <user>" );
pW.print ( this.getUserName() );
pW.println( "</user>" );
pW.print ( prefix );
pW.print ( " <project>" );
pW.print ( this.getProjectKey() );
pW.println( "</project>" );
pW.print ( prefix );
pW.print ( " <view>" );
pW.print ( this.getViewPerm() ? "true" : "false" );
pW.println( "</view>" );
pW.print ( prefix );
pW.print ( " <admin>" );
pW.print ( this.getAdminPerm() ? "true" : "false" );
pW.println( "</admin>" );
pW.println( "" );
pW.print ( prefix );
pW.println( "</jcvs-user-perm>" );
}
}
|