/**
  * 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;
 }
示例#2
0
 /**
  * Function: register
  *
  * Registers a new codec and associates the name of the template constructor
  * in the codec with the codec object. Automatically creates an alias if the
  * codename and the classname are not equal.
  *
  * Parameters:
  *
  * codec - <mxObjectCodec> to be registered.
  */
 static function register($codec)
 {
     if (isset($codec)) {
         $name = $codec->getName();
         mxCodecRegistry::$codecs[$name] = $codec;
         $classname = mxCodecRegistry::getName($codec->template);
         if ($classname != $name) {
             mxCodecRegistry::addAlias($classname, $name);
         }
     }
     return $codec;
 }
 /**
  * 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;
 }
 /**
  * Function: register
  *
  * Registers a new codec and associates the name of the template
  * constructor in the codec with the codec object.
  *
  * Parameters:
  *
  * codec - <mxObjectCodec> to be registered.
  */
 static function register($codec)
 {
     $name = mxCodecRegistry::getName($codec->template);
     mxCodecRegistry::$codecs[$name] = $codec;
 }
示例#5
0
 /**
  * Function: encode
  *
  * Encodes the specified object and returns the resulting
  * XML node.
  *
  * Parameters:
  *
  * obj - Object to be encoded. 
  */
 function encode($obj)
 {
     $node = null;
     if (is_object($obj) || is_array($obj)) {
         if (is_array($obj)) {
             $enc = new mxObjectCodec(array());
         } else {
             $enc = mxCodecRegistry::getCodec(mxCodecRegistry::getName($obj));
         }
         if (isset($enc)) {
             $node = $enc->encode($this, $obj);
         } else {
             if (get_class($obj) == "DOMElement") {
                 $node = $obj->cloneNode(true);
             } else {
                 mxLog::warn("mxCodec.encode: No codec for " . mxCodecRegistry::getName($obj));
             }
         }
     }
     return $node;
 }
示例#6
0
 /**
  * Function: getName
  *
  * Creates a new instance of the template for this codec.
  */
 function getName()
 {
     return mxCodecRegistry::getName($this->template);
 }
示例#7
0
 /**
  * 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;
     }
 }