private Resource addContentResource(Resource res, List<Capability> ccaps, boolean writeXML) throws RepositoryStorageException {
// Copy the resource to this storage, if the content URL does not match
URL urlatt = (URL) ccaps.get(0).getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
if (urlatt == null || urlatt.toExternalForm().startsWith(getBaseURL().toExternalForm()) == false) {
ResourceBuilder builder = createResourceBuilder();
for (Capability cap : res.getCapabilities(null)) {
if (!ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) {
builder.addCapability(cap.getNamespace(), cap.getAttributes(), cap.getDirectives());
}
}
for (Capability cap : ccaps) {
ContentCapability ccap = cap.adapt(ContentCapability.class);
Map<String, Object> contentAtts = new HashMap<String, Object>();
String mimeType = (String) ccap.getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE);
if (mimeType != null) {
contentAtts.put(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE, mimeType);
}
InputStream input = getResourceContent(ccap);
try {
addResourceContent(input, contentAtts);
builder.addCapability(ContentNamespace.CONTENT_NAMESPACE, contentAtts, cap.getDirectives());
} catch (RepositoryStorageException ex) {
throw new RepositoryStorageException("Cannot add resource to storeage: " + mimeType, ex);
}
}
for (Requirement req : res.getRequirements(null)) {
String namespace = req.getNamespace();
builder.addRequirement(namespace, req.getAttributes(), req.getDirectives());
}
res = builder.getResource();
}
Resource result = super.addResource(res);
if (writeXML == true) {
writeRepositoryXML();