/**
  * Function: getCodec
  *
  * Returns a codec that handles objects that are constructed
  * using the given ctor.
  *
  * Parameters:
  *
  * ctor - JavaScript constructor function. 
  */
 static function getCodec($name)
 {
     $codec = null;
     if (isset($name)) {
         if (isset(mxCodecRegistry::$aliases[$name])) {
             $tmp = mxCodecRegistry::$aliases[$name];
             if (strlen($tmp) > 0) {
                 $name = $tmp;
             }
         }
         $codec = isset(mxCodecRegistry::$codecs[$name]) ? mxCodecRegistry::$codecs[$name] : null;
         // Registers a new default codec for the given constructor
         // if no codec has been previously defined.
         if (!isset($codec)) {
             try {
                 $obj = mxCodecRegistry::getInstanceForName($name);
                 if (isset($obj)) {
                     $codec = new mxObjectCodec($obj);
                     mxCodecRegistry::register($codec);
                 }
             } catch (Exception $e) {
                 // ignore
             }
         }
     }
     return $codec;
 }
 /**
  * Override <mxObjectCodec.encode>.
  */
 function encode($enc, $obj)
 {
     $name = mxCodecRegistry::getName($obj);
     $node = $enc->document->createElement($name);
     $rootNode = $enc->document->createElement("root");
     $enc->encodeCell($obj->getRoot(), $rootNode);
     $node->appendChild($rootNode);
     return $node;
 }
 /**
  * Override <mxObjectCodec.encode>.
  */
 function encode($enc, $obj)
 {
     $name = mxCodecRegistry::getName($obj);
     $node = $enc->document->createElement($name);
     foreach ($obj->styles as $i => $value) {
         $styleNode = $enc->document->createElement("add");
         if (isset($i)) {
             $styleNode->setAttribute("as", $i);
             foreach ($style as $j => $value) {
                 // TODO: Encode functions and objects
                 if (!function_exists($value) && !is_object($value)) {
                     $entry = $enc->document->createElement("add");
                     $entry->setAttribute("as", $j);
                     $entry->setAttribute("value", $value);
                     $styleNode->appendChild($entry);
                 }
             }
             if ($styleNode->getChildCount() > 0) {
                 $node->appendChild($styleNode);
             }
         }
     }
     return node;
 }
Exemple #4
0
 /**
  * Function: getName
  *
  * Creates a new instance of the template for this codec.
  */
 function getName()
 {
     return mxCodecRegistry::getName($this->template);
 }
Exemple #5
0
 /**
  * Function: decodeCell
  *
  * Decodes cells that have been encoded using inversion, ie.
  * where the user object is the enclosing node in the XML,
  * and restores the group and graph structure in the cells.
  * Returns a new <mxCell> instance that represents the
  * given node.
  *
  * Parameters:
  *
  * node - XML node that contains the cell data.
  * restoreStructures - Optional boolean indicating whether
  * the graph structure should be restored by calling insert
  * and insertEdge on the parent and terminals, respectively.
  * Default is true.
  */
 function decodeCell($node, $restoreStructures = true)
 {
     $cell = null;
     if (isset($node) && $node->nodeType == XML_ELEMENT_NODE) {
         // Tries to find a codec for the given node name. If that does
         // not return a codec then the node is the user object (an XML node
         // that contains the mxCell, aka inversion).
         $decoder = mxCodecRegistry::getCodec($node->nodeName);
         // Tries to find the codec for the cell inside the user object.
         // This assumes all node names inside the user object are either
         // not registered or they correspond to a class for cells.
         if (!isset($decoder)) {
             $child = $node->firstChild;
             while (isset($child) && !$decoder instanceof mxCellCodec) {
                 $decoder = mxCodecRegistry::getCodec($child->nodeName);
                 $child = $child->nextSibling;
             }
         }
         if (!$decoder instanceof mxCellCodec) {
             $decoder = mxCodecRegistry::getCodec("mxCell");
         }
         $cell = $decoder->decode($this, $node);
         if ($restoreStructures) {
             $this->insertIntoGraph($cell);
         }
     }
     return $cell;
 }
Exemple #6
0
        // for the known references to cells (all).
        if (isset($inner)) {
            for ($i = 0; $i < sizeof($this->idrefs); $i++) {
                $attr = $this->idrefs[$i];
                $ref = $inner->getAttribute($attr);
                if (strlen($ref) > 0) {
                    $inner->removeAttribute($attr);
                    $object = isset($dec->objects[$ref]) ? $dec->objects[$ref] : null;
                    if (!isset($object)) {
                        $object = $dec->lookup($ref);
                    }
                    if (!isset($object)) {
                        // Needs to decode forward reference
                        $element = $dec->getElementById($ref);
                        if (isset($element)) {
                            $decoder = mxCodecRegistry::$codecs[$element->nodeName];
                            if (!isset($decoder)) {
                                $decoder = $this;
                            }
                            $object = $decoder->decode($dec, $element);
                        }
                    }
                    $obj->{$attr} = $object;
                }
            }
        }
        return $inner;
    }
}
mxCodecRegistry::register(new mxCellCodec(new mxCell()));
                        if ($entry->nodeType == XML_ELEMENT_NODE) {
                            $key = $entry->getAttribute("as");
                            if ($entry->nodeName == "add") {
                                $text = $entry->textContent;
                                $value = null;
                                if (isset($text) && strlen($text) > 0) {
                                    $value = mxUtils::evaluate($text);
                                } else {
                                    $value = $entry->getAttribute("value");
                                }
                                if ($value != null) {
                                    $style[$key] = $value;
                                }
                            } else {
                                if ($entry->nodeName == "remove") {
                                    unset($style[$key]);
                                }
                            }
                        }
                        $entry = $entry->nextSibling;
                    }
                    $obj->putCellStyle($as, $style);
                }
            }
            $node = $node->nextSibling;
        }
        return $obj;
    }
}
mxCodecRegistry::register(new mxStylesheetCodec(new mxStylesheet()));
Exemple #8
0
     */
    function decodeChild($dec, $child, &$obj)
    {
        if ($child->nodeName == "root") {
            $this->decodeRoot($dec, $child, $obj);
        } else {
            parent::decodeChild($dec, $child, $obj);
        }
    }
    /**
     * Override <mxObjectCodec.decodeRoot>.
     */
    function decodeRoot($dec, $root, $model)
    {
        $rootCell = null;
        $tmp = $root->firstChild;
        while (isset($tmp)) {
            $cell = $dec->decodeCell($tmp);
            if (isset($cell) && $cell->getParent() == null) {
                $rootCell = $cell;
            }
            $tmp = $tmp->nextSibling;
        }
        // Sets the root on the model if one has been decoded
        if (isset($rootCell)) {
            $model->setRoot($rootCell);
        }
    }
}
mxCodecRegistry::register(new mxModelCodec(new mxGraphModel()));
 /**
  * Override <mxObjectCodec.beforeDecode>.
  */
 function beforeDecode($dec, $node, $obj)
 {
     $inner = $node;
     $className = mxCodecRegistry::getName($this->template);
     if ($node->nodeName != $className) {
         // Passes the inner graphical annotation node to the
         // object codec for further processing of the cell.
         $tmp = $node->getElementsByTagName($className)->item(0);
         if (isset($tmp) && $tmp->parentNode == $node) {
             $inner = $tmp;
             // Removes annotation and whitespace from node
             $tmp2 = $tmp->previousSibling;
             while (isset($tmp2) && $tmp2->nodeType == XML_TEXT_NODE) {
                 $tmp3 = $tmp2->previousSibling;
                 if (strlen(trim($tmp2->textContent)) == 0) {
                     $tmp2->parentNode->removeChild($tmp2);
                 }
                 $tmp2 = $tmp3;
             }
             // Removes more whitespace
             $tmp2 = $tmp->nextSibling;
             while (isset($tmp2) && $tmp2->nodeType == XML_TEXT_NODE) {
                 $tmp3 = $tmp2->previousSibling;
                 if (strlen(trim($tmp2->textContent)) == 0) {
                     $tmp2->parentNode->removeChild($tmp2);
                 }
                 $tmp2 = $tmp3;
             }
             $tmp->parentNode->removeChild($tmp);
         } else {
             $inner = null;
         }
         // Creates the user object out of the XML node
         $obj->value = $node->cloneNode(true);
         $id = $obj->value->getAttribute("id");
         if (strlen($id) > 0) {
             $obj->setId($id);
             $obj->value->removeAttribute("id");
         }
     } else {
         $obj->setId($node->getAttribute("id"));
     }
     // Preprocesses and removes all Id-references
     // in order to use the correct encoder (this)
     // for the known references to cells (all).
     if (isset($inner)) {
         for ($i = 0; $i < sizeof($this->idrefs); $i++) {
             $attr = $this->idrefs[$i];
             $ref = $inner->getAttribute($attr);
             if (strlen($ref) > 0) {
                 $inner->removeAttribute($attr);
                 $object =& $dec->objects[$ref];
                 if (!isset($object)) {
                     $object =& $dec->lookup($ref);
                 }
                 if (!isset($object)) {
                     // Needs to decode forward reference
                     $element =& $dec->getElementById($ref);
                     if (isset($element)) {
                         $decoder = mxCodecRegistry::$codecs[$element->nodeName];
                         if (!isset($decoder)) {
                             $decoder = $this;
                         }
                         $object =& $decoder->decode($dec, $element);
                     }
                 }
                 $obj->{$attr} =& $object;
             }
         }
     }
     return $inner;
 }
 /**
  * Function: decodeChildren
  * 
  * Decodec all children of the given node using <decodeChild>.
  */
 function decodeChildren($dec, $node, &$obj)
 {
     $type = mxCodecRegistry::getName($obj);
     $child = $node->firstChild;
     while ($child != null) {
         $tmp = $child->nextSibling;
         if ($child->nodeType == XML_ELEMENT_NODE && !$this->processInclude($dec, $child, $obj)) {
             $this->decodeChild($dec, $child, $obj);
         }
         $child = $tmp;
     }
 }