com.vaadin.terminal.gwt.server.
Class JsonPaintTarget
java.lang.Object
com.vaadin.terminal.gwt.server.JsonPaintTarget
All Implemented Interfaces:
- extends Object
- implements PaintTarget
public class JsonPaintTarget
User Interface Description Language Target. TODO document better: role of this class, UIDL format, attributes, variables, etc.
Since:
5.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Constructor Summary | |
---|---|
JsonPaintTarget(AbstractCommunicationManager manager,
PrintWriter outWriter,
boolean cachingRequired)
Creates a new XMLPrintWriter, without automatic line flushing. |
Method Summary | |
---|---|
void |
addAttribute(String name,
boolean value)
Adds a boolean attribute to component. |
void |
addAttribute(String name,
double value)
Adds a double attribute to component. |
void |
addAttribute(String name,
float value)
Adds a float attribute to component. |
void |
addAttribute(String name,
int value)
Adds a integer attribute to component. |
void |
addAttribute(String name,
long value)
Adds a long attribute to component. |
void |
addAttribute(String name,
Map<?,?> value)
TODO |
void |
addAttribute(String name,
Object[] values)
|
void |
addAttribute(String name,
Paintable value)
Adds a Paintable type attribute. |
void |
addAttribute(String name,
Resource value)
Adds a resource attribute to component. |
void |
addAttribute(String name,
String value)
Adds a string attribute to component. |
void |
addCharacterData(String text)
Adds CDATA node to target UIDL-tree. |
void |
addSection(String sectionTagName,
String sectionData)
Prints the single text section. |
void |
addText(String str)
Prints XML-escaped text. |
void |
addUIDL(String xml)
Adds XML directly to UIDL. |
void |
addUploadStreamVariable(VariableOwner owner,
String name)
Adds a upload stream type variable. |
void |
addVariable(VariableOwner owner,
String name,
boolean value)
Adds a boolean type variable. |
void |
addVariable(VariableOwner owner,
String name,
double value)
Adds a double type variable. |
void |
addVariable(VariableOwner owner,
String name,
float value)
Adds a float type variable. |
void |
addVariable(VariableOwner owner,
String name,
int value)
Adds a int type variable. |
void |
addVariable(VariableOwner owner,
String name,
long value)
Adds a long type variable. |
void |
addVariable(VariableOwner owner,
String name,
Paintable value)
Adds a Paintable type variable. |
void |
addVariable(VariableOwner owner,
String name,
StreamVariable value)
Adds details about StreamVariable to the UIDL stream. |
void |
addVariable(VariableOwner owner,
String name,
String value)
Adds a string type variable. |
void |
addVariable(VariableOwner owner,
String name,
String[] value)
Adds a string array type variable. |
void |
addXMLSection(String sectionTagName,
String sectionData,
String namespace)
Adds XML section with namespace. |
void |
close()
Closes the paint target. |
void |
endTag(String tagName)
Prints the element end tag. |
static String |
escapeJSON(String s)
Escapes the given string so it can safely be used as a JSON string. |
static String |
escapeXML(String xml)
Substitutes the XML sensitive characters with predefined XML entities. |
String |
getPaintIdentifier(Paintable paintable)
|
String |
getTag(Paintable paintable)
|
String |
getUIDL()
Gets the UIDL already printed to stream. |
Set<Object> |
getUsedResources()
|
boolean |
isFullRepaint()
|
boolean |
needsToBePainted(Paintable p)
Method to check if paintable is already painted into this target. |
void |
paintReference(Paintable paintable,
String referenceName)
Deprecated. |
boolean |
startTag(Paintable paintable,
String tagName)
Prints element start tag of a paintable section. |
void |
startTag(String tagName)
Prints element start tag. |
void |
startTag(String tagName,
boolean isChildNode)
Prints the element start tag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
JsonPaintTarget
public JsonPaintTarget(AbstractCommunicationManager manager,
PrintWriter outWriter,
boolean cachingRequired)
throws PaintException
- Parameters:
variableMap
-manager
-outWriter
- A character-output stream.cachingRequired
- true if this is not a full repaint, i.e. caches are to be used.- Throws:
PaintException
- if the paint operation failed.
Creates a new XMLPrintWriter, without automatic line flushing.
Method Detail |
---|
startTag
public void startTag(String tagName)
throws PaintException
- Specified by:
startTag
in interfacePaintTarget
- Parameters:
tagName
- the name of the start tag.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Prints element start tag.
Todo:
Checking of input values
startTag
public void startTag(String tagName,
boolean isChildNode)
throws PaintException
- Parameters:
tagName
- the name of the start tag.- Throws:
PaintException
- if the paint operation failed.
Prints the element start tag.
Todo:
Checking of input values
endTag
public void endTag(String tagName)
throws PaintException
- Specified by:
endTag
in interfacePaintTarget
- Parameters:
tag
- the name of the end tag.- Throws:
Paintexception
- if the paint operation failed.PaintException
- if the paint operation failed.
Prints the element end tag. If the parent tag is closed before every child tag is closed an PaintException is raised.
escapeXML
public static String escapeXML(String xml)
- Parameters:
xml
- the String to be substituted.- Returns:
- A new string instance where all occurrences of XML sensitive characters are substituted with entities.
Substitutes the XML sensitive characters with predefined XML entities.
escapeJSON
public static String escapeJSON(String s)
- Parameters:
s
- The string to escape- Returns:
- Escaped version of the string
Escapes the given string so it can safely be used as a JSON string.
addText
public void addText(String str)
throws PaintException
- Specified by:
addText
in interfacePaintTarget
- Parameters:
str
-- Throws:
PaintException
- if the paint operation failed.
Prints XML-escaped text.
addAttribute
public void addAttribute(String name,
boolean value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute name.value
- the Attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a boolean attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
Resource value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute namevalue
- the Attribute value- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a resource attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
int value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute name.value
- the Attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a integer attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
long value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute name.value
- the Attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a long attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
float value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute name.value
- the Attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a float attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
double value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Attribute name.value
- the Attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a double attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
String value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the Boolean attribute name.value
- the Boolean attribute value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a string attribute to component. Atributes must be added before any content is written.
addAttribute
public void addAttribute(String name,
Paintable value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Parameters:
name
- the name of the attributevalue
- the Paintable to be referenced on client side- Throws:
PaintException
Description copied from interface: PaintTarget
Adds a Paintable type attribute. On client side the value will be a terminal specific reference to corresponding component on client side implementation.
addAttribute
public void addAttribute(String name,
Map<?,?> value)
throws PaintException
- Specified by:
addAttribute
in interfacePaintTarget
- Throws:
PaintException
Description copied from interface: PaintTarget
TODO
addAttribute
public void addAttribute(String name,
Object[] values)
- Specified by:
addAttribute
in interfacePaintTarget
addVariable
public void addVariable(VariableOwner owner,
String name,
String value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a string type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
Paintable value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changesname
- the name of the variablevalue
- the initial value of the variable- Throws:
PaintException
- if the paint oparation fails
Description copied from interface: PaintTarget
Adds a Paintable type variable. On client side the variable value will be a terminal specific reference to corresponding component on client side implementation. When updated from client side, terminal will map the client side component reference back to a corresponding server side reference.
addVariable
public void addVariable(VariableOwner owner,
String name,
int value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a int type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
long value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a long type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
float value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a float type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
double value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a double type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
boolean value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a boolean type variable.
addVariable
public void addVariable(VariableOwner owner,
String name,
String[] value)
throws PaintException
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.value
- the Variable initial value.- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds a string array type variable.
addUploadStreamVariable
public void addUploadStreamVariable(VariableOwner owner,
String name)
throws PaintException
- Specified by:
addUploadStreamVariable
in interfacePaintTarget
- Parameters:
owner
- the Listener for variable changes.name
- the Variable name.- Throws:
PaintException
- if the paint operation failed.
Adds a upload stream type variable. TODO not converted for JSON
addSection
public void addSection(String sectionTagName,
String sectionData)
throws PaintException
- Specified by:
addSection
in interfacePaintTarget
- Parameters:
sectionTagName
- the name of the tag.sectionData
- the section data to be printed.- Throws:
PaintException
- if the paint operation failed.
Prints the single text section. Prints full text section. The section data is escaped
addUIDL
public void addUIDL(String xml)
throws PaintException
- Specified by:
addUIDL
in interfacePaintTarget
- Parameters:
xml
- the Xml to be added.- Throws:
PaintException
- if the paint operation failed.
Adds XML directly to UIDL.
addXMLSection
public void addXMLSection(String sectionTagName,
String sectionData,
String namespace)
throws PaintException
- Specified by:
addXMLSection
in interfacePaintTarget
- Parameters:
sectionTagName
- the name of the tag.sectionData
- the section data.namespace
- the namespace to be added.- Throws:
PaintException
- if the paint operation failed.- See Also:
PaintTarget.addXMLSection(String, String, String)
Adds XML section with namespace.
getUIDL
public String getUIDL()
- Returns:
- the UIDL.
Gets the UIDL already printed to stream. Paint target must be closed
before the getUIDL
can be called.
close
public void close()
throws PaintException
- Throws:
PaintException
- if the paint operation failed.
Closes the paint target. Paint target must be closed before the
getUIDL
can be called. Subsequent attempts to write to paint
target. If the target was already closed, call to this function is
ignored. will generate an exception.
startTag
public boolean startTag(Paintable paintable,
String tagName)
throws PaintException
- Specified by:
startTag
in interfacePaintTarget
- Parameters:
paintable
- the paintable to start.tagName
- the name of the start tag.- Returns:
true
if paintable found in cache,false
otherwise.- Throws:
PaintException
- if the paint operation failed.- See Also:
PaintTarget.startTag(String)
Description copied from interface: PaintTarget
Prints element start tag of a paintable section. Starts a paintable section using the given tag. The PaintTarget may implement a caching scheme, that checks the paintable has actually changed or can a cached version be used instead. This method should call the startTag method.
If the Paintable is found in cache and this function returns true it may omit the content and close the tag, in which case cached content should be used.
paintReference
@Deprecated
public void paintReference(Paintable paintable,
String referenceName)
throws PaintException
- Specified by:
paintReference
in interfacePaintTarget
- Parameters:
paintable
- the Paintable to reference- Throws:
PaintException
Deprecated.
Description copied from interface: PaintTarget
Paints a component reference as an attribute to current tag. This method
is meant to enable component interactions on client side. With reference
the client side component can communicate directly to other component.
Note! This was experimental api and got replaced by
PaintTarget.addAttribute(String, Paintable)
and
PaintTarget.addVariable(VariableOwner, String, Paintable)
.
getPaintIdentifier
public String getPaintIdentifier(Paintable paintable)
throws PaintException
- Throws:
PaintException
addCharacterData
public void addCharacterData(String text)
throws PaintException
- Specified by:
addCharacterData
in interfacePaintTarget
- Parameters:
text
- the Character data to add- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds CDATA node to target UIDL-tree.
getUsedResources
public Set<Object> getUsedResources()
needsToBePainted
public boolean needsToBePainted(Paintable p)
- Parameters:
p
-- Returns:
- true if is not yet painted into this target and is connected to app
Method to check if paintable is already painted into this target.
getTag
public String getTag(Paintable paintable)
- Specified by:
getTag
in interfacePaintTarget
- Returns:
- the "tag" string used in communication to present given
Paintable
type. Terminal may define how to present paintable.
addVariable
public void addVariable(VariableOwner owner,
String name,
StreamVariable value)
throws PaintException
- a StreamVariable with same name replaces an old one
- the variable owner is no more attached
- the developer signals this by calling
StreamVariable.StreamingStartEvent.disposeStreamVariable()
- Specified by:
addVariable
in interfacePaintTarget
- Parameters:
owner
- the ReceiverOwner that can track the progress of streaming to the given StreamVariablename
- an identifying name for the StreamVariablevalue
- the StreamVariable to paint- Throws:
PaintException
- if the paint operation failed.
Description copied from interface: PaintTarget
Adds details about StreamVariable
to the UIDL stream. Eg. in web
terminals Receivers are typically rendered for the client side as URLs,
where the client side implementation can do an http post request.
The urls in UIDL message may use Vaadin specific protocol. Before
actually using the urls on the client side, they should be passed via
ApplicationConnection.translateVaadinUri(String)
.
Note that in current terminal implementation StreamVariables are cleaned from the terminal only when:
isFullRepaint
public boolean isFullRepaint()
- Specified by:
isFullRepaint
in interfacePaintTarget
- Returns:
- true if a full repaint has been requested. E.g. refresh in a browser window or such.