Search in sources :

Example 6 with Element

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

the class PermissionsPanel method prepareRequests.

/**
 * @return
 */
public List<RequestBuilder> prepareRequests() {
    ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>();
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));
    // $NON-NLS-1$//$NON-NLS-2$
    String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, url);
    builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    builder.setHeader("Content-Type", "application/xml");
    // default
    if (isInheritsAcls(fileInfo)) {
        removeAllAces(fileInfo);
    } else {
        // Check if any of the permission sets should be replaced with ALL.
        // Any non-inherited Ace with a permission set containing PERM_GRANT_PERM should be replaced
        // with a single PERM_ALL.
        NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
        for (int i = 0; i < aces.getLength(); i++) {
            Element ace = (Element) aces.item(i);
            NodeList perms = ace.getElementsByTagName(PERMISSIONS_ELEMENT_NAME);
            for (int j = 0; j < perms.getLength(); j++) {
                Element perm = (Element) perms.item(j);
                if (perm.getFirstChild() != null) {
                    if (Integer.parseInt(perm.getFirstChild().getNodeValue()) == PERM_GRANT_PERM) {
                        replacePermissionsWithAll(ace, fileInfo);
                        break;
                    }
                }
            }
        }
    }
    // set request data in builder itself
    builder.setRequestData(fileInfo.toString());
    // add builder to list to return to parent for execution
    requestBuilders.add(builder);
    return requestBuilders;
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) ArrayList(java.util.ArrayList)

Example 7 with Element

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

the class PermissionsPanel method addRecipient.

/**
 * @param recipientName
 * @param recipientType
 */
void addRecipient(String recipientName, int recipientType, Document fileInfo) {
    Element newAces = fileInfo.createElement(ACES_ELEMENT_NAME);
    Element newPermission = fileInfo.createElement(PERMISSIONS_ELEMENT_NAME);
    Element newRecipient = fileInfo.createElement(RECIPIENT_ELEMENT_NAME);
    Element newRecipientType = fileInfo.createElement(RECIPIENT_TYPE_ELEMENT_NAME);
    Element modifiableElementName = fileInfo.createElement(MODIFIABLE_ELEMENT_NAME);
    Text textNode = fileInfo.createTextNode(recipientName);
    newRecipient.appendChild(textNode);
    textNode = fileInfo.createTextNode(Integer.toString(recipientType));
    newRecipientType.appendChild(textNode);
    textNode = fileInfo.createTextNode(Boolean.toString(true));
    modifiableElementName.appendChild(textNode);
    newAces.appendChild(newPermission);
    newAces.appendChild(newRecipient);
    newAces.appendChild(newRecipientType);
    newAces.appendChild(modifiableElementName);
    fileInfo.getDocumentElement().appendChild(newAces);
    // Base recipient is created at this point.
    // Now give them the default perms.
    String strRecipientType = Integer.toString(recipientType);
    updatePermissionForUserOrRole(fileInfo, recipientName, strRecipientType, true, PERM_READ);
}
Also used : Element(com.google.gwt.xml.client.Element) Text(com.google.gwt.xml.client.Text)

Example 8 with Element

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

the class XMLToDatasourceInfoConverter method getDatasourceInfoList.

private List<IDatasourceInfo> getDatasourceInfoList(Element element) {
    List<IDatasourceInfo> datasourceInfoList = new ArrayList<IDatasourceInfo>();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element ele = (Element) nodeList.item(i);
        boolean editable = Boolean.parseBoolean(getNodeValueByTagName(ele, "editable"));
        boolean removable = Boolean.parseBoolean(getNodeValueByTagName(ele, "removable"));
        boolean importable = Boolean.parseBoolean(getNodeValueByTagName(ele, "importable"));
        boolean exportable = Boolean.parseBoolean(getNodeValueByTagName(ele, "exportable"));
        IDatasourceInfo info = new DatasourceInfo(getName(ele), getId(ele), getType(ele), editable, removable, importable, exportable);
        datasourceInfoList.add(info);
    }
    return datasourceInfoList;
}
Also used : IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo) DatasourceInfo(org.pentaho.platform.dataaccess.datasource.DatasourceInfo) NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) ArrayList(java.util.ArrayList) IDatasourceInfo(org.pentaho.platform.dataaccess.datasource.IDatasourceInfo)

Example 9 with Element

use of com.google.gwt.xml.client.Element in project gwt-test-utils by gwt-test-utils.

the class XMLElementTest method setAttribute.

@Test
public void setAttribute() {
    // Given
    Document document = XMLParser.createDocument();
    Element element = document.createElement("elem");
    // When
    element.setAttribute("myAttr", "myValue");
    // Then
    assertThat(element.getAttribute("myAttr")).isEqualTo("myValue");
}
Also used : Element(com.google.gwt.xml.client.Element) Document(com.google.gwt.xml.client.Document) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

Example 10 with Element

use of com.google.gwt.xml.client.Element in project gwt-test-utils by gwt-test-utils.

the class XMLElementTest method elementToString.

@Test
public void elementToString() {
    // Given
    Document document = XMLParser.createDocument();
    Element e = document.createElement("ThisIsATest");
    e.appendChild(document.createTextNode("SomeTextNode"));
    // When
    String toString = e.toString();
    // Then
    assertThat(toString).isEqualTo("<ThisIsATest>SomeTextNode</ThisIsATest>");
}
Also used : Element(com.google.gwt.xml.client.Element) Document(com.google.gwt.xml.client.Document) GwtTestTest(com.googlecode.gwt.test.GwtTestTest) Test(org.junit.Test)

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