com.funambol.syncml.spds
Class SyncMLFormatter

java.lang.Object
  extended by com.funambol.syncml.spds.SyncMLFormatter

public class SyncMLFormatter
extends java.lang.Object

This class represents a formatter for SyncML. A formatter is intented to generate SyncML messages starting from an abstract representation of the same message. In this current implementation the formatter is not yet connected to the abstract implementation and it performs a sort of low level formatting where the bit and pieces of a message are printed together to form the outgoing message. The current implementation supports only plain XML but the class aims at supporting WBXML at some point.


Constructor Summary
SyncMLFormatter()
           
 
Method Summary
 java.lang.String formatAlerts(java.lang.String cmdId, int syncMode, long nextAnchor, long lastAnchor, int sourceSyncMode, java.lang.String sourceName, java.lang.String sourceUri, SyncFilter filter, int maxDataSize)
          Contructs the alerts for the given source.
 java.lang.String formatAlertStatus(SyncMLStatus status, long nextAnchor)
          Prepare a status code in response to the server's alert.
 java.lang.String formatCmdId(int cmdId)
          Format the CmdID tag
 java.lang.String formatCmdId(java.lang.String cmdId)
          Format the CmdID tag
 java.lang.String formatCredentials(java.lang.String token, boolean md5)
          Format credentials into a <Cred> tag
 java.lang.String formatEndAddCommand()
          Format the syncml add command (end)
 java.lang.String formatEndDeleteCommand()
          Format the syncml delete command (end)
 java.lang.String formatEndItem()
          Format the syncml end of an item element
 java.lang.String formatEndMeta()
          Format the syncml end of a meta element
 java.lang.String formatEndReplaceCommand()
          Format the syncml replace command (end)
 java.lang.String formatEndSync()
          Format the syncml sync end tag
 java.lang.String formatEndSyncBody()
          Format the syncml end sync body
 java.lang.String formatEndSyncML()
          Format the syncml end tag
 java.lang.String formatFinal()
          Format the syncml final tag
 java.lang.String formatGetDeviceInfo(java.lang.String cmdId)
          Format a request to the server for its device capabilities
 java.lang.String formatItemData(java.lang.String data)
          Format an item data.
 java.lang.String formatItemDelete(java.lang.String key)
          This method formats an Item tag for delete commands
 java.lang.String formatItemFormat(java.lang.String format)
          Get the format string to add to the outgoing message.
 java.lang.String formatItemLuid(java.lang.String luid)
          Format an item luid.
 java.lang.String formatItemParent(java.lang.String parent)
          Format an item parent.
 java.lang.String formatItemSize(long size)
          Format an item size.
 java.lang.String formatItemStatus(SyncMLStatus status)
          Format a status in response to a server command.
 java.lang.String formatItemType(java.lang.String type)
          Format an item type.
 java.lang.String formatMappings(java.lang.String nextCmdId, java.lang.String sourceName, java.lang.String sourceUri, java.util.Hashtable mappings)
          Format a mapping message.
 java.lang.String formatMaxMsgSize(int maxMsgSize)
          Format the max message size
 java.lang.String formatMoreData()
          Format a "more data" element
 java.lang.String formatPutDeviceInfo(java.lang.String cmdId, DeviceConfig devInf, java.lang.String sourceName, java.lang.String sourceType)
          Constructs the section of a SyncML initialization message used to carry the device capabilities with the element
 java.lang.String formatResultsDeviceInfo(java.lang.String nextCmdId, java.lang.String msgIDget, java.lang.String cmdIDget, java.lang.String sourceName, java.lang.String sourceType, DeviceConfig devInf)
          Used to build the part of the SyncML modification message containing the device sync capabilities () when requested by the server with the command
 java.lang.String formatStartAddCommand()
          Format the syncml add command (start)
 java.lang.String formatStartDeleteCommand()
          Format the syncml delete command (start)
 java.lang.String formatStartItem()
          Format the syncml start of an item element
 java.lang.String formatStartMeta()
          Format the syncml start of a meta element
 java.lang.String formatStartReplaceCommand()
          Format the syncml replace command (start)
 java.lang.String formatStartSync()
          Format the syncml sync start tag
 java.lang.String formatStartSyncBody()
          Format the syncml start sync body
 java.lang.String formatStartSyncML()
          Format the syncml start tag
 java.lang.String formatSyncHdrStatus(SyncMLStatus status)
          Prepare a status code in response to the server's sync hdr command
 java.lang.String formatSyncHeader(java.lang.String sessionid, java.lang.String msgid, java.lang.String src, java.lang.String username, java.lang.String tgt, java.lang.String tags)
          Prepare a SyncML Message header.
 java.lang.String formatSyncTagPreamble(java.lang.String nextCmdId, java.lang.String sourceName, java.lang.String sourceUri)
          Format the sync tag preamble.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncMLFormatter

public SyncMLFormatter()
Method Detail

formatSyncHeader

public java.lang.String formatSyncHeader(java.lang.String sessionid,
                                         java.lang.String msgid,
                                         java.lang.String src,
                                         java.lang.String username,
                                         java.lang.String tgt,
                                         java.lang.String tags)
Prepare a SyncML Message header.

Parameters:
sessionid - the session id to use.
msgid - the message id to use.
src - the source uri
username - the username to be used as loc name in the source tag
tgt - the target uri
tags - other SyncML tags to insert in the header. (e.g. <Cred> or <Meta>).

formatSyncHdrStatus

public java.lang.String formatSyncHdrStatus(SyncMLStatus status)
Prepare a status code in response to the server's sync hdr command

Parameters:
cmdId - the command id
msgIdRef - the message id ref
deviceId - the target ref
serverUrl - the source ref
Returns:
the SyncML status

formatAlertStatus

public java.lang.String formatAlertStatus(SyncMLStatus status,
                                          long nextAnchor)
Prepare a status code in response to the server's alert.

Parameters:
cmdId - the command id
msgIdRef - the message id ref
deviceId - the target ref
serverUrl - the source ref
Returns:
the SyncML status

formatAlerts

public java.lang.String formatAlerts(java.lang.String cmdId,
                                     int syncMode,
                                     long nextAnchor,
                                     long lastAnchor,
                                     int sourceSyncMode,
                                     java.lang.String sourceName,
                                     java.lang.String sourceUri,
                                     SyncFilter filter,
                                     int maxDataSize)
Contructs the alerts for the given source.

Parameters:
src - SyncSource
syncMode -
Returns:
the SyncML Alert commands

formatCredentials

public java.lang.String formatCredentials(java.lang.String token,
                                          boolean md5)
Format credentials into a <Cred> tag

Parameters:
token - the authentication token
md5 - true if the credentials are md5
Returns:
the XML credential tag

formatMaxMsgSize

public java.lang.String formatMaxMsgSize(int maxMsgSize)
Format the max message size

Parameters:
maxMsgSize - the max message size
Returns:
a Meta tag containing the max message size

formatStartSyncML

public java.lang.String formatStartSyncML()
Format the syncml start tag

Returns:
the SyncML start tag

formatStartSyncBody

public java.lang.String formatStartSyncBody()
Format the syncml start sync body

Returns:
the SyncML start sync body

formatFinal

public java.lang.String formatFinal()
Format the syncml final tag

Returns:
the SyncML final tag

formatEndSyncBody

public java.lang.String formatEndSyncBody()
Format the syncml end sync body

Returns:
the SyncML end sync body

formatEndSyncML

public java.lang.String formatEndSyncML()
Format the syncml end tag

Returns:
the SyncML end tag

formatPutDeviceInfo

public java.lang.String formatPutDeviceInfo(java.lang.String cmdId,
                                            DeviceConfig devInf,
                                            java.lang.String sourceName,
                                            java.lang.String sourceType)
Constructs the section of a SyncML initialization message used to carry the device capabilities with the element

Parameters:
devInf - A reference to the current device configuration (DeviceConfig)
Returns:
a String to be added to the initialization SyncML message

formatResultsDeviceInfo

public java.lang.String formatResultsDeviceInfo(java.lang.String nextCmdId,
                                                java.lang.String msgIDget,
                                                java.lang.String cmdIDget,
                                                java.lang.String sourceName,
                                                java.lang.String sourceType,
                                                DeviceConfig devInf)
Used to build the part of the SyncML modification message containing the device sync capabilities () when requested by the server with the command

Parameters:
devInf - A reference to the current device configuration (DeviceConfig)
Returns:
the string containing the device capabilities part of the SyncML message sent to the server

formatMappings

public java.lang.String formatMappings(java.lang.String nextCmdId,
                                       java.lang.String sourceName,
                                       java.lang.String sourceUri,
                                       java.util.Hashtable mappings)
Format a mapping message. Mappings allow server and client to have a different representation for item's keys.

Parameters:
nextCmdId - the next command id
sourceName - is the source name
sourceUri - is the source URI
mappings - is an hashtable of strings where the key is the LUID and the value is the GUID
Returns:
a SyncML message containing the mapping

formatItemStatus

public java.lang.String formatItemStatus(SyncMLStatus status)
Format a status in response to a server command.

Parameters:
status - is the status representation
Returns:
a SyncML representation of the status

formatSyncTagPreamble

public java.lang.String formatSyncTagPreamble(java.lang.String nextCmdId,
                                              java.lang.String sourceName,
                                              java.lang.String sourceUri)
Format the sync tag preamble. This preamble is essentially the information about source and target sync source

Parameters:
nextCmdId - is the next command id
sourceName - is the local source uri
sourceUri - is the remote source uri
Returns:
the SyncML preamble

formatStartSync

public java.lang.String formatStartSync()
Format the syncml sync start tag

Returns:
the SyncML sync start tag

formatEndSync

public java.lang.String formatEndSync()
Format the syncml sync end tag

Returns:
the SyncML sync end tag

formatItemDelete

public java.lang.String formatItemDelete(java.lang.String key)
This method formats an Item tag for delete commands

Parameters:
key - is the item key
Returns:
the SyncML item

formatStartAddCommand

public java.lang.String formatStartAddCommand()
Format the syncml add command (start)

Returns:
the SyncML add command (start)

formatEndAddCommand

public java.lang.String formatEndAddCommand()
Format the syncml add command (end)

Returns:
the SyncML add command (end)

formatStartReplaceCommand

public java.lang.String formatStartReplaceCommand()
Format the syncml replace command (start)

Returns:
the SyncML replace command (start)

formatEndReplaceCommand

public java.lang.String formatEndReplaceCommand()
Format the syncml replace command (end)

Returns:
the SyncML replace command (end)

formatStartDeleteCommand

public java.lang.String formatStartDeleteCommand()
Format the syncml delete command (start)

Returns:
the SyncML delete command (start)

formatEndDeleteCommand

public java.lang.String formatEndDeleteCommand()
Format the syncml delete command (end)

Returns:
the SyncML delete command (end)

formatCmdId

public java.lang.String formatCmdId(java.lang.String cmdId)
Format the CmdID tag

Parameters:
cmId - the cmdID value
Returns:
the SyncML CmdID element

formatCmdId

public java.lang.String formatCmdId(int cmdId)
Format the CmdID tag

Parameters:
cmId - the cmdID value
Returns:
the SyncML CmdID element

formatStartItem

public java.lang.String formatStartItem()
Format the syncml start of an item element

Returns:
the SyncML start of an item element

formatEndItem

public java.lang.String formatEndItem()
Format the syncml end of an item element

Returns:
the SyncML end of an item element

formatItemType

public java.lang.String formatItemType(java.lang.String type)
Format an item type. This is the type used in modification commands.

Parameters:
type - the item's type
Returns:
the SyncML representation of the item's type

formatItemSize

public java.lang.String formatItemSize(long size)
Format an item size.

Parameters:
size - is the item's size
Returns:
the SyncML representation of the item's size

formatStartMeta

public java.lang.String formatStartMeta()
Format the syncml start of a meta element

Returns:
the SyncML start of a meta element

formatEndMeta

public java.lang.String formatEndMeta()
Format the syncml end of a meta element

Returns:
the SyncML end of a meta element

formatItemLuid

public java.lang.String formatItemLuid(java.lang.String luid)
Format an item luid.

Returns:
the SyncML luid of an item

formatItemParent

public java.lang.String formatItemParent(java.lang.String parent)
Format an item parent.

Returns:
the SyncML parent of an item

formatItemData

public java.lang.String formatItemData(java.lang.String data)
Format an item data.

Returns:
the SyncML data element

formatMoreData

public java.lang.String formatMoreData()
Format a "more data" element

Returns:
the SyncML "more data" element

formatItemFormat

public java.lang.String formatItemFormat(java.lang.String format)
Get the format string to add to the outgoing message.

Returns:
the Format string, according to the source encoding

formatGetDeviceInfo

public java.lang.String formatGetDeviceInfo(java.lang.String cmdId)
Format a request to the server for its device capabilities

Parameters:
cmdId - is the command id
Returns:
the SyncML representation of the device capabilities request


Copyright © 2001-2009 Funambol.