On Wednesday, June 4, 2003, at 06:58 PM, Johan Sj�berg wrote:
An example is a Cocoon Transfomrer that needs to lookup a Phoenix (external) service. The same goes for components in other web services that have one entry servlet to a larger system.

subclass :)


attached is the subclass of ParanoidCocoonServlet that I use. you can hack out the classpath related items and just subclass CocoonServlet. That code is in there because javac/jikes in 2.0.4 needs access to jar files when compiling XSP. in 2.1 that shouldn't be needed as the eclipse compiler compiles using just the classpath.
-pete



package com.pace2020.appbox.web;

import java.io.File;
import java.util.Arrays;
import javax.servlet.ServletException;

import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.WrapperComponentManager;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.phoenix.BlockContext;
import org.apache.cocoon.servlet.ParanoidCocoonServlet;
import org.apache.cocoon.util.IOUtils;

/**
 *
 * @author <a href="[EMAIL PROTECTED]">peter royal</a>
 */
public class AppboxCocoonServlet extends ParanoidCocoonServlet implements Serviceable, 
Contextualizable
{
    private ComponentManager m_componentManager;
    private File m_baseDirectory;

    public void contextualize( Context context )
        throws ContextException
    {
        m_baseDirectory = ( ( BlockContext ) context ).getBaseDirectory();
    }

    public void service( ServiceManager manager )
        throws ServiceException
    {
        m_componentManager = new WrapperComponentManager( manager );
    }

    protected synchronized ComponentManager getParentComponentManager()
    {
        return m_componentManager;
    }

    protected String getClassPath() throws ServletException
    {
        final StringBuffer buildClassPath = new StringBuffer( 256 );
        final File root = new File( m_baseDirectory, "webapp/lib" );

        if( !root.exists() || !root.isDirectory() )
        {
            throw new ServletException( root + " does not exist, cannot create 
classpath" );
        }

        final File[] libraries = root.listFiles();

        Arrays.sort( libraries );

        for( int i = 0; i < libraries.length; i++ )
        {
            final String fullName = IOUtils.getFullFilename( libraries[i] );

            buildClassPath.append( File.pathSeparatorChar ).append( fullName );
        }

        buildClassPath.append( File.pathSeparatorChar );
        buildClassPath.append( System.getProperty( "java.class.path" ) );

        return buildClassPath.toString();
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to