Package jodd.util

Examples of jodd.util.StringTemplateParser


  /**
   * Processes input JSP content and replace macros.
   */
  public String process(String input) {
    StringTemplateParser tagParser = createStringTemplateParser();

    return tagParser.parse(input, new StringTemplateParser.MacroResolver() {
      public String resolve(String macro) {
        HtmlTag htmlTag = new HtmlTag("<" + macro + "/>");
        String tagName = htmlTag.getTagName();

        String macroBody = loadMacro(tagName);
View Full Code Here


  /**
   * Creates new string template parser.
   */
  protected StringTemplateParser createStringTemplateParser() {
    StringTemplateParser tagParser = new StringTemplateParser();
    tagParser.setMacroStart("<" + tagPrefix);
    tagParser.setMacroEnd("/>");
    tagParser.setEscapeChar((char) 0);
    return tagParser;
  }
View Full Code Here

   * There are two ways how macros can be resolved: using active profiles
   * or using a profile of a property that is being resolved.
   */
  public void resolveMacros(String[] activeProfiles) {
    // create string template parser that will be used internally
    StringTemplateParser stringTemplateParser = new StringTemplateParser();
    stringTemplateParser.setResolveEscapes(false);

    if (!ignoreMissingMacros) {
      stringTemplateParser.setReplaceMissingKey(false);
    } else {
      stringTemplateParser.setReplaceMissingKey(true);
      stringTemplateParser.setMissingKeyReplacement(StringPool.EMPTY);
    }

    // start parsing
    int loopCount = 0;
    while (loopCount++ < MAX_INNER_MACROS) {
View Full Code Here

  /**
   * Resolves all macros in this props set. Called on property lookup.
   */
  public String resolveMacros(String value, final String... profiles) {
    // create string template parser that will be used internally
    StringTemplateParser stringTemplateParser = new StringTemplateParser();
    stringTemplateParser.setResolveEscapes(false);

    if (!ignoreMissingMacros) {
      stringTemplateParser.setReplaceMissingKey(false);
    } else {
      stringTemplateParser.setReplaceMissingKey(true);
      stringTemplateParser.setMissingKeyReplacement(StringPool.EMPTY);
    }

    final StringTemplateParser.MacroResolver macroResolver = new StringTemplateParser.MacroResolver() {
      public String resolve(String macroName) {
        String[] lookupProfiles = profiles;

        int leftIndex = macroName.indexOf('<');
        if (leftIndex != -1) {
          int rightIndex = macroName.indexOf('>');

          String profiles = macroName.substring(leftIndex + 1, rightIndex);
          macroName = macroName.substring(0, leftIndex).concat(macroName.substring(rightIndex + 1));

          lookupProfiles = StringUtil.splitc(profiles, ',');

          StringUtil.trimAll(lookupProfiles);
        }

        return lookupValue(macroName, lookupProfiles);
      }
    };

    // start parsing
    int loopCount = 0;

    while (loopCount++ < MAX_INNER_MACROS) {
      final String newValue = stringTemplateParser.parse(value, macroResolver);

      if (newValue.equals(value)) {
        break;
      }

View Full Code Here

TOP

Related Classes of jodd.util.StringTemplateParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.