Skip to content

Commit

Permalink
Updated the code for dotCMS 2.5.
Browse files Browse the repository at this point in the history
Updated code to use HTTPS, this is required since Jan 2014.
Improved error handling in OSGi activator.
Added ViewTool for fetching/formatting time lines in velocity.
  • Loading branch information
yasindilekci committed Sep 27, 2016
1 parent 23fe766 commit f92f76b
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 89 deletions.
17 changes: 0 additions & 17 deletions conf/web-ext.xml

This file was deleted.

71 changes: 41 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
<?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/xsd/maven-4.0.0.xsd">
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>nl.isaac.dotcms.plugin.twitter</groupId>
<artifactId>isaac-dotcms-twitter</artifactId>
<version>2.3.0</version>
<version>2.5.0</version>
<packaging>bundle</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<organization>
<name>ISAAC Software Solutions</name>
<url>http://www.isaac.nl</url>
</organization>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<prerequisites>
<maven>3.0</maven>
</prerequisites>

<organization>
<name>ISAAC Software Solutions</name>
<url>http://www.isaac.nl</url>
</organization>

<build>
<plugins>
<plugin>
Expand All @@ -38,40 +43,46 @@
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>nl.isaac.dotcms.twitter.osgi.TwitterActivator</Bundle-Activator>
<Import-Package>org.osgi.framework,
<Import-Package>
org.osgi.framework,
com.dotmarketing.osgi,
com.dotmarketing.beans,
com.dotmarketing.plugin.business,
com.dotmarketing.portlets.fileassets.business,
com.dotmarketing.portlets.languagesmanager.business,
com.dotmarketing.portlets.languagesmanager.model</Import-Package>
com.dotmarketing.portlets.languagesmanager.model
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>

<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>

<Data-Files>conf</Data-Files>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<dependency>
<groupId>com.dotcms</groupId>
<artifactId>dotcms-core</artifactId>
<version>2.3.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/dotcms-core-2.3.1.jar</systemPath>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>3.0.3</version>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down Expand Up @@ -115,16 +126,16 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
<scope>provided</scope>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
<scope>provided</scope>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
Expand Down
85 changes: 48 additions & 37 deletions src/main/java/nl/isaac/dotcms/twitter/osgi/TwitterActivator.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package nl.isaac.dotcms.twitter.osgi;

/**
* dotCMS Twitter plugin by ISAAC - The Full Service Internet Agency is licensed
* dotCMS Twitter plugin by ISAAC - The Full Service Internet Agency is licensed
* under a Creative Commons Attribution 3.0 Unported License
* - http://creativecommons.org/licenses/by/3.0/
* - http://www.geekyplugins.com/
*
*
* @copyright Copyright (c) 2013 ISAAC Software Solutions B.V. (http://www.isaac.nl)
*/

Expand All @@ -16,7 +16,9 @@
import nl.isaac.dotcms.twitter.servlet.SearchServlet;
import nl.isaac.dotcms.twitter.servlet.TimelineServlet;
import nl.isaac.dotcms.twitter.util.TwitterFieldFactory;
import nl.isaac.dotcms.twitter.viewtool.TwitterViewTool;
import nl.isaac.dotcms.util.osgi.ExtendedGenericBundleActivator;
import nl.isaac.dotcms.util.osgi.ViewToolScope;

import org.apache.felix.http.api.ExtHttpService;
import org.osgi.framework.BundleContext;
Expand All @@ -39,44 +41,53 @@ public class TwitterActivator extends ExtendedGenericBundleActivator {
private ServiceTracker<ExtHttpService, ExtHttpService> tracker;

public void start(BundleContext context) throws Exception {
TwitterFieldFactory twitterFieldFactory = new TwitterFieldFactory();

Logger.info(this, "Twitter: Activator.start()");

initializeServices(context);

// Register the servlet and filter
tracker = new ServiceTracker<ExtHttpService, ExtHttpService>(context, ExtHttpService.class, null) {
@Override public ExtHttpService addingService(ServiceReference<ExtHttpService> reference) {
ExtHttpService extHttpService = super.addingService(reference);
searchServlet = new SearchServlet();
timelineServlet = new TimelineServlet();
try {
extHttpService.registerServlet("/search.json", searchServlet, null, null);
extHttpService.registerServlet("/1/statuses/user_timeline.json", timelineServlet, null, null);
} catch (ServletException e) {
throw new RuntimeException("Failed to register servlet and filter", e);
} catch (NamespaceException e) {
throw new RuntimeException("Failed to register servlet and filter", e);
try {
TwitterFieldFactory twitterFieldFactory = new TwitterFieldFactory();

// Initialize the required OSGI services
initializeServices(context);

// ViewTool
addViewTool(context, TwitterViewTool.class, "isaacTwitterTool", ViewToolScope.REQUEST);

// Register the servlet and filter
tracker = new ServiceTracker<ExtHttpService, ExtHttpService>(context, ExtHttpService.class, null) {
@Override public ExtHttpService addingService(ServiceReference<ExtHttpService> reference) {
ExtHttpService extHttpService = super.addingService(reference);
searchServlet = new SearchServlet();
timelineServlet = new TimelineServlet();
try {
extHttpService.registerServlet("/search.json", searchServlet, null, null);
extHttpService.registerServlet("/1/statuses/user_timeline.json", timelineServlet, null, null);
} catch (ServletException e) {
throw new RuntimeException("Failed to register servlet and filter", e);
} catch (NamespaceException e) {
throw new RuntimeException("Failed to register servlet and filter", e);
}
Logger.info(this, "Registered servlet and filter " + new Date(System.currentTimeMillis()));
return extHttpService;
}
Logger.info(this, "Registered servlet and filter " + new Date(System.currentTimeMillis()));
return extHttpService;
}
@Override public void removedService(ServiceReference<ExtHttpService> reference, ExtHttpService extHttpService) {
extHttpService.unregisterServlet(searchServlet);
extHttpService.unregisterServlet(timelineServlet);
super.removedService(reference, extHttpService);
}
};
tracker.open();
CMSFilter.addExclude("/search.json");
CMSFilter.addExclude("/1/statuses/user_timeline.json");

addRewriteRule("^/search.json$", "/app/search.json", "forward", "TwitterSearchServlet");
addRewriteRule("^/1/statuses/user_timeline.json$", "/app/1/statuses/user_timeline.json", "forward", "TwitterTimelineServlet");

//Check if required fields exists in the Host Structure, if not add them
twitterFieldFactory.createFieldsInHosts();
@Override public void removedService(ServiceReference<ExtHttpService> reference, ExtHttpService extHttpService) {
extHttpService.unregisterServlet(searchServlet);
extHttpService.unregisterServlet(timelineServlet);
super.removedService(reference, extHttpService);
}
};
tracker.open();
CMSFilter.addExclude("/search.json");
CMSFilter.addExclude("/1/statuses/user_timeline.json");

addRewriteRule("^/search.json$", "/app/search.json", "forward", "TwitterSearchServlet");
addRewriteRule("^/1/statuses/user_timeline.json$", "/app/1/statuses/user_timeline.json", "forward", "TwitterTimelineServlet");

//Check if required fields exists in the Host Structure, if not add them
twitterFieldFactory.createFieldsInHosts();
} catch (Throwable t) {
Logger.error(this, "Error while initializing Twitter plugin. Calling stop() to unregister plugin", t);
stop(context);
}
}

public void stop(BundleContext context) throws Exception {
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/nl/isaac/dotcms/twitter/pojo/CustomStatus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package nl.isaac.dotcms.twitter.pojo;

/**
* dotCMS Twitter plugin by ISAAC - The Full Service Internet Agency is licensed
* under a Creative Commons Attribution 3.0 Unported License
* - http://creativecommons.org/licenses/by/3.0/
* - http://www.geekyplugins.com/
*
* @copyright Copyright (c) 2013 ISAAC Software Solutions B.V. (http://www.isaac.nl)
*/

import java.util.Date;

import twitter4j.GeoLocation;
Expand All @@ -12,9 +21,8 @@
import twitter4j.User;
import twitter4j.UserMentionEntity;

@SuppressWarnings("serial")
public class CustomStatus {

public class CustomStatus {

private Date createdAt;
private long id;
private String id_str;
Expand Down Expand Up @@ -76,7 +84,7 @@ public CustomStatus(Status status) {
this.accessLevel = status.getAccessLevel();
this.user = status.getUser();
}

public Date getCreatedAt() {
return createdAt;
}
Expand Down Expand Up @@ -108,7 +116,7 @@ public String getText() {
public void setText(String text) {
this.text = text;
}

public String getSource() {
return source;
}
Expand Down
Loading

0 comments on commit f92f76b

Please sign in to comment.