aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/opendd.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-20 11:38:25 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-05-20 11:38:25 +0000
commit9caa09ee888d7884e22cc46089e6e0fb6579732c (patch)
tree6ee22ea1104a337fce3a64d0b519073a4ffbabbd /engine/lib/opendd.php
parent6258b38d2e274df93333ce36696bcbf49fb8ea2e (diff)
downloadelgg-9caa09ee888d7884e22cc46089e6e0fb6579732c.tar.gz
elgg-9caa09ee888d7884e22cc46089e6e0fb6579732c.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Committed abortive Atom wrapper... we need to support different import/export git-svn-id: https://code.elgg.org/elgg/trunk@657 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/opendd.php')
-rw-r--r--engine/lib/opendd.php95
1 files changed, 82 insertions, 13 deletions
diff --git a/engine/lib/opendd.php b/engine/lib/opendd.php
index 2c87f3265..96c18bbea 100644
--- a/engine/lib/opendd.php
+++ b/engine/lib/opendd.php
@@ -6,7 +6,7 @@
* @subpackage Core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Marcus Povey
- * @version 0.2
+ * @version 0.3
* @copyright Curverider Ltd 2008
* @link http://elgg.org/
*/
@@ -32,6 +32,11 @@
*/
private $elements;
+ /**
+ * Optional wrapper factory.
+ */
+ private $wrapperfactory;
+
public function __construct(array $elements = NULL)
{
if ($elements)
@@ -57,23 +62,38 @@
public function getElements() { return $this->elements; }
/**
+ * Set an optional wrapper factory to optionally embed the ODD document in another format.
+ */
+ public function setWrapperFactory(ODDWrapperFactory $factory) { $this->wrapperfactory = $factory; }
+
+ /**
* Magic function to generate valid ODD XML for this item.
*/
public function __toString()
{
$xml = "";
- // Output begin tag
- $generated = date("r");
- $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
-
- // Get XML for elements
- foreach ($this->elements as $element)
- $xml .= "$element";
-
- // Output end tag
- $xml .= "</odd>\n";
-
+ if ($this->wrapperfactory)
+ {
+ // A wrapper has been provided
+ $wrapper = $this->wrapperfactory->getElementWrapper($this); // Get the wrapper for this element
+
+ $xml = $wrapper->wrap($this); // Wrap this element (and subelements)
+ }
+ else
+ {
+ // Output begin tag
+ $generated = date("r");
+ $xml .= "<odd version=\"{$this->ODDSupportedVersion}\" generated=\"$generated\">\n";
+
+ // Get XML for elements
+ foreach ($this->elements as $element)
+ $xml .= "$element";
+
+ // Output end tag
+ $xml .= "</odd>\n";
+ }
+
return $xml;
}
@@ -157,6 +177,7 @@
{
$this->attributes['published'] = date("r", $time);
}
+
/**
* For serialisation, implement to return a string name of the tag eg "header" or "metadata".
* @return string
@@ -182,6 +203,7 @@
return "<{$tag} $attr" . $end . "\n";
}
+
}
/**
@@ -248,6 +270,46 @@
}
/**
+ * A wrapper factory is used to construct the appropriate wrappers that permit ODD documents to be embedded
+ * as a payload in other formats.
+ */
+ abstract class ODDWrapperFactory
+ {
+ abstract function getElementWrapper($element);
+ }
+
+ /**
+ * Element wrapper superclass.
+ */
+ abstract class ODDWrapper
+ {
+ /**
+ * Wrap an element and return the encoded string.
+ */
+ abstract function wrap($element);
+ }
+
+ /**
+ * Document wrapper superclass
+ */
+ abstract class ODDDocumentWrapper extends ODDWrapper { }
+
+ /**
+ * Entity wrapper superclass
+ */
+ abstract class ODDEntityWrapper extends ODDWrapper { }
+
+ /**
+ * Metadata wrapper superclass
+ */
+ abstract class ODDMetaDataWrapper extends ODDWrapper { }
+
+ /**
+ * Relationship wrapper superclass.
+ */
+ abstract class ODDRelationshipWrapper extends ODDWrapper { }
+
+ /**
* Attempt to construct an ODD object out of a XmlElement or sub-elements.
*
* @param XmlElement $element The element(s)
@@ -309,10 +371,17 @@
* Export an ODD Document.
*
* @param ODDDocument $document The Document.
+ * @param ODDWrapperFactory $wrapper Optional wrapper permitting the export process to embed ODD in other document formats.
*/
- function ODD_Export(ODDDocument $document)
+ function ODD_Export(ODDDocument $document, ODDWrapperFactory $wrapper = null)
{
+ if ($wrapper)
+ $document->setWrapperFactory($wrapper);
+
return "$document";
}
+
+
+ // input - how? root element handler?
?> \ No newline at end of file