Package com.exedio.cope.pattern
Class Media
- java.lang.Object
-
- com.exedio.cope.Feature
-
- com.exedio.cope.Pattern
-
- com.exedio.cope.pattern.MediaPath
-
- com.exedio.cope.pattern.Media
-
- All Implemented Interfaces:
Copyable
,Settable<Media.Value>
,Serializable
public final class Media extends MediaPath implements Settable<Media.Value>, Copyable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Media.Value
-
Nested classes/interfaces inherited from class com.exedio.cope.pattern.MediaPath
MediaPath.Locator, MediaPath.Log, MediaPath.NotFound
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_LENGTH
-
Constructor Summary
Constructors Constructor Description Media()
Media(String fixedMimeMajor)
Deprecated.usecontentTypeSub(String)
instead.Media(String fixedMimeMajor, String fixedMimeMinor)
Deprecated.usecontentType(String)
instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Condition
bodyMismatchesContentType()
Deprecated.UsebodyMismatchesContentTypeIfSupported()
instead.Condition
bodyMismatchesContentTypeIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
.boolean
checkContentType(String contentType)
Media
contentType(String contentType)
Creates a new media, that must contain the given content type only.Media
contentType(String contentType1, String contentType2)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8, String contentType9)
Creates a new media, that must contain one of the given content types only.Media
contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8, String contentType9, String contentType10)
Creates a new media, that must contain one of the given content types only.Condition
contentTypeEqual(String contentType)
Media
contentTypeLengthMax(int maximumLength)
Media
contentTypeMajor(String majorContentType)
Deprecated.UsecontentTypeSub(String)
insteadMedia
contentTypeSub(String majorContentType)
Creates a new media, that must contain the a content type with the given major part only.Media
copy(CopyMapper mapper)
void
doGetAndCommit(HttpServletRequest request, HttpServletResponse response, Item item)
The implementor MUSTcommit
the transaction, if the method completes normally (without exception).SetValue<?>[]
execute(Media.Value value, Item exceptionItem)
static Media
get(DataField field)
DataField
getBody()
byte[]
getBody(Item item)
Returns the body of this media.void
getBody(Item item, File body)
Writes the body of this media into the given file.void
getBody(Item item, OutputStream body)
Writes the body of this media into the given steam.void
getBody(Item item, Path body)
FunctionField<?>
getContentType()
String
getContentType(Item item)
Returns the content type of this media.String
getContentTypeDescription()
int
getContentTypeMaximumLength()
List<String>
getContentTypesAllowed()
Returns a list of content types allowed for this media.Set<Class<? extends Throwable>>
getInitialExceptions()
Returns the exceptions possibly thrown, when setting a value for this settable.Class<?>
getInitialType()
DateField
getLastModified()
Date
getLastModified(Item item)
Returns the date of the last modification of this media.long
getLength(Item item)
Returns the length of the body of this media.long
getMaximumLength()
CheckConstraint
getUnison()
boolean
isAnnotatedVault()
boolean
isContentTypeWrapped()
boolean
isFinal()
Returns, whether the contents of this media path may change or not.boolean
isInitial()
Returns true, if a value for the settable should be specified on the creation of an item.boolean
isMandatory()
A MediaPath is "mandatory" ifMediaPath.getContentType(Item)
andMediaPath.getLocator(Item)
will not returnnull
for any item.Condition
isNotNull()
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
does not return null.Condition
isNotNull(Join join)
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
does not return null.Condition
isNull()
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
returns null.boolean
isNull(Item item)
Condition
isNull(Join join)
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
returns null.Media
lengthMax(long maximumLength)
Media
optional()
void
set(Item item, byte[] body, String contentType)
Sets the contents of this media.void
set(Item item, Media.Value value)
Sets the contents of this media.void
set(Item item, File body, String contentType)
Sets the contents of this media.void
set(Item item, InputStream body, String contentType)
Sets the contents of this media.void
set(Item item, Path body, String contentType)
void
setLastModified(Item item, Date value)
Media
toFinal()
static Media.Value
toValue(byte[] body, String contentType)
static Media.Value
toValue(DataField.Value body, String contentType)
static Media.Value
toValue(File body, String contentType)
static Media.Value
toValue(InputStream body, String contentType)
static Media.Value
toValue(Path body, String contentType)
-
Methods inherited from class com.exedio.cope.pattern.MediaPath
commit, getExceptionLogs, getGuessedUrlLogs, getInfo, getInvalidSpecialLogs, getIsNullLogs, getLocator, getNamedURL, getNoSuchItemLogs, getNoSuchPath, getNoSuchPathLogs, getNotAnItemLogs, getNotComputableLogs, getURL, incrementDelivered, isUrlFingerPrinted, isUrlGuessingPrevented, isUrlGuessingPreventedSecurely, notFoundIsNull, notFoundNotComputable, onMount
-
Methods inherited from class com.exedio.cope.Pattern
addSource, addSource, addSource, addSource, addSourceFeature, addSourceFeature, addSourceFeature, annotationField, equals, getGeneratedTypes, getSourceFeatures, getSourceFeaturesGather, getSourceFields, getSources, getSourceTypes, getType, hashCode, initialize, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newType, newType, registerSource
-
Methods inherited from class com.exedio.cope.Feature
afterModelCreated, getAbstractType, getAnnotation, getID, getLocalizationKeys, getName, getPattern, isAnnotationPresent, isSourceAlready, mount, readResolve, requireMounted, toString, toString, writeReplace
-
-
-
-
Field Detail
-
DEFAULT_LENGTH
public static final long DEFAULT_LENGTH
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Media
public Media()
-
Media
@Deprecated public Media(String fixedMimeMajor, String fixedMimeMinor)
Deprecated.usecontentType(String)
instead.
-
Media
@Deprecated public Media(String fixedMimeMajor)
Deprecated.usecontentTypeSub(String)
instead.
-
-
Method Detail
-
copy
public Media copy(CopyMapper mapper)
-
toFinal
public Media toFinal()
-
optional
public Media optional()
-
lengthMax
public Media lengthMax(long maximumLength)
-
contentType
public Media contentType(String contentType)
Creates a new media, that must contain the given content type only.
-
contentType
public Media contentType(String contentType1, String contentType2)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8, String contentType9)
Creates a new media, that must contain one of the given content types only.
-
contentType
public Media contentType(String contentType1, String contentType2, String contentType3, String contentType4, String contentType5, String contentType6, String contentType7, String contentType8, String contentType9, String contentType10)
Creates a new media, that must contain one of the given content types only.
-
contentTypeSub
public Media contentTypeSub(String majorContentType)
Creates a new media, that must contain the a content type with the given major part only.
-
contentTypeLengthMax
public Media contentTypeLengthMax(int maximumLength)
-
isFinal
public boolean isFinal()
Description copied from class:MediaPath
Returns, whether the contents of this media path may change or not. The default implementation returns false.- Specified by:
isFinal
in interfaceSettable<Media.Value>
- Overrides:
isFinal
in classMediaPath
-
isMandatory
public boolean isMandatory()
Description copied from class:MediaPath
A MediaPath is "mandatory" ifMediaPath.getContentType(Item)
andMediaPath.getLocator(Item)
will not returnnull
for any item.- Specified by:
isMandatory
in interfaceSettable<Media.Value>
- Specified by:
isMandatory
in classMediaPath
-
getInitialType
public Class<?> getInitialType()
- Specified by:
getInitialType
in interfaceSettable<Media.Value>
-
checkContentType
public boolean checkContentType(String contentType)
-
getContentTypeMaximumLength
public int getContentTypeMaximumLength()
-
getContentTypeDescription
public String getContentTypeDescription()
-
getContentTypesAllowed
public List<String> getContentTypesAllowed()
Returns a list of content types allowed for this media. Returns null, if such a list would not contain a finite number of elements.
-
getMaximumLength
public long getMaximumLength()
-
getBody
public DataField getBody()
-
getContentType
public FunctionField<?> getContentType()
-
getLastModified
public DateField getLastModified()
-
getUnison
public CheckConstraint getUnison()
-
isAnnotatedVault
public boolean isAnnotatedVault()
-
getInitialExceptions
public Set<Class<? extends Throwable>> getInitialExceptions()
Description copied from interface:Settable
Returns the exceptions possibly thrown, when setting a value for this settable.- Specified by:
getInitialExceptions
in interfaceSettable<Media.Value>
-
isContentTypeWrapped
public boolean isContentTypeWrapped()
- Overrides:
isContentTypeWrapped
in classMediaPath
-
isInitial
public boolean isInitial()
Description copied from interface:Settable
Returns true, if a value for the settable should be specified on the creation of an item.- Specified by:
isInitial
in interfaceSettable<Media.Value>
-
getContentType
public String getContentType(Item item)
Returns the content type of this media. Returns null, if this media is null.- Specified by:
getContentType
in classMediaPath
-
getLastModified
public Date getLastModified(@Nonnull Item item)
Returns the date of the last modification of this media. Returns null, if this media is null.- Overrides:
getLastModified
in classMediaPath
- Parameters:
item
- the item which has the LastModified information
-
getLength
public long getLength(@Nonnull Item item)
Returns the length of the body of this media. Returns -1, if this media is null.
-
set
public void set(@Nonnull Item item, Media.Value value) throws IOException
Sets the contents of this media.- Parameters:
value
- give null to make this media null.- Throws:
MandatoryViolationException
- if body is null and field ismandatory
.DataLengthViolationException
- if body is longer thangetMaximumLength()
IOException
- if reading value throws an IOException.
-
getBody
public byte[] getBody(@Nonnull Item item)
Returns the body of this media. Returns null, if this media is null.
-
set
public void set(@Nonnull Item item, byte[] body, String contentType)
Sets the contents of this media.- Parameters:
body
- give null to make this media null.- Throws:
MandatoryViolationException
- if body is null and field ismandatory
.DataLengthViolationException
- if body is longer thangetMaximumLength()
-
getBody
public void getBody(@Nonnull Item item, @Nonnull OutputStream body) throws IOException
Writes the body of this media into the given steam. Does nothing, if this media is null.- Throws:
NullPointerException
- ifbody
is null.IOException
- if writingbody
throws an IOException.
-
set
public void set(@Nonnull Item item, InputStream body, String contentType) throws IOException
Sets the contents of this media. Closesbody
after reading the contents of the stream.- Parameters:
body
- give null to make this media null.- Throws:
MandatoryViolationException
- ifbody
is null and field ismandatory
.DataLengthViolationException
- ifbody
is longer thangetMaximumLength()
IOException
- if readingbody
throws an IOException.
-
getBody
public void getBody(@Nonnull Item item, @Nonnull Path body) throws IOException
- Throws:
IOException
-
getBody
public void getBody(@Nonnull Item item, @Nonnull File body) throws IOException
Writes the body of this media into the given file. Does nothing, if this media is null.- Throws:
NullPointerException
- ifbody
is null.IOException
- if writingbody
throws an IOException.
-
set
public void set(@Nonnull Item item, Path body, String contentType) throws IOException
- Throws:
IOException
-
set
public void set(@Nonnull Item item, File body, String contentType) throws IOException
Sets the contents of this media.- Parameters:
body
- give null to make this media null.- Throws:
MandatoryViolationException
- ifbody
is null and field ismandatory
.DataLengthViolationException
- ifbody
is longer thangetMaximumLength()
IOException
- if readingbody
throws an IOException.
-
toValue
public static Media.Value toValue(DataField.Value body, String contentType)
-
toValue
public static Media.Value toValue(byte[] body, String contentType)
-
toValue
public static Media.Value toValue(InputStream body, String contentType)
-
toValue
public static Media.Value toValue(Path body, String contentType)
-
toValue
public static Media.Value toValue(File body, String contentType)
-
execute
public SetValue<?>[] execute(Media.Value value, Item exceptionItem)
- Specified by:
execute
in interfaceSettable<Media.Value>
-
doGetAndCommit
public void doGetAndCommit(HttpServletRequest request, HttpServletResponse response, Item item) throws IOException, MediaPath.NotFound
Description copied from class:MediaPath
The implementor MUSTcommit
the transaction, if the method completes normally (without exception). Otherwise the implementor may or may not commit the transaction.- Specified by:
doGetAndCommit
in classMediaPath
- Throws:
IOException
MediaPath.NotFound
-
isNull
public Condition isNull()
Description copied from class:MediaPath
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
returns null.
-
isNull
public Condition isNull(Join join)
Description copied from class:MediaPath
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
returns null.
-
isNotNull
public Condition isNotNull()
Description copied from class:MediaPath
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
does not return null.
-
isNotNull
public Condition isNotNull(Join join)
Description copied from class:MediaPath
Returns a condition matching all items, for whichMediaPath.getLocator(Item)
does not return null.
-
bodyMismatchesContentTypeIfSupported
public Condition bodyMismatchesContentTypeIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
.
-
bodyMismatchesContentType
@Deprecated public Condition bodyMismatchesContentType()
Deprecated.UsebodyMismatchesContentTypeIfSupported()
instead.
-
contentTypeMajor
@Deprecated public Media contentTypeMajor(String majorContentType)
Deprecated.UsecontentTypeSub(String)
instead
-
-