Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////
- // public API
- void UserRoleReaderWriter::addRolesFromFile()
- {
- QFile file(DefaultRoleFile);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- Utility::Logger::writeWarning("[UserRoleReaderWriter]::addRolesFromFile() -- Could not open default Roles file: %s", DefaultRoleFile.toStdString().c_str());
- return;
- }
- // Read the file into a dom
- QDomDocument dom;
- if (!dom.setContent(&file)) {
- Utility::Logger::writeError("[UserRoleReaderWriter]::addRolesFromFile() -- Could not load file %s into DOM tree.", DefaultRoleFile.toStdString().c_str());
- return;
- }
- file.close();
- // The dom is created now -- start parsing out the user roles.
- QDomElement xmlRoot = dom.firstChildElement();
- // The root should have the version.
- QString version = xmlRoot.attribute("version", "-1.0");
- if (version == "-1.0") {
- Utility::Logger::writeError("[UserRoleReaderWriter]::addRolesFromFile() -- User Role file at %s has no version information", DefaultRoleFile.toStdString().c_str());
- return;
- }
- // If we have the correct info now, we can simply parse things
- // by following the dom tree.
- QDomNodeList roles = xmlRoot.elementsByTagName("UserRole");
- for (int i = 0; i < roles.size(); ++i) {
- QDomNode node = roles.at(i);
- if (node.nodeType() != QDomNode::ElementNode) continue;
- QDomElement element = node.toElement();
- QString roleName = element.text();
- bool hasName = WorkflowManager::globalInstance()->hasRole(roleName);
- if (hasName) continue;
- UserRole* newRole = new UserRole();
- newRole->setName(roleName);
- WorkflowManager::globalInstance()->addRole(newRole);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement