Permalink
Browse files

Initial commit of the Flowdock Confluence plugin.

  • Loading branch information...
0 parents commit 2599ca0ef6b4590596ff218ce251d428e5d5c152 Otto Hilska committed Dec 3, 2010
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>flowdock-confluence-plugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,6 @@
+#Mon Nov 29 15:04:57 EET 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
@@ -0,0 +1,8 @@
+#Thu Nov 25 14:41:19 EET 2010
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
@@ -0,0 +1,6 @@
+To avoid future confusion, we recommend that you include a license with your plugin.
+This file is simply a reminder.
+
+For a template license you can have a look at: http://www.opensource.org/licenses/
+
+Atlassian releases most of its modules under a BSD license: http://www.opensource.org/licenses/bsd-license.php
@@ -0,0 +1,13 @@
+You have successfully created a plugin using the Confluence plugin archetype!
+
+Here are the SDK commands you'll use immediately:
+
+* atlas-run -- installs this plugin into Confluence and starts it on http://localhost:1990/confluence
+* atlas-debug -- same as atlas-run, but allows a debugger to attach at port 5005
+* atlas-cli -- after atlas-run or atlas-debug, opens a Maven command line window:
+ - 'pi' reinstalls the plugin into the running Confluence instance
+* atlas-help -- prints description for all commands in the SDK
+
+Full documentation is always available at:
+
+http://confluence.atlassian.com/display/DEVNET/Developing+your+Plugin+using+the+Atlassian+Plugin+SDK
81 pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.flowdock.plugins.confluence</groupId>
+ <artifactId>flowdock-confluence-plugin</artifactId>
+ <version>1.0</version>
+
+ <organization>
+ <name>Example Company</name>
+ <url>http://www.example.com/</url>
+ </organization>
+
+ <name>flowdock-confluence-plugin</name>
+ <description>This is the com.flowdock.plugins.confluence:flowdock-confluence-plugin plugin for Atlassian Confluence.</description>
+ <packaging>atlassian-plugin</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.atlassian.confluence</groupId>
+ <artifactId>confluence</artifactId>
+ <version>${confluence.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.atlassian.confluence.plugin</groupId>
+ <artifactId>func-test</artifactId>
+ <version>2.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jwebunit</groupId>
+ <artifactId>jwebunit-htmlunit-plugin</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.nekohtml</groupId>
+ <artifactId>nekohtml</artifactId>
+ <version>1.9.12</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.atlassian.maven.plugins</groupId>
+ <artifactId>maven-confluence-plugin</artifactId>
+ <version>3.2.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <productVersion>${confluence.version}</productVersion>
+ <productDataVersion>${confluence.data.version}</productDataVersion>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <confluence.version>3.4.1</confluence.version>
+ <confluence.data.version>3.1</confluence.data.version>
+ </properties>
+
+</project>
@@ -0,0 +1,49 @@
+package com.flowdock.plugins.confluence;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.atlassian.confluence.event.events.content.page.PageCreateEvent;
+import com.atlassian.confluence.event.events.content.page.PageUpdateEvent;
+import com.atlassian.event.api.EventListener;
+import com.atlassian.event.api.EventPublisher;
+
+public class ChangeListener {
+ public ChangeListener(EventPublisher eventPublisher) {
+ eventPublisher.register(this);
+ }
+
+ @EventListener
+ public void pageUpdateEvent(PageUpdateEvent event) {
+ Map<String, String> data = eventToMessage(event);
+ FlowdockConnection.sendApiMessage(data);
+ }
+
+ @EventListener
+ public void pageCreateEvent(PageCreateEvent event) {
+ Map<String, String> data = eventToMessage(event);
+ FlowdockConnection.sendApiMessage(data);
+ }
+
+ private Map<String, String> eventToMessage(PageCreateEvent event) {
+ HashMap<String, String> result = new HashMap<String, String>();
+
+ result.put("title", event.getPage().getDisplayTitle());
+ result.put("content", event.getContent().getContent());
+ result.put("user", event.getPage().getCreatorName());
+ result.put("space", event.getPage().getSpace().getName());
+
+ return result;
+ }
+
+ private Map<String, String> eventToMessage(PageUpdateEvent event) {
+ HashMap<String, String> result = new HashMap<String, String>();
+
+ result.put("title", event.getPage().getDisplayTitle());
+ result.put("content", event.getContent().getContent());
+ result.put("user", event.getPage().getLastModifierName());
+ result.put("space", event.getPage().getSpace().getName());
+
+ return result;
+ }
+}
@@ -0,0 +1,96 @@
+package com.flowdock.plugins.confluence;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Iterator;
+
+import com.atlassian.renderer.RenderContext;
+import com.atlassian.renderer.v2.macro.BaseMacro;
+import com.atlassian.renderer.v2.macro.MacroException;
+import com.atlassian.renderer.v2.RenderMode;
+import com.atlassian.confluence.pages.PageManager;
+import com.atlassian.confluence.pages.Page;
+import com.atlassian.confluence.spaces.SpaceManager;
+import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
+import com.atlassian.user.User;
+
+/**
+ * This very simple macro shows you the very basic use-case of displaying *something* on the Confluence page where it is used.
+ * Use this example macro to toy around, and then quickly move on to the next example - this macro doesn't
+ * really show you all the fun stuff you can do with Confluence.
+ */
+public class ExampleMacro extends BaseMacro
+{
+
+ // We just have to define the variables and the setters, then Spring injects the correct objects for us to use. Simple and efficient.
+ // You just need to know *what* you want to inject and use.
+
+ private final PageManager pageManager;
+ private final SpaceManager spaceManager;
+
+ public ExampleMacro(PageManager pageManager, SpaceManager spaceManager)
+ {
+ this.pageManager = pageManager;
+ this.spaceManager = spaceManager;
+ }
+
+ public boolean isInline()
+ {
+ return false;
+ }
+
+ public boolean hasBody()
+ {
+ return false;
+ }
+
+ public RenderMode getBodyRenderMode()
+ {
+ return RenderMode.NO_RENDER;
+ }
+
+ /**
+ * This method returns XHTML to be displayed on the page that uses this macro
+ * we just do random stuff here, trying to show how you can access the most basic
+ * managers and model objects. No emphasis is put on beauty of code nor on
+ * doing actually useful things :-)
+ */
+ public String execute(Map params, String body, RenderContext renderContext)
+ throws MacroException
+ {
+
+ // in this most simple example, we build the result in memory, appending HTML code to it at will.
+ // this is something you absolutely don't want to do once you start writing plugins for real. Refer
+ // to the next example for better ways to render content.
+ StringBuffer result = new StringBuffer();
+
+ // get the currently logged in user and display his name
+ User user = AuthenticatedUserThreadLocal.getUser();
+ if (user != null)
+ {
+ String greeting = "Hello " + user.getFullName() + "<br><br>";
+ result.append(greeting);
+ }
+
+ //get the pages added in the last 55 days to the DS space ("Demo Space"), and display them
+ List list = pageManager.getRecentlyAddedPages(55, "DS");
+ result.append("Some stats for the Demo space: <br> ");
+ for (Iterator i = list.iterator(); i.hasNext();)
+ {
+ Page page = (Page) i.next();
+ int numberOfChildren = page.getChildren().size();
+ String pageWithChildren = "Page " + page.getTitle() + " has " + numberOfChildren + " children <br> ";
+ result.append(pageWithChildren);
+ }
+
+ // and show the number of all spaces in this installation.
+ String spaces = "<br>Altogether, this installation has " + spaceManager.getAllSpaces().size() + " spaces. <br>";
+ result.append(spaces);
+
+ // this concludes our little demo. Now you should understand the basics of code injection use in Confluence, and how
+ // to get a really simple macro running.
+
+ return result.toString();
+ }
+
+}
@@ -0,0 +1,76 @@
+package com.flowdock.plugins.confluence;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class FlowdockConnection {
+ public static void main(String[] args) {
+ System.out.println("TESTING");
+ sendApiMessage(null);
+ System.out.println("DONE");
+ }
+
+ public static void sendApiMessage(Map<String, String> params) {
+ try {
+ URL apiUrl = getApiUrl();
+ postData(apiUrl, params);
+ } catch (MalformedURLException mue) {
+
+ } catch (IOException ioe) {
+
+ }
+ }
+
+ private static void postData(URL apiUrl, Map<String, String> params) throws IOException {
+ HttpURLConnection conn = (HttpURLConnection)apiUrl.openConnection();
+ conn.setRequestMethod("POST");
+ conn.setUseCaches(false);
+ conn.setDoOutput(true);
+ conn.setDoInput(true);
+ conn.setRequestProperty("User-Agent", "Flowdock Confluence Plugin");
+
+ OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
+ String postData = mapToPostData(params);
+ out.write(postData);
+ out.close();
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ while (in.readLine() != null);
+ in.close();
+
+ conn.connect();
+ }
+
+ private static String mapToPostData(Map<String, String> map) throws UnsupportedEncodingException {
+ Iterator<Entry<String, String>> iter = map.entrySet().iterator();
+ StringBuffer sb = new StringBuffer();
+ while (iter.hasNext()) {
+ Entry<String, String> keyval = iter.next();
+ String key = keyval.getKey();
+ String encodedValue = URLEncoder.encode(keyval.getValue(), "UTF-8");
+
+ sb.append(key);
+ sb.append("=");
+ sb.append(encodedValue);
+
+ if (!iter.hasNext()) break;
+
+ sb.append("&");
+ }
+ return sb.toString();
+ }
+
+ private static URL getApiUrl() throws MalformedURLException {
+ return new URL("https://api.tuntivirta.com/lol/confluence");
+ }
+}
@@ -0,0 +1,10 @@
+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+ <plugin-info>
+ <description>${project.description}</description>
+ <version>${project.version}</version>
+ <vendor name="${project.organization.name}" url="${project.organization.url}" />
+ <param name="configure.url">/admin/plugins/flowdock/configurePlugin.action</param>
+ </plugin-info>
+
+ <component name="Flowdock Change Listener" class="com.flowdock.plugins.confluence.ChangeListener" key="flowdockChangeListener"/>
+</atlassian-plugin>
Oops, something went wrong.

0 comments on commit 2599ca0

Please sign in to comment.