Author: as Date: Thu Nov 1 16:26:59 2007 New Revision: 6664 Log: - Added support for 'textinput' RSS1 feed element.
Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.out trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.out trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.out trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.out trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.out trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.in trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.out trunk/Feed/tests/rss1/regression/parse/optional/textinput/ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.in trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.out trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.in trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.out trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.in trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.out Modified: trunk/Feed/src/interfaces/processor.php trunk/Feed/src/processors/rss1.php Modified: trunk/Feed/src/interfaces/processor.php ============================================================================== --- trunk/Feed/src/interfaces/processor.php [iso-8859-1] (original) +++ trunk/Feed/src/interfaces/processor.php [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -209,6 +209,7 @@ */ public function add( $name ) { + $name = ezcFeedTools::normalizeName( $name, $this->schema->getElementsMap() ); if ( $this->schema->isMulti( $name ) ) { $element = new ezcFeedElement( $this->schema->getSchema( $name ) ); Modified: trunk/Feed/src/processors/rss1.php ============================================================================== --- trunk/Feed/src/processors/rss1.php [iso-8859-1] (original) +++ trunk/Feed/src/processors/rss1.php [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -70,8 +70,18 @@ ), 'MULTI' => 'items' ), - 'textInput' => array( '#' => 'string', - 'ATTRIBUTES' => array( 'resource' => 'string' ) ), + 'textinput' => array( '#' => 'string', + 'ATTRIBUTES' => array( 'about' => 'string' ), + + 'NODES' => array( + 'title' => array( '#' => 'string' ), + 'description' => array( '#' => 'string' ), + 'name' => array( '#' => 'string' ), + 'link' => array( '#' => 'string' ), + + 'REQUIRED' => array( 'title', 'description', 'name', + 'link' ), + ), ), 'ATTRIBUTES' => array( 'about' => 'string' ), @@ -108,6 +118,7 @@ $this->generateChannel(); $this->generateItems(); $this->generateImage(); + $this->generateTextInput(); return $this->xml->saveXML(); } @@ -216,6 +227,25 @@ $this->channel->appendChild( $imageTag ); } + + $textInput = $this->get( 'textInput' ); + if ( $textInput !== null ) + { + $textInputTag = $this->xml->createElement( 'textinput' ); + + $about = $textInput->about; + if ( is_null( $data ) ) + { + throw new ezcFeedRequiredMetaDataMissingException( 'about' ); + } + + $resourceAttr = $this->xml->createAttribute( 'rdf:resource' ); + $resourceVal = $this->xml->createTextNode( $about ); + $resourceAttr->appendChild( $resourceVal ); + $textInputTag->appendChild( $resourceAttr ); + + $this->channel->appendChild( $textInputTag ); + } } /** @@ -296,6 +326,47 @@ $attributes = array(); $this->generateMetaData( $imageTag, $attribute, $data ); + } + } + } + + /** + * Adds the feed textinput to the XML document being generated. + * + * @ignore + */ + protected function generateTextInput() + { + $textInput = $this->get( 'textInput' ); + if ( $textInput !== null ) + { + $textInputTag = $this->xml->createElement( 'textinput' ); + $this->root->appendChild( $textInputTag ); + + $data = $textInput->about; + if ( is_null( $data ) ) + { + throw new ezcFeedRequiredMetaDataMissingException( 'about' ); + } + + $aboutAttr = $this->xml->createAttribute( 'rdf:about' ); + $aboutVal = $this->xml->createTextNode( $data ); + $aboutAttr->appendChild( $aboutVal ); + $textInputTag->appendChild( $aboutAttr ); + + foreach ( $this->schema->getRequired( 'textinput' ) as $attribute ) + { + $data = $textInput->$attribute; + if ( is_null( $data ) ) + { + throw new ezcFeedRequiredMetaDataMissingException( $attribute ); + } + + $data = ( $data instanceof ezcFeedElement ) ? $data->__toString() : $data; + $normalizedAttribute = ezcFeedTools::normalizeName( $attribute, $this->schema->getItemsMap() ); + + $attributes = array(); + $this->generateMetaData( $textInputTag, $attribute, $data ); } } } @@ -395,8 +466,11 @@ $this->parseImage( $feed, $image ); break; - case 'textinput': - // @todo Implement + case 'textInput': + $resource = ezcFeedTools::getAttribute( $channelChild, 'resource' ); + + $textInput = ezcFeedTools::getNodeByAttribute( $xml->documentElement, 'textinput', 'about', $resource ); + $this->parseTextInput( $feed, $textInput ); break; default: @@ -490,5 +564,42 @@ } } } + + /** + * Parses the provided XML element object and stores it as a feed textinput in + * the provided ezcFeed object. + * + * @param ezcFeed $feed The feed object in which to store the parsed XML element as a feed textinput + * @param DOMElement $xml The XML element object to parse + * @ignore + */ + protected function parseTextInput( ezcFeed $feed, DOMElement $xml = null ) + { + $textInput = $feed->add( 'textInput' ); + if ( $xml !== null ) + { + foreach ( $xml->childNodes as $itemChild ) + { + if ( $itemChild->nodeType == XML_ELEMENT_NODE ) + { + $tagName = $itemChild->tagName; + switch ( $tagName ) + { + case 'title': + case 'description': + case 'name': + case 'link': + $textInput->$tagName = $itemChild->textContent; + break; + } + } + } + + foreach ( ezcFeedTools::getAttributes( $xml ) as $key => $value ) + { + $textInput->$key = $value; + } + } + } } ?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,15 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array( 'about' => 'Textinput about', + 'title' => 'Textinput title', + 'description' => 'Textinput description', + 'name' => 'Textinput name', + 'link' => 'Textinput link' ) ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name+link.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <channel rdf:about="Channel about"> + <title>Feed title</title> + <link>Feed link</link> + <description>Feed description</description> + <items> + <rdf:Seq> + <rdf:li resource="Item about"/> + </rdf:Seq> + </items> + <textinput rdf:resource="Textinput about"/> + </channel> + <item rdf:about="Item about"> + <title>Item title</title> + <link>Item link</link> + </item> + <textinput rdf:about="Textinput about"> + <title>Textinput title</title> + <description>Textinput description</description> + <name>Textinput name</name> + <link>Textinput link</link> + </textinput> +</rdf:RDF> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,14 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array( 'about' => 'Textinput about', + 'title' => 'Textinput title', + 'description' => 'Textinput description', + 'name' => 'Textinput name' ) ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description+name.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,1 @@ +There was no data submitted for required channel attribute 'link'. Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,13 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array( 'about' => 'Textinput about', + 'title' => 'Textinput title', + 'description' => 'Textinput description' ) ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title+description.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,1 @@ +There was no data submitted for required channel attribute 'name'. Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,12 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array( 'about' => 'Textinput about', + 'title' => 'Textinput title' ) ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about+title.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,1 @@ +There was no data submitted for required channel attribute 'description'. Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,11 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array( 'about' => 'Textinput about' ) ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_about.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,1 @@ +There was no data submitted for required channel attribute 'title'. Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.in ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.in (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,11 @@ +<?php +return array( 'about' => 'Channel about', + 'title' => 'Feed title', + 'link' => 'Feed link', + 'description' => 'Feed description', + 'item' => array( array( 'about' => 'Item about', + 'title' => 'Item title', + 'link' => 'Item link' ) ), + 'textinput' => array( array() ), + ); +?> Added: trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.out ============================================================================== --- trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.out (added) +++ trunk/Feed/tests/rss1/regression/generate/optional/textinput/textinput_empty.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,1 @@ +There was no data submitted for required channel attribute 'about'. Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.in ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.in (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> + <channel rdf:about="Channel about"> + <title>Feed title</title> + <link>Feed link</link> + <description>Feed description</description> + <textinput rdf:resource="Textinput about"/> + </channel> + + <textinput rdf:about="Textinput about"/> +</rdf:RDF> Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.out ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.out (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_about.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,13 @@ +<?php +$feed = new ezcFeed( 'rss1' ); + +$feed->about = 'Channel about'; +$feed->title = 'Feed title'; +$feed->link = 'Feed link'; +$feed->description = 'Feed description'; + +$textInput = $feed->add( 'textInput' ); +$textInput->about = 'Textinput about'; + +return $feed; +?> Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.in ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.in (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> + <channel rdf:about="Channel about"> + <title>Feed title</title> + <link>Feed link</link> + <description>Feed description</description> + <textinput rdf:resource="Textinput about"/> + </channel> + + <textinput rdf:about="Textinput about"> + <title>Textinput title</title> + <description>Textinput description</description> + <name>Textinput name</name> + <link>Textinput link</link> + </textinput> +</rdf:RDF> Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.out ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.out (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_complete.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,17 @@ +<?php +$feed = new ezcFeed( 'rss1' ); + +$feed->about = 'Channel about'; +$feed->title = 'Feed title'; +$feed->link = 'Feed link'; +$feed->description = 'Feed description'; + +$textInput = $feed->add( 'textInput' ); +$textInput->title = 'Textinput title'; +$textInput->description = 'Textinput description'; +$textInput->name = 'Textinput name'; +$textInput->link = 'Textinput link'; +$textInput->about = 'Textinput about'; + +return $feed; +?> Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.in ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.in (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.in [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> + <channel rdf:about="Channel about"> + <title>Feed title</title> + <link>Feed link</link> + <description>Feed description</description> + <textinput/> + </channel> +</rdf:RDF> Added: trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.out ============================================================================== --- trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.out (added) +++ trunk/Feed/tests/rss1/regression/parse/optional/textinput/textinput_empty.out [iso-8859-1] Thu Nov 1 16:26:59 2007 @@ -1,0 +1,12 @@ +<?php +$feed = new ezcFeed( 'rss1' ); + +$feed->about = 'Channel about'; +$feed->title = 'Feed title'; +$feed->link = 'Feed link'; +$feed->description = 'Feed description'; + +$textInput = $feed->add( 'textInput' ); + +return $feed; +?> -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components