Sorry for spamming:

I wanted to inform you that when I configure the siteMergeFilter to my own 
class it works.


Here is my class code. Would be nice if someone from the stk team is looking 
for it :-)


[code]public class SiteMergeFilter extends AbstractMgnlFilter {

    /**
     * The logger for this class.
     */
    private static final Logger LOG = 
LoggerFactory.getLogger(SiteMergeFilter.class);
    private final SiteManager siteManager;

    /**
     * @param siteManager
     */
    @Inject
    public SiteMergeFilter(final SiteManager siteManager) {

        this.siteManager = siteManager;
    }

    /*
     * (non-Javadoc)
     * @see 
info.magnolia.cms.filters.AbstractMgnlFilter#doFilter(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)
     */
    @Override
    public void doFilter(final HttpServletRequest request, final 
HttpServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

        final ExtendedAggregationState aggregationState = 
(ExtendedAggregationState) MgnlContext.getAggregationState();

        final Site currentSite =
                        aggregationState.getSite() == null ? 
siteManager.getDefaultSite() : aggregationState.getSite();

        Site site2SetOnAggregationState = currentSite;

        final String channelName = aggregationState.getChannel().getName();
        if (!StringUtils.isBlank(channelName)) {

            final Site variation = currentSite.getVariations().get(channelName);
            if (variation != null) {
                LOG.debug("Serving site variation '{}'", variation.getName());

                // See SCRUM-835. Creating/merging the fakeSite would result in 
mgnl searching for various
                // resources under <webappName>/variation-siteName instead of 
<webappName>/currentSiteName.
                final Site fakeSiteWithProperName = 
Components.newInstance(getClass(currentSite.getClass()));
                fakeSiteWithProperName.setName(currentSite.getName());

                final Site themeAndTemplatesMerge =
                                BeanMergerUtil.merge(fakeSiteWithProperName, 
variation, currentSite);
                site2SetOnAggregationState = themeAndTemplatesMerge;
            } else {
                LOG.debug("There's no variation named {} - serving site {}", 
channelName, currentSite.getName());
            }
        }
        aggregationState.setSite(site2SetOnAggregationState);
        chain.doFilter(request, response);
    }

    /**
     * @param clazz
     * @return
     */
    @SuppressWarnings("unchecked")
    private Class<Site> getClass(final Class<? extends Site> clazz) {

        return getUnproxiedClass(clazz);

    }

    /**
     * Gets the superclass of the class if it is a proxy class, else it returns 
the class itself.
     * 
     * @param clazz
     * @return
     */
    @SuppressWarnings("rawtypes")
    private Class getUnproxiedClass(final Class clazz) {

        if (isProxiedClass(clazz)) {
            return getUnproxiedClass(clazz.getSuperclass());
        }
        return clazz;
    }

    /**
     * Checks if the class is a proxy class.
     * 
     * @param clazz
     * @return
     */
    @SuppressWarnings("rawtypes")
    private boolean isProxiedClass(final Class clazz) {

        return clazz.getName().contains("$$EnhancerByCGLIB$$") ||
            clazz.getName().contains("$$FastClassByCGLIB$$") ||
            clazz.getName().contains("_$$_javassist");
    }
}[/code]

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=eb86c05f-84f7-43e5-9b5a-e041b4efa8d2


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to