use of com.google.gwt.xml.client.NodeList in project pentaho-platform by pentaho.
the class PermissionsPanel method updatePermissionForUserOrRole.
/**
* @param recipient
* @param grant true = grant the Permission, false = deny the Permission (remove it if present)
* @param perm The integer value of the Permission as defined in <code>RepositoryFilePermissions</code>
*/
private void updatePermissionForUserOrRole(Document fileInfo, String recipient, String recipientType, boolean grant, int perm) {
// first let's see if this node exists
Node foundPermission = null;
NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
for (int i = 0; i < aces.getLength(); i++) {
Element ace = (Element) aces.item(i);
if (ace.getElementsByTagName(RECIPIENT_ELEMENT_NAME).item(0).getFirstChild().getNodeValue().equals(recipient) && ace.getElementsByTagName(RECIPIENT_TYPE_ELEMENT_NAME).item(0).getFirstChild().getNodeValue().equals(recipientType)) {
NodeList permissions = ace.getElementsByTagName(PERMISSIONS_ELEMENT_NAME);
for (int j = 0; j < permissions.getLength(); j++) {
Node testNode = permissions.item(j);
if (testNode.getFirstChild() != null && Integer.parseInt(testNode.getFirstChild().getNodeValue()) == perm) {
foundPermission = testNode;
break;
}
}
break;
}
}
if (grant) {
if (foundPermission != null) {
// This permission already exists.
return;
}
addPermission(recipient, recipientType, perm, fileInfo);
} else {
if (foundPermission != null) {
foundPermission.getParentNode().removeChild(foundPermission);
}
}
}
use of com.google.gwt.xml.client.NodeList in project pentaho-platform by pentaho.
the class PermissionsPanel method addPermission.
/**
* @param recipient
* @param permission
*/
private void addPermission(String recipient, String recipientType, int permission, Document fileInfo) {
NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
for (int i = 0; i < aces.getLength(); i++) {
Element ace = (Element) aces.item(i);
if (ace.getElementsByTagName(RECIPIENT_ELEMENT_NAME).item(0).getFirstChild().getNodeValue().equals(recipient) && ace.getElementsByTagName(RECIPIENT_TYPE_ELEMENT_NAME).item(0).getFirstChild().getNodeValue().equals(recipientType)) {
Element newPerm = fileInfo.createElement(PERMISSIONS_ELEMENT_NAME);
Text textNode = fileInfo.createTextNode(Integer.toString(permission));
newPerm.appendChild(textNode);
ace.appendChild(newPerm);
}
}
}
use of com.google.gwt.xml.client.NodeList in project data-access by pentaho.
the class DatabaseConnectionConverter method getNodesByTagName.
/*
* Return all node matching the tagName, starting from the current element
* location
*/
private List<Node> getNodesByTagName(Element element, String tagName) {
List<Node> nodes = new ArrayList<Node>();
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node != null && node.getNodeName().equals(tagName)) {
nodes.add(node);
}
}
return nodes;
}
Aggregations