head	1.13;
access;
symbols
	TIGRIS_0_9_2_4:1.2
	TIGRIS_0_9_2_3:1.2
	HELM_PEER_PORT_BRANCH:1.4.0.2
	TURBINE_PEER:1.4
	TIGRIS_0_9_2_1:1.4
	TIGRIS_0_9_2:1.2.0.2;
locks; strict;
comment	@# @;


1.13
date	2001.03.15.19.47.07;	author leonardr;	state dead;
branches;
next	1.12;

1.12
date	2001.03.07.01.53.24;	author lucas;	state Exp;
branches;
next	1.11;

1.11
date	2001.02.24.11.43.01;	author dlr;	state Exp;
branches;
next	1.10;

1.10
date	2001.02.22.01.31.11;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2001.02.22.00.52.15;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2001.02.22.00.42.11;	author dlr;	state Exp;
branches;
next	1.7;

1.7
date	2001.02.22.00.38.48;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2001.02.21.04.46.52;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2001.02.21.03.47.03;	author edk;	state Exp;
branches;
next	1.4;

1.4
date	2001.01.26.18.29.04;	author edk;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.2;

1.2
date	2001.01.18.15.45.05;	author leonardr;	state Exp;
branches;
next	1.1;

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

1.4.2.1
date	2001.01.28.01.02.18;	author dlr;	state dead;
branches;
next	;


desc
@@


1.13
log
@Got rid of all references to skins; they'll reappear in some form later on.
@
text
@/* ================================================================
 * Copyright (c) 2000 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.
 *
 m ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */


package org.tigris.helm.project;

import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import javax.servlet.http.*;

import org.apache.turbine.services.db.TurbineDB;
import org.apache.turbine.util.db.pool.DBConnection;
import org.apache.turbine.util.Log;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.webmacro.TurbineWebMacro;

import org.webmacro.servlet.WebContext;

import com.workingdogs.village.DataSetException;

import org.joist.database.DataManager;

import org.tigris.helm.om.*;
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.tool.TemplateTool;
    
/**
 * Generates the CSS file for a project according to its skin. Does
 * caching.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a> 
 */
public class ProjectCSS extends HttpServlet
{
    private static final boolean DEBUG = true;

    private static Map cssMap = new HashMap();

    private static final String CSS_TEMPLATE =
        TemplateTool.getPathToMessageTemplate("ProjectCSS.wm");

    /*Get a Project and return a (possibly cached) CSS file for it.*/
    public void service (HttpServletRequest req, HttpServletResponse res)
    {
        res.setContentType("text/plain");
        PrintWriter writer = null;

        DBConnection dbConn = null;
        Connection connection = null;
        String cssFile = "";
        try {
            dbConn = TurbineDB.getConnection();
            connection = dbConn.getConnection();

            Project project = getRequestedProject(connection, req);
            String projectID = project.getID();

            writer = res.getWriter();
            if (cssMap.containsKey(projectID)) {
                cssFile = (String)cssMap.get(projectID);                
            }
            else {
                Skin skin = null;
                if (project != null)
                {
                    skin = project.getSkin();
                }
                if (skin != null)
                {
                    WebContext ctx = TurbineWebMacro.getContext();
                    ctx.put("skin", project.getSkin());
                    cssFile = TurbineWebMacro.handleRequest(ctx, CSS_TEMPLATE);
                    cssMap.put(projectID, cssFile);
                }
            }
        }
        catch (Exception e) {
            if (DEBUG) Log.error(e);
        }
        finally {
            // Return the connection to the pool.
            if (dbConn != null)
            {
                try
                {
                    TurbineDB.releaseConnection(dbConn);
                }
                catch (Exception e)
                {
                    throw new RuntimeException(e.getMessage());
                }
            }
        }
        writer.println(cssFile);
    }

    public static void invalidateCache()
    {
        cssMap.clear();
    }

    public static void invalidateCache(String projectID)
    {
        cssMap.remove(projectID);
    }

    /**
     * Returns the requested project.
     */
    private final Project getRequestedProject(Connection conn,
                                              HttpServletRequest req)
        throws Exception
    {
        String projectID = req.getParameter("projectID");
        return (projectID == null ? null : ProjectPeer.getInstance(projectID));
    }
}
@


1.12
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@@


1.11
log
@Make use of the TurbineWebMacro facade of WebMacroService for a more convienient interface.
@
text
@a68 1
import org.tigris.helm.om.peer.*;
@


1.10
log
@Find the template in the right spot.
@
text
@d60 1
a60 1
import org.apache.turbine.services.webmacro.WebMacroService;
d116 1
a116 4
                    WebMacroService wmSrvc = (WebMacroService)
                        TurbineServices.getInstance()
                        .getService(WebMacroService.SERVICE_NAME);
                    WebContext ctx = wmSrvc.getContext();
d118 1
a118 1
                    cssFile = wmSrvc.handleRequest(ctx, CSS_TEMPLATE);
@


1.9
log
@Removed reference to TemplateInterpolator.
@
text
@d71 2
a72 1

d85 2
a86 1
    private static final String CSS_TEMPLATE = "ProjectCSS.wm";
@


1.8
log
@Hopefully corrected compile time errors.
@
text
@a69 1
import org.tigris.helm.tool.TemplateInterpolator;
@


1.7
log
@Now using TurbineWebMacroService instead of TemplateInterpolator.
@
text
@d115 6
a120 5
                    WebContext context = (WebMacroService)
            TurbineServices.getInstance().getService(WebMacroService.SERVICE_NAME);
                    context.put("skin", project.getSkin());
                    cssFile = TemplateInterpolator.interpolate
                        (CSS_TEMPLATE, context, getClass());
@


1.6
log
@Ported to Peer system.
@
text
@d59 2
d62 1
a62 1
import org.webmacro.engine.BuildContext;
d115 2
a116 1
                    BuildContext context = TemplateInterpolator.createContext();
@


1.5
log
@better imports, switch to using turbine logging
@
text
@d79 1
a79 3
  public static final String versionID =
    "$Id: ProjectCSS.java,v 1.4 2001/01/26 18:29:04 edk Exp $";
  private static boolean debug = true;
d94 1
a94 2
        try 
        {
d102 1
a102 2
            if (cssMap.containsKey(projectID))
            {
d104 2
a105 1
            } else {
d120 5
a124 3
        } catch (Exception e) {
            if (debug) Log.error(e);
        } finally {
d154 3
a156 3
    private Project getRequestedProject(Connection conn,
                                        HttpServletRequest req)
        throws SQLException, DataSetException, DoesNotExist
a157 1
        Project project = null;
d159 1
a159 5
        if (projectID != null)
        {
            project = new Project(conn, new DataManager(), projectID);
        }
        return project;
d161 1
a161 2

} /* end class ProjectCSS */
@


1.4
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d58 1
a59 1
import org.webmacro.util.*;
d66 2
a67 2
import org.tigris.helm.business.Skin;
import org.tigris.helm.project.Project;
d80 1
a80 2
    "$Id: ProjectCSS.java,v 1.2 2001/01/18 15:45:05 leonardr Exp $";
  private static Log log = new Log ("ProjectCSS", "CSS Generator");
d124 1
a124 1
            log.exception(e);
@


1.4.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d80 1
a80 1
    "$Id: ProjectCSS.java,v 1.4 2001/01/26 18:29:04 edk Exp $";
@


1.3
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.2
log
@Added methods to business objects so that ProjectCSS could get an enumeration over all the styles provided by a skin.
@
text
@d80 1
a80 1
    "$Id: ProjectCSS.java,v 1.1 2001/01/18 01:15:06 leonardr Exp $";
@


1.1
log
@New servlet: ProjectCSS. This generates a .css file instead of an HTML file, so it can't subclass HelmServlet or use Webmacro templates the way most other servlets do.
@
text
@d80 1
a80 1
    "$Id: ProjectCSS.java,v 1.9 2000/12/30 05:03:39 elicia Exp $";
d93 1
a93 1
        
d105 1
a114 1
                writer = res.getWriter();
a139 1
        
@

