is-collector/src/org/gcube/informationsystem/collector/impl/resources/GCUBEProfileResource.java

59 lines
1.7 KiB
Java

package org.gcube.informationsystem.collector.impl.resources;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
public class GCUBEProfileResource extends BaseDAIXResource {
protected static String PROFILES_COLLECTION_NAME = "Profiles";
private String cachedSubtype;
/**
* @return the name of the collection including the resource
* @throws MalformedResourceException
*/
public String getCollectionName() throws MalformedResourceException {
return PROFILES_COLLECTION_NAME + "/" + this.getSubtype();
}
/**
* @param collectionName the name of the collection including the resource
*/
public void setCollectionName(String collectionName) {
// cannot change the collection name
}
/**
* @param type the resource type (if not set, it's extracted from the content, if any)
*/
public void setResourceType(String type) {
cachedSubtype = type;
}
/**
* Accesses the subtype to which the resource is related to (if any)
*
* @return the subtype or an empty string if the resource does not contain a subtype
* @throws MalformedResourceException
*/
private String getSubtype() throws MalformedResourceException {
String subtype = "";
try {
// gets the type
XPath path = XPathFactory.newInstance().newXPath();
subtype = path.evaluate("/Resource/Type", this.getContent());
} catch (Exception e) {
logger.warn("Unable to extract the profile type from the resource");
if (cachedSubtype != null)
return cachedSubtype;
throw new MalformedResourceException("Unable to extract the profile type from the resource " + e.getMessage());
}
return subtype;
}
}