简体   繁体   中英

Apache Velocity: non-latin names of the custom directives

how to do custom velocity directive with localized name. Such directives is ignored now. For example:

class MyDirective extends Directive {
  @Override
  public String getName() {
    return "Пример";
  }
  @Override
  public boolean render(InternalContextAdapter context, Writer writer, Node node) 
        throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
    writer.write("example");
    return true;
  }
}

Input text: #Пример()

Expected example , but got unmodified text #Пример()

It's a velocity parser limitation according to this Identifier definition

<PRE_REFERENCE,REFMODIFIER,REFMOD2>
TOKEN :
{
    <#ALPHA_CHAR: ["a"-"z", "A"-"Z", "_"] >
|   <#IDENTIFIER_CHAR: [ "a"-"z", "A"-"Z", "0"-"9", "_" ] >
|   <IDENTIFIER:  ( <ALPHA_CHAR> ) (<IDENTIFIER_CHAR>)* >
    {
        if (curLexState == PRE_REFERENCE)
        {
            SwitchTo(REFERENCE);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM