public class ConfigurableFilenamePolicy extends Object implements IFilenamePolicy
IFilenamePolicy
that is user-customizable by providing a pattern
string.
A pattern string is a string containing patterns enclosed in curly
braces. Each pattern starts with a variable and is optionally
followed by one or more options, each introduced by a vertical bar (
|
). Please note that all whitespace is significant.
{author|fallback|20}-{title|sep=,}.{uri}.{ext}
contains the
variables author with the options fallback
and
20
, the variable title with the option
sep=,
, and the variables uri and ext, each
without any option.
Variable | Supported Options | Description |
---|---|---|
author | fallback , sep= String,
Number, raw |
The object's author. This tries to find the nearest work object in the
aggregation tree and extracts its author or authors.
If the |
title | sep= String, Number, raw |
The object's title or titles. |
uri | — | The object's TextGrid URI. This only includes the scheme-specific part. |
ext | — | A filename extension that is suitable for the object's MIME type, or
dat if none found. This does not include a leading dot.
|
Number | If you pass any non-negative non-zero integer number as an option, the expanded value of the variable will be trimmed after at most Number characters. Trimming occurs after all other processing steps for the variable. |
raw |
Insert the result of this variable as-is, without character sanitization.
If you do not include this option, the result of the metadata-based variables will be transcribed from its original characters to a safe subset of US-ASCII characters in order to be safe from all kinds of encoding and filename issues. This tries to do something sensible with, e.g., umlauts and non-latin scripts. |
sep= String |
If present and the respective metadata field contains multiple values, use all values, joined together with the given separator String. Otherwise, only use the first value. |
fallback |
See at the corresponding variable descriptions. |
Modifier and Type | Class and Description |
---|---|
class |
ConfigurableFilenamePolicy.AuthorSegment |
class |
ConfigurableFilenamePolicy.ExtensionSegment |
class |
ConfigurableFilenamePolicy.ListSegment
Extracts the title.
|
protected class |
ConfigurableFilenamePolicy.MetadataSegment
Base class for segments that extract metadata from the given argument.
|
protected static interface |
ConfigurableFilenamePolicy.Segment
A segment represents a part of a filename pattern.
|
protected class |
ConfigurableFilenamePolicy.StaticSegment
A segment that always expands to a static string, regardless of the entry
|
class |
ConfigurableFilenamePolicy.SubPolicySegment |
class |
ConfigurableFilenamePolicy.TitleSegment |
class |
ConfigurableFilenamePolicy.URISegment
Formats an object's TextGrid URI.
|
Constructor and Description |
---|
ConfigurableFilenamePolicy(String pattern) |
ConfigurableFilenamePolicy(String pattern,
boolean isParentPolicy) |
Modifier and Type | Method and Description |
---|---|
ConfigurableFilenamePolicy |
addSubPolicy(String name,
ConfigurableFilenamePolicy policy)
Adds a sub policy to this policy.
|
com.google.common.base.Optional<URI> |
getBase(IAggregationEntry entry)
Tries to generate a base URI for the given aggregation entry.
|
URI |
getFilename(IAggregationEntry entry)
Generates a file name for the aggregation entry described by the given
metadata.
|
URI |
getFilename(IAggregationEntry entry,
boolean asParent)
Deprecated.
Use
getFilename(IAggregationEntry) instead |
String |
getFilename(info.textgrid.namespaces.metadata.core._2010.ObjectType object,
boolean asParent)
Generates a file name candidate for the object described by the given
metadata.
|
String |
translate(String source)
Creates a valid file name part for the given string.
|
public ConfigurableFilenamePolicy(String pattern)
public ConfigurableFilenamePolicy(String pattern, boolean isParentPolicy)
public ConfigurableFilenamePolicy addSubPolicy(String name, ConfigurableFilenamePolicy policy)
name
- policy
- public String translate(String source)
IFilenamePolicy
translate
in interface IFilenamePolicy
source
- The string that should be translatedpublic String getFilename(info.textgrid.namespaces.metadata.core._2010.ObjectType object, boolean asParent)
IFilenamePolicy
getFilename
in interface IFilenamePolicy
object
- The object with the metadata for which to generate a filenameasParent
- If true, the generated file name should be the parent for a
different filename. Implementors might, e.g., want to leave
out an extension.@Deprecated public URI getFilename(IAggregationEntry entry, boolean asParent)
getFilename(IAggregationEntry)
insteadIFilenamePolicy
getFilename
in interface IFilenamePolicy
IFilenamePolicy.getFilename(ObjectType, boolean)
public URI getFilename(IAggregationEntry entry)
IFilenamePolicy
getFilename
in interface IFilenamePolicy
IFilenamePolicy.getFilename(ObjectType, boolean)
public com.google.common.base.Optional<URI> getBase(IAggregationEntry entry)
IFilenamePolicy
getBase
in interface IFilenamePolicy
Copyright © 2014 TextGrid. All Rights Reserved.