- All Implemented Interfaces:
ValidMediaFilter,ValidMediaInput,ValidMediaOutput,Encoder
- Direct Known Subclasses:
BufferedEncoder,JavaScriptInXhtmlAttributeEncoder,JavaScriptInXhtmlEncoder,StyleInXhtmlAttributeEncoder,StyleInXhtmlEncoder,TextInJavaScriptEncoder,TextInMysqlEncoder,TextInPsqlEncoder,TextInShEncoder,TextInStyleEncoder,TextInXhtmlAttributeEncoder,TextInXhtmlEncoder,ValidateOnlyEncoder
Each encoder both validates its input characters and produces valid output characters.
- Author:
- AO Industries, Inc.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract MediaEncoderappend(char c, Appendable out) abstract MediaEncoderappend(CharSequence csq, int start, int end, Appendable out) abstract MediaEncoderappend(CharSequence csq, Appendable out) static MediaEncodergetInstance(EncodingContext encodingContext, MediaType contentType, MediaType containerType) Gets the media encoder for the requested types ornullif no encoding is necessary.abstract voidabstract voidabstract voidabstract voidabstract voidvoidwritePrefixTo(Appendable out) final voidwriteSuffixTo(Appendable out) Deprecated.voidwriteSuffixTo(Appendable out, boolean trim) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.aoapps.lang.io.Encoder
isBufferedMethods inherited from interface com.aoapps.encoding.ValidMediaInput
canSkipValidation, getValidMediaInputType, isValidatingMediaInputTypeMethods inherited from interface com.aoapps.encoding.ValidMediaOutput
getValidMediaOutputType
-
Constructor Details
-
MediaEncoder
protected MediaEncoder()
-
-
Method Details
-
getInstance
public static MediaEncoder getInstance(EncodingContext encodingContext, MediaType contentType, MediaType containerType) throws UnsupportedEncodingException Gets the media encoder for the requested types ornullif no encoding is necessary. When an encoder is returned it is also a validator for the contentType and produces valid output for the containerType.An encoder is not needed when no prefix or suffix is needed, all valid
contentTypecharacters are also valid incontainerType, and with the same representation. Furthermore, there must be some meaningful relationship betweencontentTypeandcontainerType- simply having compatible characters alone is insufficient.When no encoder is returned, it is necessary to use a separate validator if character validation is required.
Media encoder implementations are extremely light weight. Although they can be reused after calling
writeSuffixTo(java.lang.Appendable, boolean), there is likely no benefit in caching or reusing instances. The only possible exception would be anyBufferedEncoder, which currently is only the encoders forMediaType.URL; however, since URLs are generally fairly short, the reuse of underlying buffers would be of marginal benefit.Please note that most types can be encoded both to and from
MediaType.TEXT. Thus, when a specialized encoder is not available (as indicated by throwingUnsupportedEncodingException), it may be possible to use an intermediate TEXT to connect between types, such as CSS -> TEXT -> XHTML will just display the raw CSS directly.No automatic intermediate TEXT conversion is done, because the addition of new encoders could suddenly change the semantics.
Note: The supported encoders precisely matches the specialized subclasses of
MediaWriterthat implement per-type interfaces.- Parameters:
encodingContext- Required encoding context- Returns:
- the encoder or
nullif no encoding is necessary. If an encoder is still needed for API requirements (such as required forMediaWriter), can useValidateOnlyEncoder. - Throws:
UnsupportedEncodingException- when unable to encode the content into the container either because it is impossible or not yet implemented.
-
writePrefixTo
This default implementation validates media types in assertion but writes nothing.
- Specified by:
writePrefixToin interfaceEncoder- Throws:
IOException
-
write
- Specified by:
writein interfaceEncoder- Throws:
IOException
-
write
- Specified by:
writein interfaceEncoder- Throws:
IOException
-
write
- Specified by:
writein interfaceEncoder- Throws:
IOException
-
write
- Specified by:
writein interfaceEncoder- Throws:
IOException
-
write
- Specified by:
writein interfaceEncoder- Throws:
IOException
-
append
- Specified by:
appendin interfaceEncoder- Throws:
IOException
-
append
- Specified by:
appendin interfaceEncoder- Throws:
IOException
-
append
public abstract MediaEncoder append(CharSequence csq, int start, int end, Appendable out) throws IOException - Specified by:
appendin interfaceEncoder- Throws:
IOException
-
writeSuffixTo
Deprecated.Please usewriteSuffixTo(java.lang.Appendable, boolean)while specifying desired trim.This default implementation calls
writeSuffixTo(java.lang.Appendable, boolean)without trimming.- Specified by:
writeSuffixToin interfaceEncoder- Throws:
IOException
-
writeSuffixTo
This default implementation validates media types in assertion but writes nothing.
- Specified by:
writeSuffixToin interfaceEncoder- Throws:
IOException
-

writeSuffixTo(java.lang.Appendable, boolean)while specifying desired trim.