* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
protected void doExecute() throws Exception {
// super.doExecute();
SourceResolver resolver = null;
ResourceType resourceType = null;
try {
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
Document doc = getSourceDocument();
// sanity check
if (doc == null)
throw new IllegalArgumentException("illegal usage, source document may not be null");
if (!doc.exists()) {
DocumentManager documentManager = null;
ServiceSelector selector = null;
try {
selector = (ServiceSelector) this.manager
.lookup(ResourceType.ROLE + "Selector");
documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
DocumentFactory map = getDocumentFactory();
String path = doc.getPath();
resourceType = (ResourceType) selector.select(TYPE);
ResourceType.Sample sample = resourceType.getSample(resourceType.getSampleNames()[0]);
doc = documentManager.add(map, resourceType, sample.getUri(), getPublication(), doc
.getArea(), path, doc.getLanguage(), EXTENSION, doc.getName(), true);
doc.setMimeType(sample.getMimeType());
setMetaData(doc);