webwork/src/etc/dreamweaver/src/tagobject TagAttribute.java,NONE,1.1 TagAttributeFactory.java,NONE,1.1 TagConstants.java,NONE,1.1 TagObject.java,NONE,1.1 TagObjectFactory.java,NONE,1.1 TagObjectFilesFactory.java,NONE,1.1 TagProductionManager.java,NONE,1.1 TagSpec.java,NONE,1.1 TagSpecFactory.java,NONE,1.1 TagSpecManager.java,NONE,1.1

[email protected] Tue, 16 Jul 2002 03:18:00 -0700
Newsgroups gmane.comp.java.webwork.cvs
Message-ID <[email protected]>
Update of /cvsroot/webwork/webwork/src/etc/dreamweaver/src/tagobject
In directory usw-pr-cvs1:/tmp/cvs-serv27500/src/etc/dreamweaver/src/tagobject

Added Files:
	TagAttribute.java TagAttributeFactory.java TagConstants.java 
	TagObject.java TagObjectFactory.java 
	TagObjectFilesFactory.java TagProductionManager.java 
	TagSpec.java TagSpecFactory.java TagSpecManager.java 
Log Message:
Added source and needed files for Dreamweaver utility.

--- NEW FILE: TagAttribute.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

class TagAttribute
{
	protected String attribName = null;
	protected boolean attribRequired = false;
	protected boolean attribRtExprValue = false;

	public TagAttribute( String name,
						 boolean req,
						 boolean rtExprVal )
	{
		this.attribName = name;
		this.attribRequired = req;
		this.attribRtExprValue = rtExprVal;
	}

	public String getAttribName()
	{
		return attribName;
	}

	public void setAttribName( String aAttribName )
	{
		this.attribName = aAttribName;
	}

	public boolean getAttribRequired()
	{
		return attribRequired;
	}

	public void setAttribRequired( boolean aAttribRequired )
	{
		this.attribRequired = aAttribRequired;
	}

	public boolean getAttribRtExprValue()
	{
		return attribRtExprValue;
	}

	public void setAttribRtExprValue( boolean aAttribRtExprValue )
	{
		this.attribRtExprValue = aAttribRtExprValue;
	}

	public String toString()
	{
		return " TagAttribute -- [ Name: " + "\"" + this.attribName + "\"" +
				" | Is Attrib Required? " + this.attribRequired +
				" | Is it a Runtime Expression? " + this.attribRtExprValue + " ]";
	}
}
--- NEW FILE: TagAttributeFactory.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

import org.w3c.dom.Element;

public class TagAttributeFactory
{
	public TagAttributeFactory()
	{
	}

	public TagAttribute createTagAttribute( Element attribElement )
	{
		TagAttribute aTagAttribute = null;
		Boolean bl = null;

		try
		{
			final int FIRST_ITEM = 0;

			String attribName = TagConstants.getTheText(
					attribElement.getElementsByTagName( TagConstants.TAG_NAME ).item( FIRST_ITEM ) );

			bl = new Boolean( TagConstants.getTheText( attribElement.getElementsByTagName( TagConstants.TAG_ATTRIB_REQ ).item( FIRST_ITEM ) ) );
			boolean attribRequired = bl.booleanValue();

			bl = new Boolean( TagConstants.getTheText( attribElement.getElementsByTagName( TagConstants.TAG_ATTRIB_RTEXPRVAL ).item( FIRST_ITEM ) ) );
			boolean attribRtExprValue = bl.booleanValue();

			aTagAttribute = new TagAttribute( attribName, attribRequired, attribRtExprValue );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}

		return aTagAttribute;
	}
}
--- NEW FILE: TagConstants.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

import org.w3c.dom.NodeList;
import org.w3c.dom.Node;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

abstract public class TagConstants {
    /*
		tag
			name
			tagclass
			bodycontent
			info
			*attribute
				name
				required
				rtexprvalue
	*/
    static public String TEXT = "TEXT";
    static public String TAG = "tag";
    static public String TAG_NAME = "name";
    static public String TAG_TAGCLASS = "tagclass";
    static public String TAG_BODYCONTENT = "bodycontent";
    static public String TAG_INFO = "info";
    static public String TAG_ATTRIB = "attribute";
    static public String TAG_ATTRIB_NAME = "name";
    static public String TAG_ATTRIB_REQ = "required";
    static public String TAG_ATTRIB_RTEXPRVAL = "rtexprvalue";

    static public String TAGSPEC = "tagspec";
    static public String TAGSPEC_TAG_NAME = "tag_name";
    static public String TAGSPEC_TAG_NAME_PREFIX = "webwork:";
    static public String TAGSPEC_TAG_TYPE = "tag_type";
    static public String TAGSPEC_TAG_TYPE_DEFAULT = "nonempty";
    static public String TAGSPEC_RENDER_CONTENTS = "render_contents";
    static public boolean TAGSPEC_RENDER_CONTENTS_DEFAULT = false;
    static public String TAGSPEC_CONTENT_MODEL = "content_model";
    static public String TAGSPEC_CONTENT_MODEL_DEFAULT = "marker_model";
    static public String TAGSPEC_DETECT_IN_ATTRIBUTE = "detect_in_attribute";
    static public boolean TAGSPEC_DETECT_IN_ATTRIBUTE_DEFAULT = true;

    static public int ITEM_NAME_SIZE = 20;
    static public int ITEM_VALUE_SIZE = 60;
    static public String DIR_SEPARATOR = "\\"; //File.separator;

    static public String WEBWORK_DIR = "WebWork";
    static public String STAGE_DIR = "Stage";
    static public String SHARED_DIR = "Shared";
    static public String LIB_FILENAME = "WebWork_Lib.js";
    static public String INSPECTOR_DIR = "Inspectors";
    static public String INSPECTOR_PREFIX = "";
    //"Inspector.htm" was too long, Dreamweaver .mxi doesn't want filenames longer than 30 chars.
    static public String INSPECTOR_SUFFIX = "Insp.htm";
    static public String HELP_DIR = "Help";
    static public String HELP_PREFIX = "";
    static public String HELP_SUFFIX = "Help.htm";
    static public String TGOBJ_DIR = "Objects";
    static public String TGOBJ_PREFIX = "";
    static public String TGOBJ_SUFFIX = ".htm";
    static public String TGSPEC_DIR = "ThirdPartyTags";
    static public String TGSPEC_FILENAME = "WEBWORKScripts.xml";
    static public String TGSPEC_ICON = "icon";
    static public String TGSPEC_ICON_VAL = "small_pyramid.gif";
    static public String TGSPEC_ICON_SUFFIX = ".gif";
    static public String TGSPEC_ICON_WIDTH = "icon_width";
    static public String TGSPEC_ICON_WIDTH_VAL = "17";
    static public String TGSPEC_ICON_HEIGHT = "icon_height";
    static public String TGSPEC_ICON_HEIGHT_VAL = "15";

    static public String MXI_FILE = "WebWork.mxi";
    static public String MXI_FILE_TMPLT = "WebWork_MXI_Template.xml";
    static public String MM_EXT_TAG = "macromedia-extension";
    static public String MM_FILES_TAG = "files";
    static public String MM_FILE_TAG = "file";
    static public String MM_FILE_SRC_ATTRIB = "source";
    static public String MM_FILE_DEST_ATTRIB = "destination";
    static public String MM_FILE_DEST_PREFIX = "$dreamweaver/configuration/";

    static public String getTheText(Node node) {
        String result = new String();
        node.normalize();
        NodeList nl = node.getChildNodes();
        int i = 0;
        while (i < nl.getLength()) {
            org.w3c.dom.Node nd = nl.item(i++);
            if (nd.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
                result = nd.getNodeValue();
                break;
            }
        }
        return result;
    }

    static public void copyFile(File orig, File dest) throws java.lang.Exception {
        FileInputStream fis = new FileInputStream(orig);
        FileOutputStream fos = new FileOutputStream(dest);
        for (int tmp = fis.available(); tmp > 0; tmp = fis.available()) {
            byte[] data = new byte[tmp];
            fis.read(data);
            fos.write(data);
        }
    }
}
--- NEW FILE: TagObject.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

import java.util.StringTokenizer;
import java.util.Vector;

class TagObject
{
	protected String tagName = null;
	protected String tagClass = null;
	protected String tagBodyContent = null;
	protected String tagInfo = null;
	protected Vector attributes = new Vector();

	public TagObject( String tagName,
					  String tagClass,
					  String tagBodyContent,
					  String tagInfo )
	{
		this.tagName = tagName;
		this.tagClass = tagClass;
		this.tagBodyContent = tagBodyContent;
		this.tagInfo = tagInfo;
	}

	public TagObject( String tagName,
					  String tagClass,
					  String tagBodyContent,
					  String tagInfo,
					  Vector attributes )
	{
		this( tagName, tagClass, tagBodyContent, tagInfo );
		this.attributes = attributes;
	}

	public String getTagName()
	{
		return this.tagName;
	}

	public void setTagName( String aTagName )
	{
		this.tagName = aTagName;
	}

	public String getTagClass()
	{
		return this.tagClass;
	}

	public void setTagClass( String aTagClass )
	{
		this.tagClass = aTagClass;
	}

	public String getTagBodyContent()
	{
		return this.tagBodyContent;
	}

	public void setTagBodyContent( String aTagBodyContent )
	{
		this.tagBodyContent = aTagBodyContent;
	}

	public String getTagInfo()
	{
		return this.tagInfo;
	}

	public void setTagInfo( String aTagInfo )
	{
		this.tagInfo = aTagInfo;
	}

	public Vector getAttributes()
	{
		return this.attributes;
	}

	public void setAttributes( Vector anAttributes )
	{
		this.attributes = anAttributes;
	}

	public void addTagAttribute( TagAttribute aTagAttribute )
	{
		this.attributes.add( aTagAttribute );
	}

	public TagAttribute removeTagAttribute( String tagAttribName )
	{
		return null; // Not implemented...
	}

	public TagAttribute getTagAttributeAt( int index )
	{
		return (TagAttribute)this.attributes.elementAt( index );
	}

	public void setTagAttributeAt( int index, TagAttribute aTagAttribute )
	{
		this.attributes.set( index, aTagAttribute );
	}

	public String getProperName()
	{
		StringTokenizer st = new StringTokenizer( this.getTagClass(), "." );
		String result = new String();

		while( st.hasMoreTokens() )
		{
			result = st.nextToken();
		}

		return result;
	}


	public String toString()
	{
		String str = "TagObject -- [ Name: " + "\"" + this.tagName + "\"" +
				" | Tag Class: " + "\"" + this.tagClass + "\"" +
				" | Tag Body Content: " + "\"" + this.tagBodyContent + "\"" +
				" | Tag Info: " + "\"" + this.tagInfo + "\"";
		str += " Attribs---> " + ( attributes.size() > 0 ? "" : " None. " );
		for( int i = 0; i < attributes.size(); i++ )
		{
			str += ( (TagAttribute)attributes.get( i ) ).toString();
		}
		str += " ]";

		return str;
	}
}
--- NEW FILE: TagObjectFactory.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author Jay Bose
 * @version 1.0
 */

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.Vector;


public class TagObjectFactory
{
	public TagObjectFactory()
	{
	}

	public TagObject createTagObject( Element tagElement )
	{
		TagObject aTagObject = null;
		try
		{
			final int FIRST_ITEM = 0;

			String tagName = TagConstants.getTheText( tagElement.getElementsByTagName( TagConstants.TAG_NAME ).item( FIRST_ITEM ) );
			String tagClass = TagConstants.getTheText( tagElement.getElementsByTagName( TagConstants.TAG_TAGCLASS ).item( FIRST_ITEM ) );
			String tagBodyContent = TagConstants.getTheText( tagElement.getElementsByTagName( TagConstants.TAG_BODYCONTENT ).item( FIRST_ITEM ) );
			String tagInfo = TagConstants.getTheText( tagElement.getElementsByTagName( TagConstants.TAG_INFO ).item( FIRST_ITEM ) );

			Vector attributes = new Vector();
			NodeList ndl = tagElement.getElementsByTagName( TagConstants.TAG_ATTRIB );
			TagAttributeFactory factory = new TagAttributeFactory();
			for( int i = 0; i < ndl.getLength(); i++ )
			{
				attributes.add( factory.createTagAttribute( (Element)ndl.item( i ) ) );
			}

			aTagObject = new TagObject( tagName, tagClass, tagBodyContent, tagInfo, attributes );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}

		return aTagObject;
	}
}
--- NEW FILE: TagObjectFilesFactory.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author Jay Bose
 * @version 1.0
 */

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class TagObjectFilesFactory
{
	public TagObjectFilesFactory()
	{
		try
		{
			System.out.println( "Creating necessary directories...\n" );

			List dirsToMake = new ArrayList();
			dirsToMake.add( TagConstants.STAGE_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.HELP_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.HELP_DIR + TagConstants.DIR_SEPARATOR + TagConstants.WEBWORK_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.INSPECTOR_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGOBJ_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGOBJ_DIR + TagConstants.DIR_SEPARATOR + TagConstants.WEBWORK_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.SHARED_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.SHARED_DIR + TagConstants.DIR_SEPARATOR + TagConstants.WEBWORK_DIR );
			dirsToMake.add( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGSPEC_DIR );

			for( int i = 0; i < dirsToMake.size(); i++ )
			{
				File theDir = new File( (String)dirsToMake.get( i ) );
				if( !theDir.exists() ) theDir.mkdir();
			}

			createLibFiles();

			File dest = new File( TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGSPEC_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGSPEC_ICON_VAL );
			File orig = new File( TagConstants.TGSPEC_ICON_VAL );
			TagConstants.copyFile( orig, dest );

		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}

	public void createTagObjectFile( TagObject to )
	{
		try
		{
			String starterName = TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.TGOBJ_DIR +
					TagConstants.DIR_SEPARATOR + TagConstants.WEBWORK_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.TGOBJ_PREFIX + to.getProperName();
			String gfxName = starterName + TagConstants.TGSPEC_ICON_SUFFIX;
			String fileName = starterName + TagConstants.TGOBJ_SUFFIX;

			int lenOfAttribs = to.getAttributes().size();

			File fl = new File( fileName );
			if( !fl.exists() ) fl.createNewFile();

			TagConstants.copyFile( new File( TagConstants.TGSPEC_ICON_VAL ), new File( gfxName ) );

			PrintWriter pw = new PrintWriter( new FileWriter( fl ), true );

			pw.println( "<html>\n<head>" );
			pw.println( "<title>Insert Webwork " + to.getProperName() + "</title>" );
			pw.println( "<script language=\"JavaScript\" src=\"../../Shared/MM/Scripts/CMN/UI.js\"></script>" );
			pw.println( "<script language=\"JavaScript\" src=\"../../Shared/MM/Scripts/CMN/DOM.js\"></script>" );
			pw.println( "<script language=\"JavaScript\" src=\"../../Shared/WebWork/WebWork_Lib.js\"></script>" );
			pw.println( "<script language=\"JavaScript\">\n" );
			pw.println( "function displayHelp()\n{" );
			pw.println( "var rootPath = dw.getConfigurationPath();" );
			pw.println( "var helpFile = \"" + TagConstants.HELP_PREFIX + to.getProperName() + TagConstants.HELP_SUFFIX + "\"" );
			pw.println( "var helpPath = rootPath + \"/" +
						TagConstants.HELP_DIR + "/" + TagConstants.WEBWORK_DIR +
						"/\" + helpFile;" );
			pw.println( "dreamweaver.browseDocument(helpPath);\n}" );
			pw.println( "function objectTag()\n{" );

			String theTag = "webwork:" + to.getTagName();
			pw.println( "var content = \"<" + theTag + "\";" );
			pw.println( "var endContent = \"></" + theTag + ">\";" );
			pw.println( "var doc = document.theForm;" );

			for( int i = 0; i < lenOfAttribs; i++ )
			{
				TagAttribute ta = to.getTagAttributeAt( i );
				String theItem = "the" + ta.getAttribName();
				pw.println( "var " + theItem + " = doc." + theItem + ".value;" );
				pw.println( "if( " + theItem + " )\n{" );
				pw.println( "content += getFormattedContent( \"" + ta.getAttribName() + "\", " + theItem + " );\n}\n" );
			}

			pw.println( "content += endContent;\n\nreturn content;\n}\n</script>\n</head>" );
			pw.println( "<body>\n<form name=\"theForm\">\n<table border=\"0\">" );

			for( int n = 0; n < lenOfAttribs; n++ )
			{
				TagAttribute ta = to.getTagAttributeAt( n );
				String theItem = "the" + ta.getAttribName();
				pw.println( "<tr>" );
				pw.println( "<td width=\"" + TagConstants.ITEM_NAME_SIZE + "%\">" + ta.getAttribName() + ":</td>" );
				pw.println( "<td><input type=\"text\" name=\"" + theItem + "\" size=\"" + TagConstants.ITEM_VALUE_SIZE + "%\"></td>" );
				pw.println( "</tr>\n" );
			}

			pw.println( "</table>\n</form>\n</body>\n</html>" );
			pw.close();

		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}

	public void createTagObjectInspectorFile( TagObject to )
	{
		try
		{
			int lenOfAttribs = to.getAttributes().size();
			String fileName = TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.INSPECTOR_DIR +
					TagConstants.DIR_SEPARATOR + TagConstants.INSPECTOR_PREFIX + to.getProperName() +
					TagConstants.INSPECTOR_SUFFIX;

			File fl = new File( fileName );
			if( !fl.exists() ) fl.createNewFile();

			PrintWriter pw = new PrintWriter( new FileWriter( fl ), true );

			pw.println( "<!-- tag:webwork:" + to.getTagName() + ",priority:5,selection:exact -->" );

			pw.println( "<HTML>\n<HEAD>" );
			pw.println( "<TITLE>WebWork " + to.getProperName() + " Inspector</TITLE>" );
			pw.println( "<SCRIPT LANGUAGE=\"JavaScript\">" );
			pw.println( "var theDOM = null;" );
			pw.println( "var theObj = null;" );
			pw.println( "var frm = null;\n" );
			pw.println( "function canInspectSelection() {  return true; }" );
			pw.println( "function initializeUI()\n{" );
			pw.println( "theDOM = dw.getDocumentDOM();" );
			pw.println( "theObj = theDOM.getSelectedNode();" );
			pw.println( "frm = document.theForm;\n}\n" );
			pw.println( "function inspectSelection()\n{\ninitializeUI();\n" );

			for( int i = 0; i < lenOfAttribs; i++ )
			{
				TagAttribute ta = to.getTagAttributeAt( i );
				String theItem = "the" + ta.getAttribName();
				String theFrmItem = ta.getAttribName() + "Txt";
				pw.println( "var " + theItem + " = theObj.getAttribute('" + ta.getAttribName() + "');" );
				pw.println( "frm." + theFrmItem + ".value =  ( " + theItem + " == null ? \"\" : " + theItem + " );" );
			}

			pw.println( "\n}\n" );
			pw.println( "function setWebWork" + to.getProperName() + "()\n{\ninitializeUI();" );

			for( int i = 0; i < lenOfAttribs; i++ )
			{
				TagAttribute ta = to.getTagAttributeAt( i );
				String theItem = "the" + ta.getAttribName();
				String theFrmItem = ta.getAttribName() + "Txt";
				pw.println( "var " + theItem + " = frm." + theFrmItem + ".value;" );
				pw.println( "theObj.setAttribute('" + ta.getAttribName() + "', " + theItem + " );" );
			}

			pw.println( "}\n" );
			pw.println( "</SCRIPT>\n</HEAD>\n<BODY>" );
			pw.println( "<FORM NAME=\"theForm\">\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"image\">" );

			// Iterate over rows
			for( int i = 0; i < lenOfAttribs; i++ )
			{
				// Beginning of row?
				if( i % 3 == 0 )
				{
					pw.println( "<tr>" );
				}

				TagAttribute ta = to.getTagAttributeAt( i );
				String theFrmItem = ta.getAttribName() + "Txt";
				pw.println( "<td><span align=\"right\"><b>" + ta.getAttribName() + "</b></span></td>" );
				pw.println( "<td><input type=\"text\" name=\"" + theFrmItem + "\" onBlur=\"setWebWork" +
							to.getProperName() + "();\"></td>" );

				// End of row?
				if( ( i + 1 ) % 3 == 0 )
				{
					pw.println( "</tr>" );
				}
			}

			pw.println( "</table>\n</FORM>\n</BODY>\n</HTML>" );

			pw.close();

		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}

	public void createTagObjectHelpFile( TagObject to )
	{
		try
		{
			int lenOfAttribs = to.getAttributes().size();
			String str = "This tag has ";
			String fileName = TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR + TagConstants.HELP_DIR +
					TagConstants.DIR_SEPARATOR + TagConstants.WEBWORK_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.HELP_PREFIX + to.getProperName() + TagConstants.HELP_SUFFIX;

			File fl = new File( fileName );
			if( !fl.exists() ) fl.createNewFile();

			PrintWriter pw = new PrintWriter( new FileWriter( fl ), true );

			pw.println( "<html>\n<head>" );
			pw.println( "<title>WebWork " + to.getProperName() + " Help</title>" );
			pw.println( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n</head>" );
			pw.println( "<body bgcolor=\"#FFFFFF\" text=\"#000000\">" );

			pw.println( "This is the <b>" + to.getTagClass() + "</b>, used as the <b>" + to.getTagName() + "</b> Tag.<br>" );
			pw.println( "Brief Info: " + to.getTagInfo() + "<br>" );

			if( lenOfAttribs > 1 )
			{
				str += lenOfAttribs + " attributes.";
			}
			else if( lenOfAttribs == 1 )
			{
				str += lenOfAttribs + " attribute.";
			}
			else
			{
				str += "no attributes.";
			}
			pw.println( str );

			for( int i = 0; i < lenOfAttribs; i++ )
			{
				TagAttribute ta = to.getTagAttributeAt( i );
				pw.println( "<p>Attribute <em>" + ta.getAttribName() + "</em>" +
							( ta.attribRequired ? " is " : " is not " ) +
							"required. It" +
							( ta.getAttribRtExprValue() ? " is " : " is not " ) +
							"a runtime expression.</p>" );
			}

			pw.println( "</body>\n</html>" );

			pw.close();
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}

	public void createLibFiles()
	{
		try
		{
			String fileName = TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.SHARED_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.WEBWORK_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.LIB_FILENAME;

			File fl = new File( fileName );
			if( !fl.exists() ) fl.createNewFile();

			PrintWriter pw = new PrintWriter( new FileWriter( fl ), true );

			pw.println( "function stripWhite( theStr )\n{" );
			pw.println( "if (!theStr) theStr = '';  //ensure its not null" );
			pw.println( "theStr = theStr.replace(/^\\s*/,''); //strip leading" );
			pw.println( "theStr = theStr.replace(/[\\s*]$/,''); //strip trailing" );
			pw.println( "return theStr;\n}\n" );
			pw.println( "function getFormattedContent( aKey, aValue )\n{" );
			pw.println( "return(  \"  \" + stripWhite( aKey ) + \"=\\\"\" + stripWhite(  aValue ) + \"\\\" \" );\n}" );

			pw.close();
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}
}
--- NEW FILE: TagProductionManager.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.*;


public class TagProductionManager
{
	protected TagProductionManager( String taglibFile )
	{
		try
		{
			System.out.println( "\n\nParsing the WebWork Taglib...\n" );

			DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document doc = parser.parse( new File( taglibFile ) );

			NodeList ndl = doc.getElementsByTagName( TagConstants.TAG );
			TagObjectFactory toFactory = new TagObjectFactory();
			TagObjectFilesFactory tofFactory = new TagObjectFilesFactory();
			TagSpecFactory tsFactory = new TagSpecFactory();
			TagSpecManager mngr = new TagSpecManager();

			System.out.println( "Creating TagObjects Objects for each Tag...\n" );
			System.out.println( "Creating TagObjectHelp Objects for each Tag...\n" );
			System.out.println( "Creating TagObjectInspector Objects for each Tag...\n" );
			System.out.println( "Updating the TagSpec library from the given Taglib...\n" );
			for( int n = 0; n < ndl.getLength(); n++ )
			{
				TagObject to = toFactory.createTagObject( (Element)ndl.item( n ) );
				tofFactory.createTagObjectFile( to );
				tofFactory.createTagObjectHelpFile( to );
				tofFactory.createTagObjectInspectorFile( to );
				mngr.updateTagSpec( tsFactory.createTagSpec( to ) );
			}

			mngr.finalizeTagSpec();

			System.out.println( "Setting up the Dreamweaver components...\n" );
			updateMXIFile( getAllFilesUnderDir( "Stage", false, true ) );

			System.out.println( "Done with compilation...\n\n" );
		}
		catch( Throwable t )
		{
			t.printStackTrace();
		}
	}

	//
	// For each file in staging...
	//
	public void updateMXIFile( List flNames ) throws java.lang.Exception
	{
		final int FIRST = 0;
		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( TagConstants.MXI_FILE_TMPLT );
		Element mmEle = (Element)doc.getElementsByTagName( TagConstants.MM_EXT_TAG ).item( FIRST );
		Element filesEle = (Element)mmEle.getElementsByTagName( TagConstants.MM_FILES_TAG ).item( FIRST );

		NodeList ndl = filesEle.getChildNodes();
		for( int i = 0; i < ndl.getLength(); i++ )
		{
			filesEle.removeChild( ndl.item( i ) );
		}

		for( int i = 0; i < flNames.size(); i++ )
		{
			String orig = ( (File)flNames.get( i ) ).getPath();
			orig = orig.replace( '\\', '/' );
			int index = orig.indexOf( "Stage" ) + 6; // Length of the String "Stage"
			int endIndex = orig.lastIndexOf( "/" );
			String dest = TagConstants.MM_FILE_DEST_PREFIX + orig.substring( index, endIndex );

			Element tmp = doc.createElement( TagConstants.MM_FILE_TAG );
			tmp.setAttribute( TagConstants.MM_FILE_SRC_ATTRIB, orig );
			tmp.setAttribute( TagConstants.MM_FILE_DEST_ATTRIB, dest );
			filesEle.appendChild( tmp );
		}

		DOMSource source = new DOMSource( doc );
		StreamResult result = new StreamResult( new PrintWriter( new FileOutputStream( new File( TagConstants.MXI_FILE ) ) ) );
		Transformer transformer = TransformerFactory.newInstance().newTransformer();
		transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
		transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
		transformer.transform( source, result );
	}

	public List getAllFilesUnderDir( String startingDir, boolean getDirs, boolean getFiles ) throws java.io.IOException
	{
		File tmpFl = new File( startingDir );
		List result = new ArrayList();
		Enumeration en = ( new Vector( Arrays.asList( tmpFl.listFiles() ) ) ).elements();

		while( en.hasMoreElements() )
		{
			File tmp = (File)en.nextElement();
			if( tmp.isDirectory() )
			{
				result.addAll( getAllFilesUnderDir( tmp.getPath(), getDirs, getFiles ) );

				if( getDirs )
					result.add( tmp );
			}
			else if( tmp.isFile() )
			{
				if( getFiles )
					result.add( tmp );
			}
		}

		return result;
	}

	public static void main( String[] args )
	{
		TagProductionManager tpm = new TagProductionManager( args[ 0 ] );
	}
}
--- NEW FILE: TagSpec.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

class TagSpec
{
	protected String tagName = null;
	protected String tagType = null;
	protected boolean renderContents = false;
	protected String contentModel = null;
	protected boolean detectInAttribute = false;
	protected String iconName = null;

	public TagSpec( String tagName,
					String tagType,
					boolean renderContents,
					String contentModel,
					boolean detectInAttribute,
					String iconName )
	{
		this.tagName = tagName;
		this.tagType = tagType;
		this.renderContents = renderContents;
		this.contentModel = contentModel;
		this.detectInAttribute = detectInAttribute;
		this.iconName = iconName;
	}

	//
	// All you have is the name, we'll assume the rest of the defaults...
	//
	public TagSpec( String tagName )
	{
		this.tagName = tagName;
		this.tagType = TagConstants.TAGSPEC_TAG_TYPE_DEFAULT;
		this.renderContents = TagConstants.TAGSPEC_RENDER_CONTENTS_DEFAULT;
		this.contentModel = TagConstants.TAGSPEC_CONTENT_MODEL_DEFAULT;
		this.detectInAttribute = TagConstants.TAGSPEC_DETECT_IN_ATTRIBUTE_DEFAULT;
		this.iconName = TagConstants.TGSPEC_ICON_VAL;
	}

	public String getTagName()
	{
		return tagName;
	}

	public void setTagName( String aTagName )
	{
		this.tagName = aTagName;
	}

	public String getTagType()
	{
		return tagType;
	}

	public void setTagType( String aTagType )
	{
		this.tagType = aTagType;
	}

	public boolean getRenderContents()
	{
		return renderContents;
	}

	public void setRenderContents( boolean aRenderContents )
	{
		this.renderContents = aRenderContents;
	}

	public String getContentModel()
	{
		return contentModel;
	}

	public void setContentModel( String aContentModel )
	{
		this.contentModel = aContentModel;
	}

	public boolean getDetectInAttribute()
	{
		return this.detectInAttribute;
	}

	public void setDetectInAttribute( boolean aDetectInAttribute )
	{
		this.detectInAttribute = aDetectInAttribute;
	}

	public String getIconName()
	{
		return iconName;
	}

	public void setIconName( String aIconName )
	{
		this.iconName = aIconName;
	}

	public String toString()
	{
		String str = "TagSpec -- [ Name: " + "\"" + this.tagName + "\"" +
				" | Tag Type: " + "\"" + this.tagType + "\"" +
				" | Render Contents ? " + this.renderContents +
				" | Content Model: " + "\"" + this.contentModel + "\"" +
				" | Detect In Attribute ? " + this.detectInAttribute + " ]";
		return str;
	}
}
--- NEW FILE: TagSpecFactory.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author
 * @version 1.0
 */

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

import javax.xml.parsers.DocumentBuilderFactory;


public class TagSpecFactory
{
	public TagSpecFactory()
	{
	}

	public TagSpec createTagSpec( Element tagElement )
	{
		TagSpec aTagSpec = null;
		Boolean bl = null;
		try
		{
			NamedNodeMap mp = tagElement.getAttributes();

			String tagName = ( (Attr)mp.getNamedItem( TagConstants.TAGSPEC_TAG_NAME ) ).getValue();

			String tagType = ( (Attr)mp.getNamedItem( TagConstants.TAGSPEC_TAG_TYPE ) ).getValue();

			bl = new Boolean(
					( (Attr)mp.getNamedItem( TagConstants.TAGSPEC_RENDER_CONTENTS ) ).getValue() );
			boolean renderContents = bl.booleanValue();

			String contentModel = ( (Attr)mp.getNamedItem( TagConstants.TAGSPEC_CONTENT_MODEL ) ).getValue();

			bl = new Boolean(
					( (Attr)mp.getNamedItem( TagConstants.TAGSPEC_DETECT_IN_ATTRIBUTE ) ).getValue() );
			boolean detectInAttribute = bl.booleanValue();

			aTagSpec = new TagSpec( tagName, tagType, renderContents, contentModel, detectInAttribute, TagConstants.TGSPEC_ICON );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}

		return aTagSpec;
	}

	public TagSpec createTagSpec( TagObject to )
	{
		TagSpec aTagSpec = null;
		try
		{
			String tagName = TagConstants.TAGSPEC_TAG_NAME_PREFIX + to.getTagName();

			// Not much decipehering to do...

			aTagSpec = new TagSpec( tagName );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}

		return aTagSpec;
	}

	public Element createTagSpecElement( TagSpec ts )
	{
		Element ele = null;
		try
		{
			Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
			ele = doc.createElement( TagConstants.TAGSPEC );
			String tmp = null;

			ele.setAttribute( TagConstants.TAGSPEC_TAG_NAME, ts.getTagName() );

			ele.setAttribute( TagConstants.TAGSPEC_TAG_TYPE, ts.getTagType() );

			tmp = ( new Boolean( ts.getRenderContents() ).toString() );
			ele.setAttribute( TagConstants.TAGSPEC_RENDER_CONTENTS, tmp );

			ele.setAttribute( TagConstants.TAGSPEC_CONTENT_MODEL, ts.getContentModel() );

			tmp = ( new Boolean( ts.getDetectInAttribute() ).toString() );
			ele.setAttribute( TagConstants.TAGSPEC_DETECT_IN_ATTRIBUTE, tmp );

			ele.setAttribute( TagConstants.TGSPEC_ICON, ts.getIconName() );
			ele.setAttribute( TagConstants.TGSPEC_ICON_HEIGHT, TagConstants.TGSPEC_ICON_HEIGHT_VAL );
			ele.setAttribute( TagConstants.TGSPEC_ICON_WIDTH, TagConstants.TGSPEC_ICON_WIDTH_VAL );
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}

		return ele;
	}
}
--- NEW FILE: TagSpecManager.java ---
package tagobject;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Notiva
 * @author Jay Bose
 * @version 1.0
 */

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Vector;


public class TagSpecManager
{
	TagSpecFactory factory = null;
	Vector tagSpecs = null;

	public TagSpecManager( String fileName )
	{
		this();

		try
		{
			DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document doc = parser.parse( new File( fileName ) );

			NodeList ndl = doc.getElementsByTagName( TagConstants.TAGSPEC );
			for( int n = 0; n < ndl.getLength(); n++ )
			{
				TagSpec ts = factory.createTagSpec( (Element)ndl.item( n ) );
				tagSpecs.add( ts );
			}
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}

	public TagSpecManager()
	{
		this.factory = new TagSpecFactory();
		this.tagSpecs = new Vector();
	}

	public TagSpec findTagSpec( String tagName )
	{
		TagSpec result = null;

		for( int len = 0; len < tagSpecs.size(); len++ )
		{
			TagSpec tmp = (TagSpec)tagSpecs.elementAt( len );
			if( tmp.getTagName().compareToIgnoreCase( tagName ) == 0 )
			{
				result = tmp;
				len = tagSpecs.size(); // Flag that search is over...
			}
		}

		return result;
	}

	public void updateTagSpec( TagSpec ts )
	{
		if( findTagSpec( ts.getTagName() ) != null )
			removeTagSpec( ts.getTagName() );

		addTagSpec( ts );
	}

	public void addTagSpec( TagSpec ts )
	{
		tagSpecs.add( ts );
	}

	public TagSpec removeTagSpec( String tagSpecName )
	{
		TagSpec myTs = findTagSpec( tagSpecName );

		if( myTs != null )
			tagSpecs.remove( myTs );

		return myTs;
	}

	public void finalizeTagSpec()
	{
		try
		{
			String outFileName = TagConstants.STAGE_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.TGSPEC_DIR + TagConstants.DIR_SEPARATOR +
					TagConstants.TGSPEC_FILENAME;

			PrintWriter pw = new PrintWriter( new FileOutputStream( new File( outFileName ) ) );
			DOMSource source = new DOMSource();
			StreamResult result = new StreamResult( pw );
			Transformer transformer = TransformerFactory.newInstance().newTransformer();
			transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );

			for( int i = 0; i < tagSpecs.size(); i++ )
			{
				TagSpec ts = (TagSpec)tagSpecs.elementAt( i );
				Element ele = factory.createTagSpecElement( ts );
				source.setNode( ele );
				transformer.transform( source, result );
				pw.println();
			}
		}
		catch( Exception e )
		{
			e.printStackTrace();
		}
	}
}



-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing 
real-time communications platform! Don't just IM. Build it in! 
http://www.jabber.com/osdn/xim