C:\xampp\php\pear\PHP\UML\Output\XmiDocument.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
 * PHP_UML
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_UML
 * @author   Baptiste Autin <ohlesbeauxjours@yahoo.fr> 
 * @license  http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @version  SVN: $Revision: 175 $
 * @link     http://pear.php.net/package/PHP_UML
 * @since    $Date: 2011-09-15 17:07:58 +0200 (jeu., 15 sept. 2011) $
 */

/**
 * Wrapper for an XMI document
 * 
 * @category   PHP
 * @package    PHP_UML
 * @subpackage Output
 * @author     Baptiste Autin <ohlesbeauxjours@yahoo.fr> 
 * @license    http://www.gnu.org/licenses/lgpl.html LGPL License 3
 */
class PHP_UML_Output_XmiDocument
{
    
/**
     * The XMI code of the XMI document
     * @var string
     */
    
private $xmi;
    
    
/**
     * Constructor
     * 
     * @param string $code XMI code as string 
     */
    
public function __construct($code '')
    {
        
$this->xmi $code;
    }
    
    
/**
     * Return the code XMI as a string
     */
    
public function dump()
    {
        return 
$this->xmi;
    }
    
    
/** 
     * Load XMI from a file
     * 
     * @param string $filepath Filepath
     */
    
public function load($filepath)
    {
        if (
file_exists($filepath)) {
            
$this->xmi file_get_contents($filepath);
        } else {
            throw new 
PHP_UML_Exception('Could not open '.$filepath);
        }

        
$xmlDom = new DomDocument;
        
$xmlDom->loadXML($this->xmi);
        if (
self::isVersion1($xmlDom)) {
            
$this->xmi PHP_UML_Output_ExporterXSL::convertTo2($this->xmi);
        }
    }
    
    
/**
     * Return true if the document is in XMI version 1.x
     * 
     * @param DOMDocument $d DOM document
     * 
     * @return boolean
     */
    
static function isVersion1(DOMDocument $d)
    {
        
$version $d->getElementsByTagName('XMI')->item(0)->getAttribute('xmi.version');
        if (
$version=='')
            
$version $d->getElementsByTagName('XMI')->item(0)->getAttribute('xmi:version');
        return (
$version<2);
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586