public void pasteFromClipboard()

in eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java [1749:1801]


    public void pasteFromClipboard(Clipboard clipboard) {
        if (!canBePastedTo(clipboard)) {
            // should not occur due to 'canBePastedTo' check done by 
            // corresponding action - checking here nevertheless
            MessageDialog.openInformation(null, "Cannot paste",
                    "No applicable node (type) for pasting found.");
            return;
        }
        Repository repository = ServerUtil.getDefaultRepository(getProject());
        NodeTypeRegistry ntManager = (repository==null) ? null : repository.getNodeTypeRegistry();
        if (ntManager == null) {
            MessageDialog.openWarning(null, "Cannot paste", "Cannot paste if corresponding server is not started");
            return;
        }
        
        // try the resource transfer
        IResource[] resourceData = (IResource[]) clipboard.getContents(ResourceTransfer.getInstance());

        if (resourceData != null && resourceData.length > 0) {
            if (resourceData[0].getType() == IResource.PROJECT) {
                // do not support project pasting onto a jcr node
                MessageDialog.openInformation(null, "Cannot paste project(s)",
                        "Pasting of a project onto a (JCR) node is not possible");
                return;
            } else {
                CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
                operation.copyResources(resourceData, getDropContainer());
            }
            return;
        }

        // try the file transfer
        String[] fileData = (String[]) clipboard.getContents(FileTransfer.getInstance());
        if (fileData != null) {
            CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(null);
            operation.copyFiles(fileData, getDropContainer());
            return;
        }
        
        // then try the text transfer
        String text = (String) clipboard.getContents(TextTransfer.getInstance());
        if ((text!=null) && (this.domElement!=null)) {
            try {
                Document document = TolerantXMLParser.parse(text, "pasted from clipboard");
                this.domElement.addNode(document.getRootElement());
                this.underlying.save();
            } catch (IOException e) {
                MessageDialog.openError(null, "Could not paste from clipboard",
                        "Exception encountered while pasting from clipboard: "+e);
                Activator.getDefault().getPluginLogger().error("Error pasting from clipboard: "+e, e);
            }
        }
    }