Skip to content

Instantly share code, notes, and snippets.

@chrismccracken
Created August 26, 2016 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismccracken/77d11cec98fb636452213c9fb69c568e to your computer and use it in GitHub Desktop.
Save chrismccracken/77d11cec98fb636452213c9fb69c568e to your computer and use it in GitHub Desktop.
package com.dotmarketing.osgi.tuckey;
import com.dotcms.repackage.org.osgi.framework.BundleContext;
import com.dotmarketing.osgi.GenericBundleActivator;
import com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.NormalRule;
import com.dotcms.repackage.org.tuckey.web.filters.urlrewrite.SetAttribute;
public class Activator extends GenericBundleActivator {
@SuppressWarnings ("unchecked")
public void start ( BundleContext context ) throws Exception {
initializeServices( context );
// Create the rewrite rule with the specified request prefix "es"
NormalRule esLangRewriteRule = new NormalRule();
esLangRewriteRule.setFrom( "^/es/(.*)" );
// Set the target page language ID request attribute
SetAttribute langIdRequestAttribute = new SetAttribute();
langIdRequestAttribute.setName( "com.dotmarketing.htmlpage.language" );
langIdRequestAttribute.setValue( "2" );
esLangRewriteRule.addSetAttribute( langIdRequestAttribute );
// Set the target page language ID session attribute
SetAttribute langIdSessionAttribute = new SetAttribute();
langIdSessionAttribute.setType( "session" );
langIdSessionAttribute.setName( "com.dotmarketing.htmlpage.language" );
langIdSessionAttribute.setValue( "2" );
esLangRewriteRule.addSetAttribute( langIdSessionAttribute );
// Set the target page URL attribute
SetAttribute cmsFilterUrlMapOverrideAttribute = new SetAttribute();
cmsFilterUrlMapOverrideAttribute.setName( "CMS_FILTER_URLMAP_OVERRIDE" );
cmsFilterUrlMapOverrideAttribute.setValue( "/$1" );
esLangRewriteRule.addSetAttribute( cmsFilterUrlMapOverrideAttribute );
addRewriteRule( esLangRewriteRule );
}
public void stop ( BundleContext context ) throws Exception {
unregisterServices( context );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment