Search in sources :

Example 11 with Element

use of com.google.gwt.xml.client.Element 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);
        }
    }
}
Also used : Node(com.google.gwt.xml.client.Node) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element)

Example 12 with Element

use of com.google.gwt.xml.client.Element 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);
        }
    }
}
Also used : NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) Text(com.google.gwt.xml.client.Text)

Example 13 with Element

use of com.google.gwt.xml.client.Element in project data-access by pentaho.

the class DatabaseConnectionConverter method convertToObject.

public IDatabaseConnection convertToObject(String xml) {
    Document document = XMLParser.parse(xml);
    Element element = document.getDocumentElement();
    IDatabaseConnection databaseConnection = new DatabaseConnection();
    databaseConnection.setDatabaseName(getNodeValueByTagName(element, DATABASE_NAME));
    databaseConnection.setHostname(getNodeValueByTagName(element, HOSTNAME));
    databaseConnection.setIndexTablespace(getNodeValueByTagName(element, INDEX_TABLESPACE));
    databaseConnection.setDataTablespace(getNodeValueByTagName(element, DATA_TABLESPACE));
    databaseConnection.setName(getNodeValueByTagName(element, NAME));
    databaseConnection.setUsername(getNodeValueByTagName(element, USERNAME));
    databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
    databaseConnection.setDatabasePort(getNodeValueByTagName(element, DATABASE_PORT));
    databaseConnection.setAccessType(DatabaseAccessType.getAccessTypeByName(getNodeValueByTagName(element, ACCESS_TYPE)));
    databaseConnection.setDatabaseType((DatabaseType) databaseTypeHelper.getDatabaseTypeByShortName(getNodeValueByTagName(element, DATABASE_TYPE)));
    databaseConnection.setPassword(getNodeValueByTagName(element, PASSWORD));
    databaseConnection.setInformixServername(getNodeValueByTagName(element, SERVER_NAME));
    for (Node node : getNodesByTagName(element, ATTRIBUTES)) {
        databaseConnection.getAttributes().put(node.getNodeName(), node.getNodeValue());
    }
    return databaseConnection;
}
Also used : Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Document(com.google.gwt.xml.client.Document)

Example 14 with Element

use of com.google.gwt.xml.client.Element in project data-access by pentaho.

the class DatabaseConnectionConverter method convertToXml.

public String convertToXml(IDatabaseConnection dbConn) {
    Document document = XMLParser.createDocument();
    try {
        Element databaseConnection = document.createElement(DATABASE_CONNECTION);
        document.appendChild(databaseConnection);
        Element databaseName = document.createElement(DATABASE_NAME);
        Text databaseNameText = document.createTextNode(dbConn.getDatabaseName());
        databaseName.appendChild(databaseNameText);
        databaseConnection.appendChild(databaseName);
        Element databasePort = document.createElement(DATABASE_PORT);
        Text databasePortText = document.createTextNode(dbConn.getDatabasePort());
        databasePort.appendChild(databasePortText);
        databaseConnection.appendChild(databasePort);
        Element hostname = document.createElement(HOSTNAME);
        Text hostnameText = document.createTextNode(dbConn.getHostname());
        hostname.appendChild(hostnameText);
        databaseConnection.appendChild(hostname);
        Element indexTablespace = document.createElement(INDEX_TABLESPACE);
        Text indexTablespaceText = document.createTextNode(dbConn.getIndexTablespace());
        indexTablespace.appendChild(indexTablespaceText);
        databaseConnection.appendChild(indexTablespace);
        Element dataTablespace = document.createElement(DATA_TABLESPACE);
        Text dataTablespaceText = document.createTextNode(dbConn.getIndexTablespace());
        dataTablespace.appendChild(dataTablespaceText);
        databaseConnection.appendChild(dataTablespace);
        Element informixServername = document.createElement(SERVER_NAME);
        Text informixServernameText = document.createTextNode(dbConn.getInformixServername());
        informixServername.appendChild(informixServernameText);
        databaseConnection.appendChild(informixServername);
        Element name = document.createElement(NAME);
        Text nameText = document.createTextNode(dbConn.getName());
        name.appendChild(nameText);
        databaseConnection.appendChild(name);
        Element username = document.createElement(USERNAME);
        Text usernameTxt = document.createTextNode(dbConn.getUsername());
        username.appendChild(usernameTxt);
        databaseConnection.appendChild(username);
        Element password = document.createElement(PASSWORD);
        Text passwordText = document.createTextNode(dbConn.getPassword());
        password.appendChild(passwordText);
        databaseConnection.appendChild(password);
        Element accessType = document.createElement(ACCESS_TYPE);
        Text accessTypeText = document.createTextNode(dbConn.getAccessType().getName());
        accessType.appendChild(accessTypeText);
        databaseConnection.appendChild(accessType);
        Element databaseType = document.createElement(DATABASE_TYPE);
        Text databaseTypeText = document.createTextNode(dbConn.getDatabaseType().getShortName());
        databaseType.appendChild(databaseTypeText);
        databaseConnection.appendChild(databaseType);
        Element attrributes = document.createElement(ATTRIBUTES);
        databaseConnection.appendChild(attrributes);
        Map<String, String> attributeMap = dbConn.getAttributes();
        for (String key : attributeMap.keySet()) {
            Element attribute = document.createElement(key);
            Text attributeText = document.createTextNode(attributeMap.get(key));
            attribute.appendChild(attributeText);
            attrributes.appendChild(attribute);
        }
        return document.toString();
    } catch (Exception e) {
        return null;
    }
}
Also used : Element(com.google.gwt.xml.client.Element) Text(com.google.gwt.xml.client.Text) Document(com.google.gwt.xml.client.Document)

Example 15 with Element

use of com.google.gwt.xml.client.Element in project data-access by pentaho.

the class DatasourceServiceManagerGwtImpl method convertReponseToList.

private List<String> convertReponseToList(Response response) {
    List<String> dataList = new ArrayList<String>();
    Document document = (Document) XMLParser.parse(response.getText());
    Element element = document.getDocumentElement();
    Node node = element.getFirstChild();
    boolean done = false;
    do {
        try {
            dataList.add(getNodeValueByTagName(node, "Item"));
            node = (node.getNextSibling() != null) ? node.getNextSibling() : null;
            if (node == null) {
                done = true;
            }
        } catch (Exception e) {
            done = true;
        }
    } while (!done);
    return dataList;
}
Also used : Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) ArrayList(java.util.ArrayList) Document(com.google.gwt.xml.client.Document) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

Element (com.google.gwt.xml.client.Element)16 NodeList (com.google.gwt.xml.client.NodeList)9 Document (com.google.gwt.xml.client.Document)8 Node (com.google.gwt.xml.client.Node)6 ArrayList (java.util.ArrayList)5 Text (com.google.gwt.xml.client.Text)4 RequestBuilder (com.google.gwt.http.client.RequestBuilder)3 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)3 Test (org.junit.Test)3 RequestException (com.google.gwt.http.client.RequestException)2 Request (com.google.gwt.http.client.Request)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 Response (com.google.gwt.http.client.Response)1 FlexTable (com.google.gwt.user.client.ui.FlexTable)1 HTML (com.google.gwt.user.client.ui.HTML)1 Label (com.google.gwt.user.client.ui.Label)1 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)1