diff --git a/composer.json b/composer.json index 4576f68c..bfe528ea 100755 --- a/composer.json +++ b/composer.json @@ -7,7 +7,6 @@ "keywords": ["module", "xp"], "require" : { "xp-framework/core": "^12.0 | ^11.0 | ^10.0", - "xp-framework/xml" : "^12.0 | ^11.0 | ^10.0", "php" : ">=7.0.0" }, "require-dev" : { diff --git a/src/main/php/img/io/XMPSegment.class.php b/src/main/php/img/io/XMPSegment.class.php index 82dccf4e..f4d18d6c 100755 --- a/src/main/php/img/io/XMPSegment.class.php +++ b/src/main/php/img/io/XMPSegment.class.php @@ -1,24 +1,22 @@ document= $document; + $this->source= $source; } /** @@ -31,15 +29,25 @@ public function __construct($marker, Document $document) { public static function read($marker, $bytes) { // Begin parsing after 28 bytes - strlen("http://ns.adobe.com/xap/1.0/") - return new self($marker, Document::fromString(trim(substr($bytes, 28), "\x00"))); + return new self($marker, trim(substr($bytes, 28), "\x00")); } /** * Gets XML document * - * @return xml.dom.Document + * @return DOMDocument + * @throws lang.FormatException if parsing the XML fails */ public function document() { + if (null === $this->document) { + $this->document= new DOMDocument(); + if (false === $this->document->loadXML($this->source)) { + $this->document= null; + $e= new FormatException('Cannot parse XMP/XAP segment'); + \xp::gc(__FILE__); + throw $e; + } + } return $this->document; } @@ -49,7 +57,7 @@ public function document() { * @return string */ public function toString() { - return nameof($this).'<'.$this->marker.'>'.\xp::stringOf($this->document); + return nameof($this).'('.$this->marker.')'.$this->source; } /** @@ -62,7 +70,7 @@ public function equals($cmp) { return ( $cmp instanceof self && $cmp->marker === $this->marker && - $cmp->document->equals($this->document) + $cmp->source === $this->source ); } } \ No newline at end of file diff --git a/src/test/php/img/unittest/MetaDataReaderTest.class.php b/src/test/php/img/unittest/MetaDataReaderTest.class.php index b282350e..ff3a989f 100755 --- a/src/test/php/img/unittest/MetaDataReaderTest.class.php +++ b/src/test/php/img/unittest/MetaDataReaderTest.class.php @@ -1,17 +1,12 @@ extractFromFile('xmp.jpg')->segmentsOf('img.io.XMPSegment'); $this->assertArrayOf('img.io.XMPSegment', 1, $segments); - Assert::instance(Node::class, $segments[0]->document()->getElementsByTagName('dc:title')[0]); + + Assert::matches('/^<.+/', $segments[0]->source); + Assert::instance(DOMDocument::class, $segments[0]->document()); } #[Test]