head	1.19;
access;
symbols
	TIGRIS_1_1_0RC2:1.19
	TIGRIS_1_1_0RC1:1.19
	TIGRIS_1_1:1.19.0.12
	TIGRIS_1_0_8:1.19
	TIGRIS_1_0_8RC3:1.19
	TIGRIS_1_0_8RC2:1.19
	TIGRIS_1_0_8RC1:1.19
	TIGRIS_1_0_7:1.19
	TIGRIS_1_0_7RC3:1.19
	TIGRIS_1_0_7RC2:1.19
	TIGRIS_1_0_7RC1:1.19
	TIGRIS_1_0_6:1.19
	TIGRIS_1_0_6RC5:1.19
	TIGRIS_1_0_6RC4:1.19
	TIGRIS_1_0_6RC3:1.19
	TIGRIS_1_0_6RC2:1.19
	TIGRIS_1_0_6RC1:1.19
	TIGRIS_1_0_5:1.19
	TIGRIS_1_0_5RC6:1.19
	TIGRIS_1_0_5RC5:1.19
	TIGRIS_1_0_5RC4:1.19
	TIGRIS_1_0_5RC3:1.19
	TIGRIS_1_0_5RC2:1.19
	TIGRIS_1_0_5RC1:1.19
	TIGRIS_1_0_4:1.19
	TIGRIS_1_0_3:1.19
	TIGRIS_1_0_2:1.19
	TIGRIS_1_0_1:1.19
	TIGRIS_1_0:1.19.0.14
	TIGRIS_1_0_0:1.19
	TIGRIS_1_0_0_RC1:1.19.0.10
	HELM_PEER_PORT_BRANCH:1.19.0.8
	TIGRIS_0_9_2_4:1.19
	TIGRIS_0_9_2_3:1.19
	TIGRIS_0_9_2:1.19.0.6
	TIGRIS_0_9_0:1.19.0.4
	TIGRIS_0_8_4:1.19.0.2
	TIGRIS_710_FF:1.19
	TIGRIS_706:1.19
	TIGRIS_705:1.19
	TIGRIS_704:1.19
	TIGRIS_703:1.19
	TIGRIS_702:1.19
	TIGRIS_701:1.19
	TIGRIS_SEP_13_2000:1.14.0.2
	TIGRIS_BASELINE:1.19;
locks; strict;
comment	@# @;


1.19
date	2000.09.26.08.02.01;	author davidp;	state Exp;
branches;
next	1.18;

1.18
date	2000.09.20.17.15.29;	author kmaples;	state Exp;
branches;
next	1.17;

1.17
date	2000.09.20.16.39.52;	author leonardr;	state Exp;
branches;
next	1.16;

1.16
date	2000.09.18.19.00.22;	author davidp;	state Exp;
branches;
next	1.15;

1.15
date	2000.09.15.21.29.52;	author stack;	state Exp;
branches;
next	1.14;

1.14
date	2000.09.12.11.23.25;	author davidp;	state Exp;
branches;
next	1.13;

1.13
date	2000.08.11.20.17.07;	author davidp;	state Exp;
branches;
next	1.12;

1.12
date	2000.08.11.20.05.38;	author jon;	state Exp;
branches;
next	1.11;

1.11
date	2000.07.25.19.15.14;	author kmaples;	state Exp;
branches;
next	1.10;

1.10
date	2000.07.18.20.19.28;	author otnx;	state Exp;
branches;
next	1.9;

1.9
date	2000.07.12.01.26.49;	author davidp;	state Exp;
branches;
next	1.8;

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

1.7
date	2000.07.11.07.54.30;	author davidp;	state Exp;
branches;
next	1.6;

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

1.5
date	2000.07.06.00.43.47;	author elicia;	state Exp;
branches;
next	1.4;

1.4
date	2000.06.13.21.04.42;	author chuck;	state Exp;
branches;
next	1.3;

1.3
date	2000.06.12.23.16.58;	author chuck;	state Exp;
branches;
next	1.2;

1.2
date	2000.06.03.06.01.15;	author davidp;	state Exp;
branches;
next	1.1;

1.1
date	2000.05.06.00.49.41;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.19
log
@Does token substitution for SERVLET_TEMPLATE_ROOT, and the sub'ed value depends on whether it is to be evaluated at build time or run time.  Renamed brandDir to brandTemplateRoot. Made the default propertiesRoot look under ../java/org instead of ../java.  Moved the token substitution of SANDBOX to outside the conditional in the recursive parse function.  Removed an extra existence test for subTemplate.
@
text
@#!/usr/bin/perl -w
# template-cooker: Preprocesses the sourceXchange templates.
#
# Copyright (c) 1999 DataWeb Systems, Inc. All rights reserved.
# Copyright (c) 1999, 2000 Collab.Net, Inc.
# Last Modified by Kevin Maples <kmaples@@collab.net>

use Getopt::Std;

%option=();
# getopts("io:v", \%option);
getopts("i", \%option);


# Root of sourceXchange java source tree.
my $templateRoot = `pwd`;
chomp $templateRoot;
print "Cooking $templateRoot\n";

# Path of default master template
my $sandbox = $ENV{'SANDBOX'};
my $brandTemplateRoot = $ENV{'BRAND_TEMPLATE_ROOT'};
my $servletTemplateRoot = $ENV{'SERVLET_TEMPLATE_ROOT'};

# Tokens for a search and replace.
# NOTE: The backslashes in the string literals are needed for regexes.
my $sandboxToken = '\$SANDBOX;';
my $brandTemplateToken = '\$BRAND_TEMPLATE_ROOT;';
my $servletTemplateToken = '\$SERVLET_TEMPLATE_ROOT;';

my $defaultMaster = "$brandTemplateRoot/Standard.wm";
# Location of cooked templates
my $cooked = "$templateRoot/cooked";

# Allow some options to be specified, particularly for instantiations.
if ($option{i}) {
    $propertiesRoot = "$sandbox/site/java";
} else {
    $propertiesRoot = "$templateRoot/../java/org";
}

my @@propFiles = split(/\n/, `find $propertiesRoot -name '*.properties'`);

## MAIN #############################################################

foreach $file (@@propFiles) {
    #print "Processing: $file\n";

    # Get the name of the servlet.
    my $servlet = `grep servletName $file`;
    if ($servlet eq "") {
        print "WARN: servletName is empty -- skipping: $file\n";
        next;
    }
    $servlet =~ s/\s*servletName=\s*//;
    $servlet =~ s/\s$//;

    # Get the name of the template
    my $template = `grep servletTemplate $file`;
    if ($template eq "") {
        print "WARN: servletTemplate is empty -- skipping: $file\n";
        next;
    }
    $template =~ s/\s*servletTemplate=\s*//;
    $template =~ s/\s*$//;

    # Get the name of the template directory
    my $servletDir = `grep servletDirectory $file`;
    if ($servletDir eq "") {
        print "WARN: servletDirectory is empty -- skipping: $file\n";
        next;
    }
    $servletDir =~ s/\s*servletDirectory=\s*//;
    $servletDir =~ s/\s*$//;

    $template = $servletDir . '/' . $template;
    #print "  <> template = $template\n";

    # See if an alternate master template is defined for this servlet.
    my $master = `grep templateName $file`;
    $master =~ s/\s*templateName=\s*//;
    $master =~ s/\s*$//;

    if ($master ne '') { 
        $master = $brandTemplateRoot . '/' . $master; 
    } else { 
        $master = $defaultMaster; 
    }

    #print "[] Master template: $master\n";

    # If we have found a template in this properties file, cook it.
    if ($template ne ''){
        createDirs($template);
        parseTemplate($template, $servlet, $master);
    }
}

exit;

## END MAIN #########################################################

#--------------------
sub createDirs {
#--------------------
    my($template) = @@_;
    @@dirs = split(/\//, $template);
    $pre = $cooked;
    for ($i = 0; $i < @@dirs - 1; $i++) {
        if (!(-e "$pre/$dirs[$i]")) {
            mkdir("$pre/$dirs[$i]", 0775);
            # print "Created $pre/$dirs[$i]\n";
        }
        $pre = $pre . "/" . $dirs[$i];
    }
}
#--------------------
sub parseTemplate {
#--------------------
    my ($template, $servlet, $master) = @@_;

    # Start with the master
    open(TMPL, "$master") || die "Can't open master template: $master\n";

    # Store results in the cooked dir.
    unlink ("$cooked/$template");
    open(COOK, ">$cooked/$template") || 
        die "Can't open cooked output: $cooked/$template\n";

    # print "\tCooking: $template\n";
    my $ok = recursiveParse(TMPL, COOK, $template, $servlet);

    # If there was a serious problem, then remove the partially cooked file.
    if ($ok == -1) 
	{ 
		my $file2unlink = "$cooked/$template";
		unlink ( $file2unlink ) || die "Failed to unlink $cooked/$template: $!"; 
		# print "DEBUG: Unlinked $file2unlink\n";

	}

    close(TMPL);
    close(COOK);
}
#--------------------
sub recursiveParse {
#--------------------
    ## It probably doesn't bear repeating, but $in and $out 
    ## are both filehandles here:
    my ($in, $out, $template, $servlet) = @@_;
    my $ok;

    while (<$in>){
        if (/^\s*#parse \"(.*)\"/) {
            my $subTemplate = $1;
            # print "\t    >subTemplate 1: $subTemplate\n";
    
	    # Replace the '$SANDBOX' token with the $SANDBOX env var
	    # [davidp: I think this is obsolete; no refs in joist & xchange]
	    $subTemplate =~ s!$sandboxToken/!$sandbox/!;
	    # print "\t    >subTemplate 1.5: $subTemplate\n";
    
            # Replace the '$BRAND_TEMPLATE_ROOT' token with the corresponding 
            # environment variable.
            $subTemplate =~ s!$brandTemplateToken/!$brandTemplateRoot/!;
            # print "\t    >subTemplate 2: $subTemplate\n";
    
            # Substitute in the servlet-specific template
            $subTemplate =~ s!\$servletTemplate!$template!;
            # print "\t    >subTemplate 3: $subTemplate\n";
    
            # Don't parse for templates that are specified at runtime.
            # This applies to: Selection.wm, Help.wm, View.wm
            if (! ( /\$servletName;.wm/ || /\$documentRoot;/ ) ) {

		# Replace '$SERVLET_TEMPLATE_ROOT' with the build-time location
                $subTemplate =~ s/$servletTemplateToken/$templateRoot/;
                # print "\t    >subTemplate 4: $subTemplate\n";
        
                # print "\tsubTemplate: $subTemplate\n";
                ## Note that here, $subTemplate is both a filehandle
                ## AND the name of the file to open:
                if (!open($subTemplate, $subTemplate)) {
		    # print "DEBUG: $subTemplate missing. Remove $template.\n";

		    if ($option{i}) {
			return -1;
		    } else {
			print STDERR "Warning: can't open $subTemplate in ",
			"the template for $servlet\n";
		    }
                    next; ## while ...
                }
		
                $ok = recursiveParse($subTemplate, $out, $template, $servlet);
                close($subTemplate);
		if ($ok != 0) { return $ok; }
            } else {
		# Replace '$SERVLET_TEMPLATE_ROOT' with the run-time location
                $subTemplate =~ s/$servletTemplateToken/$servletTemplateRoot/;
                # print "\t    >subTemplate 7: $subTemplate\n";
                print $out "#parse '$subTemplate'\n";
            }
        } else {
	
            print $out $_;
        }
    }
    return 0;
}

@


1.18
log
@Undoing some debug that was accidentally checked in.
@
text
@d22 2
a23 1
my $brandDir = $ENV{'BRAND_TEMPLATE_ROOT'};
d31 1
a31 1
my $defaultMaster = "$brandDir/Standard.wm";
d39 1
a39 1
    $propertiesRoot = "$templateRoot/../java";
d47 1
a47 1
    # print "Processing: $file\n";
d77 1
a77 1
    # print "  <> template = $template\n";
d85 1
a85 1
        $master = $brandDir . '/' . $master; 
d90 1
a90 1
    # print "[] Master template: $master\n";
d158 6
a163 1
            # Replace the 'BRAND_TEMPLATE_ROOT' token with the corresponding 
d165 1
a165 1
            $subTemplate =~ s!$brandTemplateToken/!$brandDir/!;
d175 2
a179 4
                # Replace the '$SANDBOX' token with the $SANDBOX env var
                $subTemplate =~ s!$sandboxToken/!$sandbox/!;
                # print "\t    >subTemplate 5: $subTemplate\n";
        
d186 6
a191 11
		    # Why this test at all?  St.Ack
		    # I took it out.
		    #
                    #if (-e $subTemplate) {
			if ($option{i}) {
			    return -1;
			} else {
			    print STDERR "Warning: can't open $subTemplate in ",
			    "the template for $servlet\n";
			}
                    #}
d199 3
@


1.17
log
@"fi" statement was incorrectly commented out, breaking startup script.
@
text
@d120 1
a120 1
    print "DBG: parseTemplate args: $template, $servlet, $master\n";
a151 2
    print "\nDBG: recursiveParse args: $in, $out, $template, $servlet\n";

a153 3

	    print "\nDBG: In recursiveParse:\nDBG: \$_ = $_";	
	    print "DBG: \$1 = $1\n";
a155 1
	    print "DBG: \$subTemplate == $subTemplate\n";
a158 2

            print "DBG: \$subTemplate =~ s!$brandTemplateToken/!$brandDir/!;\n";
a162 1
            print "DBG: $subTemplate =~ s!\$servletTemplate!$template!;\n";
@


1.16
log
@Rewritten comments on why comment out a test
@
text
@d120 1
a120 1

d152 2
d156 3
d161 1
d165 2
d171 1
@


1.15
log
@If a subtemplate didn't exist, the 'ok' flag wasn't being set.  Meant deitrus was being left in cooked dir
@
text
@a168 2
                # Replace the 'SERVLET_TEMPLATE_ROOT' token with the
                # corresponding env var
d195 1
d203 1
@


1.14
log
@Accept command line option "-i" to cook templates for an instantiation.
@
text
@d46 1
a46 1
    print "Processing: $file\n";
d133 7
a139 1
    if ($ok == -1) { unlink ("$cooked/$template"); }
d182 6
a187 1
                    if (-e $subTemplate) {
d194 1
a194 1
                    }
@


1.13
log
@Fixed syntax error -- s/continue/next/
@
text
@d8 7
d22 1
a22 1
my $brand = $ENV{'BRAND'};
a29 5
# Corresponding value for a search and replace (the rest are not known until 
# later).
my $brandDir = "$sandbox/brands/$brand";
my $runtimeTemplateDir = "$sandbox/site/templates/$brand";

d34 8
a41 1
my @@propFiles = split(/\n/, `find $templateRoot/../java -name '*.properties'`);
d130 4
a133 1
    recursiveParse(TMPL, COOK, $template, $servlet);
d144 1
d177 6
a182 2
                        print STDERR "Warning: can't open $subTemplate in ", 
                        "the template for $servlet\n";
d186 1
a186 1
                recursiveParse($subTemplate, $out, $template, $servlet);
d188 1
d196 1
@


1.12
log
@fix template cooker to ignore properties files it shouldn't care about
anyway.
@
text
@d43 1
a43 1
        continue;
d52 1
a52 1
        continue;
d61 1
a61 1
        continue;
a70 4
    if ($master eq "") {
        print "WARN: templateName is empty -- skipping: $file\n";
        continue;
    }
@


1.11
log
@Fixed bug which was causing 'Close on unopened filehandle ...' errors; formatted script for readability.
@
text
@d41 4
d50 4
d59 4
d71 4
@


1.10
log
@Commented out some debug output.
@
text
@d6 1
a6 1
#
d33 4
a36 2
foreach $file (@@propFiles)
{
a60 4
    if ($master ne '')
	{ $master = $brandDir . '/' . $master; }
    else
	{ $master = $defaultMaster; }
d62 7
a68 1
     # print "[] Master template: $master\n";
d71 3
a73 4
    if ($template ne '')
    {
	createDirs($template);
	parseTemplate($template, $servlet, $master);
d79 1
d81 3
a83 2
sub createDirs
{
d87 6
a92 8
    for ($i = 0; $i < @@dirs - 1; $i++)
    {
	if (!(-e "$pre/$dirs[$i]"))
	{
	    mkdir("$pre/$dirs[$i]", 0775);
	    # print "Created $pre/$dirs[$i]\n";
	}
	$pre = $pre . "/" . $dirs[$i];
d95 3
a97 3

sub parseTemplate
{
d106 1
a106 1
	die "Can't open cooked output: $cooked/$template\n";
d114 5
a118 3

sub recursiveParse
{
d121 44
a164 63
    while (<$in>)
    {
	if (/^\s*#parse \"(.*)\"/)
	{
	    $subTemplate = $1;
	    # print "\t    >subTemplate 1: $subTemplate\n";

	    # Replace the 'BRAND_TEMPLATE_ROOT' token with the corresponding 
	    # environment variable.
	    $subTemplate =~ s!$brandTemplateToken/!$brandDir/!;
	    # print "\t    >subTemplate 2: $subTemplate\n";

	    # Substitute in the servlet-specific template
	    $subTemplate =~ s!\$servletTemplate!$template!;
	    # print "\t    >subTemplate 3: $subTemplate\n";

	    # Don't parse for templates that are specified at runtime.
	    # This applies to: Selection.wm, Help.wm, View.wm
	    if (! ( /\$servletName;.wm/ || /\$documentRoot;/ ) )
	    {
		# Replace the 'SERVLET_TEMPLATE_ROOT' token with the
		# corresponding env var
		$subTemplate =~ s/$servletTemplateToken/$templateRoot/;
		# print "\t    >subTemplate 4: $subTemplate\n";

		# Replace the '$SANDBOX' token with the $SANDBOX env var
		$subTemplate =~ s!$sandboxToken/!$sandbox/!;
		# print "\t    >subTemplate 5: $subTemplate\n";

		# print "\tsubTemplate: $subTemplate\n";
		if (!open($subTemplate, $subTemplate))
		{
		    if (-e $subTemplate)
		    {
			print STDERR "Warning: can't open $subTemplate in ", 
			"the template for $servlet\n";
		    }
		    next;
		}
		recursiveParse($subTemplate, $out, $template, $servlet);
		close($subTemplate);
	    }
	    else
	    {
		# Replace the 'SERVLET_TEMPLATE_ROOT' token with the
		# corresponding env var
		# $subTemplate =~ s/$servletTemplateToken/$runtimeTemplateDir/;
		# print "\t    >subTemplate 4: $subTemplate\n";

		# Replace the '$SANDBOX' token with nothing.  The template
		# root speicifed in WebMacro.properties will be operative
		# at run time.
		# $subTemplate =~ s!$sandboxToken/!$sandbox/!;
		# print "\t    >subTemplate 6: $subTemplate\n";

		#REM: print $out $_;
		print $out "#parse '$subTemplate'\n";
	    }
	}
	else
	{
	    print $out $_;
	}
d167 1
@


1.9
log
@Removed the extra debugging print's
@
text
@d105 1
a105 1
    print "\tCooking: $template\n";
d145 1
a145 1
		print "\tsubTemplate: $subTemplate\n";
@


1.8
log
@Added doc.
@
text
@d53 1
a53 1
    print "  <> template = $template\n";
d64 1
a64 1
     print "[] Master template: $master\n";
d87 1
a87 1
	    print "Created $pre/$dirs[$i]\n";
d121 1
a121 1
	    print "\t    >subTemplate 1: $subTemplate\n";
d126 1
a126 1
	    print "\t    >subTemplate 2: $subTemplate\n";
d130 1
a130 1
	    print "\t    >subTemplate 3: $subTemplate\n";
d139 1
a139 1
		print "\t    >subTemplate 4: $subTemplate\n";
d143 1
a143 1
		print "\t    >subTemplate 5: $subTemplate\n";
d163 1
a163 1
		print "\t    >subTemplate 4: $subTemplate\n";
d169 1
a169 1
		print "\t    >subTemplate 6: $subTemplate\n";
@


1.7
log
@Modified to work with the new style of template #parse file names.
@
text
@d18 1
d124 1
a124 1
	    # env var
@


1.6
log
@Adjusted to support a more reasonable directory structure.  Not
thoroughly tested.
@
text
@d18 3
a20 3
my $sandboxToken = '$SANDBOX;';
my $brandTemplateToken = '$BRAND_TEMPLATE_ROOT;';
my $servletTemplateToken = '$SERVLET_TEMPLATE_ROOT;';
d25 1
a27 1

d41 1
a41 1
    # Get the name of the template (if there is one)
d46 8
d94 1
a94 1
    my($template, $servlet, $master) = @@_;
d113 1
a113 1
    my($in, $out, $template, $servlet) = @@_;
d120 1
d122 2
a123 3
	     # print "\t    >subTemplate 1: $subTemplate\n";
            $subTemplate =~ s!$sandboxToken/!$sandbox/!;
	     # print "\t    >subTemplate 2: $subTemplate\n";
d125 3
a127 1
	     # print "\t    >subTemplate 3: $subTemplate\n";
d129 1
a129 1
	     # print "\t    >subTemplate 4: $subTemplate\n";
d135 2
d138 6
a143 1
		# print "\t    >subTemplate 4: $subTemplate\n";
d159 12
a170 1
		print $out $_;
@


1.5
log
@unlinked cooked directory
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d1 1
a1 1
#!/usr/bin/perl
d14 13
a26 4
my $sandbox=$ENV{'SANDBOX'};
my $brand=$ENV{'BRAND'};
my $common = "$sandbox/brands/$brand";
my $defaultMaster = "$common/Standard.wm";
d51 1
a51 1
	{ $master = $common . '/' . $master; }
d114 1
a114 1
	    $subTemplate =~ s/.*\/common\//$common\//;
d116 1
a116 1
	    $subTemplate =~ s/\$servletTemplate/$template/;
d118 2
d125 1
a125 1
		$subTemplate =~ s/SITE_ROOT/$templateRoot/;
@


1.4
log
@added quotes around parse statements
@
text
@d25 1
a25 1
    # print "Processing: $file\n";
d46 1
a46 1
    # print "[] Master template: $master\n";
d83 1
d104 1
a104 1
	    print "\t    >subTemplate 1: $subTemplate\n";
d106 1
a106 1
	    print "\t    >subTemplate 2: $subTemplate\n";
d108 1
a108 1
	    print "\t    >subTemplate 3: $subTemplate\n";
d115 1
a115 1
		print "\t    >subTemplate 4: $subTemplate\n";
d131 1
a131 1
		# print $out $_;
@


1.3
log
@mv the directory munge for common directory
@
text
@d131 1
a131 1
		print $out "#parse $subTemplate\n";
@


1.2
log
@Support for template branding.
@
text
@d103 6
a112 5
		# print "\t    >subTemplate 1: $subTemplate\n";
		$subTemplate =~ s/.*\/common\//$common\//;
		# print "\t    >subTemplate 2: $subTemplate\n";
		$subTemplate =~ s/\$servletTemplate/$template/;
		# print "\t    >subTemplate 3: $subTemplate\n";
d114 2
a115 2
		# print "\t    >subTemplate 4: $subTemplate\n";
		# print "\tsubTemplate: $subTemplate\n";
d130 2
a131 1
		print $out $_;
@


1.1
log
@Moved here from the sourcexchange/templates directory.  Changed the location of Perl from /usr/local/bin/perl to /usr/bin/perl.  Minor tweaks to the output of template-cooker.
@
text
@d14 4
a17 1
my $defaultMaster = 'common/Standard.wm';
d25 3
a27 1
    #print "Processing: $file\n";
d31 2
d36 3
a38 1
    my $master = `grep templateName $file` || $defaultMaster;
d41 8
a48 1
    $master = $templateRoot . '/' . $master;
d69 1
a69 2
	    $pre = $pre . "/" . $dirs[$i];
	    print "Created $pre\n";
d71 1
d86 1
d107 3
d111 1
d113 2
a114 1
		#print STDERR "subTemplate: $subTemplate\n";
@

