1 package net.sourceforge.phpeclipse.wiki.actions;
3 import net.sourceforge.phpeclipse.wiki.blog.Configuration;
4 import net.sourceforge.phpeclipse.wiki.blog.MetaWeblog;
5 import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction;
6 import net.sourceforge.phpeclipse.wiki.editor.WikiEditor;
7 import net.sourceforge.phpeclipse.wiki.preferences.Util;
8 import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer;
9 import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory;
11 import org.eclipse.core.resources.IFile;
12 import org.eclipse.jface.action.IAction;
13 import org.eclipse.jface.dialogs.MessageDialog;
14 import org.eclipse.jface.text.TextSelection;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.ui.IEditorActionDelegate;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IFileEditorInput;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.texteditor.AbstractTextEditor;
22 public final class NewPostBlogHTMLAction implements IEditorActionDelegate {
23 // public static String APPKEY =
24 // "1c0c75ffffffb512ffffff9575ffffff97ffffffd2ffffff87ffffff91ffffffe41dffffffc5320cffffffab544effffffc0546459ffffff83";
26 private IWorkbenchWindow window;
28 private AbstractTextEditor fEditor;
30 public void dispose() {
33 public void init(IWorkbenchWindow window) {
37 public void selectionChanged(IAction action, ISelection selection) {
38 if (selection.isEmpty()) {
41 if (selection instanceof TextSelection) {
42 action.setEnabled(true);
45 if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) {
46 action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class));
50 public void run(IAction action) {
51 if (fEditor == null) {
52 IEditorPart targetEditor = window.getActivePage().getActiveEditor();
53 if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
54 fEditor = (AbstractTextEditor) targetEditor;
57 if (fEditor != null) {
59 Configuration config = new Configuration("http://localhost:8080/blog/default", "1", "root", "******");
60 IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
61 IFile file = ei.getFile();
62 IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject());
63 StringBuffer htmlBuffer = new StringBuffer();
64 CreatePageAction.convertWikiBuffer(htmlBuffer, file, renderer, false);
66 String[] result = new String[2];
67 boolean cache = config.promptForPassword(config.getUser(), "Insert Config", true, result);
68 if (result[0] == null || result[1] == null) {
71 if (result[0].equals("") || result[1].equals("") ) {
75 String title = Util.getWikiTitle(file);
77 MetaWeblog metaWebLog = new MetaWeblog(config);
78 String guid = metaWebLog.newPost(file, title, htmlBuffer, true);
79 System.out.println(guid);
81 MessageDialog.openError(null, "Undefined Blog Title: ", "Blog file name must end with *.wp");
83 } catch (Exception e) {
84 MessageDialog.openError(null, "Exception: ", e.toString());
88 // IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput();
89 // IFile file = ei.getFile();
90 // IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject());
91 // StringBuffer htmlBuffer = new StringBuffer();
92 // CreatePageAction.convertWikiBuffer(htmlBuffer, file, renderer, false);
93 // XmlRpcClientLite xmlrpc = new XmlRpcClientLite("http://www.plog4u.de/xmlrpc.php");
94 // Vector rpcParams = new Vector();
95 // rpcParams.add(APPKEY);
96 // rpcParams.add("1"); // blog.getBlogId());
97 // rpcParams.add("admin");
98 // rpcParams.add("******"); // fPassword
99 // rpcParams.add(htmlBuffer.toString()); //getContent());
100 // rpcParams.add(Boolean.TRUE); // publish == yes
102 // String postId = (String) xmlrpc.execute("blogger.newPost", rpcParams);
105 // } catch (Exception e) {
106 // e.printStackTrace();
112 public void setActiveEditor(IAction action, IEditorPart targetEditor) {
113 if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) {
114 fEditor = (AbstractTextEditor) targetEditor;