Search in sources :

Example 6 with NodeList

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

the class PermissionsPanel method getNames.

/**
 * @param type
 * @return list of names of given "type"
 */
protected List<String> getNames(final Document fileInfo, int type) {
    List<String> names = new ArrayList<String>();
    NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME);
    for (int i = 0; i < aces.getLength(); i++) {
        Element ace = (Element) aces.item(i);
        NodeList recipientTypeList = ace.getElementsByTagName(RECIPIENT_TYPE_ELEMENT_NAME);
        Node recipientNode = recipientTypeList.item(0);
        String nodeValue = recipientNode.getFirstChild().getNodeValue();
        int recipientType = Integer.parseInt(nodeValue);
        if (recipientType == type) {
            names.add(ace.getElementsByTagName(RECIPIENT_ELEMENT_NAME).item(0).getFirstChild().getNodeValue());
        }
    }
    return names;
}
Also used : NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) Node(com.google.gwt.xml.client.Node) ArrayList(java.util.ArrayList)

Example 7 with NodeList

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

the class PermissionsPanel method getPermissionsForUserOrRole.

/**
 * @param recipient
 * @return
 */
private List<Integer> getPermissionsForUserOrRole(Document fileInfo, String recipient, String recipientType) {
    List<Integer> values = new ArrayList<Integer>();
    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++) {
                if (permissions.item(j).getFirstChild() != null) {
                    values.add(new Integer(permissions.item(j).getFirstChild().getNodeValue()));
                }
            }
            break;
        }
    }
    return values;
}
Also used : NodeList(com.google.gwt.xml.client.NodeList) Element(com.google.gwt.xml.client.Element) ArrayList(java.util.ArrayList)

Example 8 with NodeList

use of com.google.gwt.xml.client.NodeList 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 9 with NodeList

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

the class PasteFilesCommand method performOperation.

/*
   * (non-Javadoc)
   *
   * @see org.pentaho.mantle.client.commands.AbstractCommand#performOperation(boolean)
   */
@Override
protected void performOperation(boolean feedback) {
    final SolutionBrowserClipboard clipBoard = SolutionBrowserClipboard.getInstance();
    @SuppressWarnings("unchecked") final List<SolutionBrowserFile> clipboardFileItems = clipBoard.getClipboardItems();
    if (clipboardFileItems != null && clipboardFileItems.size() > 0 && getSolutionPath() != null) {
        String getChildrenUrl = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(getSolutionPath()) + "/tree?depth=1" + "&showHidden=" + // $NON-NLS-1$ //$NON-NLS-2$
        SolutionBrowserPanel.getInstance().getSolutionTree().isShowHiddenFiles();
        RequestBuilder childrenRequestBuilder = new RequestBuilder(RequestBuilder.GET, getChildrenUrl);
        try {
            childrenRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
            childrenRequestBuilder.sendRequest(null, new RequestCallback() {

                @Override
                public void onError(Request getChildrenRequest, Throwable exception) {
                    Window.alert(exception.getLocalizedMessage());
                    event.setMessage(exception.getLocalizedMessage());
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                }

                @Override
                public void onResponseReceived(Request getChildrenRequest, Response getChildrenResponse) {
                    event.setMessage("Click");
                    EventBusUtil.EVENT_BUS.fireEvent(event);
                    boolean cutSameDir = false;
                    if (getChildrenResponse.getStatusCode() >= 200 && getChildrenResponse.getStatusCode() < 300) {
                        boolean promptForOptions = false;
                        Document children = XMLParser.parse(getChildrenResponse.getText());
                        NodeList childrenNameNodes = children.getElementsByTagName(NAME_NODE_TAG);
                        List<String> childNames = new ArrayList<String>();
                        for (int i = 0; i < childrenNameNodes.getLength(); i++) {
                            Node childNameNode = childrenNameNodes.item(i);
                            childNames.add(childNameNode.getFirstChild().getNodeValue());
                        }
                        for (SolutionBrowserFile file : clipboardFileItems) {
                            if (file.getPath() != null) {
                                String pasteFileParentPath = file.getPath();
                                // $NON-NLS-1$
                                String fileNameWithExt = pasteFileParentPath.substring(pasteFileParentPath.lastIndexOf("/") + 1, pasteFileParentPath.length());
                                // $NON-NLS-1$
                                pasteFileParentPath = pasteFileParentPath.substring(0, pasteFileParentPath.lastIndexOf("/"));
                                if (childNames.contains(fileNameWithExt) && !getSolutionPath().equals(pasteFileParentPath)) {
                                    promptForOptions = true;
                                    break;
                                } else if (childNames.contains(fileNameWithExt) && getSolutionPath().equals(pasteFileParentPath) && SolutionBrowserClipboard.getInstance().getClipboardAction() == SolutionBrowserClipboard.ClipboardAction.CUT) {
                                    cutSameDir = true;
                                    break;
                                }
                            }
                        }
                        if (promptForOptions) {
                            final OverwritePromptDialog overwriteDialog = new OverwritePromptDialog();
                            final IDialogCallback callback = new IDialogCallback() {

                                public void cancelPressed() {
                                    event.setMessage("Cancel");
                                    EventBusUtil.EVENT_BUS.fireEvent(event);
                                    overwriteDialog.hide();
                                }

                                public void okPressed() {
                                    performSave(clipBoard, overwriteDialog.getOverwriteMode());
                                }
                            };
                            overwriteDialog.setCallback(callback);
                            overwriteDialog.center();
                        } else {
                            if (!cutSameDir) {
                                performSave(clipBoard, 2);
                            } else {
                                event.setMessage("Cancel");
                                EventBusUtil.EVENT_BUS.fireEvent(event);
                            }
                        }
                    } else {
                        Window.alert(getChildrenResponse.getText());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.getLocalizedMessage());
        }
    }
}
Also used : SolutionBrowserFile(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserFile) RequestBuilder(com.google.gwt.http.client.RequestBuilder) NodeList(com.google.gwt.xml.client.NodeList) Node(com.google.gwt.xml.client.Node) Request(com.google.gwt.http.client.Request) Document(com.google.gwt.xml.client.Document) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback) RequestException(com.google.gwt.http.client.RequestException) Response(com.google.gwt.http.client.Response) RequestCallback(com.google.gwt.http.client.RequestCallback) OverwritePromptDialog(org.pentaho.mantle.client.dialogs.OverwritePromptDialog) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(com.google.gwt.xml.client.NodeList) SolutionBrowserClipboard(org.pentaho.mantle.client.solutionbrowser.SolutionBrowserClipboard)

Example 10 with NodeList

use of com.google.gwt.xml.client.NodeList 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)

Aggregations

NodeList (com.google.gwt.xml.client.NodeList)13 Element (com.google.gwt.xml.client.Element)9 Node (com.google.gwt.xml.client.Node)7 ArrayList (java.util.ArrayList)7 RequestBuilder (com.google.gwt.http.client.RequestBuilder)4 Document (com.google.gwt.xml.client.Document)4 Request (com.google.gwt.http.client.Request)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 RequestException (com.google.gwt.http.client.RequestException)2 Response (com.google.gwt.http.client.Response)2 Text (com.google.gwt.xml.client.Text)2 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 List (java.util.List)1 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)1 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)1 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)1 OverwritePromptDialog (org.pentaho.mantle.client.dialogs.OverwritePromptDialog)1 SolutionBrowserClipboard (org.pentaho.mantle.client.solutionbrowser.SolutionBrowserClipboard)1