Class StylesheetCodec

Codec for Stylesheets.

This class is created and registered dynamically at load time and used implicitly via Codec and the CodecRegistry.

Hierarchy (view full)

Constructors

Properties

exclude: string[]

Array containing the variable names that should be ignored by the codec.

idrefs: string[]

Array containing the variable names that should be turned into or converted from references. See Codec.getId and Codec.getObject.

mapping: {
    [key: string]: string;
}

Maps from field names to XML attribute names.

reverse: {
    [key: string]: string;
}

Maps from XML attribute names to fieldnames.

template: any

Holds the template object associated with this codec.

allowEval: boolean = true

Static global switch that specifies if the use of eval is allowed for evaluating text content. Default is true. Set this to false if stylesheets may contain user input.

Methods

  • Sets the decoded child node as a value of the given object. If the object is a map, then the value is added with the given field name as a key. If the field name is not empty, then setFieldValue is called or else, if the object is a collection, the value is added to the collection. For strongly typed languages it may be required to override this with the correct code to add an entry to an object.

    Parameters

    • obj: any
    • fieldname: string
    • value: any
    • template: any

    Returns void

  • Hook for subclassers to post-process the object after decoding. This implementation returns the given object without any changes. The return value of this method is returned to the decoder from decode.

    Parameters

    • dec: Codec

      Codec that controls the encoding process.

    • node: null | Element

      XML node to be decoded.

    • Optionalobj: any

      Object that represents the default decoding.

    Returns any

  • Hook for subclassers to post-process the node for the given object after encoding and return the post-processed node. This implementation returns the input node. The return value of this method is returned to the encoder from encode.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object to be encoded.

    • node: Element

      XML node that represents the default encoding.

    Returns Element

  • Hook for subclassers to pre-process the node for the specified object and return the node to be used for further processing by decode. The object is created based on the template in the calling method and is never null. This implementation returns the input node. The return value of this function is used in decode to perform the default decoding into the given object.

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • node: Element

      XML node to be decoded.

    • obj: any

      Object to encode the node into.

    Returns null | Element

  • Hook for subclassers to pre-process the object before encoding. This returns the input object. The return value of this function is used in encode to perform the default encoding into the given node.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object to be encoded.

    • Optionalnode: Element

      XML node to encode the object into.

    Returns any

  • Converts true to "1" and false to "0" is isBooleanAttribute returns true. All other values are not converted.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Objec to convert the attribute for.

    • name: null | string

      Name of the attribute to be converted.

    • value: any

      Value to be converted.

    • node: Element

    Returns any

  • Reads a sequence of the following child nodes and attributes:

    Child Nodes:

    add - Adds a new style.

    Attributes:

    as - Name of the style. extend - Name of the style to inherit from.

    Each node contains another sequence of add and remove nodes with the following attributes:

    as - Name of the style (see Constants). value - Value for the style.

    Instead of the value-attribute, one can put Javascript expressions into the node as follows if allowEval is true: mxPerimeter.RectanglePerimeter

    A remove node will remove the entry with the name given in the as-attribute from the style.

    Example:

    <mxStylesheet as="stylesheet">
    <add as="text">
    <add as="fontSize" value="12"/>
    </add>
    <add as="defaultVertex" extend="text">
    <add as="shape" value="rectangle"/>
    </add>
    </mxStylesheet>

    Parameters

    • dec: Codec
    • _node: Element
    • into: any

    Returns any

  • Reads the given attribute into the specified object.

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • attr: any

      XML attribute to be decoded.

    • Optionalobj: any

      Objec to encode the attribute into.

    Returns void

  • Reads the specified child into the given object.

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • child: Element

      XML child element to be decoded.

    • obj: any

      Objec to encode the node into.

    Returns void

  • Converts the given value according to the mappings and id-refs in this codec and uses writeAttribute to write the attribute into the given node.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object whose property is going to be encoded.

    • name: null | string

      XML node that contains the encoded object.

    • value: any

      Value of the property to be encoded.

    • node: Element

      XML node that contains the encoded object.

    Returns void

  • Returns the attribute name for the given field name. Looks up the value in the mapping or returns the input if there is no mapping for the given name.

    Parameters

    • fieldname: null | string

    Returns null | string

  • Returns the field name for the given attribute name. Looks up the value in the reverse mapping or returns the input if there is no reverse mapping for the given name.

    Parameters

    • attributename: string

    Returns string

  • Returns the template instance for the given field. This returns the value of the field, null if the value is an array or an empty collection if the value is a collection. The value is then used to populate the field for a new instance. For strongly typed languages it may be required to override this to return the correct collection instance based on the encoded child.

    Parameters

    • obj: any
    • fieldname: string
    • child: Element

    Returns any

  • Returns the name used for the node names and lookup of the codec when classes are encoded and nodes are decoded. For classes to work with this the codec registry automatically adds an alias for the classname if that is different from what this returns.

    The default implementation returns the classname of the template class if no name is set.

    Returns string

  • Returns true if the given object attribute is a boolean value.

    Parameters

    • enc: Codec

      Codec that controls the encoding process.

    • obj: any

      Object to convert the attribute for.

    • name: null | string

      Name of the attribute to be converted.

    • value: any

      Value of the attribute to be converted.

    Returns boolean

  • Returns true if the given attribute is to be ignored by the codec. This implementation returns true if the given field name is in exclude or if the field name equals ObjectIdentity.FIELD_NAME.

    Parameters

    • obj: any

      Object instance that contains the field.

    • attr: string

      Fieldname of the field.

    • value: any

      Value of the field.

    • Optionalwrite: boolean

      Boolean indicating if the field is being encoded or decoded. Write is true if the field is being encoded, else it is being decoded.

    Returns boolean

  • Returns true if the given attribute should be ignored. This implementation returns true if the attribute name is "as" or "id".

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • attr: any

      XML attribute to be decoded.

    • Optionalobj: any

      Objec to encode the attribute into.

    Returns boolean

  • Returns true if the given XML attribute is or should be a numeric value.

    Parameters

    • dec: Codec

      Codec that controls the decoding process.

    • attr: any

      XML attribute to be converted.

    • obj: any

      Object to convert the attribute for.

    Returns boolean

  • Returns true if the given field name is to be treated as a textual reference (ID). This implementation returns true if the given field name is in idrefs.

    Parameters

    • obj: any

      Object instance that contains the field.

    • attr: string

      Field name of the field.

    • value: any

      Value of the field.

    • Optionalwrite: boolean

      Boolean indicating if the field is being encoded or decoded. Write is true if the field is being encoded, else it is being decoded.

    Returns boolean

  • Returns true if the given node is an include directive and executes the include by decoding the XML document. Returns false if the given node is not an include directive.

    Parameters

    • dec: Codec

      Codec that controls the encoding/decoding process.

    • node: Element

      XML node to be checked.

    • Optionalinto: any

      Optional object to pass-thru to the codec.

    Returns boolean