prismicio-community / java-kit

Community maintained development kit for Prismic and the Java language
https://prismic.io
15 stars 38 forks source link

[enhancement] Exposes DocumentLink's lang field #61

Closed damienbeaufils closed 7 years ago

damienbeaufils commented 7 years ago

Hello team!

We need the lang field of DocumentLink to build an url in our LinkResolver.

We had to use reflection to expose this field:

public class PrismicLinkResolver extends SimpleLinkResolver {

    @Override
    public String resolve(DocumentLink link) {
        String lang = getLang(link);
        String type = link.getType();
        String uid = link.getUid();

        return "/" + lang + "/" + type + "/" + uid;
    }

    private String getLang(DocumentLink link) {
        try {
            Field field = ReflectionUtils.findField(DocumentLink.class, "lang", String.class);
            field.setAccessible(true);
            return (String) field.get(link);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}

We would prefer a simple lang getter, instead of using reflection. This PR exposes DocumentLink's lang field.

This PR depends on #56

Thanks and happy hacktoberfest!