Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

In this page you can find the example usage for org.dom4j Element add.

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

From source file:com.openedit.users.filesystem.FileSystemUserManager.java

License:Open Source License

public void saveUser(User user) throws UserManagerException {
    if (user.isVirtual()) {
        log.error("Cannot save virtual users: " + user.getUserName());
        return;/*from w w w . ja  va2  s .com*/
    }
    DocumentFactory factory = DocumentFactory.getInstance();
    Document doc = factory.createDocument();
    Element userElem = doc.addElement("user");
    userElem.addAttribute("enabled", Boolean.toString(user.isEnabled()));
    if (user.getUserName() == null) {
        int id = getUserIdCounter().incrementCount();
        String newid = String.valueOf(id);
        user.setId(newid);
    }
    Element userNameElem = userElem.addElement("user-name");
    userNameElem.setText(user.getUserName());

    Element passwordElem = userElem.addElement("password");
    //
    if (user.getPassword() != null && !user.getPassword().equals("")) {
        String ps = user.getPassword();
        ps = encrypt(ps);
        //password may have changed we should set it so it's not in plain text anymore.
        user.setPassword(ps);
        passwordElem.setText(ps);
    }
    Element creationDateElem = userElem.addElement("creation-date");
    if (user.getCreationDate() != null) {
        creationDateElem.setText(String.valueOf(user.getCreationDate().getTime()));
    } else {
        creationDateElem.setText(String.valueOf(System.currentTimeMillis()));
    }

    //Tuan add property lastLogined-Time
    Element lastLoginTime = userElem.addElement("lastLogined-Time");
    lastLoginTime.setText(DateStorageUtil.getStorageUtil().formatForStorage(new Date()));

    MapPropertyContainer map = (MapPropertyContainer) user.getPropertyContainer();
    if (map != null) {
        Element propertiesElem = map.createPropertiesElement("properties");
        userElem.add(propertiesElem);
    }
    if (user.getGroups() != null) {
        for (Iterator iter = user.getGroups().iterator(); iter.hasNext();) {
            Group group = (Group) iter.next();
            Element child = userElem.addElement("group");
            child.addAttribute("id", group.getId());
        }
    }
    File file = loadUserFile(user.getUserName());
    getXmlUtil().saveXml(doc, file);
    getUserNameToUserMap().put(user.getUserName(), user);
}

From source file:com.openedit.users.filesystem.FileSystemUserManager.java

License:Open Source License

public void saveGroup(Group inGroup) throws UserManagerException {
    Document doc = DocumentFactory.getInstance().createDocument();
    Element root = doc.addElement("group");
    if (inGroup.getId() == null) {

        int id = getUserIdCounter().incrementCount();
        String inAccount = String.valueOf(id);
        inGroup.setId(inAccount);/* ww  w . j  a  va 2  s  . c  o  m*/

    }
    root.addAttribute("id", inGroup.getId());
    Element groupNameElem = root.addElement("group-name");
    groupNameElem.setText(inGroup.getName());

    Element permissionsElem = root.addElement("permissions");

    for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) {
        Object permission = (Object) iter.next();
        Element permissionElem = permissionsElem.addElement("permission");
        permissionElem.setText(permission.toString());
    }

    MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer();
    if (map != null) {
        Element propertiesElem = map.createPropertiesElement("properties");
        root.add(propertiesElem);
    }
    File file = loadGroupFile(inGroup.getId());
    getXmlUtil().saveXml(doc, file);

    getGroupIdToGroupMap().put(inGroup.getId(), inGroup);
}

From source file:com.openedit.users.filesystem.XmlUserArchive.java

License:Open Source License

public void saveUser(User user) throws UserManagerException {
    if (user.isVirtual()) {
        log.error("Cannot save virtual users: " + user.getUserName());
        return;/*from   ww  w  .j a va2 s  .  c o m*/
    }
    DocumentFactory factory = DocumentFactory.getInstance();
    Document doc = factory.createDocument();
    Element userElem = doc.addElement("user");
    userElem.addAttribute("enabled", Boolean.toString(user.isEnabled()));
    if (user.getUserName() == null) {
        int id = getUserIdCounter().incrementCount();
        String newid = String.valueOf(id);
        user.setId(newid);
    }
    Element userNameElem = userElem.addElement("user-name");
    userNameElem.addCDATA(user.getUserName());

    Element passwordElem = userElem.addElement("password");
    //
    if (user.getPassword() != null && !user.getPassword().equals("")) {
        String ps = user.getPassword();
        ps = encrypt(ps);
        // password may have changed we should set it so it's not in plain
        // text anymore.
        user.setPassword(ps);
        passwordElem.addCDATA(ps);
    }
    Element creationDateElem = userElem.addElement("creation-date");
    if (user.getCreationDate() != null) {
        creationDateElem.setText(String.valueOf(user.getCreationDate().getTime()));
    } else {
        creationDateElem.setText(String.valueOf(System.currentTimeMillis()));
    }

    // Tuan add property lastLogined-Time
    Element lastLoginTime = userElem.addElement("lastLogined-Time");
    lastLoginTime.setText(DateStorageUtil.getStorageUtil().formatForStorage(new Date()));

    MapPropertyContainer map = (MapPropertyContainer) user.getPropertyContainer();
    if (map != null) {
        Element propertiesElem = map.createPropertiesElement("properties");
        userElem.add(propertiesElem);
    }
    if (user.getGroups() != null) {
        for (Iterator iter = user.getGroups().iterator(); iter.hasNext();) {
            Group group = (Group) iter.next();
            Element child = userElem.addElement("group");
            child.addAttribute("id", group.getId());
        }
    }
    synchronized (user) {
        // File file = loadUserFile(user.getUserName());
        XmlFile xfile = new XmlFile();
        xfile.setRoot(doc.getRootElement());
        xfile.setPath(getUserDirectory() + "/" + user.getUserName() + ".xml");
        getXmlArchive().saveXml(xfile, null);

        getUserNameToUserMap().put(user.getUserName(), user);
    }
}

From source file:com.openedit.users.filesystem.XmlUserArchive.java

License:Open Source License

public void saveGroup(Group inGroup) throws UserManagerException {
    Document doc = DocumentFactory.getInstance().createDocument();
    Element root = doc.addElement("group");
    if (inGroup.getId() == null) {

        int id = getUserIdCounter().incrementCount();
        String inAccount = String.valueOf(id);
        inGroup.setId(inAccount);//from  ww w .j av  a 2 s.  com

    }
    root.addAttribute("id", inGroup.getId());
    Element groupNameElem = root.addElement("group-name");
    groupNameElem.setText(inGroup.getName());

    Element permissionsElem = root.addElement("permissions");

    for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) {
        Object permission = (Object) iter.next();
        Element permissionElem = permissionsElem.addElement("permission");
        permissionElem.setText(permission.toString());
    }

    MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer();
    if (map != null) {
        Element propertiesElem = map.createPropertiesElement("properties");
        root.add(propertiesElem);
    }
    File file = loadGroupFile(inGroup.getId());
    getXmlUtil().saveXml(doc, file);

    getGroupIdToGroupMap().remove(inGroup.getId());
}

From source file:com.pureinfo.ark.auth2.model.AllowDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*from   w w w  .j  a va2 s . c  o  m*/
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("action", m_sActions);
    if (m_rules != null) {
        for (int i = 0; i < m_rules.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_rules[i], "rule"));
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.ResourceDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*from  w  w w  . j a va  2s .  c om*/
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("type", String.valueOf(m_type.getId()));
    _element.addAttribute("desc", m_type.getDesc());

    if (m_base != null) {
        _element.add(XMLUtil.toXMLElement(m_base, "base"));
    }
    if (m_rights != null) {
        for (int i = 0; i < m_rights.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_rights[i], "right"));
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.RightDefBase.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*w w w  .  j  av a  2s  . c  om*/
public void toXMLElement(Element _element) throws PureException {
    if (m_allows != null) {
        for (int i = 0; i < m_allows.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_allows[i], "allow"));
        }
    }
    if (m_switch != null) {
        _element.add(XMLUtil.toXMLElement(m_switch, "switch"));
    }
}

From source file:com.pureinfo.ark.auth2.model.RightsConfig.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *///from  ww  w  .j  a v a  2  s . co  m
public void toXMLElement(Element _element) throws PureException {
    Element ele = _element.addElement("roles");
    if (m_roles != null) {
        for (int i = 0; i < m_roles.length; i++) {
            ele.add(XMLUtil.toXMLElement(m_roles[i], "role"));
        }
    }

    ele = _element.addElement("actions");
    if (m_actions != null) {
        for (int i = 0; i < m_actions.length; i++) {
            ele.add(XMLUtil.toXMLElement(m_actions[i], "action"));
        }
    }

    if (m_resources != null) {
        for (int i = 0; i < m_resources.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_resources[i], "resource"));
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.RuleDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 */// www  . java 2  s . c o m
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("res-property", m_sResProperty);
    if (m_sResProperty4sql != null) {
        _element.addAttribute("res-property4sql", m_sResProperty4sql);
        _element.addAttribute("type", DataTypes.getName(m_nValueType));
    }
    if (m_sUserProperty != null) {
        _element.addAttribute("user-property", m_sUserProperty);
    }
    if (m_values != null) {
        _element.addAttribute("value", m_values.toString());
    }
    _element.addAttribute("test", ScriptOperator.getSymbol(m_nTestOp));

    //to export children
    if (m_children != null) {
        for (int i = 0; i < m_children.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_children[i], "rule"));
        }
    }
}

From source file:com.pureinfo.ark.auth2.model.SwitchDef.java

License:Open Source License

/**
 * @see com.pureinfo.force.xml.IXMLSupporter#toXMLElement(org.dom4j.Element)
 *//*from  ww w  . ja  v a 2 s .  c  om*/
public void toXMLElement(Element _element) throws PureException {
    _element.addAttribute("property", m_sProperty);
    if (m_sProperty4sql != null) {
        _element.addAttribute("property4sql", m_sProperty4sql);
        _element.addAttribute("type", DataTypes.getName(m_nValueType));
    }

    if (m_cases != null) {
        for (int i = 0; i < m_cases.length; i++) {
            _element.add(XMLUtil.toXMLElement(m_cases[i], "case"));
        }
    }
}