}
// Case 1: content is an external DOM node
else if (root != null && !(root instanceof NodeValue)) {
final StringWriter writer = new StringWriter();
final DOMSerializer serializer = new DOMSerializer(writer, getProperties());
try {
serializer.serialize(root);
content = writer.toString();
} catch (final TransformerException e) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e
.getMessage(), e);
}
return content;
// Case 2: content is an atomic value
} else if (value != null) {
try {
if (Type.subTypeOf(value.getType(),Type.STRING)) {
return ((StringValue)value).getStringValue(true);
}
else {
return value.getStringValue();
}
} catch (final XPathException e) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e
.getMessage(), e);
}
// Case 3: content is a file
} else if (file != null) {
try {
content = XMLUtil.readFile(file);
return content;
} catch (final IOException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
"error while reading resource contents", e);
}
// Case 4: content is an input source
} else if (inputSource != null) {
try {
content = XMLUtil.readFile(inputSource);
return content;
} catch (final IOException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
"error while reading resource contents", e);
}
// Case 5: content is a document or internal node
} else {
DocumentImpl document = null;
final Subject preserveSubject = pool.getSubject();
DBBroker broker = null;
try {
broker = pool.get(user);
final Serializer serializer = broker.getSerializer();
serializer.setUser(user);
serializer.setProperties(getProperties());
if (root != null) {
content = serializer.serialize((NodeValue) root);
} else if (proxy != null) {
content = serializer.serialize(proxy);
} else {
document = openDocument(broker, Lock.READ_LOCK);
if (!document.getPermissions().validate(user,
Permission.READ))
{throw new XMLDBException(ErrorCodes.PERMISSION_DENIED,
"permission denied to read resource");}
content = serializer.serialize(document);
}
return content;
} catch (final SAXException saxe) {
saxe.printStackTrace();
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, saxe