Index: src/org/openstreetmap/josm/actions/PasteTagsAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/PasteTagsAction.java	(revision 5771)
+++ src/org/openstreetmap/josm/actions/PasteTagsAction.java	(working copy)
@@ -45,28 +45,16 @@
  */
 public final class PasteTagsAction extends JosmAction {
 
+    private static final String help = ht("/Action/PasteTags");
+    
     public PasteTagsAction() {
         super(tr("Paste Tags"), "pastetags",
                 tr("Apply tags of contents of paste buffer to all selected items."),
                 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")),
                 KeyEvent.VK_V, Shortcut.CTRL_SHIFT), true);
-        putValue("help", ht("/Action/PasteTags"));
+        putValue("help", help);
     }
 
-    private void showBadBufferMessage() {
-        String msg = tr("<html><p> Sorry, it is impossible to paste tags from buffer. It does not contain any JOSM object"
-            + " or suitable text. </p></html>");
-        JPanel p = new JPanel(new GridBagLayout());
-        p.add(new JLabel(msg),GBC.eop());
-        p.add(new UrlLabel(
-                HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic((String)getValue("help")))),
-                GBC.eop());
-
-        ConditionalOptionPaneUtil.showMessageDialog(
-            "paste_badbuffer", Main.parent,
-            p, tr("Warning"), JOptionPane.WARNING_MESSAGE);
-    }
-
     public static class TagPaster {
 
         private final Collection<PrimitiveData> source;
@@ -268,30 +256,66 @@
             return;
         
         String buf = Utils.getClipboardContent();
+        boolean ok = false;
 
-        List<Command> commands = new ArrayList<Command>();
-        if (buf==null) {
+        if (buf == null || buf.matches("(\\d+,)*\\d+")) {
+            ok = pasteTagsFromJOSMBuffer(selection);
+        } else { 
+            // Paste tags from arbitrary text
+            ok = pasteTagsFromText(selection, buf);
+            if (!ok) {
+                ok = pasteTagsFromJOSMBuffer(selection);
+            }
+        }
+        if (!ok) {
             showBadBufferMessage();
-            return;
         }
-        if (buf.matches("(\\d+,)*\\d+")) { // Paste tags from JOSM buffer
-            PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(Main.pasteBuffer.getDirectlyAdded(), selection);
-            for (Tag tag: tagPaster.execute()) {
-                commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue())?null:tag.getValue()));
-            }
-        } else { // Paste tags from arbitrary text
-            Map<String, String> tags = TextTagParser.readTagsFromText(buf);
-            if (tags==null || tags.isEmpty()) {
-                showBadBufferMessage();
-                return;
-            }
-            if (!TextTagParser.validateTags(tags)) return;
+    }
+
+    /** Paste tags from arbitrary text
+     * @return true if action was successful
+     */
+    public static boolean pasteTagsFromText(Collection<OsmPrimitive> selection, String text) {
+        Map<String, String> tags = TextTagParser.readTagsFromText(text);
+        List<Command> commands = new ArrayList<Command>();
+        if (tags==null || tags.isEmpty()) {
+            return false;
+        } else {
+            if (!TextTagParser.validateTags(tags)) return false;
             String v;
             for (String key: tags.keySet()) {
                 v = tags.get(key);
                 commands.add(new ChangePropertyCommand(selection, key, "".equals(v)?null:v));
             }
+        }        
+        commitCommands(selection, commands);
+        return !commands.isEmpty();
+    }
+    
+    
+    /** Paste tags from JOSM buffer
+     * @param selection objects 
+     * @param commands
+     * @return 
+     */
+    public static boolean pasteTagsFromJOSMBuffer(Collection<OsmPrimitive> selection) {
+        List<PrimitiveData> directlyAdded = Main.pasteBuffer.getDirectlyAdded();
+        if (directlyAdded==null || directlyAdded.isEmpty()) return false;
+
+        PasteTagsAction.TagPaster tagPaster = new PasteTagsAction.TagPaster(directlyAdded, selection);
+        List<Command> commands = new ArrayList<Command>();
+        for (Tag tag : tagPaster.execute()) {
+            commands.add(new ChangePropertyCommand(selection, tag.getKey(), "".equals(tag.getValue()) ? null : tag.getValue()));
         }
+        commitCommands(selection, commands);
+        return true;
+    }
+
+    /**
+     * Create and execute SequenceCommand with descriptive title
+     * @param commands 
+     */
+    private static void commitCommands(Collection<OsmPrimitive> selection, List<Command> commands) {
         if (!commands.isEmpty()) {
             String title1 = trn("Pasting {0} tag", "Pasting {0} tags", commands.size(), commands.size());
             String title2 = trn("to {0} object", "to {0} objects", selection.size(), selection.size());
@@ -301,10 +325,22 @@
                             commands
                     ));
         }
-        
     }
+    
+    private static void showBadBufferMessage() {
+        String msg = tr("<html><p> Sorry, it is impossible to paste tags from buffer. It does not contain any JOSM object"
+            + " or suitable text. </p></html>");
+        JPanel p = new JPanel(new GridBagLayout());
+        p.add(new JLabel(msg),GBC.eop());
+        p.add(new UrlLabel(
+                HelpUtil.getHelpTopicUrl(HelpUtil.buildAbsoluteHelpTopic(help))),
+                GBC.eop());
 
-
+        ConditionalOptionPaneUtil.showMessageDialog(
+            "paste_badbuffer", Main.parent,
+            p, tr("Warning"), JOptionPane.WARNING_MESSAGE);
+    }
+    
     @Override
     protected void updateEnabledState() {
         if (getCurrentDataSet() == null) {
