Search in sources :

Example 1 with Translations

use of org.xwiki.rest.model.jaxb.Translations in project xwiki-platform by xwiki.

the class ModelFactory method toRestTranslations.

public Translations toRestTranslations(URI baseUri, Document doc) throws XWikiException {
    Translations translations = this.objectFactory.createTranslations();
    List<String> languages = doc.getTranslationList();
    List<String> spaces = Utils.getSpacesFromSpaceId(doc.getSpace());
    if (!languages.isEmpty()) {
        if (!doc.getDefaultLanguage().equals("")) {
            translations.setDefault(doc.getDefaultLanguage());
            Translation translation = this.objectFactory.createTranslation();
            translation.setLanguage(doc.getDefaultLanguage());
            /* Add the default page with the default translation explicitely */
            String pageTranslationUri = Utils.createURI(baseUri, PageResource.class, doc.getWiki(), spaces, doc.getName()).toString();
            Link pageTranslationLink = this.objectFactory.createLink();
            pageTranslationLink.setHref(pageTranslationUri);
            pageTranslationLink.setRel(Relations.PAGE);
            translation.getLinks().add(pageTranslationLink);
            String historyUri = Utils.createURI(baseUri, PageHistoryResource.class, doc.getWiki(), spaces, doc.getName()).toString();
            Link historyLink = this.objectFactory.createLink();
            historyLink.setHref(historyUri);
            historyLink.setRel(Relations.HISTORY);
            translation.getLinks().add(historyLink);
            translations.getTranslations().add(translation);
        }
    }
    for (String language : languages) {
        Translation translation = this.objectFactory.createTranslation();
        translation.setLanguage(language);
        String pageTranslationUri = Utils.createURI(baseUri, PageTranslationResource.class, doc.getWiki(), spaces, doc.getName(), language).toString();
        Link pageTranslationLink = this.objectFactory.createLink();
        pageTranslationLink.setHref(pageTranslationUri);
        pageTranslationLink.setRel(Relations.PAGE);
        translation.getLinks().add(pageTranslationLink);
        String historyUri = Utils.createURI(baseUri, PageTranslationHistoryResource.class, doc.getWiki(), spaces, doc.getName(), language).toString();
        Link historyLink = this.objectFactory.createLink();
        historyLink.setHref(historyUri);
        historyLink.setRel(Relations.HISTORY);
        translation.getLinks().add(historyLink);
        translations.getTranslations().add(translation);
    }
    return translations;
}
Also used : PageResource(org.xwiki.rest.resources.pages.PageResource) Translation(org.xwiki.rest.model.jaxb.Translation) PageTranslationResource(org.xwiki.rest.resources.pages.PageTranslationResource) PageTranslationHistoryResource(org.xwiki.rest.resources.pages.PageTranslationHistoryResource) PageHistoryResource(org.xwiki.rest.resources.pages.PageHistoryResource) Translations(org.xwiki.rest.model.jaxb.Translations) Link(org.xwiki.rest.model.jaxb.Link)

Aggregations

Link (org.xwiki.rest.model.jaxb.Link)1 Translation (org.xwiki.rest.model.jaxb.Translation)1 Translations (org.xwiki.rest.model.jaxb.Translations)1 PageHistoryResource (org.xwiki.rest.resources.pages.PageHistoryResource)1 PageResource (org.xwiki.rest.resources.pages.PageResource)1 PageTranslationHistoryResource (org.xwiki.rest.resources.pages.PageTranslationHistoryResource)1 PageTranslationResource (org.xwiki.rest.resources.pages.PageTranslationResource)1