<commit_before><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

class RestoATOMFeed extends RestoXML {
    
    /**
     * Constructor
     * 
     * @param string $id
     * @param string $title
     * @param string $subtitle
     */
    public function __construct($id, $title, $subtitle) {
        
        parent::__construct();
        
        /*
         * Start ATOM feed
         */
        $this->startAtomFeed($id, $title, $subtitle);
        
        /*
         * Set title, subtitle and generator
         */
        $this->setBaseElements($title, $subtitle);
        
        /*
         * Set id
         */
        $this->writeElement('id', $id);
        
    }
    
    /**
     * Add Atom feed entry
     * 
     * @param array $feature
     * @param RestoContext $context
     */
    public function addEntry($feature, $context) {
        
        /*
         * Add entry
         */
        $this->startElement('entry');
        
        /*
         * Add entry base elements, time and geometry
         */
        $this->addEntryElements($feature);
        
        /*
         * Links
         */
        $this->addLinks($feature);
        
        /*
         * Media (i.e. Quicklook / Thumbnail / etc.)
         */
        $this->addQuicklooks($feature);
        
        /*
         * Summary
         */
        $this->addSummary($feature, $context);
        
        /*
         * entry - close element
         */
        $this->endElement(); // entry   
    }
    
    /**
     * Add Atom feed entries
     * 
     * @param array $features
     * @param RestoContext $context
     */
    public function addEntries($features, $context) {
        for ($i = 0, $l = count($features); $i < $l; $i++) {
            $this->addEntry($features[$i]->toArray(), $context);
        }
    }
    
    /**
     * Return stringified XML document
     */
    public function toString() {
        
        /*
         * End feed element
         */
        $this->endElement();
        
        /*
         * Write result
         */
        return parent::toString();
    }
    
    /**
     * Set elements for FeatureCollection
     * 
     * @param array $properties
     */
    public function setCollectionElements($properties) {
        
        /*
         * Update outputFormat links except for OSDD 'search'
         */
        $this->setCollectionLinks($properties);
        
        /*
         * Total results, startIndex and itemsPerpage
         */
        if (isset($properties['totalResults'])) {
            $this->writeElement('os:totalResults', $properties['totalResults']);
        }
        if (isset($properties['startIndex'])) {
            $this->writeElement('os:startIndex', $properties['startIndex']);
        }
        if (isset($properties['itemsPerPage'])) {
            $this->writeElement('os:itemsPerPage', $properties['itemsPerPage']);
        }

        /*
         * Query element
         */
        $this->setQuery($properties);
        
    }
    
    /**
     * Start XML ATOM feed with all namespaces attributes
     *
     */
    private function startAtomFeed() {
        $this->startElement('feed');
        $this->writeAttributes(array(
            'xml:lang' => 'en',
            'xmlns' => 'http://www.w3.org/2005/Atom',
            'xmlns:time' => 'http://a9.com/-/opensearch/extensions/time/1.0/',
            'xmlns:os' => 'http://a9.com/-/spec/opensearch/1.1/',
            'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
            'xmlns:georss' => 'http://www.georss.org/georss',
            'xmlns:gml' => 'http://www.opengis.net/gml',
            'xmlns:geo' => 'http://a9.com/-/opensearch/extensions/geo/1.0/',
            'xmlns:eo' => 'http://a9.com/-/opensearch/extensions/eo/1.0/',
            'xmlns:metalink' => 'urn:ietf:params:xml:ns:metalink',
            'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
            'xmlns:media' => 'http://search.yahoo.com/mrss/'
        ));
    }
    
    /**
     * Set title, subtitle and generator
     * 
     * @param string $id
     * @param string $title
     * @param string $subtitle
     */
    private function setBaseElements($title, $subtitle) {
        
        /*
         *  Title
         */
        $this->writeElement('title', $title);

        /*
         *  Subtitle
         */
        $this->startElement('subtitle');
        $this->writeAttributes(array('type' => 'html'));
        $this->text($subtitle);
        $this->endElement();

        /* 
         * Generator
         */
        $this->startElement('generator');
        $this->writeAttributes(array(
            'uri' => 'http://github.com/jjrom/resto2',
            'version' => Resto::VERSION
        ));
        $this->text('resto');
        $this->endElement();
        
        /*
         * Date of creation is now
         */
        $this->writeElement('updated', date('Y-m-dTH:i:sO'));
    }
    
    /**
     * Add summary entry
     * 
     * @param array $feature
     * @param RestoContext $context
     */<commit_msg>ATOM output - correct invalid format for "updated" element<commit_after><?php
/*
 * Copyright 2014 <NAME>
 *
 * Licensed under the Apache License, version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

class RestoATOMFeed extends RestoXML {
    
    /**
     * Constructor
     * 
     * @param string $id
     * @param string $title
     * @param string $subtitle
     */
    public function __construct($id, $title, $subtitle) {
        
        parent::__construct();
        
        /*
         * Start ATOM feed
         */
        $this->startAtomFeed($id, $title, $subtitle);
        
        /*
         * Set title, subtitle and generator
         */
        $this->setBaseElements($title, $subtitle);
        
        /*
         * Set id
         */
        $this->writeElement('id', $id);
        
    }
    
    /**
     * Add Atom feed entry
     * 
     * @param array $feature
     * @param RestoContext $context
     */
    public function addEntry($feature, $context) {
        
        /*
         * Add entry
         */
        $this->startElement('entry');
        
        /*
         * Add entry base elements, time and geometry
         */
        $this->addEntryElements($feature);
        
        /*
         * Links
         */
        $this->addLinks($feature);
        
        /*
         * Media (i.e. Quicklook / Thumbnail / etc.)
         */
        $this->addQuicklooks($feature);
        
        /*
         * Summary
         */
        $this->addSummary($feature, $context);
        
        /*
         * entry - close element
         */
        $this->endElement(); // entry   
    }
    
    /**
     * Add Atom feed entries
     * 
     * @param array $features
     * @param RestoContext $context
     */
    public function addEntries($features, $context) {
        for ($i = 0, $l = count($features); $i < $l; $i++) {
            $this->addEntry($features[$i]->toArray(), $context);
        }
    }
    
    /**
     * Return stringified XML document
     */
    public function toString() {
        
        /*
         * End feed element
         */
        $this->endElement();
        
        /*
         * Write result
         */
        return parent::toString();
    }
    
    /**
     * Set elements for FeatureCollection
     * 
     * @param array $properties
     */
    public function setCollectionElements($properties) {
        
        /*
         * Update outputFormat links except for OSDD 'search'
         */
        $this->setCollectionLinks($properties);
        
        /*
         * Total results, startIndex and itemsPerpage
         */
        if (isset($properties['totalResults'])) {
            $this->writeElement('os:totalResults', $properties['totalResults']);
        }
        if (isset($properties['startIndex'])) {
            $this->writeElement('os:startIndex', $properties['startIndex']);
        }
        if (isset($properties['itemsPerPage'])) {
            $this->writeElement('os:itemsPerPage', $properties['itemsPerPage']);
        }

        /*
         * Query element
         */
        $this->setQuery($properties);
        
    }
    
    /**
     * Start XML ATOM feed with all namespaces attributes
     *
     */
    private function startAtomFeed() {
        $this->startElement('feed');
        $this->writeAttributes(array(
            'xml:lang' => 'en',
            'xmlns' => 'http://www.w3.org/2005/Atom',
            'xmlns:time' => 'http://a9.com/-/opensearch/extensions/time/1.0/',
            'xmlns:os' => 'http://a9.com/-/spec/opensearch/1.1/',
            'xmlns:dc' => 'http://purl.org/dc/elements/1.1/',
            'xmlns:georss' => 'http://www.georss.org/georss',
            'xmlns:gml' => 'http://www.opengis.net/gml',
            'xmlns:geo' => 'http://a9.com/-/opensearch/extensions/geo/1.0/',
            'xmlns:eo' => 'http://a9.com/-/opensearch/extensions/eo/1.0/',
            'xmlns:metalink' => 'urn:ietf:params:xml:ns:metalink',
            'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
            'xmlns:media' => 'http://search.yahoo.com/mrss/'
        ));
    }
    
    /**
     * Set title, subtitle and generator
     * 
     * @param string $id
     * @param string $title
     * @param string $subtitle
     */
    private function setBaseElements($title, $subtitle) {
        
        /*
         *  Title
         */
        $this->writeElement('title', $title);

        /*
         *  Subtitle
         */
        $this->startElement('subtitle');
        $this->writeAttributes(array('type' => 'html'));
        $this->text($subtitle);
        $this->endElement();

        /* 
         * Generator
         */
        $this->startElement('generator');
        $this->writeAttributes(array(
            'uri' => 'http://github.com/jjrom/resto2',
            'version' => Resto::VERSION
        ));
        $this->text('resto');
        $this->endElement();
        
        /*
         * Date of creation is now
         */
        $this->writeElement('updated', date('Y-m-d\TH:i:s\Z'));
    }
    
    /**
     * Add summary entry
     * 
     * @param array $feature
     * @param RestoContext $context
     */
{'fraction_non_alphanumeric': 0.14777490412913583, 'fraction_numerical': 0.00606438954784625, 'mean_word_length': 1.6030640668523677, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6594858', 'n_tokens_mistral': 3284, 'n_tokens_neox': 3221, 'n_words': 659}