/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $node = $helper->findNodeRelativeTo('./' . $name, $parent_node); if ($node === false) { if (!isset($attributes[$name])) { if ($this->isRelaxed($params)) { return false; } else { throw new Horde_Kolab_Format_Exception_MissingUid(); } } } else { if (isset($attributes[$name])) { if (($old = $this->loadNodeValue($node, $helper, $params)) != $attributes[$name]) { if (!$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception(sprintf('Not attempting to overwrite old %s %s with new value %s!', $name, $old, $attributes['uid'])); } } else { return $node; } } } $result = $this->saveNodeValue($name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node); return $node !== false ? $node : $result; }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); if ($result !== null) { $this->_checkColor($result, $params); } return $result; }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); if (strlen($result) == 10) { return array('date' => Horde_Kolab_Format_Date::readDate($result), 'date-only' => true); } return array('date' => Horde_Kolab_Format_Date::readDateTime($result), 'date-only' => false); }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); $date = Horde_Kolab_Format_Date::readDate($result); if ($date === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception(sprintf('Invalid date input "%s"!', $result)); } return $date; }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); $type = $node->getAttribute('type'); if (empty($type) || $type == 'none') { return null; } if ($type == 'date') { return Horde_Kolab_Format_Date::readDate($result); } return $result; }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $node = $helper->findNodeRelativeTo('./' . $name, $parent_node); if (!isset($attributes[$name])) { if ($node !== false) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); } return false; } return $this->saveNodeValue($name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node); }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); if (strlen($result) == 10) { $date = array('date' => Horde_Kolab_Format_Date::readDate($result), 'date-only' => true); } else { $date = array('date' => Horde_Kolab_Format_Date::readDateTime($result), 'date-only' => false); } if ($date['date'] === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception(sprintf('Invalid date input "%s"!', $result)); } return $date; }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); if ($result !== null) { if ($result == 'false') { $result = false; } else { if ($result == 'true') { $result = true; } else { $result = (bool) $result; } } } return $result; }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $node = $helper->findNodeRelativeTo('./' . $name, $parent_node); if (!isset($attributes[$name])) { if (!empty($attributes['categories'])) { $attributes[$name] = $attributes['categories']; unset($attributes['categories']); } } if (!isset($attributes[$name]) && $node === false && !$this->isRelaxed($params)) { throw new Horde_Kolab_Format_Exception_MissingValue('Preferences data is missing an application setting.'); } if ($node === false) { $categories = $helper->findNodeRelativeTo('./categories', $parent_node); /** Remove old categories entry */ $helper->removeNodes($parent_node, 'categories'); } return $this->saveNodeValue($name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node); }
/** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue($name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false) { if ($old_node === false) { $node = $helper->createNewNode($parent_node, $name); $this->_writeComposite($node, $name, $value, $helper, $params); return $node; } else { $this->_writeComposite($old_node, $name, $value, $helper, $params); return $old_node; } }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { if (!($root = $helper->findNode('/' . $name, $parent_node))) { $root = $helper->createNewNode($parent_node, $name); $root->setAttribute('version', $params['expected-version']); } else { if (!$this->isRelaxed($params)) { if (version_compare($params['expected-version'], $root->getAttribute('version')) < 0) { throw new Horde_Kolab_Format_Exception_InvalidRoot(sprintf('Not attempting to overwrite higher root version of %s with our version %s!', $root->getAttribute('version'), $params['expected-version'])); } } if ($params['expected-version'] != $root->getAttribute('version')) { $root->setAttribute('version', $params['expected-version']); } } $this->_prepareCompositeParameters($params, $params['expected-version']); parent::save($name, $attributes, $parent_node, $helper, $params); return $root; }
/** * Update the specified attribute. * * @param string $name The name of the attribute * to be updated. * @param mixed $value The value to store. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params The parameters for this * write operation. * @param DOMNode|NULL $old_node The previous value (or * null if there is none). * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function saveNodeValue($name, $value, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array(), $old_node = false) { if ($old_node === false) { return $helper->storeNewNodeValue($parent_node, $name, $value); } else { $helper->replaceFirstNodeTextValue($old_node, $value); return $old_node; } }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $children = $helper->findNodesRelativeTo('./' . $name, $parent_node); if (!isset($attributes[$name])) { if ($children->length == 0) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING || $this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && $this->isRelaxed($params)) { return false; } } else { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); return false; } else { return $children; } } } //@todo What is required to get around this overwriting of the old values? $helper->removeNodes($parent_node, $name); return $this->_writeMultiple($parent_node, $name, $this->generateWriteValue($name, $attributes, $params), $helper, $params); }
/** * Load the value of a node. * * @param DOMNode $node Retrieve value for this node. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additiona parameters for * this parse operation. * * @return mixed|null The value or null if no value was found. */ public function loadNodeValue($node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $result = $helper->fetchNodeValue($node); return Horde_Kolab_Format_Date::readDate($result); }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $value = $this->generateWriteValue($name, $attributes, $params); return empty($value) ? false : $helper->appendXml($parent_node, $value); }
/** * Update the specified attribute. * * @param string $name The name of the the * attribute to be updated. * @param array $attributes The data array that holds * all attribute values. * @param DOMNode $parent_node The parent node of the * node that should be * updated. * @param Horde_Kolab_Format_Xml_Helper $helper A XML helper instance. * @param array $params Additional parameters * for this write operation. * * @return DOMNode|boolean The new/updated child node or false if this * failed. * * @throws Horde_Kolab_Format_Exception If converting the data to XML failed. */ public function save($name, $attributes, $parent_node, Horde_Kolab_Format_Xml_Helper $helper, $params = array()) { $node = $helper->findNodeRelativeTo('./' . $name, $parent_node); if (!isset($attributes[$name])) { if ($node === false) { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING || $this->value == Horde_Kolab_Format_Xml::VALUE_NOT_EMPTY && $this->isRelaxed($params)) { return false; } } else { if ($this->value == Horde_Kolab_Format_Xml::VALUE_MAYBE_MISSING) { /** Client indicates that the value should get removed */ $helper->removeNodes($parent_node, $name); return false; } else { return $node; } } } return $this->saveNodeValue($name, $this->generateWriteValue($name, $attributes, $params), $parent_node, $helper, $params, $node); }