4 * This file is (c) Copyright 2009 by Olivier BERGER & Sabri LABBENE, Institut
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * This program has been developed in the frame of the HELIOS
22 * project with financial support of its funders.
28 // Generate an OSLC Core V2 ServiceProviderCatalog that lists trackers inside a FusionForge project as OSLC-CM Service Providers.
29 function project_trackers_to_service_catalog($server_url, $base_url, $trackers, $project) {
30 $doc = new DOMDocument();
31 $doc->formatOutput = true;
33 $root = $doc->createElementNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:RDF");
34 $root = $doc->appendChild($root);
35 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
36 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:dcterms', 'http://purl.org/dc/terms/');
37 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:foaf', 'http://xmlns.com/foaf/0.1/');
38 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:oslc', 'http://open-services.net/ns/core#');
40 $provider = $doc->createElement("oslc:ServiceProvider");
41 $provider->setAttribute("rdf:about", $base_url.'/cm/oslc-cm-services/'.$project);
43 // Title of the ServiceProvider.
44 $titlenode = $doc->createElement("dcterms:title", "FusionForge OSLC Core V2 ServiceProvider corresponding to project ".$project);
45 $provider->appendChild($titlenode);
47 // Description of the ServiceProvider.
48 $descriptionnode = $doc->createElement("dcterms:description", "Lists all trackers as Service Providers");
49 $provider->appendChild($descriptionnode);
51 // Add rdf:type ressource to the ServiceProvider node.
52 $rdftype = $doc->createElement("rdf:type");
53 $rdftype->setAttribute("rdf:resource", 'http://open-services.net/ns/core#ServiceProvider');
54 $provider->appendChild($rdftype);
56 // Add oslc:Publisher ressource inside a dcterms:publisher node.
57 $publishernode = $doc->createElement("dcterms:publisher");
58 $publishernodecontent = $doc->createElement("oslc:Publisher");
59 $publishernodecontentid = $doc->createElement("dcterms:identifier", $base_url);
60 $publishernodecontenttitle = $doc->createElement("dcterms:title", "FusionForge OSLC V2 plugin");
61 $publishernodecontent->appendChild($publishernodecontentid);
62 $publishernodecontent->appendChild($publishernodecontenttitle);
63 $publishernode->appendChild($publishernodecontent);
64 // Add created dcterms:publisher node in the ServiceProvider node.
65 $provider->appendChild($publishernode);
67 // Service Provider details
68 $project_trackers_url = $server_url."/tracker/?group_id=".$project;
69 $spdetails = $doc->createElement("oslc:details");
70 $spdetails->setAttribute("rdf:resource", htmlentities($project_trackers_url));
71 $provider->appendChild($spdetails);
73 // We list trackers as Services or ServiceProvider (s) ???????????
74 foreach ($trackers as $tracker) {
76 $service = $doc->createElement("oslc:service");
77 $service->setAttribute("rdf:about", $base_url.'/cm/oslc-cm-service/'.$tracker['group_id'].'/tracker/'.$tracker['id']);
80 $stitle = $doc->createElement("dcterms:title", "OSLC-CM Service for ".$tracker['name']);
81 $service->appendChild($stitle);
83 // dcterms:description
84 $sdesc = $doc->createElement("dcterms:description", $tracker['description']);
85 $service->appendChild($sdesc);
88 $rdftype = $doc->createElement("rdf:type");
89 $rdftype->setAttribute("rdf:resource", 'http://open-services.net/ns/core#Service');
90 $service->appendChild($rdftype);
93 $sdomain = $doc->createElement("oslc:domain");
94 $sdomain->setAttribute("rdf:resource", "http://open-services.net/ns/cm#");
95 $service->appendChild($sdomain);
98 $tracker_url = $server_url."/tracker/index.php?group_id=".$tracker['group_id']."&atid=".$tracker['id'];
99 $sdetails = $doc->createElement("oslc:details");
100 $sdetails->setAttribute("rdf:resource", htmlentities($tracker_url));
101 $service->appendChild($sdetails);
103 $provider->appendChild($service);
104 $root->appendChild($provider);
108 $root->appendChild($provider);
110 /* // A service provider should mention at least one (empty?) service. */
111 /* if(count($trackers) == 0){ */
112 /* $service = $doc->createElement("oslc:service"); */
113 /* $provider->appendChild($service); */
114 /* $root->appendChild($provider); */
116 return $doc->saveXML();
120 // Generate an OSLC Core V2 ServiceProviderCatalog that lists projects as OSLC Service Providers.
121 function projects_to_service_catalog($base_url, $projects) {
123 $doc = new DOMDocument();
124 $doc->formatOutput = true;
126 // Generate namespaces for root rdf:RDF node.
127 $root = $doc->createElementNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:RDF");
128 $root = $doc->appendChild($root);
129 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
130 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:dcterms', 'http://purl.org/dc/terms/');
131 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:foaf', 'http://xmlns.com/foaf/0.1/');
132 $root->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:oslc', 'http://open-services.net/ns/core#');
134 $catalog = $doc->createElement("oslc:ServiceProviderCatalog");
135 $catalog->setAttribute("rdf:about", $base_url.'/cm/oslc-services/');
137 // Title of the ServiceProviderCatalog.
138 $titlenode = $doc->createElement("dcterms:title", "FusionForge OSLC Core V2 Service Provider Catalog");
139 $catalog->appendChild($titlenode);
141 // Description of the ServiceProviderCatalog.
142 $descriptionnode = $doc->createElement("dcterms:description", "Lists all projects as Service (trackers) Providers");
143 $catalog->appendChild($descriptionnode);
145 // Add rdf:type ressource to the ServiceProviderCatalog node.
146 $rdftype = $doc->createElement("rdf:type");
147 $rdftype->setAttribute("rdf:resource", 'http://open-services.net/ns/core#ServiceProviderCatalog');
148 $catalog->appendChild($rdftype);
150 // Add oslc:Publisher ressource inside a dcterms:publisher node.
151 $publishernode = $doc->createElement("dcterms:publisher");
152 $publishernodecontent = $doc->createElement("oslc:Publisher");
153 $publishernodecontentid = $doc->createElement("dcterms:identifier", $base_url);
154 $publishernodecontenttitle = $doc->createElement("dcterms:title", "FusionForge OSLC V2 plugin");
155 $publishernodecontent->appendChild($publishernodecontentid);
156 $publishernodecontent->appendChild($publishernodecontenttitle);
157 $publishernode->appendChild($publishernodecontent);
158 // Add created dcterms:publisher node in the ServiceProviderCatalog node.
159 $catalog->appendChild($publishernode);
161 $root->appendChild($catalog);
163 foreach ($projects as $proj) {
165 $spnode = $doc->createElement("oslc:serviceProvider");
167 $sp = $doc->createElement("oslc:ServiceProvider");
168 $sp->setAttribute("rdf:about", $base_url.'/cm/oslc-cm-services/'.$proj['id']);
171 $sptitle = $doc->createElement("dcterms:title", "Project: ".$proj["name"]);
172 $sp->appendChild($sptitle);
174 // dcterms:description
175 $spdescription = $doc->createElement("dcterms:description", "FusionForge project ".$proj['name']." as an OSLC-CM ServiceProvider");
176 $sp->appendChild($spdescription);
179 $rdftype = $doc->createElement("rdf:type");
180 $rdftype->setAttribute("rdf:resource", 'http://open-services.net/ns/core#ServiceProvider');
181 $sp->appendChild($rdftype);
184 $sppublisher = $doc->createElement("dcterms:publisher");
185 $sppublishercontent = $doc->createElement("oslc:Publisher");
186 $sppublishercontentid = $doc->createElement("dcterms:identifier", $base_url);
187 $sppublishercontenttitle = $doc->createElement("dcterms:title", "FusionForge OSLC V2 plugin");
188 $sppublishercontent->appendChild($sppublishercontentid);
189 $sppublishercontent->appendChild($sppublishercontenttitle);
190 $sppublisher->appendChild($sppublishercontent);
191 $sp->appendChild($sppublisher);
193 // ServiceProvider should lis at least one oslc:service.
194 // Telling about the oslc:domain of the service is mandatory.
195 $service = $doc->createElement("oslc:Service");
196 $servicedomain = $doc->createElement("oslc:domain", "http://open-services.net/ns/core#Service");
197 $service->appendChild($servicedomain);
198 $sp->appendChild($service);
200 $spnode->appendChild($sp);
202 $catalog->appendChild($spnode);
204 $root->appendChild($catalog);
206 return $doc->saveXML();