[Pkg-owncloud-commits] [php-sabre-vobject] 181/341: Support extensibility with `@xmlns`.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit f949054fee1c0f8e3bcded25a0bced65d43ae54e
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Wed Jan 21 16:07:02 2015 +0100

    Support extensibility with `@xmlns`.
    
    If a property has a `@xmlns`, thus, it is not part of vCard or vCal. In
    this case, this is a `XML` property where its value is the property
    itself in XML notation.
    
    For example:
    
        <?xml version="1.0"?>
        <vcards xmlns="urn:ietf:params:xml:ns:vcard-4.0">
          <vcard>
            <a xmlns="http://www.w3.org/1999/xhtml" href="http://www.example.com">My web page!</a>
          </vcard>
        </vcards>
    
    becomes
    
        BEGIN:VCARD
        VERSION:4.0
        XML:<a xmlns="http://www.w3.org/1999/xhtml" href="http://www.example.com">M
         y web page!</a>
        END:VCARD
---
 lib/Parser/XML.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php
index 267189e..b76695b 100644
--- a/lib/Parser/XML.php
+++ b/lib/Parser/XML.php
@@ -158,11 +158,38 @@ class XML extends Parser {
 
         foreach ($this->pointer as $xmlProperty) {
 
-            $propertyName       = static::getTagName($xmlProperty['name']);
+            list($namespace, $tagName) = SabreXml\Util::parseClarkNotation($xmlProperty['name']);
+
+            $propertyName       = $tagName;
             $propertyValue      = [];
             $propertyParameters = [];
             $propertyType       = 'text';
 
+            if (   $namespace !== self::XCAL_NAMESPACE
+                && $namespace !== self::XCARD_NAMESPACE) {
+
+                $propertyName = 'xml';
+                $value = '<' . $tagName . ' xmlns="' . $namespace . '"';
+
+                foreach ($xmlProperty['attributes'] as $attributeName => $attributeValue) {
+                    $value .= ' ' . $attributeName . '="' . str_replace('"', '\"', $attributeValue) . '"';
+                }
+
+                $value .= '>' . $xmlProperty['value'] . '</' . $tagName. '>';
+
+                $propertyValue = [$value];
+
+                $this->createProperty(
+                    $parentComponent,
+                    $propertyName,
+                    $propertyParameters,
+                    $propertyType,
+                    $propertyValue
+                );
+
+                continue;
+            }
+
             foreach ($xmlProperty['value'] as $i => $xmlPropertyChild) {
 
                 if (   !is_array($xmlPropertyChild)
@@ -246,18 +273,31 @@ class XML extends Parser {
                     break;
             }
 
-            $property = $this->root->createProperty(
+            $this->createProperty(
+                $parentComponent,
                 $propertyName,
-                null,
                 $propertyParameters,
-                $propertyType
+                $propertyType,
+                $propertyValue
             );
-            $parentComponent->add($property);
-            $property->setXmlValue($propertyValue);
+
         }
 
     }
 
+    protected function createProperty(Component $parentComponent, $name, $parameters, $type, $value) {
+
+        $property = $this->root->createProperty(
+            $name,
+            null,
+            $parameters,
+            $type
+        );
+        $parentComponent->add($property);
+        $property->setXmlValue($value);
+
+    }
+
     protected function parseComponent(Component $parentComponent) {
 
         $components = $this->pointer['value'] ?: [];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list