Oslc - get all project area names and url
Hi All,
i have read the "Open Services for Lifecycle Collaboration Workshop" and used the examples for my own project, but now I have one more question. Beside to get all Names of the project areas, i need in addition the url from the project area (e.g. via REST Client: https://localhost:9443/ccm/process/project-areas/_ZOfGcD3yEea3-J04vnQkIQ)
My actual Steps are:
....
1) Request the Root Services document
...
2) Define the XPath evaluation environment
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(
new NamespaceContextMap(new String[]
{ "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"oslc_cm","http://open-services.net/xmlns/cm/1.0/"}));
String catalogXPath = "/rdf:Description/oslc_cm:cmServiceProviders/@rdf:resource";
String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title";
3) Parse the response body to retrieve the catalog URI
....
4) Setup the catalog request
...
5) Access to the Service Providers catalog
...
6) Define the XPath evaluation environment
...
7) Parse the response body to retrieve the Service Provider
source = new InputSource(catalogResponse.getEntity().getContent());
NodeList titleNodes = (NodeList) (xpath2.evaluate(serviceProviderTitleXPath, source, XPathConstants.NODESET));
// Print out the title of each Service Provider
int length = titleNodes.getLength();
System.out.println(">> Project Areas:");
for (int i = 0; i < length; i++) {
System.out.println(">> \t - "+ titleNodes.item(i).getTextContent());
projectAreaNamesList.add(titleNodes.item(i).getTextContent());
}
How can i get in addition to the names the URLs from the project area (from the "catalogResponse")? Is that possible to add them? i think i have to define it somewhere in Step 2, "String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title"; " ??
Best Regards!
i have read the "Open Services for Lifecycle Collaboration Workshop" and used the examples for my own project, but now I have one more question. Beside to get all Names of the project areas, i need in addition the url from the project area (e.g. via REST Client: https://localhost:9443/ccm/process/project-areas/_ZOfGcD3yEea3-J04vnQkIQ)
My actual Steps are:
....
1) Request the Root Services document
...
2) Define the XPath evaluation environment
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
xpath.setNamespaceContext(
new NamespaceContextMap(new String[]
{ "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"oslc_cm","http://open-services.net/xmlns/cm/1.0/"}));
String catalogXPath = "/rdf:Description/oslc_cm:cmServiceProviders/@rdf:resource";
String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title";
3) Parse the response body to retrieve the catalog URI
....
4) Setup the catalog request
...
5) Access to the Service Providers catalog
...
6) Define the XPath evaluation environment
...
7) Parse the response body to retrieve the Service Provider
source = new InputSource(catalogResponse.getEntity().getContent());
NodeList titleNodes = (NodeList) (xpath2.evaluate(serviceProviderTitleXPath, source, XPathConstants.NODESET));
// Print out the title of each Service Provider
int length = titleNodes.getLength();
System.out.println(">> Project Areas:");
for (int i = 0; i < length; i++) {
System.out.println(">> \t - "+ titleNodes.item(i).getTextContent());
projectAreaNamesList.add(titleNodes.item(i).getTextContent());
}
How can i get in addition to the names the URLs from the project area (from the "catalogResponse")? Is that possible to add them? i think i have to define it somewhere in Step 2, "String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title"; " ??
Best Regards!
One answer
You just need to step back a bit, as you seem to try to retrieve two "strings" from one "Node" at step 7, which makes it no longer a simple "string". You should parse the node to a predefined class (holding the structure of <oslc:ServiceProvider>), and of course your XPath should point to the <oslc:ServiceProvider>, not the <dcterms:title> within it. Since the <oslc:ServiceProvider> node is well-structured in XML, you can use XPath against it as well, if you don't want to define a class for it.