This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
RmUtil.java
95 lines (81 loc) · 4.17 KB
/
RmUtil.java
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
87
88
89
90
91
92
93
94
95
/*******************************************************************************
* Copyright (c) 2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Gabriel Ruelas - initial API and implementation
* Carlos A Arreola - initial API and implementation
*******************************************************************************/
package org.eclipse.lyo.oslc4j.client.resources;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.ws.rs.core.Response;
import org.eclipse.lyo.oslc4j.client.OSLCConstants;
import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.client.exception.ResourceNotFoundException;
import org.eclipse.lyo.oslc4j.core.model.CreationFactory;
import org.eclipse.lyo.oslc4j.core.model.ResourceShape;
import org.eclipse.lyo.oslc4j.core.model.Service;
import org.eclipse.lyo.oslc4j.core.model.ServiceProvider;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import net.oauth.OAuthException;
public final class RmUtil {
public static ResourceShape lookupRequirementsInstanceShapes(final String serviceProviderUrl, final String oslcDomain, final String oslcResourceType, OslcClient client, String requiredInstanceShape)
throws IOException, URISyntaxException, ResourceNotFoundException, OAuthException{
return lookupRequirementsInstanceShapes(serviceProviderUrl, oslcDomain, oslcResourceType, client, requiredInstanceShape,null);
}
public static ResourceShape lookupRequirementsInstanceShapes(final String serviceProviderUrl, final String oslcDomain, final String oslcResourceType, OslcClient client, String requiredInstanceShape, String configurationContext)
throws IOException, URISyntaxException, ResourceNotFoundException, OAuthException
{
Response response = client.getResource(serviceProviderUrl,null, OSLCConstants.CT_RDF, configurationContext);
ServiceProvider serviceProvider = response.readEntity(ServiceProvider.class);
if (serviceProvider != null) {
for (Service service:serviceProvider.getServices()) {
URI domain = service.getDomain();
if (domain != null && domain.toString().equals(oslcDomain)) {
CreationFactory [] creationFactories = service.getCreationFactories();
if (creationFactories != null && creationFactories.length > 0) {
for (CreationFactory creationFactory:creationFactories) {
for (URI resourceType:creationFactory.getResourceTypes()) {
if (resourceType.toString() != null && resourceType.toString().equals(oslcResourceType)) {
URI[] instanceShapes = creationFactory.getResourceShapes();
if (instanceShapes != null ){
for ( URI typeURI : instanceShapes) {
response = client.getResource(typeURI.toString(), null, OSLCConstants.CT_RDF, configurationContext);
ResourceShape resourceShape = response.readEntity(ResourceShape.class);
String typeTitle = resourceShape.getTitle();
String typeAbout = resourceShape.getAbout().toString();
if ( ( typeTitle != null) && (typeTitle.equalsIgnoreCase(requiredInstanceShape)) ||
(typeAbout != null && typeAbout.equalsIgnoreCase(requiredInstanceShape)) ) {
return resourceShape;
}
}
}
}
}
}
}
}
}
}
throw new ResourceNotFoundException(serviceProviderUrl, "InstanceShapes");
}
public static Element convertStringToHTML(String text) throws ParserConfigurationException {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element divElement = document.createElementNS(RmConstants.NAMESPACE_URI_XHTML, "div");
divElement.setTextContent(text);
return divElement;
}
}