head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2001.08.30.17.57.12;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2001.08.30.16.02.35;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.08.30.02.01.38;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2001.08.30.01.50.38;	author dlr;	state Exp;
branches;
next	1.1;

1.1
date	2001.08.29.19.42.49;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Servlet configuration is now part of component configuration. ComponentTools and ComponentTool provide an interface to component configuration and will be used in templates to process component-specific template fragments.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet (http://www.collab.net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of CollabNet.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.component;

import java.util.*;
import java.io.File;

import org.apache.turbine.util.Log;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.commons.util.StringUtils;

import org.apache.fulcrum.ServiceManager;
import org.apache.fulcrum.TurbineServices;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.util.Log;

/**
 * A class for accessing the installed components from a template.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 * @@author <a href="mailto:dlr@@finemaltcoding.com">Daniel Rall</a>
 * @@version $Id: ComponentTool.java,v 1.4 2001/08/30 16:02:35 leonardr Exp $
 */
public class ComponentTool
{
    private static String SERVLET_CONF_PREFIX="servlet";

    private static String COMPONENT_KEY="component";
    private static String HUMAN_READABLE_NAME_KEY="humanReadableName";
    private static String COMPONENT_PACKAGE_KEY="package";
    private static String LISTENER_KEY ="listener";

    private String componentName;
    private String humanReadableName;
    private String componentPackage;
    private String componentDir;
    private Class listener;

    private ExtendedProperties componentConfig;
    private ExtendedProperties servletConfig;
    
    /**
     * Creates a new component tool.
     *
     * @@param componentName The name of the component to create a tool
     * for.
     */
    public ComponentTool(String componentName, ExtendedProperties config)
    {
        this.componentName = componentName;
        this.componentConfig = config;
        servletConfig = componentConfig.subset(SERVLET_CONF_PREFIX);

        humanReadableName = config.getString
            (HUMAN_READABLE_NAME_KEY, componentName); 
        componentPackage = config.getString
            (COMPONENT_PACKAGE_KEY, "org.tigris." 
             + componentName.toLowerCase());       
        componentDir = StringUtils.replace
            (componentPackage, ".", File.separator);

        listener = null;
        String listenerName = config.getString(LISTENER_KEY);
        if (listenerName != null)
        {
            try
            {
                listener = Class.forName(listenerName);
            }
            catch (ClassNotFoundException e)
            {
                throw new Error("Could not find listener class " 
                                + listenerName + '!');
            }
        }
    }

    /**
     * Returns the name of this component.
     */
    public String getName()
    {
        return componentName;
    }

    /**
     * Returns the human-readable name of this component.
     */
    public String getHumanReadableName()
    {
        return humanReadableName;
    }

    /**
     * Returns the package of this component.
     */
    public String getPackage()
    {
        return componentPackage;
    }

    /**
     * Returns the package directory of this component.
     */
    public String getDirectory()
    {
        return componentDir;
    }

    /**
     * Returns the designated listener for this component
     */
    public Class getListener()
    {
        return listener;
    }

    /**
     * Returns the properties this component provides for the given
     * servlet.
     */
    public Properties getServletProperties(String servletName)
    {
        Properties servletProperties = null;
        ExtendedProperties subset = servletConfig.subset(servletName);
        if (subset != null)
        {
            servletProperties = subset.getProperties("properties");
            servletProperties.put(COMPONENT_KEY, componentName);
        }        
        return servletProperties;
    }
}
@


1.4
log
@Sorted out my and dlr's code.
@
text
@d66 1
a66 1
 * @@version $Id: ComponentTool.java,v 1.3 2001/08/30 02:01:38 dlr Exp $
d72 1
d75 1
d81 1
d105 31
d155 1
a155 1
     * Returns the package directory of this component.
d157 1
a157 1
    public String getHumanReadableName()
d159 1
a159 1
        return humanReadableName;
d168 1
a168 1
        Properties myProperties = null;
d172 4
a175 4
            myProperties = subset.getProperties("properties");
        }
        Log.debug("Servlet properties: " + myProperties);
        return myProperties;
@


1.3
log
@Now setting up packageDir (previously servletDirectory).
@
text
@d47 1
a47 1
package org.tigris.helm.tool;
d49 4
d66 1
a66 1
 * @@version $Id: ComponentTool.java,v 1.2 2001/08/30 01:50:38 dlr Exp $
d68 1
a68 1
public class ComponentTool implements ApplicationTool
d70 5
d76 3
d81 2
a82 6

    /**
     * Previously <code>servletDirectory</code>, on a per-servlet basis.
     */
    private String packageDir;

d89 1
a89 1
    public ComponentTool(String componentName)
d92 18
d115 1
a115 1
    public String getPackageDirectory()
d117 1
a117 1
        return packageDir;
a119 6
    // TODO: Add methods corresponding to various component UI and
    // configuration options here.


    // ApplicationTool implementation

d121 1
a121 1
     * Calls {@@link #refresh()}.
d123 1
a123 1
    public void init(Object ignored)
d125 1
a125 1
        refresh();
d129 2
a130 1
     * Refreshes this component's configuration.
d132 1
a132 1
    public void refresh()
d134 3
a136 2
        ServiceManager mgr = TurbineServices.getInstance();
        if (mgr != null)
d138 1
a138 12
            componentConfig = mgr.getConfiguration().subset("component." +
                                                            componentName);
            packageDir = componentConfig.getString
                ("packageDir", "org.tigris." + componentName.toLowerCase());
            if (StringUtils.isEmpty(packageDir))
            {
                Log.warn("Missing package directory configuration for " +
                         "component:" + componentName);
            }

            // Add component property assignments here
            //i.e. foo = componentConfig.getString("foo");
d140 2
@


1.2
log
@Began to flesh out ComponentTool as an implementation of Turbine's
ApplicationTool interface (the thing used by the TurbinePullService).
@
text
@a48 2
import java.io.File;

d50 1
d55 1
d62 1
a62 1
 * @@version $Id: ComponentTool.java,v 1.1 2001/08/29 19:42:49 leonardr Exp $
d73 1
a73 1
    private File packageDir;
d86 8
d118 8
@


1.1
log
@Moved integration-oriented code into new component package.
@
text
@d51 5
a55 1
import org.tigris.helm.tool.HelmProperties;
d61 2
a62 1
 * @@version $Id: TemplateTool.java,v 1.12 2001/07/23 19:52:23 dlr Exp $
d64 1
a64 1
public class ComponentTool
d66 33
d100 14
@

