@Provider public class TemplateEncoder extends Encoder implements javax.ws.rs.ext.MessageBodyWriter<java.lang.Object>
The HTML encoder.
It is used to convert the content of the resource, i.e., the Java object, into HTML format representation.
Note: When generating the HTML format representation, the HTML template file, i.e., the *ftl file needs to be specified.The template specifies the information about the page layout, page elements, etc. The representation varies for different templates.
Below shows how to generate the HTML format representation for the sampleResource resource. The template file is sample.ftl.
Object content = sampleResource.getResourceContent(); TemplateEncoder encoder = new TemplateEncoder(); encoder.setTemplateName("sample.ftl"); Representation entity = templateEncoder.toRepresentation(MediaType.TEXT_HTML, content);
Constructor and Description |
---|
TemplateEncoder()
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByDefault_Title}
|
TemplateEncoder(ServletConfig servletConfig, HttpServletRequest servletRequest)
The constructor.
|
TemplateEncoder(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_Title}
|
Modifier and Type | Method and Description |
---|---|
protected java.util.List<Language> |
createSupportedLanguages()
${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_Title}
|
protected java.util.List<MediaType> |
createSupportedMediaTypes()
${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_Title}
|
protected ResourceConfigList |
getAllConfigs()
Gets the resource configuration list in the context.
|
protected java.lang.String |
getApplicationRootPath()
Gets the root directory of the REST application.
|
protected static Configuration |
getConfiguration(java.lang.String character)
Gets Freemarker collocation method and adds the character set parameter of browser.
|
protected static LocLogger |
getLocLogger()
Gets the local logger.
|
protected ResourceManager |
getMessageManager()
Gets the message manager.
|
protected java.util.List<ChildResourceInfo> |
getParentResourceInfos(java.lang.String rootPath, java.lang.String requestURL, java.lang.Class resourceClz)
Gets the mapping between names and addresses of all parent resources of the current request resource.
|
static java.lang.String |
getProductType()
Gets the product type.
|
protected Representation |
getRepresentation(MediaType mediaType, java.lang.Object content, java.lang.String templateName) |
protected java.lang.String |
getServletID()
Gets the Servlet name.
|
long |
getSize(java.lang.Object arg0, java.lang.Class arg1, java.lang.reflect.Type arg2, java.lang.annotation.Annotation[] arg3, javax.ws.rs.core.MediaType arg4)
Determines the length of the object to be written after serialization.
|
java.lang.String |
getTemplateName()
${services_rest_encoders_TemplateEncoder_method_getTemplateName_Title}
|
boolean |
isWriteable(java.lang.Class arg0, java.lang.reflect.Type arg1, java.lang.annotation.Annotation[] arg2, javax.ws.rs.core.MediaType arg3)
Determines whether the encoder supports the representation of the specified media type.
|
void |
setExpectedLanguage(java.lang.String expectedLanguage)
Sets the expected language type.
|
void |
setExtendedUriInfo(ExtendedUriInfo value) |
void |
setTemplateName(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_method_setTemplateName_Title}
|
protected java.util.List<MediaType> |
supportedMediaTypes(java.lang.String... mediaTypeNames)
The list of supported media types.
|
Representation |
toRepresentation(MediaType mediaType, java.lang.Object content)
${services_rest_encoders_TemplateEncoder_method_toRepresentation_Title}
|
void |
writeTo(java.lang.Object arg0, java.lang.Class arg1, java.lang.reflect.Type arg2, java.lang.annotation.Annotation[] arg3, javax.ws.rs.core.MediaType arg4, javax.ws.rs.core.MultivaluedMap arg5, java.io.OutputStream arg6)
Generates the HTTP response of the specified media type.
|
getSupportedMediaTypes, isEncodeAllow
public TemplateEncoder()
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByDefault_Title}
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByDefault_Description}
public TemplateEncoder(@Context ServletConfig servletConfig, @Context HttpServletRequest servletRequest)
The constructor.
servletConfig
- The Servlet config info.servletRequest
- The request supported by Servlet.public TemplateEncoder(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_Title}
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_Description}
templateName
- ${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_param_templateName}public java.lang.String getTemplateName()
${services_rest_encoders_TemplateEncoder_method_getTemplateName_Title}
${services_rest_encoders_TemplateEncoder_method_getTemplateName_Description}
@Context public void setExtendedUriInfo(ExtendedUriInfo value)
public void setTemplateName(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_method_setTemplateName_Title}
${services_rest_encoders_TemplateEncoder_method_setTemplateName_Description}
templateName
- ${services_rest_encoders_TemplateEncoder_method_setTemplateName_param_templateName}public Representation toRepresentation(MediaType mediaType, java.lang.Object content)
${services_rest_encoders_TemplateEncoder_method_toRepresentation_Title}
${services_rest_encoders_TemplateEncoder_method_toRepresentation_Description}
toRepresentation
in class Encoder
mediaType
- ${services_rest_encoders_TemplateEncoder_method_toRepresentation_param_mediaType}content
- ${services_rest_encoders_TemplateEncoder_method_toRepresentation_param_content}protected Representation getRepresentation(MediaType mediaType, java.lang.Object content, java.lang.String templateName)
protected static Configuration getConfiguration(java.lang.String character)
Gets Freemarker collocation method and adds the character set parameter of browser.
protected java.util.List<Language> createSupportedLanguages()
${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_Title}
${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_Description}
protected java.util.List<MediaType> createSupportedMediaTypes()
${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_Title}
${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_Description}
createSupportedMediaTypes
in class Encoder
public long getSize(java.lang.Object arg0, java.lang.Class arg1, java.lang.reflect.Type arg2, java.lang.annotation.Annotation[] arg3, javax.ws.rs.core.MediaType arg4)
Determines the length of the object to be written after serialization. It is called before the HTTP response.
getSize
in interface javax.ws.rs.ext.MessageBodyWriter<java.lang.Object>
arg0
- The object to generate representation.arg1
- The corresponding Java class of the object to generate representation.arg2
- The type of the object to generate representation.arg3
- The annotation array. Methods of the resource contain these annotations return the object to be written.arg4
- The media type of the HTTP request body.public boolean isWriteable(java.lang.Class arg0, java.lang.reflect.Type arg1, java.lang.annotation.Annotation[] arg2, javax.ws.rs.core.MediaType arg3)
Determines whether the encoder supports the representation of the specified media type.
isWriteable
in interface javax.ws.rs.ext.MessageBodyWriter<java.lang.Object>
arg0
- The object to generate representation.arg1
- The specified media type.arg2
- The annotation array. Methods of the resource contain these annotations return the object to be written.arg3
- The media type of the expected response.public void writeTo(java.lang.Object arg0, java.lang.Class arg1, java.lang.reflect.Type arg2, java.lang.annotation.Annotation[] arg3, javax.ws.rs.core.MediaType arg4, javax.ws.rs.core.MultivaluedMap arg5, java.io.OutputStream arg6) throws java.io.IOException, javax.ws.rs.WebApplicationException
Generates the HTTP response of the specified media type.
writeTo
in interface javax.ws.rs.ext.MessageBodyWriter<java.lang.Object>
arg0
- The object to generate representation.arg1
- The corresponding Java class of the object to generate representation.arg2
- The type of the object to generate representation.arg3
- The annotation array. Methods of the resource contain these annotations return the object to be written.arg4
- The media type of the HTTP response.arg5
- The header of the HTTP response.arg6
- The HTTP response.java.io.IOException
- When errors occur during reading and writing.javax.ws.rs.WebApplicationException
- When errors occur to the HTTP response.protected java.util.List<ChildResourceInfo> getParentResourceInfos(java.lang.String rootPath, java.lang.String requestURL, java.lang.Class resourceClz)
Gets the mapping between names and addresses of all parent resources of the current request resource.
rootPath
- The root directory of the resource of the REST application.requestURL
- The request URI.resourceClz
- The implementation class of the request resource.protected ResourceConfigList getAllConfigs()
Gets the resource configuration list in the context.
protected java.lang.String getServletID()
Gets the Servlet name.
protected java.lang.String getApplicationRootPath()
Gets the root directory of the REST application.
protected static LocLogger getLocLogger()
Gets the local logger.
protected ResourceManager getMessageManager()
Gets the message manager.
public void setExpectedLanguage(java.lang.String expectedLanguage)
Sets the expected language type.
expectedLanguage
-protected java.util.List<MediaType> supportedMediaTypes(java.lang.String... mediaTypeNames)
The list of supported media types.
mediaTypeNames
- The media type name.public static java.lang.String getProductType()