1 <?php
 2 /**
 3  * @package     Joomla.Platform
 4  * @subpackage  Document
 5  *
 6  * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
 7  * @license     GNU General Public License version 2 or later; see LICENSE
 8  */
 9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * DocumentXML class, provides an easy interface to parse and display XML output
14  *
15  * @since  11.1
16  */
17 class JDocumentXml extends JDocument
18 {
19     /**
20      * Document name
21      *
22      * @var    string
23      * @since  12.1
24      */
25     protected $name = 'joomla';
26 
27     /**
28      * Class constructor
29      *
30      * @param   array  $options  Associative array of options
31      *
32      * @since   11.1
33      */
34     public function __construct($options = array())
35     {
36         parent::__construct($options);
37 
38         // Set mime type
39         $this->_mime = 'application/xml';
40 
41         // Set document type
42         $this->_type = 'xml';
43     }
44 
45     /**
46      * Render the document.
47      *
48      * @param   boolean  $cache   If true, cache the output
49      * @param   array    $params  Associative array of attributes
50      *
51      * @return  The rendered data
52      *
53      * @since  11.1
54      */
55     public function render($cache = false, $params = array())
56     {
57         parent::render();
58 
59         JFactory::getApplication()->setHeader('Content-disposition', 'inline; filename="' . $this->getName() . '.xml"', true);
60 
61         return $this->getBuffer();
62     }
63 
64     /**
65      * Returns the document name
66      *
67      * @return  string
68      *
69      * @since  11.1
70      */
71     public function getName()
72     {
73         return $this->name;
74     }
75 
76     /**
77      * Sets the document name
78      *
79      * @param   string  $name  Document name
80      *
81      * @return  JDocumentXml instance of $this to allow chaining
82      *
83      * @since   11.1
84      */
85     public function setName($name = 'joomla')
86     {
87         $this->name = $name;
88 
89         return $this;
90     }
91 }
92