001package org.apache.turbine.modules;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.turbine.Turbine;
023import org.apache.turbine.pipeline.PipelineData;
024
025/**
026 * The purpose of this class is to allow one to load and execute Page
027 * modules.
028 *
029 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
030 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
031 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
032 * @version $Id: PageLoader.java 1773378 2016-12-09 13:19:59Z tv $
033 */
034public class PageLoader
035    extends GenericLoader<Page>
036    implements Loader<Page>
037{
038    /** The single instance of this class. */
039    private static PageLoader instance = new PageLoader();
040
041    /**
042     * These ctor's are private to force clients to use getInstance()
043     * to access this class.
044     */
045    private PageLoader()
046    {
047        super();
048    }
049
050    /**
051     * Attempts to load and execute the external page.
052     *
053     * @param pipelineData Turbine information.
054     * @param name Name of object that will execute the page.
055     * @throws Exception a generic exception.
056     */
057    @Override
058    public void exec(PipelineData pipelineData, String name)
059            throws Exception
060    {
061        // Execute page
062        getAssembler(name).build(pipelineData);
063    }
064
065    /**
066     * Pulls out an instance of the object by name.  Name is just the
067     * single name of the object.
068     *
069     * @param name Name of object instance.
070     * @return A Screen with the specified name, or null.
071     * @throws Exception a generic exception.
072     */
073    @Override
074    public Page getAssembler(String name)
075        throws Exception
076    {
077        return getAssembler(Page.class, name);
078    }
079
080    /**
081     * @see org.apache.turbine.modules.Loader#getCacheSize()
082     */
083    @Override
084    public int getCacheSize()
085    {
086        return PageLoader.getConfiguredCacheSize();
087    }
088
089    /**
090     * The method through which this class is accessed.
091     *
092     * @return The single instance of this class.
093     */
094    public static PageLoader getInstance()
095    {
096        return instance;
097    }
098
099    /**
100     * Helper method to get the configured cache size for this module
101     *
102     * @return the configure cache size
103     */
104    private static int getConfiguredCacheSize()
105    {
106        return Turbine.getConfiguration().getInt(Page.CACHE_SIZE_KEY,
107                Page.CACHE_SIZE_DEFAULT);
108    }
109}