use of freemarker.core.CombinedMarkupOutputFormat in project freemarker by apache.
the class Configuration method getOutputFormat.
/**
* Returns the output format for a name.
*
* @param name
* Either the name of the output format as it was registered with
* {@link Configuration#setRegisteredCustomOutputFormats(Collection)}, or a combined output format name.
* A combined output format is created ad-hoc from the registered formats. For example, if you need RTF
* embedded into HTML, the name will be <code>HTML{RTF}</code>, where "HTML" and "RTF" refer to the
* existing formats. This logic can be used recursively, so for example <code>XML{HTML{RTF}}</code> is
* also valid.
*
* @return Not {@code null}.
*
* @throws UnregisteredOutputFormatException
* If there's no output format registered with the given name.
* @throws IllegalArgumentException
* If the usage of <code>{</code> and <code>}</code> in the name is syntactically wrong, or if not all
* {@link OutputFormat}-s are {@link MarkupOutputFormat}-s in the <code>...{...}</code> expression.
*
* @since 2.3.24
*/
public OutputFormat getOutputFormat(String name) throws UnregisteredOutputFormatException {
if (name.length() == 0) {
throw new IllegalArgumentException("0-length format name");
}
if (name.charAt(name.length() - 1) == '}') {
// Combined markup
int openBrcIdx = name.indexOf('{');
if (openBrcIdx == -1) {
throw new IllegalArgumentException("Missing opening '{' in: " + name);
}
MarkupOutputFormat outerOF = getMarkupOutputFormatForCombined(name.substring(0, openBrcIdx));
MarkupOutputFormat innerOF = getMarkupOutputFormatForCombined(name.substring(openBrcIdx + 1, name.length() - 1));
return new CombinedMarkupOutputFormat(name, outerOF, innerOF);
} else {
OutputFormat custOF = registeredCustomOutputFormats.get(name);
if (custOF != null) {
return custOF;
}
OutputFormat stdOF = STANDARD_OUTPUT_FORMATS.get(name);
if (stdOF == null) {
StringBuilder sb = new StringBuilder();
sb.append("Unregistered output format name, ");
sb.append(StringUtil.jQuote(name));
sb.append(". The output formats registered in the Configuration are: ");
Set<String> registeredNames = new TreeSet<String>();
registeredNames.addAll(STANDARD_OUTPUT_FORMATS.keySet());
registeredNames.addAll(registeredCustomOutputFormats.keySet());
boolean first = true;
for (String registeredName : registeredNames) {
if (first) {
first = false;
} else {
sb.append(", ");
}
sb.append(StringUtil.jQuote(registeredName));
}
throw new UnregisteredOutputFormatException(sb.toString());
}
return stdOF;
}
}
Aggregations