Codota Logo
TemplateMarkupOutputModel
Code IndexAdd Codota to your IDE (free)

How to use
TemplateMarkupOutputModel
in
freemarker.core

Best Java code snippets using freemarker.core.TemplateMarkupOutputModel (Showing top 20 results out of 315)

  • Common ways to obtain TemplateMarkupOutputModel
private void myMethod () {
TemplateMarkupOutputModel t =
  • Codota IconStringLiteral stringLiteral;TemplateMarkupOutputModel leftMO;TemplateMarkupOutputModel rightMO;EvalUtil.concatMarkupOutputs(stringLiteral, leftMO, rightMO)
  • Codota IconMarkupOutputFormat markupOutputFormat;MarkupOutputFormat markupOutputFormat2;String textToEsc;TemplateMarkupOutputModel mo2;markupOutputFormat.concat(markupOutputFormat2.fromPlainTextByEscaping(textToEsc), mo2)
  • Codota IconMarkupOutputFormat markupOutputFormat;TemplateMarkupOutputModel mo1;TemplateMarkupOutputModel mo2;markupOutputFormat.concat(mo1, mo2)
  • Smart code suggestions by Codota
}
origin: org.freemarker/freemarker

@Override
protected TemplateModel calculateResult(TemplateMarkupOutputModel model) throws TemplateModelException {
  return new SimpleScalar(model.getOutputFormat().getMarkupString(model));
}
 
origin: org.freemarker/freemarker

if (markupResult != null) {
  TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String
      ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart)
      : (TemplateMarkupOutputModel<?>) calcedPart;
  markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO);
    TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart;
    if (plainTextResult != null) {
      TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat()
          .fromPlainTextByEscaping(plainTextResult.toString());
      markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
origin: org.freemarker/freemarker

@Override
TemplateModel _eval(Environment env)
throws TemplateException {
  TemplateModel tm = target.eval(env);
  Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env);
  if (moOrStr instanceof String) {
    return calculateResult((String) moOrStr, env);
  } else {
    TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr;
    if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) {
      return mo;
    }
    throw new NonStringException(target, tm, env);
  }
}
 
origin: org.freemarker/freemarker

static boolean isEmpty(TemplateModel model) throws TemplateModelException {
  if (model instanceof BeanModel) {
    return ((BeanModel) model).isEmpty();
  } else if (model instanceof TemplateSequenceModel) {
    return ((TemplateSequenceModel) model).size() == 0;
  } else if (model instanceof TemplateScalarModel) {
    String s = ((TemplateScalarModel) model).getAsString();
    return (s == null || s.length() == 0);
  } else if (model == null) {
    return true;
  } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check
    TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model;
    return mo.getOutputFormat().isEmpty(mo);
  } else if (model instanceof TemplateCollectionModel) {
    return !((TemplateCollectionModel) model).iterator().hasNext();
  } else if (model instanceof TemplateHashModel) {
    return ((TemplateHashModel) model).isEmpty();
  } else if (model instanceof TemplateNumberModel
      || model instanceof TemplateDateModel
      || model instanceof TemplateBooleanModel) {
    return false;
  } else {
    return true;
  }
}
 
origin: org.freemarker/freemarker

private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env)
    throws NonStringException {
  if (formatResult instanceof String) { 
    return (String) formatResult;
  }
  
  assertFormatResultNotNull(formatResult);
  
  TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult;
  _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder(
      "Value was formatted to convert it to string, but the result was markup of ouput format ",
      new _DelayedJQuote(mo.getOutputFormat()), ".")
      .tip("Use value?string to force formatting to plain text.")
      .blame(exp);
  throw new NonStringException(null, desc);
}
origin: org.freemarker/freemarker

static TemplateMarkupOutputModel concatMarkupOutputs(TemplateObject parent, TemplateMarkupOutputModel leftMO,
    TemplateMarkupOutputModel rightMO) throws TemplateException {
  MarkupOutputFormat leftOF = leftMO.getOutputFormat();
  MarkupOutputFormat rightOF = rightMO.getOutputFormat();
  if (rightOF != leftOF) {
    String rightPT;
    String leftPT;
    if ((rightPT = rightOF.getSourcePlainText(rightMO)) != null) {
      return leftOF.concat(leftMO, leftOF.fromPlainTextByEscaping(rightPT));
    } else if ((leftPT = leftOF.getSourcePlainText(leftMO)) != null) {
      return rightOF.concat(rightOF.fromPlainTextByEscaping(leftPT), rightMO);
    } else {
      Object[] message = { "Concatenation left hand operand is in ", new _DelayedToString(leftOF),
          " format, while the right hand operand is in ", new _DelayedToString(rightOF),
          ". Conversion to common format wasn't possible." };
      if (parent instanceof Expression) {
        throw new _MiscTemplateException((Expression) parent, message);
      } else {
        throw new _MiscTemplateException(message);
      }
    }
  } else {
    return leftOF.concat(leftMO, rightMO);
  }
}
origin: org.freemarker/freemarker

final MarkupOutputFormat moOF = mo.getOutputFormat();
origin: org.freemarker/freemarker

  TemplateMarkupOutputModel<?> rightMO = (TemplateMarkupOutputModel<?>) rightOMOrStr; 
  return EvalUtil.concatMarkupOutputs(parent,
      rightMO.getOutputFormat().fromPlainTextByEscaping((String) leftOMOrStr),
      rightMO);
  return EvalUtil.concatMarkupOutputs(parent,
      leftMO,
      leftMO.getOutputFormat().fromPlainTextByEscaping((String) rightOMOrStr));
} else { // rightOMOrStr instanceof TemplateMarkupOutputModel
  return EvalUtil.concatMarkupOutputs(parent,
origin: org.freemarker/freemarker

@Override
protected TemplateModel calculateResult(Environment env) throws TemplateException {
  TemplateModel lhoTM = target.eval(env);
  Object lhoMOOrStr = EvalUtil.coerceModelToStringOrMarkup(lhoTM, target, null, env);
  MarkupOutputFormat contextOF = outputFormat;
  if (lhoMOOrStr instanceof String) { // TemplateMarkupOutputModel
    return calculateResult((String) lhoMOOrStr, contextOF, env);
  } else {
    TemplateMarkupOutputModel lhoMO = (TemplateMarkupOutputModel) lhoMOOrStr;
    MarkupOutputFormat lhoOF = lhoMO.getOutputFormat();
    // ATTENTION: Keep this logic in sync. with ${...}'s logic!
    if (lhoOF == contextOF || contextOF.isOutputFormatMixingAllowed()) {
      // bypass
      return lhoMO;
    } else {
      // ATTENTION: Keep this logic in sync. with ${...}'s logic!
      String lhoPlainTtext = lhoOF.getSourcePlainText(lhoMO);
      if (lhoPlainTtext == null) {
        throw new _TemplateModelException(target,
            "The left side operand of ?", key, " is in ", new _DelayedToString(lhoOF),
            " format, which differs from the current output format, ",
            new _DelayedToString(contextOF), ". Conversion wasn't possible.");
      }
      // Here we know that lho is escaped plain text. So we re-escape it to the current format and
      // bypass it, just as if the two output formats were the same earlier.
      return contextOF.fromPlainTextByEscaping(lhoPlainTtext);
    }
  }
}
 
origin: org.freemarker/freemarker-gae

@Override
protected TemplateModel calculateResult(TemplateMarkupOutputModel model) throws TemplateModelException {
  return new SimpleScalar(model.getOutputFormat().getMarkupString(model));
}
 
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

@Override
protected TemplateModel calculateResult(TemplateMarkupOutputModel model) throws TemplateModelException {
  return new SimpleScalar(model.getOutputFormat().getMarkupString(model));
}
 
origin: org.freemarker/freemarker-gae

if (markupResult != null) {
  TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String
      ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart)
      : (TemplateMarkupOutputModel<?>) calcedPart;
  markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO);
    TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart;
    if (plainTextResult != null) {
      TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat()
          .fromPlainTextByEscaping(plainTextResult.toString());
      markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

if (markupResult != null) {
  TemplateMarkupOutputModel<?> partMO = calcedPart instanceof String
      ? markupResult.getOutputFormat().fromPlainTextByEscaping((String) calcedPart)
      : (TemplateMarkupOutputModel<?>) calcedPart;
  markupResult = EvalUtil.concatMarkupOutputs(this, markupResult, partMO);
    TemplateMarkupOutputModel<?> moPart = (TemplateMarkupOutputModel<?>) calcedPart;
    if (plainTextResult != null) {
      TemplateMarkupOutputModel<?> leftHandMO = moPart.getOutputFormat()
          .fromPlainTextByEscaping(plainTextResult.toString());
      markupResult = EvalUtil.concatMarkupOutputs(this, leftHandMO, moPart);
origin: org.freemarker/freemarker-gae

@Override
TemplateModel _eval(Environment env)
throws TemplateException {
  TemplateModel tm = target.eval(env);
  Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env);
  if (moOrStr instanceof String) {
    return calculateResult((String) moOrStr, env);
  } else {
    TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr;
    if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) {
      return mo;
    }
    throw new NonStringException(target, tm, env);
  }
}
 
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

@Override
TemplateModel _eval(Environment env)
throws TemplateException {
  TemplateModel tm = target.eval(env);
  Object moOrStr = EvalUtil.coerceModelToStringOrMarkup(tm, target, null, env);
  if (moOrStr instanceof String) {
    return calculateResult((String) moOrStr, env);
  } else {
    TemplateMarkupOutputModel<?> mo = (TemplateMarkupOutputModel<?>) moOrStr;
    if (mo.getOutputFormat().isLegacyBuiltInBypassed(key)) {
      return mo;
    }
    throw new NonStringException(target, tm, env);
  }
}
 
origin: org.freemarker/freemarker-gae

static boolean isEmpty(TemplateModel model) throws TemplateModelException {
  if (model instanceof BeanModel) {
    return ((BeanModel) model).isEmpty();
  } else if (model instanceof TemplateSequenceModel) {
    return ((TemplateSequenceModel) model).size() == 0;
  } else if (model instanceof TemplateScalarModel) {
    String s = ((TemplateScalarModel) model).getAsString();
    return (s == null || s.length() == 0);
  } else if (model == null) {
    return true;
  } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check
    TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model;
    return mo.getOutputFormat().isEmpty(mo);
  } else if (model instanceof TemplateCollectionModel) {
    return !((TemplateCollectionModel) model).iterator().hasNext();
  } else if (model instanceof TemplateHashModel) {
    return ((TemplateHashModel) model).isEmpty();
  } else if (model instanceof TemplateNumberModel
      || model instanceof TemplateDateModel
      || model instanceof TemplateBooleanModel) {
    return false;
  } else {
    return true;
  }
}
 
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

static boolean isEmpty(TemplateModel model) throws TemplateModelException {
  if (model instanceof BeanModel) {
    return ((BeanModel) model).isEmpty();
  } else if (model instanceof TemplateSequenceModel) {
    return ((TemplateSequenceModel) model).size() == 0;
  } else if (model instanceof TemplateScalarModel) {
    String s = ((TemplateScalarModel) model).getAsString();
    return (s == null || s.length() == 0);
  } else if (model == null) {
    return true;
  } else if (model instanceof TemplateMarkupOutputModel) { // Note: happens just after FTL string check
    TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) model;
    return mo.getOutputFormat().isEmpty(mo);
  } else if (model instanceof TemplateCollectionModel) {
    return !((TemplateCollectionModel) model).iterator().hasNext();
  } else if (model instanceof TemplateHashModel) {
    return ((TemplateHashModel) model).isEmpty();
  } else if (model instanceof TemplateNumberModel
      || model instanceof TemplateDateModel
      || model instanceof TemplateBooleanModel) {
    return false;
  } else {
    return true;
  }
}
 
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.freemarker

private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env)
    throws NonStringException {
  if (formatResult instanceof String) { 
    return (String) formatResult;
  }
  
  assertFormatResultNotNull(formatResult);
  
  TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult;
  _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder(
      "Value was formatted to convert it to string, but the result was markup of ouput format ",
      new _DelayedJQuote(mo.getOutputFormat()), ".")
      .tip("Use value?string to force formatting to plain text.")
      .blame(exp);
  throw new NonStringException(null, desc);
}
origin: org.freemarker/freemarker-gae

private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env)
    throws NonStringException {
  if (formatResult instanceof String) { 
    return (String) formatResult;
  }
  
  assertFormatResultNotNull(formatResult);
  
  TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult;
  _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder(
      "Value was formatted to convert it to string, but the result was markup of ouput format ",
      new _DelayedJQuote(mo.getOutputFormat()), ".")
      .tip("Use value?string to force formatting to plain text.")
      .blame(exp);
  throw new NonStringException(null, desc);
}
origin: org.freemarker/freemarker-gae

static TemplateMarkupOutputModel concatMarkupOutputs(TemplateObject parent, TemplateMarkupOutputModel leftMO,
    TemplateMarkupOutputModel rightMO) throws TemplateException {
  MarkupOutputFormat leftOF = leftMO.getOutputFormat();
  MarkupOutputFormat rightOF = rightMO.getOutputFormat();
  if (rightOF != leftOF) {
    String rightPT;
    String leftPT;
    if ((rightPT = rightOF.getSourcePlainText(rightMO)) != null) {
      return leftOF.concat(leftMO, leftOF.fromPlainTextByEscaping(rightPT));
    } else if ((leftPT = leftOF.getSourcePlainText(leftMO)) != null) {
      return rightOF.concat(rightOF.fromPlainTextByEscaping(leftPT), rightMO);
    } else {
      Object[] message = { "Concatenation left hand operand is in ", new _DelayedToString(leftOF),
          " format, while the right hand operand is in ", new _DelayedToString(rightOF),
          ". Conversion to common format wasn't possible." };
      if (parent instanceof Expression) {
        throw new _MiscTemplateException((Expression) parent, message);
      } else {
        throw new _MiscTemplateException(message);
      }
    }
  } else {
    return leftOF.concat(leftMO, rightMO);
  }
}
freemarker.coreTemplateMarkupOutputModel

Javadoc

"markup output" template language data-type; stores markup (some kind of "rich text" / structured format, as opposed to plain text) that meant to be printed as template output. This type is related to the OutputFormatmechanism. Values of this kind are exempt from OutputFormat-based automatic escaping.

Each implementation of this type has a OutputFormat subclass pair, whose singleton instance is returned by #getOutputFormat(). See more about how markup output values work at OutputFormat.

Note that TemplateMarkupOutputModel-s are by design not treated like TemplateScalarModel-s, and so the implementations of this interface usually shouldn't implement TemplateScalarModel. (Because, operations applicable on plain strings, like converting to upper case, substringing, etc., can corrupt markup.) If the template author wants to pass in the "source" of the markup as string somewhere, he should use ?markup_string.

Most used methods

  • getOutputFormat
    Returns the singleton OutputFormat object that implements the operations for the "markup output" val

Popular in Java

  • Making http requests using okhttp
  • getSharedPreferences (Context)
  • getContentResolver (Context)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • PrintStream (java.io)
    A PrintStream adds functionality to another output stream, namely the ability to print representatio
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now