throws IOException, WebApplicationException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
RdfConfiguration configuration = getConfiguration();
try
{
Document doc = factory.newDocumentBuilder().newDocument();
Element rdf = XMLUtils.addNode(doc, doc, "rdf:RDF");
XMLUtils.addAttribute(doc, rdf, RDF_NAMESPACE_NAME, RDF_NAMESPACE_VALUE);
if (configuration != null)
{
Map<String, String> namespaceMap = configuration.getNamespaces();
for (Entry<String, String> entry : namespaceMap.entrySet())
{
XMLUtils.addAttribute(doc, rdf, "xmlns:" + entry.getKey(),
entry.getValue());
}
}
else
{
XMLUtils.addAttribute(doc, rdf, CAS_NAMESPACE_NAME,
CAS_NAMESPACE_VALUE);
}
for (ProductResource productResource : resource.getProductResources())
{
String productTypeName = productResource.getProductTypeName();
String productId = productResource.getProductId();
String productNs = configuration != null
? configuration.getTypeNamespace(productTypeName)
: CAS_NAMESPACE_PREFIX;
Element productRdf = XMLUtils.addNode(doc, rdf,
productNs + ":" + productTypeName);
XMLUtils.addAttribute(doc, productRdf, "rdf:about",
getBaseUri() + "product?productId=" + productId);
if (configuration != null)
{
MetadataResource metadataResource = productResource
.getMetadataResource();
for (MetadataEntry entry : metadataResource.getMetadataEntries())
{
for (String value : entry.getValues())
{
Element metaElement = configuration.createElement(entry.getKey(),
value, doc);
productRdf.appendChild(metaElement);
}
}
}