public class EntityEncodingManager extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
BATCH_PREFIX |
static String |
COLLECTION |
protected static String |
DATA_KEY |
static String |
ENTITY_ID |
static String |
ENTITY_PREFIX |
static String |
ENTITY_REFERENCE |
static String |
ENTITY_TITLE |
static String |
ENTITY_URL |
static String[] |
HANDLED_INPUT_FORMATS |
static String[] |
HANDLED_OUTPUT_FORMATS |
static String |
JSON_CALLBACK_PARAM |
static String |
JSON_DEFAULT_CALLBACK |
protected static String |
XHTML_FOOTER |
protected static String |
XHTML_HEADER |
protected static String |
XML_HEADER |
protected static String |
XML_HEADER_PREFIX |
protected static String |
XML_HEADER_SUFFIX |
| Modifier | Constructor and Description |
|---|---|
protected |
EntityEncodingManager() |
|
EntityEncodingManager(EntityProviderManager entityProviderManager,
EntityBrokerManager entityBrokerManager) |
| Modifier and Type | Method and Description |
|---|---|
Map<String,Object> |
decodeData(String data,
String format)
Decode a string of a specified format into a java map
Returned map can be fed into the ReflectUtils.populate(Object, Map) if you want to convert it
into a known object type Types are likely to require conversion as guesses are made about the right formats, use of the ReflectUtils.convert(Object, Class) method is recommended |
String |
encodeData(Object data,
String format,
String name,
Map<String,Object> properties)
Encode data into a given format, can handle any java object,
note that unsupported formats will result in an exception
|
String |
encodeEntity(String prefix,
String format,
EntityData entityData,
EntityView view)
Encodes entity data
|
void |
formatAndOutputEntity(EntityReference ref,
String format,
List<EntityData> entities,
OutputStream outputStream,
Map<String,Object> params)
Format and output an entity or collection included or referred to by this entity ref object
into output according to the format string provided,
Should take into account the reference when determining what the entities are
and how to encode them
(This is basically a copy of the code in EntityHandlerImpl with stuff removed)
|
org.azeckoski.reflectutils.transcoders.Transcoder |
getTranscoder(String format) |
Object |
internalInputTranslator(EntityReference ref,
String format,
InputStream input,
javax.servlet.http.HttpServletRequest req)
Handled the internal encoding of data into an entity object
|
void |
internalOutputFormatter(EntityReference ref,
String format,
List<EntityData> entities,
Map<String,Object> params,
OutputStream output,
EntityView view)
Format entities for output based on the reference into a format,
use the provided list or get the entities
|
protected String |
makeFormViewUrl(String contextUrl,
String viewKey,
EntityView view) |
protected String |
sanitizeJsonCallback(Object param)
Clean the JSONP callback parameter to make sure it is sensible
|
void |
setEntityBrokerManager(EntityBrokerManager entityBrokerManager) |
void |
setEntityProviderManager(EntityProviderManager entityProviderManager) |
void |
setTranscoder(org.azeckoski.reflectutils.transcoders.Transcoder transcoder)
Override the transcoder used for a specific format
|
void |
setTranscoders(Map<String,org.azeckoski.reflectutils.transcoders.Transcoder> transcoders) |
Object |
translateInputToEntity(EntityReference ref,
String format,
InputStream inputStream,
Map<String,Object> params)
Translates the input data stream in the supplied format into an entity object for this reference
(This is basically a copy of the code in EntityHandlerImpl with stuff removed)
|
boolean |
validateFormat(String data,
String format)
Will attempt to validate that string data is of a specific format
|
public static final String ENTITY_REFERENCE
public static final String ENTITY_ID
public static final String ENTITY_URL
public static final String ENTITY_TITLE
public static final String ENTITY_PREFIX
public static final String COLLECTION
public static final String BATCH_PREFIX
public static final String[] HANDLED_INPUT_FORMATS
public static final String[] HANDLED_OUTPUT_FORMATS
public static final String JSON_CALLBACK_PARAM
public static final String JSON_DEFAULT_CALLBACK
protected static final String XML_HEADER_PREFIX
protected static final String XML_HEADER_SUFFIX
protected static final String XML_HEADER
protected static final String XHTML_HEADER
protected static final String XHTML_FOOTER
protected static final String DATA_KEY
protected EntityEncodingManager()
public EntityEncodingManager(EntityProviderManager entityProviderManager, EntityBrokerManager entityBrokerManager)
public void setEntityProviderManager(EntityProviderManager entityProviderManager)
public void setEntityBrokerManager(EntityBrokerManager entityBrokerManager)
public void formatAndOutputEntity(EntityReference ref, String format, List<EntityData> entities, OutputStream outputStream, Map<String,Object> params)
ref - a globally unique reference to an entity,
consists of the entity prefix and optional segmentsformat - a string constant indicating the format (from Formats)
for output, (example: #XML)entities - (optional) a list of entities to create formatted output for,
if this is null then the entities should be retrieved based on the reference,
if this contains only a single item AND the ref refers to a single entity
then the entity should be extracted from the list and encoded without the indication
that it is a collection, for all other cases the encoding should include an indication that
this is a list of entitiesoutputStream - the output stream to place the formatted data in,
should be UTF-8 encoded if there is char dataFormatUnsupportedException - if you do not handle this format type (passes control to the internal handlers)EntityEncodingException - if you cannot encode the received data into an entityIllegalArgumentException - if any of the arguments are invalidIllegalStateException - for all other failurespublic Object translateInputToEntity(EntityReference ref, String format, InputStream inputStream, Map<String,Object> params)
ref - a globally unique reference to an entity,
consists of the entity prefix and optional segmentsformat - a string constant indicating the format (from Formats)
of the input, (example: #XML)input - a stream which contains the data to make up this entity,
you may assume this is UTF-8 encoded if you don't know anything else about itFormatUnsupportedException - if you do not handle this format type (passes control to the internal handlers)EntityEncodingException - if you cannot encode the received data into an entityIllegalArgumentException - if any of the arguments are invalidIllegalStateException - for all other failurespublic boolean validateFormat(String data, String format)
data - a chunk of data to validateformat - the format which the data is supposed encoded inpublic Object internalInputTranslator(EntityReference ref, String format, InputStream input, javax.servlet.http.HttpServletRequest req)
ref - the entity referenceformat - the format which the input is encoded ininput - the data being inputFormatUnsupportedException - if you do not handle this format type (passes control to the internal handlers)EntityEncodingException - if you cannot encode the received data into an entityIllegalArgumentException - if any of the arguments are invalidIllegalStateException - for all other failurespublic void internalOutputFormatter(EntityReference ref, String format, List<EntityData> entities, Map<String,Object> params, OutputStream output, EntityView view)
ref - the entity reference for this,
if this is a reference to a collection then this will be rendered as a collection of entities,
if a reference to a single entity then only the matching one from the collection will be usedformat - the format to use for the output dataentities - (optional) if this is null then the entities will be fetchedoutput - the outputstream to place the encoded data intoview - (optional)FormatUnsupportedException - if you do not handle this format type (passes control to the internal handlers)EntityEncodingException - if you cannot encode the received data into an entityIllegalArgumentException - if any of the arguments are invalidIllegalStateException - for all other failurespublic String encodeEntity(String prefix, String format, EntityData entityData, EntityView view)
prefix - the entity prefix related to this dataformat - the format to encode the data intoentityData - (optional) entity data to encodeview - (optional) used to generate links and determine the correct incoming viewprotected String makeFormViewUrl(String contextUrl, String viewKey, EntityView view)
public void setTranscoders(Map<String,org.azeckoski.reflectutils.transcoders.Transcoder> transcoders)
public void setTranscoder(org.azeckoski.reflectutils.transcoders.Transcoder transcoder)
transcoder - a transcoder implementationpublic org.azeckoski.reflectutils.transcoders.Transcoder getTranscoder(String format)
public String encodeData(Object data, String format, String name, Map<String,Object> properties)
data - the data to encode (can be a POJO or Map or pretty much any java object)format - the format to use for output (from Formats)name - (optional) the name to use for the encoded data (e.g. root node for XML)properties - (optional) extra properties to add into the encoding, ignored if encoded object is not a map or beanUnsupportedOperationException - if the data cannot be encodedprotected String sanitizeJsonCallback(Object param)
param - The parameter for the callback, should be a Stringpublic Map<String,Object> decodeData(String data, String format)
ReflectUtils.populate(Object, Map) if you want to convert it
into a known object type ReflectUtils.convert(Object, Class) method is recommendeddata - encoded dataformat - the format of the encoded data (from Formats)UnsupportedOperationException - if the data cannot be decodedCopyright © 2003–2020 Sakai Project. All rights reserved.