There's redundant code between these two cases, and also we should account for the possibility that there's no userId (although that probably won't happen, the existing code did show something in that case). So I think you could collapse the whole thing into something like:

```
if (this.metadata && this.metadata.author) {
    result = htmlEscape(this.metadata.author.name || this.metadata.author);
} else if (userId) {
    result = htmlEscape(userId);
}
if (ownerLink) {
    result = "<a href='" + htmlEscape(ownerLink) + "' title='" + htmlEscape(ownerLink) + "'>" + result + "</a>";
}
```