[stringtemplate-interest] Embedded loader problems

brian at protexis.com brian at protexis.com
Mon Aug 28 15:42:15 PDT 2006


Hi

I'll answer my own question ...

The following C# code works ...

Assembly assembly = Assembly.GetExecutingAssembly();

// define the loader for the string template group
EmbeddedResourceGroupLoader embeddedResourceGroupLoader = new
    EmbeddedResourceGroupLoader(
    null,
    assembly,
    WebPageResource.TemplateGroupNameSpace);

// define the loader for the string template
EmbeddedResourceTemplateLoader embeddedResourceTemplateLoader = new
    EmbeddedResourceTemplateLoader(
    assembly,
    WebPageResource.TemplateNameSpace);

// before the string template group can be used, the static instance
// needs to know which loader to use
StringTemplateGroup.RegisterGroupLoader(embeddedResourceGroupLoader);

StringTemplateGroup stringTemplateGroup = new StringTemplateGroup(
    WebPageConstant.GROUP_TYPE_NAME,
    embeddedResourceTemplateLoader);

StringTemplate stringTemplate =
    stringTemplateGroup.LookupTemplate(templateTypeName);





-----Original Message-----
From: brian at protexis.com
Sent: Mon, August 28, 2006 14:39
To: stringtemplate-interest at antlr.org
Subject: [stringtemplate-interest] Embedded loader problems

Hi

Suppose I create two templates (One.st and Two.st) and a template group
(Common.stg)

The contents of One.st are as follows:

$Two()$

The contents of Two.st are as follows:

"I'm not having fun here"

The contents of Common.stg are as follows:

group Common;

Here's the C# code:

Assembly assembly = Assembly.GetExecutingAssembly();

// define the loader for the string template group
EmbeddedResourceGroupLoader embeddedResourceGroupLoader = new
EmbeddedResourceGroupLoader(
    null,
    assembly,
    WebPageResource.TemplateGroupNameSpace);

StringTemplateGroup stringTemplateGroup =
embeddedResourceGroupLoader.LoadGroup(
    WebPageConstant.GROUP_TYPE_NAME);

// define the loader for the string template
EmbeddedResourceTemplateLoader embeddedResourceTemplateLoader = new
EmbeddedResourceTemplateLoader(
    assembly,
    WebPageResource.TemplateNameSpace);

StringTemplate stringTemplate = new StringTemplate(
    stringTemplateGroup,
    embeddedResourceTemplateLoader.LoadTemplate(templateTypeName));

When I run the code with templateTypeName set to "One", an exception is
thrown because the StringTemplate class has no idea where "Two.st" is
located.

Could someone please point me in the right direction? What do I need to do
to get the output "I'm not having fun here"?

If the StringTemplate library doesn't support thing, can I add another
constructor to the StringTemplate class that takes a StringTemplateLoader
as a parameter?

Thanks





_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest




More information about the stringtemplate-interest mailing list