thanks for picking up the link handling and finally bringing it into the next versions of components! - unfortunately I had very little time the last months and could not help much. looking at what is currently in develop branch I've some remarks on the current API design:
1. LinkHandler.getLink: Optional<Link> redundant to Link.isValid
that is redundant and we should use only one of the concepts:
- having the linkhandler returning an empty optional element to signal an invalid link, removing the isValid method
- or having the linkhandler return and link without optional that is never null, and that can be check via isValid method
- furthermore the model interfaces all just define a @Nullable Link - unclear whether invalid means null, or not null with isValid=false
with the current state it's quite confusing. there is already code where links are consumed always checking both !=null && isValid which is very ugly.
2. Link<?> generic signature
i currently see no benefit with the concept of having a generic signature like Link<Page> or Link<Asset>. in theory it makes sense, in practice not.
whenever you consume a link object from link handler or from an model interface, you have no idea on what item the link really points to when you declare your variable, and you can only use Link<?> or Link. same applies in model interfaces that return links. you only know what's in it after you actually got the link instance. this makes using link objects very clumsy, and you already see code scattered with @SuppressWarnings("rawtypes") to get rid of related warnings.
the only place where you are sure what the link is pointing at is during link building/handling, but this piece of code is inside the link handling and not relevant for the users of the API.
i would propose to drop this generic concept completely.
3. Download component without getLink method
the download component model seems to be the only model that was not switched to the new Link concept. is this component obsolete, or is it an oversight?
4. Link with separate getURL/getMappedURL/getExternalizedURL methods
i find it a bit confusing as well what's to do with those three methods. the javadocs are clear, but I still suppose most users who "just want a link" will be puzzled which is the correct one for their HTL script, and in a big project with lots of developers every developer will use a different method leading to much inconsistency. in
wcm.io Link handler/URL handler for comparison we have also concepts for influencing if links should be externalized or not (avoiding the ill-designed com.day.cq.commons.Externalizer altogether), but this are only optional aspects which can be activated during link resolution with special builder methods, and there is always a sensible default handling which is the right thing to use in 95% of the cases.
providing access to these special case methods in this three variants of URLs may lead to confusion and inconsistencies.
sorry for bringing this up quite late in the game - although 3.0.0 is not release officially most of it is already baked in the public APIs that are released and probably cannot be changed any more.
stefan