Search in sources :

Example 6 with Document

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

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

the class XMLElementTest method emptyElementToString.

@Test
public void emptyElementToString() {
    // Given
    Document document = XMLParser.createDocument();
    Element e = document.createElement("ThisIsATest");
    // When
    String toString = e.toString();
    // Then
    assertThat(toString).isEqualTo("<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)

Example 8 with Document

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

the class GeneralPanel method setAclResponse.

/**
 * Get owner name from acl response
 *
 * @param response
 */
protected void setAclResponse(Response response) {
    Document permissions = XMLParser.parse(response.getText());
    ownerLabel.setText(permissions.getElementsByTagName(OWNER_NAME_ELEMENT_NAME).item(0).getFirstChild().getNodeValue());
}
Also used : Document(com.google.gwt.xml.client.Document)

Example 9 with Document

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

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

Aggregations

Document (com.google.gwt.xml.client.Document)11 Element (com.google.gwt.xml.client.Element)8 Node (com.google.gwt.xml.client.Node)4 NodeList (com.google.gwt.xml.client.NodeList)4 RequestBuilder (com.google.gwt.http.client.RequestBuilder)3 RequestException (com.google.gwt.http.client.RequestException)3 GwtTestTest (com.googlecode.gwt.test.GwtTestTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Request (com.google.gwt.http.client.Request)2 RequestCallback (com.google.gwt.http.client.RequestCallback)2 Response (com.google.gwt.http.client.Response)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 Text (com.google.gwt.xml.client.Text)1 List (java.util.List)1 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)1 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)1 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)1