You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Katrin Möller <ka...@gmail.com> on 2005/05/31 13:41:06 UTC

parse custom markers

I'm trying to parse a given template containing custom markers.
Sample template:
"sometext $KEY$ sometext"
The easyiest way would be to parse it with a VelocityContext
containing KEY as a marker:
context.put("KEY","value");
The parsed String is then "sometext value$ sometext".
This is nasty because first, the remaining "$" must be replaced
manually and second, even an incomplete marker ($KEY) would be parsed.

How can I find a smarter workaround for this?
Thanks for help.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Katrin Möller <ka...@gmail.com>.
Hi Shinobu,

thanks for your advice! I don't know by now which way I will choose
but your suggestions sound good.

Best regards,
Katrin


On 6/3/05, Shinobu Kawai <sh...@gmail.com> wrote:
> Hi Katrin,
> 
> > nope,
> > context.put("KEY$","value");
> > isn't working (it's not identifying the whole key):
> >
> > and I can't swap to
> > sometext $KEY sometext
> > because of other requirements of the project.
> 
> I can think of two solutions.
> 
> 1. Don't use Velocity.
> Looks like you're not dealing with a Velocity template.  You might be
> better off using other technologies, such as regular expressions.
>   http://jakarta.apache.org/oro/index.html
>   http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/package-summary.html
> 
> 2. Hack Velocity.
> You'll have to change the parser behaviour to achieve what you want.
> Take a look at this article for some starter information:
>   http://wiki.apache.org/jakarta-velocity/HackingVelocity
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu Kawai <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Katrin,

> nope,
> context.put("KEY$","value");
> isn't working (it's not identifying the whole key):
> 
> and I can't swap to
> sometext $KEY sometext
> because of other requirements of the project.

I can think of two solutions.

1. Don't use Velocity.
Looks like you're not dealing with a Velocity template.  You might be
better off using other technologies, such as regular expressions.
  http://jakarta.apache.org/oro/index.html
  http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/package-summary.html

2. Hack Velocity.
You'll have to change the parser behaviour to achieve what you want. 
Take a look at this article for some starter information:
  http://wiki.apache.org/jakarta-velocity/HackingVelocity

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Katrin Möller <ka...@gmail.com>.
Hi,

nope,
context.put("KEY$","value");
isn't working (it's not identifying the whole key):

and I can't swap to
sometext $KEY sometext 
because of other requirements of the project.

On 5/31/05, Shinobu Kawai <sh...@gmail.com> wrote:
> Hi Katrin,
> 
> > I'm trying to parse a given template containing custom markers.
> > Sample template:
> > "sometext $KEY$ sometext"
> > The easyiest way would be to parse it with a VelocityContext
> > containing KEY as a marker:
> > context.put("KEY","value");
> > The parsed String is then "sometext value$ sometext".
> > This is nasty because first, the remaining "$" must be replaced
> > manually and second, even an incomplete marker ($KEY) would be parsed.
> >
> > How can I find a smarter workaround for this?
> 
> What's stopping you from just doing this?
> sometext $KEY sometext
> 
> Best regards,
> -- Shinobu
> 
> --
> Shinobu Kawai <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Katrin,

> I'm trying to parse a given template containing custom markers.
> Sample template:
> "sometext $KEY$ sometext"
> The easyiest way would be to parse it with a VelocityContext
> containing KEY as a marker:
> context.put("KEY","value");
> The parsed String is then "sometext value$ sometext".
> This is nasty because first, the remaining "$" must be replaced
> manually and second, even an incomplete marker ($KEY) would be parsed.
> 
> How can I find a smarter workaround for this?

What's stopping you from just doing this?
sometext $KEY sometext

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by "E.R. van Es" <er...@cdls.nl>.
Hi,
isn't it possible to make the keyname 'key$'?

cheers,
Eric

On Tue, 2005-05-31 at 15:07 +0200, Katrin Möller wrote:
> Hi Adam,
> no, the result should not contain the $-signs. The well parsed
> template should look like this:
> "sometext value sometext"
> 
> Cheers,
> Katrin
> 
> 
> On 5/31/05, Adam Williams <ad...@gmail.com> wrote:
> > Hello, Katrin.
> > 
> > Do you want the product to contain $KEY$? If so, you need to escape
> > that first $. You've likely seen
> > http://jakarta.apache.org/velocity/user-guide.html#Escaping%20Valid%20VTL%20References
> > 
> >   adam
> > 
> > On 5/31/05, Katrin Möller <ka...@gmail.com> wrote:
> > > I'm trying to parse a given template containing custom markers.
> > > Sample template:
> > > "sometext $KEY$ sometext"
> > > The easyiest way would be to parse it with a VelocityContext
> > > containing KEY as a marker:
> > > context.put("KEY","value");
> > > The parsed String is then "sometext value$ sometext".
> > > This is nasty because first, the remaining "$" must be replaced
> > > manually and second, even an incomplete marker ($KEY) would be parsed.
> > >
> > > How can I find a smarter workaround for this?
> > > Thanks for help.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Katrin Möller <ka...@gmail.com>.
Hi Adam,
no, the result should not contain the $-signs. The well parsed
template should look like this:
"sometext value sometext"

Cheers,
Katrin


On 5/31/05, Adam Williams <ad...@gmail.com> wrote:
> Hello, Katrin.
> 
> Do you want the product to contain $KEY$? If so, you need to escape
> that first $. You've likely seen
> http://jakarta.apache.org/velocity/user-guide.html#Escaping%20Valid%20VTL%20References
> 
>   adam
> 
> On 5/31/05, Katrin Möller <ka...@gmail.com> wrote:
> > I'm trying to parse a given template containing custom markers.
> > Sample template:
> > "sometext $KEY$ sometext"
> > The easyiest way would be to parse it with a VelocityContext
> > containing KEY as a marker:
> > context.put("KEY","value");
> > The parsed String is then "sometext value$ sometext".
> > This is nasty because first, the remaining "$" must be replaced
> > manually and second, even an incomplete marker ($KEY) would be parsed.
> >
> > How can I find a smarter workaround for this?
> > Thanks for help.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: parse custom markers

Posted by Adam Williams <ad...@gmail.com>.
Hello, Katrin.

Do you want the product to contain $KEY$? If so, you need to escape
that first $. You've likely seen
http://jakarta.apache.org/velocity/user-guide.html#Escaping%20Valid%20VTL%20References

  adam

On 5/31/05, Katrin Möller <ka...@gmail.com> wrote:
> I'm trying to parse a given template containing custom markers.
> Sample template:
> "sometext $KEY$ sometext"
> The easyiest way would be to parse it with a VelocityContext
> containing KEY as a marker:
> context.put("KEY","value");
> The parsed String is then "sometext value$ sometext".
> This is nasty because first, the remaining "$" must be replaced
> manually and second, even an incomplete marker ($KEY) would be parsed.
> 
> How can I find a smarter workaround for this?
> Thanks for help.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org