head	1.9;
access;
symbols
	TIGRIS_0_9_2_4:1.5
	TIGRIS_0_9_2_3:1.5
	HELM_PEER_PORT_BRANCH:1.8.0.2
	TURBINE_PEER:1.8
	TIGRIS_0_9_2_1:1.8
	TIGRIS_0_9_2:1.5.0.2;
locks; strict;
comment	@# @;


1.9
date	2001.02.21.02.17.29;	author dlr;	state dead;
branches;
next	1.8;

1.8
date	2001.01.26.18.29.00;	author edk;	state Exp;
branches
	1.8.2.1;
next	1.7;

1.7
date	2001.01.26.05.24.05;	author edk;	state dead;
branches;
next	1.6;

1.6
date	2001.01.23.19.55.02;	author leonardr;	state Exp;
branches;
next	1.5;

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

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

1.3
date	2001.01.17.21.52.12;	author leonardr;	state Exp;
branches;
next	1.2;

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

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

1.8.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	;


desc
@@


1.9
log
@Deprecated by peer port merge.
@
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.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.business;

import java.sql.*;
import java.util.*;
import java.io.*;

import org.webmacro.util.Log;

import com.workingdogs.village.*;

import org.joist.database.*;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.database.*;
import org.tigris.helm.domain.*;
import org.tigris.helm.project.Project;

public class Style extends BusinessObject
{

    protected final String getTableName() 
    { 
        return StyleManager.TABLE_NAME;
    }

    public static Log log = new Log("Style", "Style");
    public static final boolean debug = true;

    private StyleManager styleMgr;
    private SkinStyleElementValueManager skinStyleElementValueMgr;

    /**
     * The Skin which this Style partially describes.
     */
    private Skin skin;

    /**
     *A Map of all key-value pairs for this Style.
     */
    private Map elements;

    /**
     * Order of the tags in an HTML representation of this style.
     */
    private List tagOrder;

    /**
     * A Map of Maps of key-value pairs for this Style, keyed by HTML tag.
     * There could be a Map for "td", for example, and a map for "font".
     * It is built the first time getElementsForHTMLTag is called.
     */
    private Map elementsByHTMLTag;

    /**
     * Initialize this object's private TableManagers.
     */
    protected void createManagers() 
    {
        styleMgr = (StyleManager)dMgr.getManager
            ("org.tigris.helm.database.StyleManager");
        skinStyleElementValueMgr = (SkinStyleElementValueManager)
            dMgr.getManager("org.tigris.helm.database.SkinStyleElementValueManager");
    }
        
    public Style (Connection conn, DataManager dMgr, Skin skin, 
                  String styleName)
        throws SQLException, DataSetException, DoesNotExist
    {
        super(conn, dMgr);        
        this.skin = skin;
        setRecord(styleMgr.getStyle(conn, styleName));

        elements = buildElements();
    }

    /**
     * Build the map containing the description of the style.
     */
    public Map buildElements()
        throws SQLException, DataSetException, DoesNotExist
    {
        //Start out with derived elements.        
        Map e = getDerivedElements();
        
        //Find elements specific to this skin's description of this
        //style, and overwrite derived elements with them.
        Map base = getBaseElements();
        for (Iterator i = base.keySet().iterator(); i.hasNext();)
        {
            StyleElement element = (StyleElement)i.next();
            String value = (String)base.get(element);
            e.put(element,value);
        }
        buildElementsByHTMLTag();
        return e;
    }

    /**
     * Build the Map containing Maps of html tags to style
     * element-value pairs. Assumes buildElements() has already run.
     */
    private void buildElementsByHTMLTag()
        throws DataSetException
    {
        elementsByHTMLTag = new HashMap();
        for (Iterator i = elements.keySet().iterator(); i.hasNext();)
        {
            StyleElement element = (StyleElement)i.next();
            String tag = element.getAssociatedHTMLTag();
            if (tag != null) 
            {
                Map elementsForTag = null;                
                if (elementsByHTMLTag.containsKey(tag))
                {
                    elementsForTag = (Map)elementsByHTMLTag.get(tag);
                } else {
                    elementsForTag = new HashMap();
                }
                elementsForTag.put(element, (String)elements.get(element));
                elementsByHTMLTag.put(tag,elementsForTag);
            }
        }
    }

    /**
     * Get the complete description of this style.
     */
    public Map getElements()
        throws SQLException, DataSetException, DoesNotExist
    {
        return elements;
    }

    /**
     * Get all the elements used by this style in a particular tag.
     */
    public Map getElementsForHTMLTag(String tag)
        throws SQLException, DataSetException, DoesNotExist
    {
        Map m = null;
        if (elementsByHTMLTag.containsKey(tag))
        {
            m = (Map)elementsByHTMLTag.get(tag);
        } else {
            m = new HashMap();
        }
        return m;
    }

    /**
     * Returns a string containing a number of HTML tags with attributes,
     * without the initial and final < and >.
     */
    public String openHTMLDescription()
        throws SQLException, DataSetException, DoesNotExist
    {
        StringBuffer desc = new StringBuffer();
        List tagOrder = new ArrayList();
        for (Iterator i = elementsByHTMLTag.keySet().iterator(); i.hasNext();)
        {
            String tag = (String)i.next();
            tagOrder.add(tag);
            desc.append(attributedTag(tag));
            if (i.hasNext()) desc.append("> <");
        }
        this.tagOrder = tagOrder;
        return desc.toString();
    }

    /**
     * Closes all the tags that were opened by describeAsHTML. Does not
     * include the initial < or the final >.
     */
    public String closeHTMLDescription()
        throws SQLException, DataSetException, DoesNotExist
    {
        StringBuffer desc = new StringBuffer();
        for (int i = tagOrder.size(); i>=0; i--)
        {            
            String tag = (String)tagOrder.get(i);
            desc.append("/").append(tag);
            if (i>0) desc.append("> <");
        }
        return desc.toString();
    }

    /**
     * Turns the attributes of a tag into the actual tag, except for
     * the < and > characters.
     */
    public String attributedTag(String tag)
        throws SQLException, DataSetException, DoesNotExist
    {
        StringBuffer a = new StringBuffer();
        a.append(tag);
        Map m = getElementsForHTMLTag(tag);
        for (Iterator i = m.keySet().iterator(); i.hasNext();)
        {
            StyleElement element = (StyleElement)i.next();
            a.append(" ").append(element.getHTMLName())
                .append("=").append(getElementValue(element));
        }
        return a.toString();
    }

    /**
     * Get the value of the given element.
     */
    public String getElementValue(StyleElement e)
    {
        String value = "";
        if (elements.containsKey(e))
        {
            value = (String)elements.get(e);
        }
        return value;
    }

    /**
     * Get the elements for this style specified by the parent Skin.
     */
    public Map getDerivedElements()
        throws SQLException, DataSetException, DoesNotExist
    {
        Map e = null;
        Skin parent = skin.getParent();
        if (parent == null)
        {
            e = new HashMap();
        } else {
            e = parent.getStyle(getName()).getElements();
        }
        return e;
    }

    /**
     * Get the elements for this style specified by this Skin.
     */
    public Map getBaseElements()
        throws SQLException, DataSetException, DoesNotExist
    {
        Map e = new HashMap();
        DataSet s = skinStyleElementValueMgr.getElementsForSkinStyle(conn, skin.getID(), getID());
        for (int i = 0; i < s.size(); i++)
        {
            Record r = s.getRecord(i);
            String elementID = r.getValue
                (SkinStyleElementValueManager.ELEMENT_ID).asString();
            StyleElement element = StyleElement.getStyleElement(conn, dMgr, elementID);
            String value = r.getValue
                (SkinStyleElementValueManager.VALUE).asString();
            e.put(element, value);
        }
        return e;
    }
    
    /**
     * Describe this style's elements.
     */ 
    public String describe()
    {
        StringBuffer desc = new StringBuffer();
        for (Iterator i = elements.keySet().iterator(); i.hasNext();)
        {
            String element = (String)i.next();
            String value = (String)elements.get(element);
            desc.append(" " + element+"=\"" + value + "\"");
        }
        desc.append(" ");
        return desc.toString();
    }

    /**
     * Get the skin which this style partially describes.
     */
    public Skin getSkin()
        throws DataSetException
    {
        return skin;
    }

    /**
     * Get the ID of this style.
     */
    public String getID()
        throws DataSetException
    {
        return getField(StyleManager.STYLE_ID);
    }

    /**
     * Get the name of this style.
     */
    public String getName()
        throws DataSetException
    {
        return getField(StyleManager.NAME);
    }

    /**
     * Get the description of this style.
     */
    public String getDescription()
        throws DataSetException
    {
        return getField(StyleManager.DESCRIPTION);
    }
}

@


1.8
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@@


1.8.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.7
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.6
log
@Skin patch enabling skin data to be used directly in templates.
@
text
@@


1.5
log
@Skins can now be recursively based upon other skins.
@
text
@d89 12
d123 1
a123 1
     * Get the complete description of this style.
d128 1
a128 1
        //Start out with derived elements.
d140 1
d145 27
d178 72
@


1.4
log
@Added methods to business objects so that ProjectCSS could get an enumeration over all the styles provided by a skin.
@
text
@d93 4
a96 2
        styleMgr = (StyleManager)dMgr.getManager("org.tigris.helm.database.StyleManager");
        skinStyleElementValueMgr = (SkinStyleElementValueManager)dMgr.getManager("org.tigris.helm.database.SkinStyleElementValueManager");
d107 1
a107 1
        elements = getElements();
d113 1
a113 1
    public Map getElements()
d132 1
a132 1
     * Get the complete description of this style as a list.
d134 1
a134 1
    public List listElements()
a136 12
        List elements = new ArrayList();
        //Start out with derived elements.
        Map e = getDerivedElements();
        
        //Find elements specific to this skin's description of this
        //style, and overwrite derived elements with them.
        Map base = getBaseElements();
        for (Iterator i = base.keySet().iterator(); i.hasNext();)
        {
            StyleElement element = (StyleElement)i.next();
            elements.add(element);
        }
@


1.3
log
@Added method to retrieve the value of a given StyleElement
@
text
@d130 21
a186 1
        
a193 1

@


1.2
log
@Another big batch of skin changes.
@
text
@d130 13
@


1.1
log
@More code written for skins and styles.
@
text
@d76 1
a76 1
    private StyleElementManager styleElementMgr;
d88 3
d94 1
a94 1
        styleElementMgr = (StyleElementManager)dMgr.getManager("org.tigris.helm.database.StyleElementManager");
d122 1
a122 1
            String element = (String)i.next();
d150 1
a150 1
        throws SQLException, DataSetException
d154 1
a154 1
        DataSet s = styleElementMgr.getElementsForSkinStyle(conn, skin.getID(), getID());
d158 6
a163 2
            String element = r.getValue(StyleElementManager.ELEMENT).asString();
            String value = r.getValue(StyleElementManager.VALUE).asString();
d168 4
a171 1

d185 3
d189 1
a189 1
    throws DataSetException
d194 3
d198 1
a198 1
    throws DataSetException
d203 3
d207 1
a207 1
    throws DataSetException
d210 9
@

