final Map keyMap = (Map) key;
final String uri = this.getURI( keyMap );
// first test: modifiable source?
SourceResolver resolver = null;
CastorSourceConverter converter = null;
Source source = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
source = resolver.resolveURI(uri);
if ( source instanceof ModifiableSource ) {
converter = (CastorSourceConverter) this.manager.lookup(CastorSourceConverter.ROLE);
converter.storeObject( ((ModifiableSource)source).getOutputStream(), parameters, profile);
return;
}
} finally {
if ( resolver != null ) {
resolver.release(source);
}
manager.release(converter);
manager.release(resolver);
source = null;
converter = null;
resolver = null;
}
final StringBuffer buffer = this.getSaveURI( keyMap );
SAXParser parser = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
converter = (CastorSourceConverter) this.manager.lookup(CastorSourceConverter.ROLE);
ByteArrayOutputStream writer = new ByteArrayOutputStream();
converter.storeObject(writer, parameters, profile);
buffer.append("&content=");
buffer.append(SourceUtil.encode(writer.toString()));
source = resolver.resolveURI(buffer.toString());
parser = (SAXParser)this.manager.lookup(SAXParser.ROLE);
Element element = DOMUtil.getDocumentFragment(parser, new InputStreamReader(source.getInputStream())).getOwnerDocument().getDocumentElement();
if (!DOMUtil.getValueOf(element, "descendant::sourceResult/execution", this.xpathProcessor).trim().equals("success")) {
throw new IOException("Could not save profile: "+DOMUtil.getValueOf(element, "descendant::sourceResult/message", this.xpathProcessor));
}
} finally {
if ( resolver != null ) {
resolver.release(source);
}
manager.release(parser);
manager.release(converter);
manager.release(resolver);
}