package net.sourceforge.phpeclipse.wiki.actions; import net.sourceforge.phpeclipse.wiki.blog.Configuration; import net.sourceforge.phpeclipse.wiki.blog.MetaWeblog; import net.sourceforge.phpeclipse.wiki.builder.CreatePageAction; import net.sourceforge.phpeclipse.wiki.editor.WikiEditor; import net.sourceforge.phpeclipse.wiki.preferences.Util; import net.sourceforge.phpeclipse.wiki.renderer.IContentRenderer; import net.sourceforge.phpeclipse.wiki.renderer.RendererFactory; import org.eclipse.core.resources.IFile; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.texteditor.AbstractTextEditor; public final class NewPostBlogHTMLAction implements IEditorActionDelegate { // public static String APPKEY = // "1c0c75ffffffb512ffffff9575ffffff97ffffffd2ffffff87ffffff91ffffffe41dffffffc5320cffffffab544effffffc0546459ffffff83"; private IWorkbenchWindow window; private AbstractTextEditor fEditor; public void dispose() { } public void init(IWorkbenchWindow window) { this.window = window; } public void selectionChanged(IAction action, ISelection selection) { if (selection.isEmpty()) { return; } if (selection instanceof TextSelection) { action.setEnabled(true); return; } if (window.getActivePage() != null && window.getActivePage().getActivePart() != null) { action.setEnabled(window.getActivePage().getActivePart().getClass().equals(WikiEditor.class)); } } public void run(IAction action) { if (fEditor == null) { IEditorPart targetEditor = window.getActivePage().getActiveEditor(); if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) { fEditor = (AbstractTextEditor) targetEditor; } } if (fEditor != null) { try { Configuration config = new Configuration("http://localhost:8080/blog/default", "1", "root", "******"); IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput(); IFile file = ei.getFile(); IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject()); StringBuffer htmlBuffer = new StringBuffer(); CreatePageAction.convertWikiBuffer(htmlBuffer, file, renderer, false); String[] result = new String[2]; boolean cache = config.promptForPassword(config.getUser(), "Insert Config", true, result); if (result[0] == null || result[1] == null) { return; } if (result[0].equals("") || result[1].equals("") ) { return; } String title = Util.getWikiTitle(file); if (title != null) { MetaWeblog metaWebLog = new MetaWeblog(config); String guid = metaWebLog.newPost(file, title, htmlBuffer, true); System.out.println(guid); } else { MessageDialog.openError(null, "Undefined Blog Title: ", "Blog file name must end with *.wp"); } } catch (Exception e) { MessageDialog.openError(null, "Exception: ", e.toString()); e.printStackTrace(); } // try { // IFileEditorInput ei = (IFileEditorInput) fEditor.getEditorInput(); // IFile file = ei.getFile(); // IContentRenderer renderer = RendererFactory.createContentRenderer(file.getProject()); // StringBuffer htmlBuffer = new StringBuffer(); // CreatePageAction.convertWikiBuffer(htmlBuffer, file, renderer, false); // XmlRpcClientLite xmlrpc = new XmlRpcClientLite("http://www.plog4u.de/xmlrpc.php"); // Vector rpcParams = new Vector(); // rpcParams.add(APPKEY); // rpcParams.add("1"); // blog.getBlogId()); // rpcParams.add("admin"); // rpcParams.add("******"); // fPassword // rpcParams.add(htmlBuffer.toString()); //getContent()); // rpcParams.add(Boolean.TRUE); // publish == yes // // String postId = (String) xmlrpc.execute("blogger.newPost", rpcParams); // // // return postId; // } catch (Exception e) { // e.printStackTrace(); // // return null; // } } } public void setActiveEditor(IAction action, IEditorPart targetEditor) { if (targetEditor != null && (targetEditor instanceof AbstractTextEditor)) { fEditor = (AbstractTextEditor) targetEditor; } } }