com.izforge.izpack.rules.UserCondition Maven / Gradle / Ivy
package com.izforge.izpack.rules;
import com.izforge.izpack.util.Debug;
import net.n3.nanoxml.XMLElement;
/**
* Checks to see whether the user who is running the installer is the same as the user who should be
* running the installer.
*
* @author J. Chris Folsom
* @author Dennis Reil
*
*/
public class UserCondition extends Condition
{
private static final long serialVersionUID = -2076347348048202718L;
private String requiredUsername;
@Override
public boolean isTrue()
{
boolean result = false;
if (this.requiredUsername == null)
{
Debug.log("Expected user name not set in user condition. Condition will return false.");
}
else
{
String actualUsername = System.getProperty("user.name");
if ((actualUsername != null) || (actualUsername.length() >= 0)){
result = this.requiredUsername.equals(actualUsername);
}
else {
Debug.log("No user.name found in system properties. Condition will return false.");
}
}
return result;
}
@Override
public void readFromXML(XMLElement xmlcondition)
{
XMLElement userElement = xmlcondition.getFirstChildNamed("requiredusername");
if (userElement == null)
{
Debug.log("Condition or type \"user\" requires child element: user");
}
else
{
this.requiredUsername = userElement.getContent();
}
}
}