1 package net.sourceforge.phpeclipse.wiki.actions.blogwiki;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import net.sourceforge.phpeclipse.wiki.blog.MetaWeblog;
8 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
9 import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
10 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
11 import net.sourceforge.phpeclipse.wiki.internal.Configuration;
12 import net.sourceforge.phpeclipse.wiki.internal.ConfigurationManager;
13 import net.sourceforge.phpeclipse.wiki.internal.IConfiguration;
14 import net.sourceforge.phpeclipse.wiki.preferences.Util;
15 import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer;
16 import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.dialogs.MessageDialog;
21 import org.eclipse.jface.text.TextSelection;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.LabelProvider;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.ui.IEditorActionDelegate;
26 import org.eclipse.ui.IEditorPart;
27 import org.eclipse.ui.IFileEditorInput;
28 import org.eclipse.ui.IWorkbenchWindow;
29 import org.eclipse.ui.dialogs.ListSelectionDialog;
30 import org.eclipse.ui.internal.dialogs.ListContentProvider;
31 import org.eclipse.ui.texteditor.AbstractTextEditor;
33 public final class NewPostBlogHTMLAction implements IEditorActionDelegate {
34 // public static String APPKEY =
35 // "1c0c75ffffffb512ffffff9575ffffff97ffffffd2ffffff87ffffff91ffffffe41dffffffc5320cffffffab544effffffc0546459ffffff83";
37 private IWorkbenchWindow window;
39 private AbstractTextEditor fEditor;
41 public void dispose() {
44 public void init(IWorkbenchWindow window) {
48 public void selectionChanged(IAction action, ISelection selection) {
49 if (selection.isEmpty()) {
52 if (selection instanceof TextSelection) {
53 action.setEnabled(true);
56 if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
57 action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
61 protected Configuration getConfiguration(){
62 List allConfigsList = ConfigurationManager.getInstance().getConfigurations();
63 ArrayList configsList = new ArrayList();
64 for (int i = 0; i < allConfigsList.size(); i++) {
65 IConfiguration temp = (IConfiguration) allConfigsList.get(i);
66 if (temp.getType().equals(WikiEditorPlugin.BLOG_A_HTML)) {
67 configsList.add(temp);
70 Collections.sort(configsList);
71 Configuration configuration = null;
72 ListSelectionDialog listSelectionDialog = new ListSelectionDialog(WikiEditorPlugin.getDefault().getWorkbench()
73 .getActiveWorkbenchWindow().getShell(), configsList, new ListContentProvider(), new LabelProvider(),
74 "Select blog configuration for your wiki HTMl text.");
75 listSelectionDialog.setTitle("Multiple active configuration found");
76 if (listSelectionDialog.open() == Window.OK) {
77 Object[] locations = listSelectionDialog.getResult();
78 if (locations != null) {
79 for (int i = 0; i < locations.length; i++) {
80 configuration = (Configuration) locations[i];
88 public void run(IAction action) {
89 if (fEditor == null) {
90 IEditorPart targetEditor = window.getActivePage().getActiveEditor();
91 if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
92 fEditor = (AbstractTextEditor) targetEditor;
95 if (fEditor != null) {
97 Configuration config = getConfiguration();
98 IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
99 IFile file = ei.getFile();
100 IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject());
101 StringBuffer htmlBuffer = new StringBuffer();
102 CreatePageAction.convertWikiBuffer(null, htmlBuffer, file, renderer, false);
104 String[] result = new String[2];
105 boolean cache = config.promptForPassword(config.getUser(), "Insert Config", true, result);
106 if (result[0] == null || result[1] == null) {
109 if (result[0].equals("") || result[1].equals("") ) {
113 String title = Util.getWikiTitle(file);
115 MetaWeblog metaWebLog = new MetaWeblog(config);
116 String guid = metaWebLog.newPost(file, title, htmlBuffer, true);
117 System.out.println(guid);
119 MessageDialog.openError(null, "Undefined Blog Title: ", "Blog file name must end with *.wp");
121 } catch (Exception e) {
122 MessageDialog.openError(null, "Exception: ", e.toString());
126 // IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
127 // IFile file = ei.getFile();
128 // IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject());
129 // StringBuffer htmlBuffer = new StringBuffer();
130 // CreatePageAction.convertWikiBuffer(htmlBuffer, file, renderer, false);
131 // XmlRpcClientLite xmlrpc = new XmlRpcClientLite("http://www.plog4u.de/xmlrpc.php");
132 // Vector rpcParams = new Vector();
133 // rpcParams.add(APPKEY);
134 // rpcParams.add("1"); // blog.getBlogId());
135 // rpcParams.add("admin");
136 // rpcParams.add("******"); // fPassword
137 // rpcParams.add(htmlBuffer.toString()); //getContent());
138 // rpcParams.add(Boolean.TRUE); // publish == yes
140 // String postId = (String) xmlrpc.execute("blogger.newPost", rpcParams);
143 // } catch (Exception e) {
144 // e.printStackTrace();
150 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
151 if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
152 fEditor = (AbstractTextEditor) targetEditor;