-
-
Save nkeiter/64fbaf94166a02ae8b4dc014922cab51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.gettysburg.nkeiter.transportation.portlet.osgi; | |
import com.dotcms.repackage.org.apache.commons.io.FileUtils; | |
import com.dotcms.repackage.org.apache.logging.log4j.LogManager; | |
import com.dotcms.repackage.org.apache.logging.log4j.core.LoggerContext; | |
import com.dotmarketing.loggers.Log4jUtil; | |
import com.dotmarketing.osgi.GenericBundleActivator; | |
import com.dotmarketing.util.Logger; | |
import com.liferay.util.FileUtil; | |
import java.io.File; | |
import java.net.URL; | |
import org.osgi.framework.BundleContext; | |
public class Activator extends GenericBundleActivator | |
{ | |
public static Class<Activator> clazz = Activator.class; | |
private LoggerContext pluginLoggerContext; | |
private static final String PLUGIN_NAME = "Transportation Portlets"; | |
private static final String PORTLET_1 = "REST_PORTLET_TRANSPORTATION_SCHEDULING"; | |
private static final String PORTLET_2 = "REST_PORTLET_TRANSPORTATION_CALENDAR"; | |
private static final String PORTLET_3 = "REST_PORTLET_TRANSPORTATION"; | |
private static final String[] PORTLETS = { PORTLET_1, PORTLET_2, PORTLET_3 }; | |
private void copyJSPs() | |
{ | |
for ( String portlet : PORTLETS ) | |
{ | |
String portletDirectory = portlet.toLowerCase(); | |
URL sourceURL = getClass().getResource( "/resources/jsp/" + portletDirectory + "/" ); | |
File sourceDirectory = new File ( sourceURL.toString() ); | |
File destinationDirectory = new File ( "WEB-INF/jsp/" + portletDirectory + "/" ); | |
try | |
{ | |
FileUtils.copyDirectory( sourceDirectory, destinationDirectory ); | |
} | |
catch ( Exception exception ) | |
{ | |
Logger.error( this, "Can't copy directory [" + portletDirectory + "]", exception ); | |
} | |
} | |
} | |
private void deleteJSPs() | |
{ | |
for ( String portlet : PORTLETS ) | |
{ | |
String portletDirectory = portlet.toLowerCase(); | |
File destinationDirectory = new File ( "WEB-INF/jsp/" + portletDirectory + "/" ); | |
try | |
{ | |
FileUtil.deltree( destinationDirectory ); | |
} | |
catch ( Exception exception ) | |
{ | |
Logger.error( this, "Can't delete directory [" + portletDirectory + "]", exception ); | |
} | |
} | |
} | |
@Override | |
public void start( BundleContext bundleContext ) throws Exception | |
{ | |
// Initializing log4j... | |
LoggerContext dotcmsLoggerContext = Log4jUtil.getLoggerContext(); | |
// Initialing the log4j context of this plugin based on the dotCMS logger context | |
this.pluginLoggerContext = (LoggerContext) LogManager.getContext( clazz.getClassLoader(), false, dotcmsLoggerContext, dotcmsLoggerContext.getConfigLocation() ); | |
Logger.info( this, "Got to start( BundleContext ) " + PLUGIN_NAME ); | |
// Initializing services... | |
initializeServices( bundleContext ); | |
// Copy JSPs | |
copyJSPs(); | |
// Register our portlets | |
String[] xmls = new String[]{ "conf/liferay-portlet.xml" }; | |
registerPortlets( bundleContext, xmls ); | |
} | |
@Override | |
public void stop( BundleContext bundleContext ) throws Exception | |
{ | |
Logger.info( this, "Got to stop( BundleContext ) " + PLUGIN_NAME ); | |
// Unregister all bundle services | |
unregisterServices( bundleContext ); | |
// Delete JSPs | |
deleteJSPs(); | |
// Shutting down log4j in order to avoid memory leaks | |
Log4jUtil.shutdown( this.pluginLoggerContext ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment