use of freemarker.core.PlainTextOutputFormat in project freemarker by apache.
the class Configuration method setRegisteredCustomOutputFormats.
/**
* Sets the custom output formats that can be referred by their unique name ({@link OutputFormat#getName()}) from
* templates. Names are also used to look up the {@link OutputFormat} for standard file extensions; see them at
* {@link #setRecognizeStandardFileExtensions(boolean)}.
*
* <p>
* When there's a clash between a custom output format name and a standard output format name, the custom format
* will win, thus you can override the meaning of standard output format names. Except, it's not allowed to override
* {@link UndefinedOutputFormat} and {@link PlainTextOutputFormat}.
*
* <p>
* The default value is an empty collection.
*
* @param registeredCustomOutputFormats
* The collection of the {@link OutputFormat}-s, each must be different and has a unique name (
* {@link OutputFormat#getName()}) within this collection.
*
* @throws IllegalArgumentException
* When multiple different {@link OutputFormat}-s have the same name in the parameter collection. When
* the same {@link OutputFormat} object occurs for multiple times in the collection. If an
* {@link OutputFormat} name is 0 long. If an {@link OutputFormat} name doesn't start with letter or
* digit. If an {@link OutputFormat} name contains {@code '+'} or <code>'{'</code> or <code>'}'</code>.
* If an {@link OutputFormat} name equals to {@link UndefinedOutputFormat#getName()} or
* {@link PlainTextOutputFormat#getName()}.
*
* @since 2.3.24
*/
public void setRegisteredCustomOutputFormats(Collection<? extends OutputFormat> registeredCustomOutputFormats) {
NullArgumentException.check(registeredCustomOutputFormats);
Map<String, OutputFormat> m = new LinkedHashMap<String, OutputFormat>(registeredCustomOutputFormats.size() * 4 / 3, 1f);
for (OutputFormat outputFormat : registeredCustomOutputFormats) {
String name = outputFormat.getName();
if (name.equals(UndefinedOutputFormat.INSTANCE.getName())) {
throw new IllegalArgumentException("The \"" + name + "\" output format can't be redefined");
}
if (name.equals(PlainTextOutputFormat.INSTANCE.getName())) {
throw new IllegalArgumentException("The \"" + name + "\" output format can't be redefined");
}
if (name.length() == 0) {
throw new IllegalArgumentException("The output format name can't be 0 long");
}
if (!Character.isLetterOrDigit(name.charAt(0))) {
throw new IllegalArgumentException("The output format name must start with letter or digit: " + name);
}
if (name.indexOf('+') != -1) {
throw new IllegalArgumentException("The output format name can't contain \"+\" character: " + name);
}
if (name.indexOf('{') != -1) {
throw new IllegalArgumentException("The output format name can't contain \"{\" character: " + name);
}
if (name.indexOf('}') != -1) {
throw new IllegalArgumentException("The output format name can't contain \"}\" character: " + name);
}
OutputFormat replaced = m.put(outputFormat.getName(), outputFormat);
if (replaced != null) {
if (replaced == outputFormat) {
throw new IllegalArgumentException("Duplicate output format in the collection: " + outputFormat);
}
throw new IllegalArgumentException("Clashing output format names between " + replaced + " and " + outputFormat + ".");
}
}
this.registeredCustomOutputFormats = Collections.unmodifiableMap(m);
clearTemplateCache();
}
Aggregations