Class TemplateEncoder
- java.lang.Object
-
- com.supermap.services.rest.encoders.Encoder
-
- com.supermap.services.rest.encoders.TemplateEncoder
-
- All Implemented Interfaces:
- javax.ws.rs.ext.MessageBodyWriter<java.lang.Object>
- Direct Known Subclasses:
- AjaxEncoder, Flash3DEncoder, FlexEncoder, LeafletEncoder, OpenLayersEncoder, SceneRealspaceEncoder, SilverLightEncoder, SuperMapCloudEncoder, TianDiTuEncoder, VectorTileEncoder
@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 Summary
Constructors 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}
-
Method Summary
Methods 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 ResourceConfigListgetAllConfigs()Gets the resource configuration list in the context.protected java.lang.StringgetApplicationRootPath()Gets the root directory of the REST application.protected static ConfigurationgetConfiguration(java.lang.String character)Gets Freemarker collocation method and adds the character set parameter of browser.protected static LocLoggergetLocLogger()Gets the local logger.protected ResourceManagergetMessageManager()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.StringgetProductType()Gets the product type.protected RepresentationgetRepresentation(MediaType mediaType, java.lang.Object content, java.lang.String templateName)protected java.lang.StringgetServletID()Gets the Servlet name.longgetSize(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.StringgetTemplateName()${services_rest_encoders_TemplateEncoder_method_getTemplateName_Title}booleanisWriteable(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.voidsetExpectedLanguage(java.lang.String expectedLanguage)Sets the expected language type.voidsetExtendedUriInfo(ExtendedUriInfo value)voidsetTemplateName(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.RepresentationtoRepresentation(MediaType mediaType, java.lang.Object content)${services_rest_encoders_TemplateEncoder_method_toRepresentation_Title}voidwriteTo(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.-
Methods inherited from class com.supermap.services.rest.encoders.Encoder
getSupportedMediaTypes, isEncodeAllow
-
-
-
-
Constructor Detail
-
TemplateEncoder
public TemplateEncoder()
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByDefault_Title}
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByDefault_Description}
-
TemplateEncoder
public TemplateEncoder(@Context ServletConfig servletConfig, @Context HttpServletRequest servletRequest)The constructor.
- Parameters:
servletConfig- The Servlet config info.servletRequest- The request supported by Servlet.
-
TemplateEncoder
public TemplateEncoder(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_Title}
${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_Description}
- Parameters:
templateName- ${services_rest_encoders_TemplateEncoder_constructor_TemplateEncoderByName_param_templateName}
-
-
Method Detail
-
getTemplateName
public java.lang.String getTemplateName()
${services_rest_encoders_TemplateEncoder_method_getTemplateName_Title}
${services_rest_encoders_TemplateEncoder_method_getTemplateName_Description}
- Returns:
- ${services_rest_encoders_TemplateEncoder_method_getTemplateName_return}
-
setExtendedUriInfo
@Context public void setExtendedUriInfo(ExtendedUriInfo value)
-
setTemplateName
public void setTemplateName(java.lang.String templateName)
${services_rest_encoders_TemplateEncoder_method_setTemplateName_Title}
${services_rest_encoders_TemplateEncoder_method_setTemplateName_Description}
- Parameters:
templateName- ${services_rest_encoders_TemplateEncoder_method_setTemplateName_param_templateName}
-
toRepresentation
public Representation toRepresentation(MediaType mediaType, java.lang.Object content)${services_rest_encoders_TemplateEncoder_method_toRepresentation_Title}
${services_rest_encoders_TemplateEncoder_method_toRepresentation_Description}
- Specified by:
toRepresentationin classEncoder- Parameters:
mediaType- ${services_rest_encoders_TemplateEncoder_method_toRepresentation_param_mediaType}content- ${services_rest_encoders_TemplateEncoder_method_toRepresentation_param_content}- Returns:
- ${services_rest_encoders_TemplateEncoder_method_toRepresentation_return}
-
getRepresentation
protected Representation getRepresentation(MediaType mediaType, java.lang.Object content, java.lang.String templateName)
-
getConfiguration
protected static Configuration getConfiguration(java.lang.String character)
Gets Freemarker collocation method and adds the character set parameter of browser.
- Returns:
- Freemarker config info.
-
createSupportedLanguages
protected java.util.List<Language> createSupportedLanguages()
${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_Title}
${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_Description}
- Returns:
- ${services_rest_encoders_TemplateEncoder_method_createSupportedLanguages_return}
-
createSupportedMediaTypes
protected java.util.List<MediaType> createSupportedMediaTypes()
${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_Title}
${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_Description}
- Specified by:
createSupportedMediaTypesin classEncoder- Returns:
- ${services_rest_encoders_TemplateEncoder_method_createSupportedMediaTypes_return}
-
getSize
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.
- Specified by:
getSizein interfacejavax.ws.rs.ext.MessageBodyWriter<java.lang.Object>- Parameters:
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.- Returns:
- the length of the object to be written.
-
isWriteable
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.
- Specified by:
isWriteablein interfacejavax.ws.rs.ext.MessageBodyWriter<java.lang.Object>- Parameters:
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.- Returns:
- true if the encoder supports the representation of the specified media type, or false otherwise.
-
writeTo
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.WebApplicationExceptionGenerates the HTTP response of the specified media type.
- Specified by:
writeToin interfacejavax.ws.rs.ext.MessageBodyWriter<java.lang.Object>- Parameters:
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.- Throws:
java.io.IOException- When errors occur during reading and writing.javax.ws.rs.WebApplicationException- When errors occur to the HTTP response.
-
getParentResourceInfos
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.
- Parameters:
rootPath- The root directory of the resource of the REST application.requestURL- The request URI.resourceClz- The implementation class of the request resource.- Returns:
- The list of all parent resources of the current request resource.
-
getAllConfigs
protected ResourceConfigList getAllConfigs()
Gets the resource configuration list in the context.
- Returns:
- The ResourceConfigList to be added.
-
getServletID
protected java.lang.String getServletID()
Gets the Servlet name.
- Returns:
- Servlet name.
-
getApplicationRootPath
protected java.lang.String getApplicationRootPath()
Gets the root directory of the REST application.
- Returns:
- The root directory of the REST application.
-
getLocLogger
protected static LocLogger getLocLogger()
Gets the local logger.
- Returns:
- The local logger.
-
getMessageManager
protected ResourceManager getMessageManager()
Gets the message manager.
- Returns:
-
setExpectedLanguage
public void setExpectedLanguage(java.lang.String expectedLanguage)
Sets the expected language type.
- Parameters:
expectedLanguage-
-
supportedMediaTypes
protected java.util.List<MediaType> supportedMediaTypes(java.lang.String... mediaTypeNames)
The list of supported media types.
- Parameters:
mediaTypeNames- The media type name.- Returns:
- The media type list.
-
getProductType
public static java.lang.String getProductType()
Gets the product type.- Returns:
- iServer, iPortal or iExpress
-
-